From 7aa5833636168ba9989927eb04dc999194aa0d6d Mon Sep 17 00:00:00 2001 From: ed Date: Wed, 13 Jan 2010 18:09:21 +0000 Subject: Port w(1) to utmpx. Let it print "-" when the TTY string is empty. In this case, it must also make sure it doesn't match processes who also have no controlling TTY. Otherwise it will print random kernel processes when trying to pick the best matching process. Eventually it should look at the value of ut_pid as well. --- usr.bin/w/w.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'usr.bin/w/w.c') diff --git a/usr.bin/w/w.c b/usr.bin/w/w.c index 0e4397d..0612cd8 100644 --- a/usr.bin/w/w.c +++ b/usr.bin/w/w.c @@ -83,9 +83,8 @@ static const char sccsid[] = "@(#)w.c 8.4 (Berkeley) 4/16/94"; #include #include #include -#define _ULOG_POSIX_NAMES -#include #include +#include #include #include "extern.h" @@ -283,7 +282,8 @@ main(int argc, char *argv[]) if ((kp = kvm_getprocs(kd, KERN_PROC_ALL, 0, &nentries)) == NULL) err(1, "%s", kvm_geterr(kd)); for (i = 0; i < nentries; i++, kp++) { - if (kp->ki_stat == SIDL || kp->ki_stat == SZOMB) + if (kp->ki_stat == SIDL || kp->ki_stat == SZOMB || + kp->ki_tdev == NODEV) continue; for (ep = ehead; ep != NULL; ep = ep->next) { if (ep->tdev == kp->ki_tdev) { @@ -418,9 +418,10 @@ main(int argc, char *argv[]) (void)printf("%-*.*s %-*.*s %-*.*s ", W_DISPUSERSIZE, W_DISPUSERSIZE, ep->utmp.ut_user, W_DISPLINESIZE, W_DISPLINESIZE, - strncmp(ep->utmp.ut_line, "tty", 3) && + *ep->utmp.ut_line ? + (strncmp(ep->utmp.ut_line, "tty", 3) && strncmp(ep->utmp.ut_line, "cua", 3) ? - ep->utmp.ut_line : ep->utmp.ut_line + 3, + ep->utmp.ut_line : ep->utmp.ut_line + 3) : "-", W_DISPHOSTSIZE, W_DISPHOSTSIZE, *p ? p : "-"); t = ep->utmp.ut_tv.tv_sec; longattime = pr_attime(&t, &now); -- cgit v1.1