Add a new "-y" flag which causes the year to be included in the

session start time. This is useful when looking at old or long-running
wtmp files.

PR:		bin/12982
Obtained from:	KOJIMA Hajime <kjm@rins.ryukoku.ac.jp>, keramida
Reviewed by:	keramida
MFC after:	1 week
This commit is contained in:
Ian Dowse 2002-03-01 21:12:19 +00:00
parent 9ac0768d74
commit 139db33f22
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=91541
2 changed files with 13 additions and 5 deletions

View File

@ -32,7 +32,7 @@
.\" @(#)last.1 8.1 (Berkeley) 6/6/93 .\" @(#)last.1 8.1 (Berkeley) 6/6/93
.\" $FreeBSD$ .\" $FreeBSD$
.\" .\"
.Dd May 2, 2001 .Dd March 1, 2002
.Dt LAST 1 .Dt LAST 1
.Os .Os
.Sh NAME .Sh NAME
@ -41,6 +41,7 @@
.Sh SYNOPSIS .Sh SYNOPSIS
.Nm .Nm
.Op Fl Ns Ar n .Op Fl Ns Ar n
.Op Fl y
.Oo .Oo
.Fl d .Fl d
.Sm off .Sm off
@ -161,6 +162,8 @@ equivalent to
.It Fl w .It Fl w
Widen the duration field to show seconds, as well as the Widen the duration field to show seconds, as well as the
default days, hours and minutes. default days, hours and minutes.
.It Fl y
Report the year in the session start time.
.El .El
.Pp .Pp
If multiple arguments are given, If multiple arguments are given,

View File

@ -90,6 +90,7 @@ static long currentout, /* current logout value */
static const char *file = _PATH_WTMP; /* wtmp file */ static const char *file = _PATH_WTMP; /* wtmp file */
static int sflag = 0; /* show delta in seconds */ static int sflag = 0; /* show delta in seconds */
static int width = 5; /* show seconds in delta */ static int width = 5; /* show seconds in delta */
static int yflag; /* show year */
static int d_first; static int d_first;
static int snapfound = 0; /* found snapshot entry? */ static int snapfound = 0; /* found snapshot entry? */
static time_t snaptime; /* if != 0, we will only static time_t snaptime; /* if != 0, we will only
@ -112,7 +113,7 @@ void
usage(void) usage(void)
{ {
(void)fprintf(stderr, (void)fprintf(stderr,
"usage: last [-#] [-d [[CC]YY][MMDD]hhmm[.SS]] [-f file] [-h hostname]\n" "usage: last [-#] [-y] [-d [[CC]YY][MMDD]hhmm[.SS]] [-f file] [-h host]\n"
"\t[-t tty] [-s|w] [user ...]\n"); "\t[-t tty] [-s|w] [user ...]\n");
exit(1); exit(1);
} }
@ -130,7 +131,7 @@ main(argc, argv)
maxrec = -1; maxrec = -1;
snaptime = 0; snaptime = 0;
while ((ch = getopt(argc, argv, "0123456789d:f:h:st:w")) != -1) while ((ch = getopt(argc, argv, "0123456789d:f:h:st:wy")) != -1)
switch (ch) { switch (ch) {
case '0': case '1': case '2': case '3': case '4': case '0': case '1': case '2': case '3': case '4':
case '5': case '6': case '7': case '8': case '9': case '5': case '6': case '7': case '8': case '9':
@ -167,6 +168,9 @@ main(argc, argv)
case 'w': case 'w':
width = 8; width = 8;
break; break;
case 'y':
yflag++;
break;
case '?': case '?':
default: default:
usage(); usage();
@ -334,8 +338,9 @@ printentry(bp, tt)
exit(0); exit(0);
t = _int_to_time(bp->ut_time); t = _int_to_time(bp->ut_time);
tm = localtime(&t); tm = localtime(&t);
(void) strftime(ct, sizeof(ct), d_first ? "%a %e %b %R" : (void) strftime(ct, sizeof(ct), d_first ?
"%a %b %e %R", tm); (yflag ? "%a %e %b %Y %R" : "%a %e %b %R") :
(yflag ? "%a %b %e %Y %R" : "%a %b %e %R"), tm);
printf("%-*.*s %-*.*s %-*.*s %s%c", printf("%-*.*s %-*.*s %-*.*s %s%c",
UT_NAMESIZE, UT_NAMESIZE, bp->ut_name, UT_NAMESIZE, UT_NAMESIZE, bp->ut_name,
UT_LINESIZE, UT_LINESIZE, bp->ut_line, UT_LINESIZE, UT_LINESIZE, bp->ut_line,