FreeBSD last command -y support patch Tested: FreeBSD 3.2-RELEASE Apply: # cd /usr/src/usr.bin/last # patch < this-patch # make; make install --- last.1.dist Thu Aug 5 17:37:58 1999 +++ last.1 Thu Aug 5 17:41:08 1999 @@ -45,6 +45,7 @@ .Op Fl s .Op Fl t Ar tty .Op Fl w +.Op Fl y .Op user ... .Sh DESCRIPTION .Nm Last @@ -89,6 +90,8 @@ .It Fl w Widen the duration field to show seconds, as well as the default days, hours and minutes. +.It Fl y +Report the duration of the login session with year. .El .Pp If --- last.c.dist Thu Aug 5 17:18:37 1999 +++ last.c Thu Aug 5 18:04:12 1999 @@ -85,6 +85,8 @@ static char *file = _PATH_WTMP; /* wtmp file */ static int sflag = 0; /* show delta in seconds */ static int width = 5; /* show seconds in delta */ +static int showyear = NO; /* show year */ +#define YEAR_SIZE 4 /* Y10K BUG HERE: to fix, change 4 to 5 */ void addarg __P((int, char *)); void hostconv __P((char *)); @@ -97,7 +99,7 @@ usage(void) { (void)fprintf(stderr, - "usage: last [-#] [-f file] [-h hostname] [-t tty] [-s|w] [user ...]\n"); + "usage: last [-#] [-f file] [-h hostname] [-t tty] [-s|w] [-y] [user ...]\n"); exit(1); } @@ -114,7 +116,7 @@ (void) setlocale(LC_TIME, ""); maxrec = -1; - while ((ch = getopt(argc, argv, "0123456789f:h:st:w")) != -1) + while ((ch = getopt(argc, argv, "0123456789f:h:st:wy")) != -1) switch (ch) { case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': @@ -148,6 +150,9 @@ case 'w': width = 8; break; + case 'y': + showyear = YES; + break; case '?': default: usage(); @@ -240,11 +245,21 @@ if (want(bp)) { tm = localtime(&bp->ut_time); (void) strftime(ct, sizeof(ct), "%c", tm); - printf("%-*.*s %-*.*s %-*.*s %10.10s %5.5s \n", - UT_NAMESIZE, UT_NAMESIZE, bp->ut_name, - UT_LINESIZE, UT_LINESIZE, bp->ut_line, - UT_HOSTSIZE, UT_HOSTSIZE, bp->ut_host, - ct, ct + 11); + if (showyear) { + printf("%-*.*s %-*.*s %-*.*s %10.10s %*.*s %5.5s \n", + UT_NAMESIZE, UT_NAMESIZE, bp->ut_name, + UT_LINESIZE, UT_LINESIZE, bp->ut_line, + UT_HOSTSIZE, UT_HOSTSIZE, bp->ut_host, + ct, + YEAR_SIZE, YEAR_SIZE, ct + 20, + ct + 11); + } else { + printf("%-*.*s %-*.*s %-*.*s %10.10s %5.5s \n", + UT_NAMESIZE, UT_NAMESIZE, bp->ut_name, + UT_LINESIZE, UT_LINESIZE, bp->ut_line, + UT_HOSTSIZE, UT_HOSTSIZE, bp->ut_host, + ct, ct + 11); + } if (maxrec && !--maxrec) return; } @@ -278,11 +293,21 @@ bp->ut_line[4] = '\0'; tm = localtime(&bp->ut_time); (void) strftime(ct, sizeof(ct), "%c", tm); - printf("%-*.*s %-*.*s %-*.*s %10.10s %5.5s ", - UT_NAMESIZE, UT_NAMESIZE, bp->ut_name, - UT_LINESIZE, UT_LINESIZE, bp->ut_line, - UT_HOSTSIZE, UT_HOSTSIZE, bp->ut_host, - ct, ct + 11); + if (showyear) { + printf("%-*.*s %-*.*s %-*.*s %10.10s %*.*s %5.5s ", + UT_NAMESIZE, UT_NAMESIZE, bp->ut_name, + UT_LINESIZE, UT_LINESIZE, bp->ut_line, + UT_HOSTSIZE, UT_HOSTSIZE, bp->ut_host, + ct, + YEAR_SIZE, YEAR_SIZE, ct + 20, + ct + 11); + } else { + printf("%-*.*s %-*.*s %-*.*s %10.10s %5.5s ", + UT_NAMESIZE, UT_NAMESIZE, bp->ut_name, + UT_LINESIZE, UT_LINESIZE, bp->ut_line, + UT_HOSTSIZE, UT_HOSTSIZE, bp->ut_host, + ct, ct + 11); + } if (!tt->logout) puts(" still logged in"); else {