Date: Tue, 9 Sep 1997 23:10:32 +0000 (GMT) From: Terry Lambert <tlambert@primenet.com> To: current@freebsd.org Subject: Resubmission of patch to add SunOS "-d" option to "w" Message-ID: <199709092310.QAA03289@usr02.primenet.com>
next in thread | raw e-mail | index | archive | help
Apparently this was overlooked? This patch adds the "-d" option to the "w" command. The "-d" option dumps out the entire process list on a per controlling tty basis, instead of just the top level process. This makes "w" useful for job control. This is a traditional SunOS 4.x undocumented option which was not carried over into Solaris because the SVR4 "w" sources didn't have the SunOS extension. Please commit this patch... Context diff follows signature. Regards, Terry Lambert terry@lambert.org --- Any opinions in this posting are my own and not those of my present or previous employers. ------------------------------------------------------------------------------- Index: w.c =================================================================== RCS file: /b/cvstree/ncvs/src/usr.bin/w/w.c,v retrieving revision 1.21 diff -c -r1.21 /usr/src/usr.bin/w.c *** 1.21 1997/08/25 06:42:19 --- /usr/src/usr.bin/w.c 1997/09/09 22:30:17 *************** *** 96,101 **** --- 96,102 ---- 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,115 **** 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 */ } *ep, *ehead = NULL, **nextp = &ehead; static void pr_header __P((time_t *, int)); --- 107,117 ---- 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 */ ! struct kinfo_proc *dkp; /* debug option proc list */ } *ep, *ehead = NULL, **nextp = &ehead; static void pr_header __P((time_t *, int)); *************** *** 126,131 **** --- 128,134 ---- { extern char *__progname; struct kinfo_proc *kp; + struct kinfo_proc *dkp; struct hostent *hp; struct stat *stp; FILE *ut; *************** *** 146,157 **** p = ""; } else { wcmd = 1; ! p = "hiflM:N:nsuw"; } memf = nlistf = NULL; while ((ch = getopt(argc, argv, p)) != -1) switch (ch) { case 'h': header = 0; break; --- 149,163 ---- p = ""; } else { wcmd = 1; ! 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,266 **** 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) { /* ! * Proc is in foreground of this terminal */ ! if (proc_compare(&ep->kp->kp_proc, p)) ! ep->kp = kp; ! break; } } } --- 260,285 ---- continue; e = &kp->kp_eproc; for (ep = ehead; ep != NULL; ep = ep->next) { ! 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 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. */ ! dkp = ep->dkp; ! ep->dkp = kp; ! *((struct kinfo_proc **)(&kp->kp_eproc.e_spare[ 0])) = dkp; } } } *************** *** 341,346 **** --- 360,375 ---- (void)snprintf(buf, sizeof(buf), "%s:%.*s", p, 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, -------------------------------------------------------------------------------
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199709092310.QAA03289>