Module Name: src
Committed By: christos
Date: Fri Oct 21 02:26:09 UTC 2011
Modified Files:
src/usr.bin/w: Makefile extern.h w.c
Removed Files:
src/usr.bin/w: proc_compare.c
Log Message:
Remove stale proc_compare code and use the shared one in libutil.
To generate a diff of this commit:
cvs rdiff -u -r1.20 -r1.21 src/usr.bin/w/Makefile
cvs rdiff -u -r1.6 -r1.7 src/usr.bin/w/extern.h
cvs rdiff -u -r1.14 -r0 src/usr.bin/w/proc_compare.c
cvs rdiff -u -r1.75 -r1.76 src/usr.bin/w/w.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/usr.bin/w/Makefile
diff -u src/usr.bin/w/Makefile:1.20 src/usr.bin/w/Makefile:1.21
--- src/usr.bin/w/Makefile:1.20 Wed Aug 17 09:48:11 2011
+++ src/usr.bin/w/Makefile Thu Oct 20 22:26:09 2011
@@ -1,13 +1,13 @@
-# $NetBSD: Makefile,v 1.20 2011/08/17 13:48:11 christos Exp $
+# $NetBSD: Makefile,v 1.21 2011/10/21 02:26:09 christos Exp $
# @(#)Makefile 8.1 (Berkeley) 6/6/93
.include <bsd.own.mk>
PROG= w
-SRCS= fmt.c pr_time.c proc_compare.c w.c
+SRCS= fmt.c pr_time.c w.c
MAN= w.1 uptime.1
-DPADD= ${LIBKVM}
-LDADD= -lkvm
+DPADD= ${LIBKVM} ${LIBUTIL}
+LDADD= -lkvm -lutil
LINKS= ${BINDIR}/w ${BINDIR}/uptime
CPPFLAGS+= -DSUPPORT_UTMP -DSUPPORT_UTMPX
Index: src/usr.bin/w/extern.h
diff -u src/usr.bin/w/extern.h:1.6 src/usr.bin/w/extern.h:1.7
--- src/usr.bin/w/extern.h:1.6 Thu Aug 7 07:17:12 2003
+++ src/usr.bin/w/extern.h Thu Oct 20 22:26:09 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: extern.h,v 1.6 2003/08/07 11:17:12 agc Exp $ */
+/* $NetBSD: extern.h,v 1.7 2011/10/21 02:26:09 christos Exp $ */
/*-
* Copyright (c) 1993
@@ -36,4 +36,3 @@ void fmt_puts(char *, int *);
void fmt_putc(int, int *);
void pr_attime(time_t *, time_t *);
void pr_idle(time_t);
-int proc_compare(struct kinfo_proc2 *, struct kinfo_proc2 *);
Index: src/usr.bin/w/w.c
diff -u src/usr.bin/w/w.c:1.75 src/usr.bin/w/w.c:1.76
--- src/usr.bin/w/w.c:1.75 Fri Sep 16 11:39:30 2011
+++ src/usr.bin/w/w.c Thu Oct 20 22:26:09 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: w.c,v 1.75 2011/09/16 15:39:30 joerg Exp $ */
+/* $NetBSD: w.c,v 1.76 2011/10/21 02:26:09 christos Exp $ */
/*-
* Copyright (c) 1980, 1991, 1993, 1994
@@ -39,7 +39,7 @@ __COPYRIGHT("@(#) Copyright (c) 1980, 19
#if 0
static char sccsid[] = "@(#)w.c 8.6 (Berkeley) 6/30/94";
#else
-__RCSID("$NetBSD: w.c,v 1.75 2011/09/16 15:39:30 joerg Exp $");
+__RCSID("$NetBSD: w.c,v 1.76 2011/10/21 02:26:09 christos Exp $");
#endif
#endif /* not lint */
@@ -120,6 +120,8 @@ struct entry {
static void pr_args(struct kinfo_proc2 *);
static void pr_header(time_t *, int);
+static int proc_compare_wrapper(const struct kinfo_proc2 *,
+ const struct kinfo_proc2 *);
#if defined(SUPPORT_UTMP) || defined(SUPPORT_UTMPX)
static int ttystat(const char *, struct stat *);
static void process(struct entry *);
@@ -302,9 +304,6 @@ main(int argc, char **argv)
/* Include trailing space because TTY header starts one column early. */
for (i = 0; i < nentries; i++, kp++) {
- if (kp->p_stat == SIDL || kp->p_stat == SZOMB)
- continue;
-
for (ep = ehead; ep != NULL; ep = ep->next) {
if (ep->tdev != 0 && ep->tdev == kp->p_tdev &&
kp->p__pgid == kp->p_tpgid) {
@@ -312,7 +311,7 @@ main(int argc, char **argv)
* Proc is in foreground of this
* terminal
*/
- if (proc_compare(ep->tp, kp))
+ if (proc_compare_wrapper(ep->tp, kp))
ep->tp = kp;
break;
}
@@ -618,6 +617,27 @@ process(struct entry *ep)
}
#endif
+static int
+proc_compare_wrapper(const struct kinfo_proc2 *p1,
+ const struct kinfo_proc2 *p2)
+{
+ struct kinfo_lwp *l1, *l2;
+ int cnt;
+
+ if (p1 == NULL)
+ return 1;
+
+ l1 = kvm_getlwps(kd, p1->p_pid, 0, sizeof(*l1), &cnt);
+ if (l1 == NULL || cnt == 0)
+ return 1;
+
+ l2 = kvm_getlwps(kd, p2->p_pid, 0, sizeof(*l1), &cnt);
+ if (l2 == NULL || cnt == 0)
+ return 0;
+
+ return proc_compare(p1, l1, p2, l2);
+}
+
static void
usage(int wcmd)
{