Source-Changes-HG archive

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

[src/trunk]: src/usr.bin/last Keep track of the timestamp of the last (thus o...



details:   https://anonhg.NetBSD.org/src/rev/2068d92273e1
branches:  trunk
changeset: 778067:2068d92273e1
user:      dholland <dholland%NetBSD.org@localhost>
date:      Thu Mar 15 02:55:02 2012 +0000

description:
Keep track of the timestamp of the last (thus oldest) record seen and use
it to print "wtmp[x] begins" at the end, instead of knowing where to look
in the final utmp buffer to get a final timestamp out. This is both tidier
and fixes a problem with wtmpx files, which is that if the header record
is missing (which it seems to be on my machines) it would fetch the wrong
time out, and if you happened to have a one-record wtmp file it would use
the current time instead. This change restores the traditional behavior
of printing the time of the oldest record in the file, and if no records
are present to use the current time.

It might be a bug that wtmpx files don't seem to have the header
record they supposedly ought to.

diffstat:

 usr.bin/last/want.c |  13 ++++++++-----
 1 files changed, 8 insertions(+), 5 deletions(-)

diffs (55 lines):

diff -r 9613e0358352 -r 2068d92273e1 usr.bin/last/want.c
--- a/usr.bin/last/want.c       Thu Mar 15 02:02:20 2012 +0000
+++ b/usr.bin/last/want.c       Thu Mar 15 02:55:02 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: want.c,v 1.14 2011/09/16 15:39:27 joerg Exp $  */
+/*     $NetBSD: want.c,v 1.15 2012/03/15 02:55:02 dholland Exp $       */
 
 /*
  * Copyright (c) 1987, 1993, 1994
@@ -29,6 +29,7 @@
  * SUCH DAMAGE.
  */
 static struct utmp *buf;
+static time_t seentime;
 
 static void onintr(int);
 static int want(struct utmp *, int);
@@ -130,7 +131,7 @@
        if (!S_ISREG(stb.st_mode))
                errx(EXIT_FAILURE, "%s: Not a regular file", file);
 
-       buf[FIRSTVALID].ut_timefld = time(NULL);
+       seentime = time(NULL);
        (void)signal(SIGINT, onintr);
        (void)signal(SIGQUIT, onintr);
 
@@ -157,6 +158,9 @@
                        NULTERM(name);
                        NULTERM(line);
                        NULTERM(host);
+
+                       seentime = bp->ut_timefld;
+
                        /*
                         * if the terminal line is '~', the machine stopped.
                         * see utmp(5) for more info.
@@ -250,7 +254,7 @@
                }
        }
        fulltime = 1;   /* show full time */
-       crmsg = fmttime(buf[FIRSTVALID].ut_timefld, FULLTIME);
+       crmsg = fmttime(seentime, FULLTIME);
        if ((ct = strrchr(file, '/')) != NULL)
                ct++;
        printf("\n%s begins %s\n", ct ? ct : file, crmsg);
@@ -305,8 +309,7 @@
 onintr(int signo)
 {
        /* FIXME: None of this is allowed in a signal handler */
-       printf("\ninterrupted %s\n", fmttime(buf[FIRSTVALID].ut_timefld,
-           FULLTIME));
+       printf("\ninterrupted %s\n", fmttime(seentime, FULLTIME));
        if (signo == SIGINT) {
                (void)raise_default_signal(signo);
                exit(EXIT_FAILURE);



Home | Main Index | Thread Index | Old Index