From: Sascha Wildner Date: Sun, 14 Jun 2009 22:40:51 +0000 (+0200) Subject: lastcomm(1): Sync with FreeBSD's RELENG_6. X-Git-Tag: v2.3.2~95^2~2 X-Git-Url: https://gitweb.dragonflybsd.org/dragonfly.git/commitdiff_plain/2fda1eb2cb17969c7a15a4971892659cddd29caa lastcomm(1): Sync with FreeBSD's RELENG_6. --- diff --git a/usr.bin/lastcomm/Makefile b/usr.bin/lastcomm/Makefile index a1763167da..d443d80031 100644 --- a/usr.bin/lastcomm/Makefile +++ b/usr.bin/lastcomm/Makefile @@ -1,5 +1,5 @@ # From: @(#)Makefile 8.1 (Berkeley) 6/6/93 -# $FreeBSD: src/usr.bin/lastcomm/Makefile,v 1.1.1.1.14.1 2001/10/01 12:51:15 dd Exp $ +# $FreeBSD: src/usr.bin/lastcomm/Makefile,v 1.3 2002/02/08 22:31:41 markm Exp $ # $DragonFly: src/usr.bin/lastcomm/Makefile,v 1.4 2007/08/27 16:50:55 pavalos Exp $ PROG= lastcomm diff --git a/usr.bin/lastcomm/lastcomm.1 b/usr.bin/lastcomm/lastcomm.1 index 8c22fe033d..3a36a0585b 100644 --- a/usr.bin/lastcomm/lastcomm.1 +++ b/usr.bin/lastcomm/lastcomm.1 @@ -30,15 +30,15 @@ .\" SUCH DAMAGE. .\" .\" From: @(#)lastcomm.1 8.1 (Berkeley) 6/6/93 -.\" $FreeBSD: src/usr.bin/lastcomm/lastcomm.1,v 1.7.2.4 2002/06/21 15:27:39 charnier Exp $ +.\" $FreeBSD: src/usr.bin/lastcomm/lastcomm.1,v 1.13.8.1 2007/04/18 05:53:50 dds Exp $ .\" $DragonFly: src/usr.bin/lastcomm/lastcomm.1,v 1.3 2008/05/02 02:05:07 swildner Exp $ .\" -.Dd September 18, 1996 +.Dd June 14, 2009 .Dt LASTCOMM 1 .Os .Sh NAME .Nm lastcomm -.Nd show last commands executed in reverse order +.Nd show last commands executed .Sh SYNOPSIS .Nm .Op Fl EScesu @@ -56,8 +56,7 @@ prints information about all the commands recorded during the current accounting file's lifetime. .Pp The following options are available: -.Pp -.Bl -tag -width XXfXfileX -compact +.Bl -tag -width indent .It Fl E Print the time the process exited. .It Fl S @@ -75,6 +74,12 @@ Read from .Ar file rather than the default .Pa /var/account/acct . +If +.Ar file +is a single dash +.Pq Sq \&- +.Nm +reads accounting entries from the standard input. .El .Pp If no options are specified, @@ -102,7 +107,7 @@ executions of commands named by user .Ar root on the terminal -.Ar ttyd0 . +.Ar ttyd0 . .Pp For each process entry, the following are printed. .Pp @@ -140,11 +145,28 @@ a fork, but without a following ``D'' indicates the command terminated with the generation of a .Pa core file, and ``X'' indicates the command was terminated with a signal. +.Pp +By default, accounting entries are printed going backwards in time, +starting from the time +.Nm +was executed. +However, if +.Nm +reads entries from its standard input, then entries are printed in +the order they are read. .Sh FILES .Bl -tag -width /var/account/acct -compact .It Pa /var/account/acct -Default accounting file. +default accounting file .El +.Sh EXAMPLES +The command +.Dl lastcomm -Ee +will print the exit time and elapsed time of each command logged in +.Pa /var/account/acct , +while +.Dl tail -f -c 0 /var/account/acct | lastcomm -f - +will print details of each terminating command. .Sh SEE ALSO .Xr last 1 , .Xr sigvec 2 , diff --git a/usr.bin/lastcomm/lastcomm.c b/usr.bin/lastcomm/lastcomm.c index a5e83e950d..bf67bac61b 100644 --- a/usr.bin/lastcomm/lastcomm.c +++ b/usr.bin/lastcomm/lastcomm.c @@ -32,7 +32,7 @@ * * @(#) Copyright (c) 1980, 1993 The Regents of the University of California. All rights reserved. * @(#)lastcomm.c 8.1 (Berkeley) 6/6/93 - * $FreeBSD: src/usr.bin/lastcomm/lastcomm.c,v 1.10.2.3 2001/10/01 12:51:15 dd Exp $ + * $FreeBSD: src/usr.bin/lastcomm/lastcomm.c,v 1.20.2.1 2007/04/18 05:53:50 dds Exp $ * $DragonFly: src/usr.bin/lastcomm/lastcomm.c,v 1.3 2003/10/04 20:36:47 hmp Exp $ */ @@ -68,13 +68,13 @@ static void usage(void); #define AC_HZ ((double)AHZ) int -main(int argc, char **argv) +main(int argc, char *argv[]) { char *p; struct acct ab; struct stat sb; FILE *fp; - off_t size; + off_t size = 0; time_t t; int ch; const char *acctfile; @@ -96,14 +96,14 @@ main(int argc, char **argv) case 'e': flags |= AC_ETIME; /* elapsed time */ break; - case 'c': + case 'c': flags |= AC_CTIME; /* user + system time */ break; - case 'S': + case 'S': flags |= AC_BTIME; /* starting time */ break; - case 'E': + case 'E': /* exit time (starting time + elapsed time )*/ flags |= AC_FTIME; break; @@ -121,38 +121,40 @@ main(int argc, char **argv) argc -= optind; argv += optind; - /* Open the file. */ - if ((fp = fopen(acctfile, "r")) == NULL || fstat(fileno(fp), &sb)) - err(1, "%s", acctfile); - - /* - * Round off to integral number of accounting records, probably - * not necessary, but it doesn't hurt. - */ - size = sb.st_size - sb.st_size % sizeof(struct acct); - - /* Check if any records to display. */ - if ((unsigned)size < sizeof(struct acct)) - exit(0); - - /* - * Seek to before the last entry in the file; use lseek(2) in case - * the file is bigger than a "long". - */ - size -= sizeof(struct acct); - if (lseek(fileno(fp), size, SEEK_SET) == -1) - err(1, "%s", acctfile); + if (strcmp(acctfile, "-") == 0) + fp = stdin; + else { + /* Open the file. */ + if ((fp = fopen(acctfile, "r")) == NULL || + fstat(fileno(fp), &sb)) + err(1, "could not open %s", acctfile); + + /* + * Round off to integral number of accounting records, + * probably not necessary, but it doesn't hurt. + */ + size = sb.st_size - sb.st_size % sizeof(struct acct); + + /* Check if any records to display. */ + if ((unsigned)size < sizeof(struct acct)) + exit(0); + } - for (;;) { - if (fread(&ab, sizeof(struct acct), 1, fp) != 1) - err(1, "%s", acctfile); + do { + int rv; - if (fseek(fp, 2 * -(long)sizeof(struct acct), SEEK_CUR) == -1) - err(1, "%s", acctfile); + if (fp != stdin) { + size -= sizeof(struct acct); + if (fseeko(fp, size, SEEK_SET) == -1) + err(1, "seek %s failed", acctfile); + } - if (size == 0) - break; - size -= sizeof(struct acct); + if ((rv = fread(&ab, sizeof(struct acct), 1, fp)) != 1) { + if (feof(fp)) + break; + else + err(1, "read %s returned %d", acctfile, rv); + } if (ab.ac_comm[0] == '\0') { ab.ac_comm[0] = '?'; @@ -206,8 +208,9 @@ main(int argc, char **argv) (void)printf(" %.16s", ctime(&t)); } printf("\n"); - } - exit(0); + + } while (size > 0); + exit(0); } time_t @@ -243,7 +246,7 @@ flagbits(int f) } int -requested(char **argv, struct acct *acp) +requested(char *argv[], struct acct *acp) { const char *p; @@ -278,6 +281,6 @@ static void usage(void) { (void)fprintf(stderr, -"usage: lastcomm [-EScesu] [ -f file ] [command ...] [user ...] [tty ...]\n"); +"usage: lastcomm [-EScesu] [-f file] [command ...] [user ...] [terminal ...]\n"); exit(1); }