CVS commit: src/usr.bin/last

2012-03-14 Thread David A. Holland
Module Name:src
Committed By:   dholland
Date:   Thu Mar 15 02:55:02 UTC 2012

Modified Files:
src/usr.bin/last: want.c

Log Message:
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.


To generate a diff of this commit:
cvs rdiff -u -r1.14 -r1.15 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.14 src/usr.bin/last/want.c:1.15
--- src/usr.bin/last/want.c:1.14	Fri Sep 16 15:39:27 2011
+++ src/usr.bin/last/want.c	Thu Mar 15 02:55:02 2012
@@ -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 @@ 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 = time(NULL);
 	(void)signal(SIGINT, onintr);
 	(void)signal(SIGQUIT, onintr);
 
@@ -157,6 +158,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.
@@ -250,7 +254,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);
@@ -305,8 +309,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);



CVS commit: src/usr.bin/last

2012-03-14 Thread David A. Holland
Module Name:src
Committed By:   dholland
Date:   Thu Mar 15 03:01:03 UTC 2012

Modified Files:
src/usr.bin/last: want.c

Log Message:
When the wtmp file is empty, for the wtmp[x] begins... output, use
the last mod time of the wtmp file (in practice, the time it was last
rotated, which is when it begins) instead of the current time, which
wasn't ever particularly useful. PR 39444.


To generate a diff of this commit:
cvs rdiff -u -r1.15 -r1.16 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.15 src/usr.bin/last/want.c:1.16
--- src/usr.bin/last/want.c:1.15	Thu Mar 15 02:55:02 2012
+++ src/usr.bin/last/want.c	Thu Mar 15 03:01:03 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: want.c,v 1.15 2012/03/15 02:55:02 dholland Exp $	*/
+/*	$NetBSD: want.c,v 1.16 2012/03/15 03:01:03 dholland Exp $	*/
 
 /*
  * Copyright (c) 1987, 1993, 1994
@@ -131,7 +131,7 @@ wtmp(const char *file, int namesz, int l
 	if (!S_ISREG(stb.st_mode))
 		errx(EXIT_FAILURE, %s: Not a regular file, file);
 
-	seentime = time(NULL);
+	seentime = stb.st_mtime;
 	(void)signal(SIGINT, onintr);
 	(void)signal(SIGQUIT, onintr);
 



CVS commit: src/usr.bin/last

2012-03-14 Thread David A. Holland
Module Name:src
Committed By:   dholland
Date:   Thu Mar 15 03:04:05 UTC 2012

Modified Files:
src/usr.bin/last: last.c want.c

Log Message:
Tidy up: we no longer need FIRSTVALID for its original purpose, so change
the name of the symbol to something that applies to the remaining use.


To generate a diff of this commit:
cvs rdiff -u -r1.35 -r1.36 src/usr.bin/last/last.c
cvs rdiff -u -r1.16 -r1.17 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/last.c
diff -u src/usr.bin/last/last.c:1.35 src/usr.bin/last/last.c:1.36
--- src/usr.bin/last/last.c:1.35	Fri Sep 16 15:39:27 2011
+++ src/usr.bin/last/last.c	Thu Mar 15 03:04:05 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: last.c,v 1.35 2011/09/16 15:39:27 joerg Exp $	*/
+/*	$NetBSD: last.c,v 1.36 2012/03/15 03:04:05 dholland Exp $	*/
 
 /*
  * Copyright (c) 1987, 1993, 1994
@@ -39,7 +39,7 @@ __COPYRIGHT(@(#) Copyright (c) 1987, 19
 #if 0
 static char sccsid[] = @(#)last.c	8.2 (Berkeley) 4/2/94;
 #endif
-__RCSID($NetBSD: last.c,v 1.35 2011/09/16 15:39:27 joerg Exp $);
+__RCSID($NetBSD: last.c,v 1.36 2012/03/15 03:04:05 dholland Exp $);
 #endif /* not lint */
 
 #include sys/param.h
@@ -378,14 +378,14 @@ fmttime(time_t t, int flags)
 #define LINESIZE UT_LINESIZE
 #define HOSTSIZE UT_HOSTSIZE
 #define ut_timefld ut_time
-#define FIRSTVALID 0
+#define HAS_UT_SS 0
 #include want.c
 #undef TYPE /*(a)*/
 #undef NAMESIZE
 #undef LINESIZE
 #undef HOSTSIZE
 #undef ut_timefld
-#undef FIRSTVALID
+#undef HAS_UT_SS
 #endif
 
 #ifdef SUPPORT_UTMPX
@@ -400,6 +400,6 @@ fmttime(time_t t, int flags)
 #define LINESIZE UTX_LINESIZE
 #define HOSTSIZE UTX_HOSTSIZE
 #define ut_timefld ut_xtime
-#define FIRSTVALID 1
+#define HAS_UT_SS 1
 #include want.c
 #endif

Index: src/usr.bin/last/want.c
diff -u src/usr.bin/last/want.c:1.16 src/usr.bin/last/want.c:1.17
--- src/usr.bin/last/want.c:1.16	Thu Mar 15 03:01:03 2012
+++ src/usr.bin/last/want.c	Thu Mar 15 03:04:05 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: want.c,v 1.16 2012/03/15 03:01:03 dholland Exp $	*/
+/*	$NetBSD: want.c,v 1.17 2012/03/15 03:04:05 dholland Exp $	*/
 
 /*
  * Copyright (c) 1987, 1993, 1994
@@ -39,7 +39,7 @@ static const char *
 /*ARGSUSED*/
 gethost(struct utmp *ut, const char *host, int numeric)
 {
-#if FIRSTVALID == 0
+#if HAS_UT_SS == 0
 	return numeric ?  : host;
 #else
 	if (numeric) {



CVS commit: src/usr.bin/last

2012-03-14 Thread David A. Holland
Module Name:src
Committed By:   dholland
Date:   Thu Mar 15 02:55:02 UTC 2012

Modified Files:
src/usr.bin/last: want.c

Log Message:
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.


To generate a diff of this commit:
cvs rdiff -u -r1.14 -r1.15 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.



CVS commit: src/usr.bin/last

2012-03-14 Thread David A. Holland
Module Name:src
Committed By:   dholland
Date:   Thu Mar 15 03:01:03 UTC 2012

Modified Files:
src/usr.bin/last: want.c

Log Message:
When the wtmp file is empty, for the wtmp[x] begins... output, use
the last mod time of the wtmp file (in practice, the time it was last
rotated, which is when it begins) instead of the current time, which
wasn't ever particularly useful. PR 39444.


To generate a diff of this commit:
cvs rdiff -u -r1.15 -r1.16 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.



CVS commit: src/usr.bin/last

2012-03-14 Thread David A. Holland
Module Name:src
Committed By:   dholland
Date:   Thu Mar 15 03:04:05 UTC 2012

Modified Files:
src/usr.bin/last: last.c want.c

Log Message:
Tidy up: we no longer need FIRSTVALID for its original purpose, so change
the name of the symbol to something that applies to the remaining use.


To generate a diff of this commit:
cvs rdiff -u -r1.35 -r1.36 src/usr.bin/last/last.c
cvs rdiff -u -r1.16 -r1.17 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.



CVS commit: src/usr.bin/last

2011-10-18 Thread Jeremy C. Reed
Module Name:src
Committed By:   reed
Date:   Wed Oct 19 00:27:40 UTC 2011

Modified Files:
src/usr.bin/last: last.1

Log Message:
patch from from Snader_LB via IRC.

- mention  The following options are available:

- improve grammar

- provide useful tip about -x


To generate a diff of this commit:
cvs rdiff -u -r1.18 -r1.19 src/usr.bin/last/last.1

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/last.1
diff -u src/usr.bin/last/last.1:1.18 src/usr.bin/last/last.1:1.19
--- src/usr.bin/last/last.1:1.18	Fri Jul 27 16:59:25 2007
+++ src/usr.bin/last/last.1	Wed Oct 19 00:27:40 2011
@@ -1,4 +1,4 @@
-.\	$NetBSD: last.1,v 1.18 2007/07/27 16:59:25 reed Exp $
+.\	$NetBSD: last.1,v 1.19 2011/10/19 00:27:40 reed Exp $
 .\
 .\ Copyright (c) 1980, 1990, 1993
 .\	The Regents of the University of California.  All rights reserved.
@@ -29,7 +29,7 @@
 .\
 .\ @(#)last.1	8.1 (Berkeley) 6/6/93
 .\
-.Dd December 27, 2006
+.Dd October 18, 2011
 .Dt LAST 1
 .Os
 .Sh NAME
@@ -63,6 +63,8 @@ a crash or shutdown,
 .Nm
 will so indicate.
 .Pp
+The following options are available:
+.Pp
 .Bl -tag -width xHxhostsizexx
 .It Fl Ar n
 Limits the report to
@@ -111,10 +113,11 @@ Tty names may be given fully or abbrevia
 is equivalent to
 .Dq Li last -t tty03 .
 .It Fl x
-Assume that the file given is
+Assume that the file given is in
 .Xr wtmpx 5
 format, even if the filename does not end with an
 .Sq x .
+Also useful when reading such format from standard input.
 .El
 .Pp
 If multiple arguments are given, the information which applies to any of the



CVS commit: src/usr.bin/last

2011-10-18 Thread Jeremy C. Reed
Module Name:src
Committed By:   reed
Date:   Wed Oct 19 00:27:40 UTC 2011

Modified Files:
src/usr.bin/last: last.1

Log Message:
patch from from Snader_LB via IRC.

- mention  The following options are available:

- improve grammar

- provide useful tip about -x


To generate a diff of this commit:
cvs rdiff -u -r1.18 -r1.19 src/usr.bin/last/last.1

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



CVS commit: src/usr.bin/last

2010-06-04 Thread David A. Holland
Module Name:src
Committed By:   dholland
Date:   Sat Jun  5 03:24:02 UTC 2010

Modified Files:
src/usr.bin/last: last.c

Log Message:
Avoid SIGSEGV on out-of-range time_t.


To generate a diff of this commit:
cvs rdiff -u -r1.33 -r1.34 src/usr.bin/last/last.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/last.c
diff -u src/usr.bin/last/last.c:1.33 src/usr.bin/last/last.c:1.34
--- src/usr.bin/last/last.c:1.33	Sun Apr 12 13:07:21 2009
+++ src/usr.bin/last/last.c	Sat Jun  5 03:24:01 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: last.c,v 1.33 2009/04/12 13:07:21 lukem Exp $	*/
+/*	$NetBSD: last.c,v 1.34 2010/06/05 03:24:01 dholland Exp $	*/
 
 /*
  * Copyright (c) 1987, 1993, 1994
@@ -39,7 +39,7 @@
 #if 0
 static char sccsid[] = @(#)last.c	8.2 (Berkeley) 4/2/94;
 #endif
-__RCSID($NetBSD: last.c,v 1.33 2009/04/12 13:07:21 lukem Exp $);
+__RCSID($NetBSD: last.c,v 1.34 2010/06/05 03:24:01 dholland Exp $);
 #endif /* not lint */
 
 #include sys/param.h
@@ -362,6 +362,10 @@
 	static char tbuf[TBUFLEN];
 
 	tm = (flags  GMT) ? gmtime(t) : localtime(t);
+	if (tm == NULL) {
+		strcpy(tbuf, );
+		return tbuf;
+	}
 	strftime(tbuf, sizeof(tbuf),
 	(flags  TIMEONLY)
 	 ? (flags  FULLTIME ? LTFMTS : TFMTS)



CVS commit: src/usr.bin/last

2010-06-04 Thread David A. Holland
Module Name:src
Committed By:   dholland
Date:   Sat Jun  5 03:24:02 UTC 2010

Modified Files:
src/usr.bin/last: last.c

Log Message:
Avoid SIGSEGV on out-of-range time_t.


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

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



CVS commit: src/usr.bin/last

2009-04-12 Thread Luke Mewburn
Module Name:src
Committed By:   lukem
Date:   Sun Apr 12 13:07:21 UTC 2009

Modified Files:
src/usr.bin/last: last.c want.c

Log Message:
Fix WARNS=4 issues (-Wshadow -Wcast-qual -Wsign-compare)


To generate a diff of this commit:
cvs rdiff -u -r1.32 -r1.33 src/usr.bin/last/last.c
cvs rdiff -u -r1.12 -r1.13 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/last.c
diff -u src/usr.bin/last/last.c:1.32 src/usr.bin/last/last.c:1.33
--- src/usr.bin/last/last.c:1.32	Mon Jul 21 14:19:23 2008
+++ src/usr.bin/last/last.c	Sun Apr 12 13:07:21 2009
@@ -1,4 +1,4 @@
-/*	$NetBSD: last.c,v 1.32 2008/07/21 14:19:23 lukem Exp $	*/
+/*	$NetBSD: last.c,v 1.33 2009/04/12 13:07:21 lukem Exp $	*/
 
 /*
  * Copyright (c) 1987, 1993, 1994
@@ -39,7 +39,7 @@
 #if 0
 static char sccsid[] = @(#)last.c	8.2 (Berkeley) 4/2/94;
 #endif
-__RCSID($NetBSD: last.c,v 1.32 2008/07/21 14:19:23 lukem Exp $);
+__RCSID($NetBSD: last.c,v 1.33 2009/04/12 13:07:21 lukem Exp $);
 #endif /* not lint */
 
 #include sys/param.h
@@ -92,11 +92,11 @@
 #define MAXUTMP		1024
 
 typedef struct arg {
-	char	*name;			/* argument */
+	const char	*name;		/* argument */
 #define	HOST_TYPE	-2
 #define	TTY_TYPE	-3
 #define	USER_TYPE	-4
-	int	type;			/* type of arg */
+	int		type;		/* type of arg */
 	struct arg	*next;		/* linked list pointer */
 } ARG;
 static ARG	*arglist;		/* head of linked list */
@@ -115,10 +115,10 @@
 
 int	 main(int, char *[]);
 
-static void	 addarg(int, char *);
+static void	 addarg(int, const char *);
 static TTY	*addtty(const char *);
 static void	 hostconv(char *);
-static char	*ttyconv(char *);
+static const char *ttyconv(char *);
 #ifdef SUPPORT_UTMPX
 static void	 wtmpx(const char *, int, int, int, int);
 #endif
@@ -148,7 +148,7 @@
 {
 	int ch;
 	char *p;
-	char	*file = NULL;
+	const char *file = NULL;
 	int namesize = UT_NAMESIZE;
 	int linesize = UT_LINESIZE;
 	int hostsize = UT_HOSTSIZE;
@@ -271,7 +271,7 @@
  *	add an entry to a linked list of arguments
  */
 static void
-addarg(int type, char *arg)
+addarg(int type, const char *arg)
 {
 	ARG *cur;
 
@@ -288,7 +288,7 @@
  *	add an entry to a linked list of ttys
  */
 static TTY *
-addtty(const char *ttyname)
+addtty(const char *tty)
 {
 	TTY *cur;
 
@@ -296,7 +296,7 @@
 		err(EXIT_FAILURE, malloc failure);
 	cur-next = ttylist;
 	cur-logout = currentout;
-	memmove(cur-tty, ttyname, sizeof(cur-tty));
+	memmove(cur-tty, tty, sizeof(cur-tty));
 	return (ttylist = cur);
 }
 
@@ -330,7 +330,7 @@
  * ttyconv --
  *	convert tty to correct name.
  */
-static char *
+static const char *
 ttyconv(char *arg)
 {
 	char *mval;

Index: src/usr.bin/last/want.c
diff -u src/usr.bin/last/want.c:1.12 src/usr.bin/last/want.c:1.13
--- src/usr.bin/last/want.c:1.12	Mon Dec 29 01:25:04 2008
+++ src/usr.bin/last/want.c	Sun Apr 12 13:07:21 2009
@@ -1,4 +1,4 @@
-/*	$NetBSD: want.c,v 1.12 2008/12/29 01:25:04 christos Exp $	*/
+/*	$NetBSD: want.c,v 1.13 2009/04/12 13:07:21 lukem Exp $	*/
 
 /*
  * Copyright (c) 1987, 1993, 1994
@@ -42,11 +42,11 @@
 	return numeric ?  : host;
 #else
 	if (numeric) {
-		static char buf[512];
-		buf[0] = '\0';
-		(void)sockaddr_snprintf(buf, sizeof(buf), %a,
+		static char hbuf[512];
+		hbuf[0] = '\0';
+		(void)sockaddr_snprintf(hbuf, sizeof(hbuf), %a,
 		(struct sockaddr *)ut-ut_ss);
-		return buf;
+		return hbuf;
 	} else
 		return host;
 #endif
@@ -71,14 +71,15 @@
 	struct stat	stb;		/* stat of file for sz */
 	off_t	offset;
 	int	wfd;
-	char	*ct, *crmsg;
+	char	*ct;
+	const char *crmsg;
 	size_t  len = sizeof(*buf) * MAXUTMP;
 	char namebuf[sizeof(bp-ut_name) + 1], *namep;
 	char linebuf[sizeof(bp-ut_line) + 1], *linep;
 	char hostbuf[sizeof(bp-ut_host) + 1], *hostp;
-	int checkname = namesz  sizeof(bp-ut_name);
-	int checkline = linesz  sizeof(bp-ut_line);
-	int checkhost = hostsz  sizeof(bp-ut_host);
+	int checkname = namesz  (int)sizeof(bp-ut_name);
+	int checkline = linesz  (int)sizeof(bp-ut_line);
+	int checkhost = hostsz  (int)sizeof(bp-ut_host);
 
 	if ((buf = malloc(len)) == NULL)
 		err(EXIT_FAILURE, Cannot allocate utmp buffer);
@@ -141,7 +142,7 @@
 		ssize_t ret, i;
 		size_t size;
 
-		size = MIN(len, offset);
+		size = MIN((off_t)len, offset);
 		offset -= size; /* Always a multiple of sizeof(*buf) */
 		ret = pread(wfd, buf, size, offset);
 		if (ret  0) {