Fri Oct 21 02:26:09 2011 UTC ()
Remove stale proc_compare code and use the shared one in libutil.


(christos)
diff -r1.20 -r1.21 src/usr.bin/w/Makefile
diff -r1.6 -r1.7 src/usr.bin/w/extern.h
diff -r1.14 -r0 src/usr.bin/w/proc_compare.c
diff -r1.75 -r1.76 src/usr.bin/w/w.c

cvs diff -r1.20 -r1.21 src/usr.bin/w/Makefile (expand / switch to unified diff)

--- src/usr.bin/w/Makefile 2011/08/17 13:48:11 1.20
+++ src/usr.bin/w/Makefile 2011/10/21 02:26:09 1.21
@@ -1,18 +1,18 @@ @@ -1,18 +1,18 @@
1# $NetBSD: Makefile,v 1.20 2011/08/17 13:48:11 christos Exp $ 1# $NetBSD: Makefile,v 1.21 2011/10/21 02:26:09 christos Exp $
2# @(#)Makefile 8.1 (Berkeley) 6/6/93 2# @(#)Makefile 8.1 (Berkeley) 6/6/93
3 3
4.include <bsd.own.mk> 4.include <bsd.own.mk>
5 5
6PROG= w 6PROG= w
7SRCS= fmt.c pr_time.c proc_compare.c w.c 7SRCS= fmt.c pr_time.c w.c
8MAN= w.1 uptime.1 8MAN= w.1 uptime.1
9DPADD= ${LIBKVM} 9DPADD= ${LIBKVM} ${LIBUTIL}
10LDADD= -lkvm 10LDADD= -lkvm -lutil
11LINKS= ${BINDIR}/w ${BINDIR}/uptime 11LINKS= ${BINDIR}/w ${BINDIR}/uptime
12CPPFLAGS+= -DSUPPORT_UTMP -DSUPPORT_UTMPX 12CPPFLAGS+= -DSUPPORT_UTMP -DSUPPORT_UTMPX
13 13
14.PATH: ${NETBSDSRCDIR}/bin/ps 14.PATH: ${NETBSDSRCDIR}/bin/ps
15 15
16COPTS.pr_time.c += -Wno-format-y2k 16COPTS.pr_time.c += -Wno-format-y2k
17 17
18.include <bsd.prog.mk> 18.include <bsd.prog.mk>

cvs diff -r1.6 -r1.7 src/usr.bin/w/extern.h (expand / switch to unified diff)

--- src/usr.bin/w/extern.h 2003/08/07 11:17:12 1.6
+++ src/usr.bin/w/extern.h 2011/10/21 02:26:09 1.7
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: extern.h,v 1.6 2003/08/07 11:17:12 agc Exp $ */ 1/* $NetBSD: extern.h,v 1.7 2011/10/21 02:26:09 christos Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 1993 4 * Copyright (c) 1993
5 * The Regents of the University of California. All rights reserved. 5 * The Regents of the University of California. All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
@@ -26,14 +26,13 @@ @@ -26,14 +26,13 @@
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE. 29 * SUCH DAMAGE.
30 * 30 *
31 * @(#)extern.h 8.1 (Berkeley) 6/6/93 31 * @(#)extern.h 8.1 (Berkeley) 6/6/93
32 */ 32 */
33 33
34struct kinfo_proc2; 34struct kinfo_proc2;
35void fmt_puts(char *, int *); 35void fmt_puts(char *, int *);
36void fmt_putc(int, int *); 36void fmt_putc(int, int *);
37void pr_attime(time_t *, time_t *); 37void pr_attime(time_t *, time_t *);
38void pr_idle(time_t); 38void pr_idle(time_t);
39int proc_compare(struct kinfo_proc2 *, struct kinfo_proc2 *); 

File Deleted: src/usr.bin/w/Attic/proc_compare.c

cvs diff -r1.75 -r1.76 src/usr.bin/w/w.c (expand / switch to unified diff)

--- src/usr.bin/w/w.c 2011/09/16 15:39:30 1.75
+++ src/usr.bin/w/w.c 2011/10/21 02:26:09 1.76
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: w.c,v 1.75 2011/09/16 15:39:30 joerg Exp $ */ 1/* $NetBSD: w.c,v 1.76 2011/10/21 02:26:09 christos Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 1980, 1991, 1993, 1994 4 * Copyright (c) 1980, 1991, 1993, 1994
5 * The Regents of the University of California. All rights reserved. 5 * The Regents of the University of California. All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
@@ -29,27 +29,27 @@ @@ -29,27 +29,27 @@
29 * SUCH DAMAGE. 29 * SUCH DAMAGE.
30 */ 30 */
31 31
32#include <sys/cdefs.h> 32#include <sys/cdefs.h>
33#ifndef lint 33#ifndef lint
34__COPYRIGHT("@(#) Copyright (c) 1980, 1991, 1993, 1994\ 34__COPYRIGHT("@(#) Copyright (c) 1980, 1991, 1993, 1994\
35 The Regents of the University of California. All rights reserved."); 35 The Regents of the University of California. All rights reserved.");
36#endif /* not lint */ 36#endif /* not lint */
37 37
38#ifndef lint 38#ifndef lint
39#if 0 39#if 0
40static char sccsid[] = "@(#)w.c 8.6 (Berkeley) 6/30/94"; 40static char sccsid[] = "@(#)w.c 8.6 (Berkeley) 6/30/94";
41#else 41#else
42__RCSID("$NetBSD: w.c,v 1.75 2011/09/16 15:39:30 joerg Exp $"); 42__RCSID("$NetBSD: w.c,v 1.76 2011/10/21 02:26:09 christos Exp $");
43#endif 43#endif
44#endif /* not lint */ 44#endif /* not lint */
45 45
46/* 46/*
47 * w - print system status (who and what) 47 * w - print system status (who and what)
48 * 48 *
49 * This program is similar to the systat command on Tenex/Tops 10/20 49 * This program is similar to the systat command on Tenex/Tops 10/20
50 * 50 *
51 */ 51 */
52#include <sys/param.h> 52#include <sys/param.h>
53#include <sys/types.h> 53#include <sys/types.h>
54#include <sys/time.h> 54#include <sys/time.h>
55#include <sys/stat.h> 55#include <sys/stat.h>
@@ -110,26 +110,28 @@ struct entry { @@ -110,26 +110,28 @@ struct entry {
110 char line[UTX_LINESIZE + 1]; 110 char line[UTX_LINESIZE + 1];
111 char host[UTX_HOSTSIZE + 1]; 111 char host[UTX_HOSTSIZE + 1];
112 char type[2]; 112 char type[2];
113 struct timeval tv; 113 struct timeval tv;
114 dev_t tdev; /* dev_t of terminal */ 114 dev_t tdev; /* dev_t of terminal */
115 time_t idle; /* idle time of terminal in seconds */ 115 time_t idle; /* idle time of terminal in seconds */
116 struct kinfo_proc2 *tp; /* `most interesting' tty proc */ 116 struct kinfo_proc2 *tp; /* `most interesting' tty proc */
117 struct kinfo_proc2 *pp; /* pid proc */ 117 struct kinfo_proc2 *pp; /* pid proc */
118 pid_t pid; /* pid or ~0 if not known */ 118 pid_t pid; /* pid or ~0 if not known */
119} *ehead = NULL, **nextp = &ehead; 119} *ehead = NULL, **nextp = &ehead;
120 120
121static void pr_args(struct kinfo_proc2 *); 121static void pr_args(struct kinfo_proc2 *);
122static void pr_header(time_t *, int); 122static void pr_header(time_t *, int);
 123static int proc_compare_wrapper(const struct kinfo_proc2 *,
 124 const struct kinfo_proc2 *);
123#if defined(SUPPORT_UTMP) || defined(SUPPORT_UTMPX) 125#if defined(SUPPORT_UTMP) || defined(SUPPORT_UTMPX)
124static int ttystat(const char *, struct stat *); 126static int ttystat(const char *, struct stat *);
125static void process(struct entry *); 127static void process(struct entry *);
126#endif 128#endif
127__dead static void usage(int); 129__dead static void usage(int);
128 130
129int 131int
130main(int argc, char **argv) 132main(int argc, char **argv)
131{ 133{
132 struct kinfo_proc2 *kp; 134 struct kinfo_proc2 *kp;
133 struct hostent *hp; 135 struct hostent *hp;
134 struct in_addr l; 136 struct in_addr l;
135 struct entry *ep; 137 struct entry *ep;
@@ -292,37 +294,34 @@ main(int argc, char **argv) @@ -292,37 +294,34 @@ main(int argc, char **argv)
292 if (header || wcmd == 0) { 294 if (header || wcmd == 0) {
293 pr_header(&now, nusers); 295 pr_header(&now, nusers);
294 if (wcmd == 0) 296 if (wcmd == 0)
295 exit (0); 297 exit (0);
296 } 298 }
297 299
298 if ((kp = kvm_getproc2(kd, KERN_PROC_ALL, 0, 300 if ((kp = kvm_getproc2(kd, KERN_PROC_ALL, 0,
299 sizeof(struct kinfo_proc2), &nentries)) == NULL) 301 sizeof(struct kinfo_proc2), &nentries)) == NULL)
300 errx(1, "%s", kvm_geterr(kd)); 302 errx(1, "%s", kvm_geterr(kd));
301 303
302 /* Include trailing space because TTY header starts one column early. */ 304 /* Include trailing space because TTY header starts one column early. */
303 for (i = 0; i < nentries; i++, kp++) { 305 for (i = 0; i < nentries; i++, kp++) {
304 306
305 if (kp->p_stat == SIDL || kp->p_stat == SZOMB) 
306 continue; 
307 
308 for (ep = ehead; ep != NULL; ep = ep->next) { 307 for (ep = ehead; ep != NULL; ep = ep->next) {
309 if (ep->tdev != 0 && ep->tdev == kp->p_tdev && 308 if (ep->tdev != 0 && ep->tdev == kp->p_tdev &&
310 kp->p__pgid == kp->p_tpgid) { 309 kp->p__pgid == kp->p_tpgid) {
311 /* 310 /*
312 * Proc is in foreground of this 311 * Proc is in foreground of this
313 * terminal 312 * terminal
314 */ 313 */
315 if (proc_compare(ep->tp, kp)) 314 if (proc_compare_wrapper(ep->tp, kp))
316 ep->tp = kp; 315 ep->tp = kp;
317 break; 316 break;
318 }  317 }
319 if (ep->pid != 0 && ep->pid == kp->p_pid) { 318 if (ep->pid != 0 && ep->pid == kp->p_pid) {
320 ep->pp = kp; 319 ep->pp = kp;
321 break; 320 break;
322 } 321 }
323 } 322 }
324 } 323 }
325 324
326 if ((ioctl(STDOUT_FILENO, TIOCGWINSZ, &ws) == -1 && 325 if ((ioctl(STDOUT_FILENO, TIOCGWINSZ, &ws) == -1 &&
327 ioctl(STDERR_FILENO, TIOCGWINSZ, &ws) == -1 && 326 ioctl(STDERR_FILENO, TIOCGWINSZ, &ws) == -1 &&
328 ioctl(STDIN_FILENO, TIOCGWINSZ, &ws) == -1) || ws.ws_col == 0) 327 ioctl(STDIN_FILENO, TIOCGWINSZ, &ws) == -1) || ws.ws_col == 0)
@@ -608,25 +607,46 @@ process(struct entry *ep) @@ -608,25 +607,46 @@ process(struct entry *ep)
608 (void) sysctl(mib, 2, &ep->tdev, &size, NULL, 0); 607 (void) sysctl(mib, 2, &ep->tdev, &size, NULL, 0);
609 } 608 }
610 609
611 touched = st.st_atime; 610 touched = st.st_atime;
612 if (touched < ep->tv.tv_sec) { 611 if (touched < ep->tv.tv_sec) {
613 /* tty untouched since before login */ 612 /* tty untouched since before login */
614 touched = ep->tv.tv_sec; 613 touched = ep->tv.tv_sec;
615 } 614 }
616 if ((ep->idle = now - touched) < 0) 615 if ((ep->idle = now - touched) < 0)
617 ep->idle = 0; 616 ep->idle = 0;
618} 617}
619#endif 618#endif
620 619
 620static int
 621proc_compare_wrapper(const struct kinfo_proc2 *p1,
 622 const struct kinfo_proc2 *p2)
 623{
 624 struct kinfo_lwp *l1, *l2;
 625 int cnt;
 626
 627 if (p1 == NULL)
 628 return 1;
 629
 630 l1 = kvm_getlwps(kd, p1->p_pid, 0, sizeof(*l1), &cnt);
 631 if (l1 == NULL || cnt == 0)
 632 return 1;
 633
 634 l2 = kvm_getlwps(kd, p2->p_pid, 0, sizeof(*l1), &cnt);
 635 if (l2 == NULL || cnt == 0)
 636 return 0;
 637
 638 return proc_compare(p1, l1, p2, l2);
 639}
 640
621static void 641static void
622usage(int wcmd) 642usage(int wcmd)
623{ 643{
624 644
625 if (wcmd) 645 if (wcmd)
626 (void)fprintf(stderr, 646 (void)fprintf(stderr,
627 "Usage: %s [-hinw] [-M core] [-N system] [user]\n", 647 "Usage: %s [-hinw] [-M core] [-N system] [user]\n",
628 getprogname()); 648 getprogname());
629 else 649 else
630 (void)fprintf(stderr, "Usage: %s\n", getprogname()); 650 (void)fprintf(stderr, "Usage: %s\n", getprogname());
631 exit(1); 651 exit(1);
632} 652}