Module Name:    src
Committed By:   sborrill
Date:           Thu Mar 15 08:50:41 UTC 2012

Modified Files:
        src/usr.bin/last [netbsd-5]: want.c

Log Message:
Pull up the following revisions(s) (requested by dholland in ticket #1744):
        usr.bin/last/want.c:    revision 1.15-1.16

Keep track of the timestamp of the last (thus oldest) record seen and use
it to print "wtmp[x] begins" at the end. When the wtmp file is empty, use
the last mod time of the wtmp file. Fixes PR/39444.


To generate a diff of this commit:
cvs rdiff -u -r1.11 -r1.11.12.1 src/usr.bin/last/want.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/last/want.c
diff -u src/usr.bin/last/want.c:1.11 src/usr.bin/last/want.c:1.11.12.1
--- src/usr.bin/last/want.c:1.11	Fri Oct  5 07:27:42 2007
+++ src/usr.bin/last/want.c	Thu Mar 15 08:50:41 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: want.c,v 1.11 2007/10/05 07:27:42 lukem Exp $	*/
+/*	$NetBSD: want.c,v 1.11.12.1 2012/03/15 08:50:41 sborrill 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);
@@ -129,7 +130,7 @@ wtmp(const char *file, int namesz, int l
 	if (!S_ISREG(stb.st_mode))
 		errx(EXIT_FAILURE, "%s: Not a regular file", file);
 
-	buf[FIRSTVALID].ut_timefld = time(NULL);
+	seentime = stb.st_mtime;
 	(void)signal(SIGINT, onintr);
 	(void)signal(SIGQUIT, onintr);
 
@@ -156,6 +157,9 @@ wtmp(const char *file, int namesz, int l
 			NULTERM(name);
 			NULTERM(line);
 			NULTERM(host);
+
+			seentime = bp->ut_timefld;
+
 			/*
 			 * if the terminal line is '~', the machine stopped.
 			 * see utmp(5) for more info.
@@ -248,7 +252,7 @@ wtmp(const char *file, int namesz, int l
 		}
 	}
 	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);
@@ -303,8 +307,7 @@ static void
 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);

Reply via email to