diff options
author | ache <ache@FreeBSD.org> | 1997-09-12 02:22:21 +0000 |
---|---|---|
committer | ache <ache@FreeBSD.org> | 1997-09-12 02:22:21 +0000 |
commit | 0357dcdb999675bbb8c47200eecd74b1886c3e15 (patch) | |
tree | 36f242be3e0d94f9f00324d4ce581c0e13a7724c /usr.bin/w/w.c | |
parent | 5e33bd85aa0ac3b3e087e259e57bdd033095831d (diff) | |
download | FreeBSD-src-0357dcdb999675bbb8c47200eecd74b1886c3e15.zip FreeBSD-src-0357dcdb999675bbb8c47200eecd74b1886c3e15.tar.gz |
The "-d" option dumps out the entire process list on a per controlling
tty basis, instead of just the top level process.
Submitted by: terry
Diffstat (limited to 'usr.bin/w/w.c')
-rw-r--r-- | usr.bin/w/w.c | 51 |
1 files changed, 40 insertions, 11 deletions
diff --git a/usr.bin/w/w.c b/usr.bin/w/w.c index 1f16154..61de1ef 100644 --- a/usr.bin/w/w.c +++ b/usr.bin/w/w.c @@ -42,7 +42,7 @@ static const char copyright[] = static char sccsid[] = "@(#)w.c 8.4 (Berkeley) 4/16/94"; #endif static const char rcsid[] = - "$Id$"; + "$Id: w.c,v 1.21 1997/08/25 06:42:19 charnier Exp $"; #endif /* not lint */ /* @@ -96,6 +96,7 @@ int ttywidth; /* width of tty */ int argwidth; /* width of tty */ int header = 1; /* true if -h flag: don't print heading */ int nflag; /* true if -n flag: don't convert addrs */ +int dflag; /* true if -d flag: output debug info */ int sortidle; /* sort bu idle time */ char *sel_user; /* login of particular user selected */ char domain[MAXHOSTNAMELEN]; @@ -106,10 +107,11 @@ char domain[MAXHOSTNAMELEN]; struct entry { struct entry *next; struct utmp utmp; - dev_t tdev; /* dev_t of terminal */ - time_t idle; /* idle time of terminal in seconds */ - struct kinfo_proc *kp; /* `most interesting' proc */ - char *args; /* arg list of interesting process */ + dev_t tdev; /* dev_t of terminal */ + time_t idle; /* idle time of terminal in seconds */ + struct kinfo_proc *kp; /* `most interesting' proc */ + char *args; /* arg list of interesting process */ + struct kinfo_proc *dkp; /* debug option proc list */ } *ep, *ehead = NULL, **nextp = &ehead; static void pr_header __P((time_t *, int)); @@ -126,6 +128,7 @@ main(argc, argv) { extern char *__progname; struct kinfo_proc *kp; + struct kinfo_proc *dkp; struct hostent *hp; struct stat *stp; FILE *ut; @@ -146,12 +149,15 @@ main(argc, argv) p = ""; } else { wcmd = 1; - p = "hiflM:N:nsuw"; + p = "dhiflM:N:nsuw"; } memf = nlistf = NULL; while ((ch = getopt(argc, argv, p)) != -1) switch (ch) { + case 'd': + dflag = 1; + break; case 'h': header = 0; break; @@ -254,13 +260,26 @@ main(argc, argv) continue; e = &kp->kp_eproc; for (ep = ehead; ep != NULL; ep = ep->next) { - if (ep->tdev == e->e_tdev && e->e_pgid == e->e_tpgid) { + if (ep->tdev == e->e_tdev) { + /* + * proc is associated with this terminal + */ + if (ep->kp == NULL && e->e_pgid == e->e_tpgid) { + /* + * Proc is 'most interesting' + */ + if (proc_compare(&ep->kp->kp_proc, p)) + ep->kp = kp; + } /* - * Proc is in foreground of this terminal + * Proc debug option info; add to debug + * list using kinfo_proc kp_eproc.e_spare + * as next pointer; ptr to ptr avoids the + * ptr = long assumption. */ - if (proc_compare(&ep->kp->kp_proc, p)) - ep->kp = kp; - break; + dkp = ep->dkp; + ep->dkp = kp; + *((struct kinfo_proc **)(&kp->kp_eproc.e_spare[ 0])) = dkp; } } } @@ -342,6 +361,16 @@ main(argc, argv) ep->utmp.ut_host + UT_HOSTSIZE - x, x); p = buf; } + if( dflag) { + for( dkp = ep->dkp; dkp != NULL; dkp = *((struct kinfo_proc **)(&dkp->kp_eproc.e_spare[ 0]))) { + char *p; + p = fmt_argv(kvm_getargv(kd, dkp, argwidth), + dkp->kp_proc.p_comm, MAXCOMLEN); + if (p == NULL) + p = "-"; + (void)printf( "\t\t%-9d %s\n", dkp->kp_proc.p_pid, p); + } + } (void)printf("%-*.*s %-3.3s %-*.*s ", UT_NAMESIZE, UT_NAMESIZE, ep->utmp.ut_name, strncmp(ep->utmp.ut_line, "tty", 3) && |