diff options
author | kib <kib@FreeBSD.org> | 2012-05-17 11:10:13 +0000 |
---|---|---|
committer | kib <kib@FreeBSD.org> | 2012-05-17 11:10:13 +0000 |
commit | 8f04882e813fa954297b81d08c8c32c235b2e7ae (patch) | |
tree | 87c6a7767f29607fb05e55b73994d30ecc853db6 /usr.bin/lastcomm/lastcomm.c | |
parent | 6e55e4c37b1234d85faf78d185ca3eefc6df3a41 (diff) | |
download | FreeBSD-src-8f04882e813fa954297b81d08c8c32c235b2e7ae.zip FreeBSD-src-8f04882e813fa954297b81d08c8c32c235b2e7ae.tar.gz |
Allow to specify strftime(3) format for process start end exit times.
Submitted by: Andrey Zonov <andrey zonov org>
MFC after: 1 week
Diffstat (limited to 'usr.bin/lastcomm/lastcomm.c')
-rw-r--r-- | usr.bin/lastcomm/lastcomm.c | 28 |
1 files changed, 24 insertions, 4 deletions
diff --git a/usr.bin/lastcomm/lastcomm.c b/usr.bin/lastcomm/lastcomm.c index e140c70..b2a0f0f 100644 --- a/usr.bin/lastcomm/lastcomm.c +++ b/usr.bin/lastcomm/lastcomm.c @@ -52,6 +52,7 @@ __FBSDID("$FreeBSD$"); #include <stdio.h> #include <stdlib.h> #include <string.h> +#include <time.h> #include <unistd.h> #include "pathnames.h" @@ -82,10 +83,12 @@ main(int argc, char *argv[]) int (*readrec)(FILE *f, struct acctv2 *av2); time_t t; int ch, rv; - const char *acctfile; + const char *acctfile, *format; + char buf[1024]; int flags = 0; acctfile = _PATH_ACCT; + format = NULL; while ((ch = getopt(argc, argv, "f:usecSE")) != -1) switch((char)ch) { case 'f': @@ -126,6 +129,12 @@ main(int argc, char *argv[]) argc -= optind; argv += optind; + if (argc > 0 && **argv == '+') { + format = *argv + 1; /* skip + */ + argc--; + argv++; + } + if (strcmp(acctfile, "-") == 0) { fp = stdin; readrec = readrec_forward; @@ -177,14 +186,24 @@ main(int argc, char *argv[]) /* starting time */ if (flags & AC_BTIME) { - (void)printf(" %.16s", ctime(&ab.ac_btime)); + if (format != NULL) { + (void)strftime(buf, sizeof(buf), format, + localtime(&ab.ac_btime)); + (void)printf(" %s", buf); + } else + (void)printf(" %.16s", ctime(&ab.ac_btime)); } /* exit time (starting time + elapsed time )*/ if (flags & AC_FTIME) { t = ab.ac_btime; t += (time_t)(ab.ac_etime / 1000000); - (void)printf(" %.16s", ctime(&t)); + if (format != NULL) { + (void)strftime(buf, sizeof(buf), format, + localtime(&t)); + (void)printf(" %s", buf); + } else + (void)printf(" %.16s", ctime(&t)); } printf("\n"); } @@ -250,6 +269,7 @@ static void usage(void) { (void)fprintf(stderr, -"usage: lastcomm [-EScesu] [-f file] [command ...] [user ...] [terminal ...]\n"); + "usage: lastcomm [-EScesu] [-f file] [+format] [command ...] " + "[user ...] [terminal ...]\n"); exit(1); } |