From owner-freebsd-current Tue Apr 29 15:40:10 1997 Return-Path: Received: (from root@localhost) by hub.freebsd.org (8.8.5/8.8.5) id PAA15465 for current-outgoing; Tue, 29 Apr 1997 15:40:10 -0700 (PDT) Received: from phaeton.artisoft.com (phaeton.Artisoft.COM [198.17.250.50]) by hub.freebsd.org (8.8.5/8.8.5) with SMTP id PAA15458 for ; Tue, 29 Apr 1997 15:40:05 -0700 (PDT) Received: (from terry@localhost) by phaeton.artisoft.com (8.6.11/8.6.9) id PAA00766; Tue, 29 Apr 1997 15:39:43 -0700 From: Terry Lambert Message-Id: <199704292239.PAA00766@phaeton.artisoft.com> Subject: Re: Longer user names: take 2 To: handy@sag.space.lockheed.com (Brian N. Handy) Date: Tue, 29 Apr 1997 15:39:43 -0700 (MST) Cc: terry@lambert.org, current@freebsd.org In-Reply-To: from "Brian N. Handy" at Apr 29, 97 11:35:05 am X-Mailer: ELM [version 2.4 PL24] MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: owner-current@freebsd.org X-Loop: FreeBSD.org Precedence: bulk > >> > I made the change to ps. It now outputs with a width of "USER" or > >> > the largest active name, whichever is greater. Ah, to have the > >> > column space back! > >> > >> Definitely! Nice job, thanks. Committed. > > > >But I feel dirty... user space code is so ...trivial. > > Terry's secret shame: Userland fixes. "Hi, my name's Terry, and I fix > userland code. I first realized I had to fix userland code when ..." Ugh. To add to my shame, since I was deluged by mail (is 12 a deluge?) from other forlorn ex-SunOS users, here's the '-d' (debug) flag for 'w'. I didn't shrink up the user field, since the 'w' display isn't too wide, even with the width expansion of the user field. Patches follow .sig. These things are taking me less than 30 minutes, including writing and sending the mail -- they really aren't worthy... >B-6. 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.20 diff -c -r1.20 w.c *** 1.20 1997/03/29 04:33:51 --- w.c 1997/04/29 22:31:34 *************** *** 92,97 **** --- 92,98 ---- 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]; *************** *** 102,111 **** 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)); --- 103,113 ---- 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)); *************** *** 122,127 **** --- 124,130 ---- { extern char *__progname; struct kinfo_proc *kp; + struct kinfo_proc *dkp; struct hostent *hp; struct stat *stp; FILE *ut; *************** *** 142,153 **** 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; --- 145,159 ---- 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; *************** *** 250,262 **** 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; } } } --- 256,281 ---- 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; } } } *************** *** 337,342 **** --- 356,371 ---- (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, --------------------------------------------------------------------------