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.41 by christos (approved by tho...



details:   https://anonhg.NetBSD.org/src/rev/7c98a071104a
branches:  netbsd-1-5
changeset: 489556:7c98a071104a
user:      simonb <simonb%NetBSD.org@localhost>
date:      Thu Sep 28 15:53:18 2000 +0000

description:
Pull up rev 1.41 by christos (approved by thorpej):
  - Don't core dump when we have stale utmp entries; warn the user instead.
  - Make this work again in single user when invoked as uptime and utmp is
    not present.

diffstat:

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

diffs (60 lines):

diff -r 24baeae70e20 -r 7c98a071104a usr.bin/w/w.c
--- a/usr.bin/w/w.c     Thu Sep 28 15:38:18 2000 +0000
+++ b/usr.bin/w/w.c     Thu Sep 28 15:53:18 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: w.c,v 1.36.2.2 2000/07/22 04:47:54 simonb Exp $        */
+/*     $NetBSD: w.c,v 1.36.2.3 2000/09/28 15:53:18 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.2.2 2000/07/22 04:47:54 simonb Exp $");
+__RCSID("$NetBSD: w.c,v 1.36.2.3 2000/09/28 15:53:18 simonb Exp $");
 #endif
 #endif /* not lint */
 
@@ -180,13 +180,13 @@
                errx(1, "%s", errbuf);
 
        (void)time(&now);
-       if ((ut = fopen(_PATH_UTMP, "r")) == NULL)
+       if ((ut = fopen(_PATH_UTMP, "r")) == NULL && wcmd)
                err(1, "%s", _PATH_UTMP);
 
        if (*argv)
                sel_user = *argv;
 
-       for (nusers = 0; fread(&utmp, sizeof(utmp), 1, ut);) {
+       for (nusers = 0; ut && fread(&utmp, sizeof(utmp), 1, ut);) {
                if (utmp.ut_name[0] == '\0')
                        continue;
                ++nusers;
@@ -217,7 +217,10 @@
                if ((ep->idle = now - stp->st_atime) < 0)
                        ep->idle = 0;
        }
-       (void)fclose(ut);
+       if (ut)
+               (void)fclose(ut);
+       else
+               nusers = 1;
 
        if (header || wcmd == 0) {
                pr_header(&now, nusers);
@@ -319,6 +322,13 @@
                            (int)(ep->utmp.ut_host + UT_HOSTSIZE - x), x);
                        p = buf;
                }
+               if (ep->kp == NULL) {
+                   warnx("Stale utmp entry: %.*s %.*s %.*s",
+                       UT_NAMESIZE, ep->utmp.ut_name,
+                       UT_LINESIZE, ep->utmp.ut_line,
+                       UT_HOSTSIZE, ep->utmp.ut_host);
+                   continue;
+               }
                (void)printf("%-*s %-2.2s %-*.*s ",
                    lognamelen, ep->kp->p_login,
                    (strncmp(ep->utmp.ut_line, "tty", 3) &&



Home | Main Index | Thread Index | Old Index