diff options
author | dds <dds@FreeBSD.org> | 2007-04-18 08:55:54 +0000 |
---|---|---|
committer | dds <dds@FreeBSD.org> | 2007-04-18 08:55:54 +0000 |
commit | c7e7d9561a6743e70667d899ed0b8e9adb997d27 (patch) | |
tree | cbdda052d9e79817f0493d37623bf1ebb4a1887e /usr.bin/lastcomm | |
parent | f3971f41d35f40951fdd1d21a978ac5c2ca5beff (diff) | |
download | FreeBSD-src-c7e7d9561a6743e70667d899ed0b8e9adb997d27.zip FreeBSD-src-c7e7d9561a6743e70667d899ed0b8e9adb997d27.tar.gz |
Add export capability through the new -w flag.
Discussed in: -arch
MFC after: 8 days
Diffstat (limited to 'usr.bin/lastcomm')
-rw-r--r-- | usr.bin/lastcomm/lastcomm.1 | 17 | ||||
-rw-r--r-- | usr.bin/lastcomm/lastcomm.c | 47 |
2 files changed, 57 insertions, 7 deletions
diff --git a/usr.bin/lastcomm/lastcomm.1 b/usr.bin/lastcomm/lastcomm.1 index 8ce6c8a..22a37d2 100644 --- a/usr.bin/lastcomm/lastcomm.1 +++ b/usr.bin/lastcomm/lastcomm.1 @@ -32,7 +32,7 @@ .\" From: @(#)lastcomm.1 8.1 (Berkeley) 6/6/93 .\" $FreeBSD$ .\" -.Dd April 4, 2007 +.Dd April 18, 2007 .Dt LASTCOMM 1 .Os .Sh NAME @@ -40,7 +40,11 @@ .Nd show last commands executed .Sh SYNOPSIS .Nm +.Oo .Op Fl EScesu +| +.Op Fl w +.Oc .Op Fl f Ar file .Op Ar command ...\& .Op Ar user ...\& @@ -68,6 +72,17 @@ Print the amount of elapsed time used by the process. Print the amount of system time used by the process. .It Fl u Print the amount of user time used by the process. +.It Fl w +Write out the complete contents of each accounting record in a text format +that can be parsed by programs. +The elements are written in the order defined in +.Xr acct 5 . +Time intervals are printed in seconds using the C +.Xr printf 3 +.Ql %g +format specifier, +the starting time is printed in seconds since the epoch, +and the various identifiers are printed using their symbolic names. .It Fl f Ar file Read from .Ar file diff --git a/usr.bin/lastcomm/lastcomm.c b/usr.bin/lastcomm/lastcomm.c index c513aec..4218858 100644 --- a/usr.bin/lastcomm/lastcomm.c +++ b/usr.bin/lastcomm/lastcomm.c @@ -67,6 +67,7 @@ char *flagbits(int); const char *getdev(dev_t); int requested(char *[], struct acct *); static void usage(void); +static void write_record(struct acct *acp); #define AC_UTIME 1 /* user */ #define AC_STIME 2 /* system */ @@ -90,17 +91,20 @@ main(int argc, char *argv[]) int ch; const char *acctfile; int flags = 0; + int write_text = 0; acctfile = _PATH_ACCT; - while ((ch = getopt(argc, argv, "f:usecSE")) != -1) + while ((ch = getopt(argc, argv, "f:uwsecSE")) != -1) switch((char)ch) { case 'f': acctfile = optarg; break; - case 'u': flags |= AC_UTIME; /* user time */ break; + case 'w': + write_text = 1; /* user time */ + break; case 's': flags |= AC_STIME; /* system time */ break; @@ -125,9 +129,11 @@ main(int argc, char *argv[]) } /* default user + system time and starting time */ - if (!flags) { + if (!flags && !write_text) flags = AC_CTIME | AC_BTIME; - } + + if (flags && write_text) + usage(); argc -= optind; argv += optind; @@ -154,7 +160,7 @@ main(int argc, char *argv[]) do { int rv; - if (fp != stdin) { + if (fp != stdin && !write_text) { size -= sizeof(struct acct); if (fseeko(fp, size, SEEK_SET) == -1) err(1, "seek %s failed", acctfile); @@ -178,6 +184,11 @@ main(int argc, char *argv[]) if (*argv && !requested(argv, &ab)) continue; + if (write_text) { + write_record(&ab); + continue; + } + (void)printf("%-*.*s %-7s %-*s %-*s", AC_COMM_LEN, AC_COMM_LEN, ab.ac_comm, flagbits(ab.ac_flag), @@ -292,6 +303,30 @@ static void usage(void) { (void)fprintf(stderr, -"usage: lastcomm [-EScesu] [-f file] [command ...] [user ...] [terminal ...]\n"); +"usage: lastcomm [[-EScesu] | [-w]] [-f file] [command ...] [user ...] [terminal ...]\n"); exit(1); } + +static void +write_record(struct acct *acp) +{ + (void)printf("%s %g %g %g", + acp->ac_comm, + expand(acp->ac_utime) / AC_HZ, + expand(acp->ac_stime) / AC_HZ, + expand(acp->ac_etime) / AC_HZ); + + /* See if time_t is signed and use appropriate format. */ + if ((time_t)-1 < 0) + (void)printf(" %ld", (long)(acp->ac_btime)); + else + (void)printf(" %lu", (unsigned long)(acp->ac_btime)); + + (void)printf(" %s %s %d %g %s %s\n", + user_from_uid(acp->ac_uid, 0), + group_from_gid(acp->ac_gid, 0), + acp->ac_mem, + expand(acp->ac_io) / AC_HZ, + getdev(acp->ac_tty), + flagbits(acp->ac_flag)); +} |