Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/netbsd-1-5]: src/usr.bin/w Pull up rev 1.37:



details:   https://anonhg.NetBSD.org/src/rev/064e77a730c1
branches:  netbsd-1-5
changeset: 488263:064e77a730c1
user:      simonb <simonb%NetBSD.org@localhost>
date:      Mon Jun 26 00:45:30 2000 +0000

description:
Pull up rev 1.37:
Use p_login from struct proc instead of ut_name from struct utmp so
that a truncated name isn't used if the login name is over 8 characters
long.  Size USER field to suit.

Fixes PR bin/2459 from Neil McRae.

diffstat:

 usr.bin/w/w.c |  32 ++++++++++++++++++++------------
 1 files changed, 20 insertions(+), 12 deletions(-)

diffs (102 lines):

diff -r b7f41c927265 -r 064e77a730c1 usr.bin/w/w.c
--- a/usr.bin/w/w.c     Mon Jun 26 00:40:38 2000 +0000
+++ b/usr.bin/w/w.c     Mon Jun 26 00:45:30 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: w.c,v 1.36 2000/06/08 02:37:28 enami Exp $     */
+/*     $NetBSD: w.c,v 1.36.2.1 2000/06/26 00:45:30 simonb Exp $        */
 
 /*-
  * Copyright (c) 1980, 1991, 1993, 1994
@@ -43,7 +43,7 @@
 #if 0
 static char sccsid[] = "@(#)w.c        8.6 (Berkeley) 6/30/94";
 #else
-__RCSID("$NetBSD: w.c,v 1.36 2000/06/08 02:37:28 enami Exp $");
+__RCSID("$NetBSD: w.c,v 1.36.2.1 2000/06/26 00:45:30 simonb Exp $");
 #endif
 #endif /* not lint */
 
@@ -85,6 +85,8 @@
 
 #include "extern.h"
 
+#define        max(a,b)        (((a)>(b))?(a):(b))
+
 struct timeval boottime;
 struct utmp    utmp;
 struct winsize ws;
@@ -128,7 +130,7 @@
        struct stat *stp;
        FILE *ut;
        struct in_addr l;
-       int ch, i, nentries, nusers, wcmd;
+       int ch, i, nentries, nusers, wcmd, lognamelen;
        char *memf, *nlistf, *p, *x;
        char buf[MAXHOSTNAMELEN], errbuf[_POSIX2_LINE_MAX];
 
@@ -225,13 +227,10 @@
                        exit (0);
        }
 
-#define HEADER "USER    TTY FROM              LOGIN@  IDLE WHAT\n"
-#define WUSED  (sizeof (HEADER) - sizeof ("WHAT\n"))
-       (void)printf(HEADER);
-
        if ((kp = kvm_getproc2(kd, KERN_PROC_ALL, 0,
            sizeof(struct kinfo_proc2), &nentries)) == NULL)
                errx(1, "%s", kvm_geterr(kd));
+       lognamelen = 0;
        for (i = 0; i < nentries; i++, kp++) {
 
                if (kp->p_stat == SIDL || kp->p_stat == SZOMB)
@@ -242,19 +241,28 @@
                                /*
                                 * Proc is in foreground of this terminal
                                 */
-                               if (proc_compare(ep->kp, kp))
+                               if (proc_compare(ep->kp, kp)) {
                                        ep->kp = kp;
+                                       lognamelen = max(lognamelen,
+                                           strlen(kp->p_login));
+                               }
                                break;
                        }
                }
        }
+
+       argwidth = printf("%-*sTTY %-*s %*s  IDLE WHAT\n",
+           lognamelen, "USER", UT_HOSTSIZE, "FROM",
+           7 /* "dddhhXm" */, "LOGIN@");
+       argwidth -= sizeof("WHAT\n");
+
        if ((ioctl(STDOUT_FILENO, TIOCGWINSZ, &ws) == -1 &&
             ioctl(STDERR_FILENO, TIOCGWINSZ, &ws) == -1 &&
             ioctl(STDIN_FILENO, TIOCGWINSZ, &ws) == -1) || ws.ws_col == 0)
               ttywidth = 79;
         else
               ttywidth = ws.ws_col - 1;
-       argwidth = ttywidth - WUSED;
+       argwidth = ttywidth - argwidth;
        if (argwidth < 4)
                argwidth = 8;
        /* sort by idle time */
@@ -311,8 +319,8 @@
                            (int)(ep->utmp.ut_host + UT_HOSTSIZE - x), x);
                        p = buf;
                }
-               (void)printf("%-*.*s %-2.2s %-*.*s ",
-                   UT_NAMESIZE, UT_NAMESIZE, ep->utmp.ut_name,
+               (void)printf("%-*s %-2.2s %-*.*s ",
+                   lognamelen, ep->kp->p_login,
                    (strncmp(ep->utmp.ut_line, "tty", 3) &&
                    strncmp(ep->utmp.ut_line, "dty", 3)) ?
                    ep->utmp.ut_line : ep->utmp.ut_line + 3,
@@ -320,7 +328,7 @@
                pr_attime(&ep->utmp.ut_time, &now);
                pr_idle(ep->idle);
                pr_args(ep->kp);
-               printf("\n");
+               (void)printf("\n");
        }
        exit(0);
 }



Home | Main Index | Thread Index | Old Index