diff options
author | Michael Shalayeff <mickey@cvs.openbsd.org> | 1997-07-25 02:23:35 +0000 |
---|---|---|
committer | Michael Shalayeff <mickey@cvs.openbsd.org> | 1997-07-25 02:23:35 +0000 |
commit | 02d4a8343379e9c85bbee1216d4c01d83df33ffc (patch) | |
tree | 2dd2f3ad9fc586c98a8684262b5ae42eb200c8ef | |
parent | d495ee6167048dbdd319c94e54d28707324d399c (diff) |
-T to display seconds, from jhawk netbsd-pr#1548
-rw-r--r-- | usr.bin/last/last.1 | 5 | ||||
-rw-r--r-- | usr.bin/last/last.c | 60 |
2 files changed, 41 insertions, 24 deletions
diff --git a/usr.bin/last/last.1 b/usr.bin/last/last.1 index 07708ea3a9c..067a9ae9919 100644 --- a/usr.bin/last/last.1 +++ b/usr.bin/last/last.1 @@ -1,4 +1,4 @@ -.\" $OpenBSD: last.1,v 1.3 1997/07/20 07:54:08 jdm Exp $ +.\" $OpenBSD: last.1,v 1.4 1997/07/25 02:23:34 mickey Exp $ .\" $NetBSD: last.1,v 1.3 1994/12/21 22:41:23 jtc Exp $ .\" .\" Copyright (c) 1980, 1990, 1993 @@ -43,6 +43,7 @@ .Sh SYNOPSIS .Nm last .Op Fl Ns Ar n +.Op Fl Ns Ar T .Op Fl f Ar file .Op Fl h Ar host .Op Fl t Ar tty @@ -87,6 +88,8 @@ equivalent to .It Fl h Ar host .Ar Host names may be names or internet numbers. +.It Fl T +Display better time information, including seconds. .It Fl d Ar date Specify the snapshot date & time. All users logged in at the snapshot date & time will diff --git a/usr.bin/last/last.c b/usr.bin/last/last.c index 3de5bdf1ac1..78aeea25cc0 100644 --- a/usr.bin/last/last.c +++ b/usr.bin/last/last.c @@ -1,4 +1,4 @@ -/* $OpenBSD: last.c,v 1.5 1997/07/20 09:07:17 jdm Exp $ */ +/* $OpenBSD: last.c,v 1.6 1997/07/25 02:23:34 mickey Exp $ */ /* $NetBSD: last.c,v 1.6 1994/12/24 16:49:02 cgd Exp $ */ /* @@ -44,7 +44,7 @@ static char copyright[] = #if 0 static char sccsid[] = "@(#)last.c 8.2 (Berkeley) 4/2/94"; #endif -static char rcsid[] = "$OpenBSD: last.c,v 1.5 1997/07/20 09:07:17 jdm Exp $"; +static char rcsid[] = "$OpenBSD: last.c,v 1.6 1997/07/25 02:23:34 mickey Exp $"; #endif /* not lint */ #include <sys/param.h> @@ -88,6 +88,7 @@ TTY *ttylist; /* head of linked list */ static time_t currentout; /* current logout value */ static long maxrec; /* records to display */ static char *file = _PATH_WTMP; /* wtmp file */ +static int fulltime = 0; /* Display seconds? */ static time_t snaptime; /* if != 0, we will only * report users logged in * at this snapshot time @@ -115,7 +116,7 @@ main(argc, argv) maxrec = -1; snaptime = 0; - while ((ch = getopt(argc, argv, "0123456789f:h:t:d:")) != -1) + while ((ch = getopt(argc, argv, "0123456789f:h:t:d:T")) != -1) switch (ch) { case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': @@ -146,10 +147,13 @@ main(argc, argv) case 'd': snaptime = dateconv(optarg); break; + case 'T': + fulltime = -1; + break; case '?': default: (void)fprintf(stderr, - "usage: last [-#] [-f file] [-t tty]" + "usage: last [-#] [-f file] [-T] [-t tty]" " [-h host] [-d [MMDD]hhmm[.SS]]" " [user ...]\n"); exit(1); @@ -220,17 +224,23 @@ checkargs() void wtmp() { - struct utmp *bp; /* current structure */ - TTY *T; /* tty list entry */ - struct stat stb; /* stat of file for size */ - time_t bl, delta; /* time difference */ + struct utmp *bp; /* current structure */ + TTY *T; /* tty list entry */ + struct stat stb; /* stat of file for size */ + time_t bl, delta; /* time difference */ + int timesize; /* how long time string gonna be */ int bytes, wfd; char *ct, *crmsg; - int snapfound = 0; /* found snapshot entry? */ + int snapfound = 0; /* found snapshot entry? */ if ((wfd = open(file, O_RDONLY, 0)) < 0 || fstat(wfd, &stb) == -1) err(1, "%s", file); bl = (stb.st_size + sizeof(buf) - 1) / sizeof(buf); + if (fulltime) + timesize = 8; /* HH:MM:SS */ + else + timesize = 5; /* HH:MM */ + (void)time(&buf[0].ut_time); (void)signal(SIGINT, onintr); (void)signal(SIGQUIT, onintr); @@ -265,12 +275,13 @@ wtmp() */ if (want(bp, NO)) { ct = ctime(&bp->ut_time); - printf("%-*.*s %-*.*s %-*.*s %10.10s %5.5s \n", + printf("%-*.*s %-*.*s %-*.*s %10.10s %*.*s \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); + bp->ut_host, ct, timesize, + timesize, ct + 11); if (maxrec != -1 && !--maxrec) return; } @@ -284,11 +295,11 @@ wtmp() && !bp->ut_line[1]) { if (want(bp, NO)) { ct = ctime(&bp->ut_time); - printf("%-*.*s %-*.*s %-*.*s %10.10s %5.5s \n", + printf("%-*.*s %-*.*s %-*.*s %10.10s %*.*s \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); + ct, timesize, timesize, ct + 11); if (maxrec && !--maxrec) return; } @@ -315,11 +326,11 @@ wtmp() T->logout < 0)))) { snapfound = 1; ct = ctime(&bp->ut_time); - 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); + printf("%-*.*s %-*.*s %-*.*s %10.10s %*.*s ", + UT_NAMESIZE, UT_NAMESIZE, bp->ut_name, + UT_LINESIZE, UT_LINESIZE, bp->ut_line, + UT_HOSTSIZE, UT_HOSTSIZE, bp->ut_host, + ct, timesize, timesize, ct + 11); if (!T->logout) puts(" still logged in"); else { @@ -328,15 +339,18 @@ wtmp() printf("- %s", crmsg); } else - printf("- %5.5s", + printf("- %*.*s", + timesize, timesize, ctime(&T->logout)+11); delta = T->logout - bp->ut_time; if (delta < SECSPERDAY) - printf(" (%5.5s)\n", + printf(" (%*.*s)\n", + timesize, timesize, asctime(gmtime(&delta))+11); else - printf(" (%ld+%5.5s)\n", + printf(" (%ld+%*.*s)\n", delta / SECSPERDAY, + timesize, timesize, asctime(gmtime(&delta))+11); } if (maxrec != -1 && !--maxrec) @@ -346,7 +360,7 @@ wtmp() } } ct = ctime(&buf[0].ut_time); - printf("\nwtmp begins %10.10s %5.5s \n", ct, ct + 11); + printf("\nwtmp begins %10.10s %*.*s \n", ct, timesize, timesize, ct + 11); } /* @@ -575,7 +589,7 @@ onintr(signo) char *ct; ct = ctime(&buf[0].ut_time); - printf("\ninterrupted %10.10s %5.5s \n", ct, ct + 11); + printf("\ninterrupted %10.10s %8.8s \n", ct, ct + 11); if (signo == SIGINT) exit(1); (void)fflush(stdout); /* fix required for rsh */ |