From owner-svn-src-all@FreeBSD.ORG Thu May 24 09:11:39 2012 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 83E2E1065670; Thu, 24 May 2012 09:11:39 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 6D0448FC0C; Thu, 24 May 2012 09:11:39 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.4/8.14.4) with ESMTP id q4O9BdDN026974; Thu, 24 May 2012 09:11:39 GMT (envelope-from kib@svn.freebsd.org) Received: (from kib@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id q4O9BdUw026971; Thu, 24 May 2012 09:11:39 GMT (envelope-from kib@svn.freebsd.org) Message-Id: <201205240911.q4O9BdUw026971@svn.freebsd.org> From: Konstantin Belousov Date: Thu, 24 May 2012 09:11:39 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-8@freebsd.org X-SVN-Group: stable-8 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r235888 - stable/8/usr.bin/lastcomm X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 24 May 2012 09:11:39 -0000 Author: kib Date: Thu May 24 09:11:38 2012 New Revision: 235888 URL: http://svn.freebsd.org/changeset/base/235888 Log: MFC r235541: Allow to specify strftime(3) format for process start end exit times. Modified: stable/8/usr.bin/lastcomm/lastcomm.1 stable/8/usr.bin/lastcomm/lastcomm.c Directory Properties: stable/8/usr.bin/lastcomm/ (props changed) Modified: stable/8/usr.bin/lastcomm/lastcomm.1 ============================================================================== --- stable/8/usr.bin/lastcomm/lastcomm.1 Thu May 24 08:43:10 2012 (r235887) +++ stable/8/usr.bin/lastcomm/lastcomm.1 Thu May 24 09:11:38 2012 (r235888) @@ -32,7 +32,7 @@ .\" From: @(#)lastcomm.1 8.1 (Berkeley) 6/6/93 .\" $FreeBSD$ .\" -.Dd May 14, 2007 +.Dd May 17, 2012 .Dt LASTCOMM 1 .Os .Sh NAME @@ -42,6 +42,7 @@ .Nm .Op Fl EScesu .Op Fl f Ar file +.Op Cm + Ns Ar format .Op Ar command ...\& .Op Ar user ...\& .Op Ar terminal ...\& @@ -81,6 +82,15 @@ is a single dash reads accounting entries from the standard input. .El .Pp +An operand with a leading plus sign +.Pq Sq + +is followed a user-defined format string which specifies the format +in which to display the process's start or exit date and time. +The format string may contain any of the conversion specifications +described in the +.Xr strftime 3 +manual page, as well as arbitrary text. +.Pp If no options are specified, .Fl cS is assumed. @@ -169,6 +179,7 @@ will print details of each terminating c .Sh SEE ALSO .Xr last 1 , .Xr sigaction 2 , +.Xr strftime 3 , .Xr acct 5 , .Xr core 5 .Sh HISTORY Modified: stable/8/usr.bin/lastcomm/lastcomm.c ============================================================================== --- stable/8/usr.bin/lastcomm/lastcomm.c Thu May 24 08:43:10 2012 (r235887) +++ stable/8/usr.bin/lastcomm/lastcomm.c Thu May 24 09:11:38 2012 (r235888) @@ -56,6 +56,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include #include "pathnames.h" @@ -87,10 +88,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': @@ -131,6 +134,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; @@ -182,14 +191,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"); } @@ -255,6 +274,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); }