Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.bin/lastcomm PR/45897: Takahiro Kambe: Make default disp...
details: https://anonhg.NetBSD.org/src/rev/8ace044383b2
branches: trunk
changeset: 773342:8ace044383b2
user: christos <christos%NetBSD.org@localhost>
date: Tue Jan 31 16:30:40 2012 +0000
description:
PR/45897: Takahiro Kambe: Make default display < 80 characters and add -w flag
to display unlimited
diffstat:
usr.bin/lastcomm/lastcomm.1 | 7 ++-
usr.bin/lastcomm/lastcomm.c | 92 ++++++++++++++++++++++----------------------
2 files changed, 51 insertions(+), 48 deletions(-)
diffs (235 lines):
diff -r 45d59d8892a1 -r 8ace044383b2 usr.bin/lastcomm/lastcomm.1
--- a/usr.bin/lastcomm/lastcomm.1 Tue Jan 31 13:25:05 2012 +0000
+++ b/usr.bin/lastcomm/lastcomm.1 Tue Jan 31 16:30:40 2012 +0000
@@ -1,4 +1,4 @@
-.\" $NetBSD: lastcomm.1,v 1.11 2006/12/22 08:00:20 ad Exp $
+.\" $NetBSD: lastcomm.1,v 1.12 2012/01/31 16:30:40 christos Exp $
.\"
.\" Copyright (c) 1980, 1990, 1993
.\" The Regents of the University of California. All rights reserved.
@@ -29,7 +29,7 @@
.\"
.\" @(#)lastcomm.1 8.1 (Berkeley) 6/6/93
.\"
-.Dd December 22, 2006
+.Dd January 31, 2012
.Dt LASTCOMM 1
.Os
.Sh NAME
@@ -37,6 +37,7 @@
.Nd show last commands executed in reverse order
.Sh SYNOPSIS
.Nm
+.Op Fl w
.Op Fl f Ar file
.Op Ar command ...
.Op Ar user ...
@@ -57,6 +58,8 @@
.Ar file
rather than the default
accounting file.
+.It Fl w
+Use as many columns as needed to print the output instead of limiting it to 80.
.El
.Pp
If called with arguments, only accounting entries with a
diff -r 45d59d8892a1 -r 8ace044383b2 usr.bin/lastcomm/lastcomm.c
--- a/usr.bin/lastcomm/lastcomm.c Tue Jan 31 13:25:05 2012 +0000
+++ b/usr.bin/lastcomm/lastcomm.c Tue Jan 31 16:30:40 2012 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: lastcomm.c,v 1.21 2009/04/12 13:08:31 lukem Exp $ */
+/* $NetBSD: lastcomm.c,v 1.22 2012/01/31 16:30:40 christos Exp $ */
/*
* Copyright (c) 1980, 1993
@@ -39,7 +39,7 @@
#if 0
static char sccsid[] = "@(#)lastcomm.c 8.2 (Berkeley) 4/29/95";
#endif
-__RCSID("$NetBSD: lastcomm.c,v 1.21 2009/04/12 13:08:31 lukem Exp $");
+__RCSID("$NetBSD: lastcomm.c,v 1.22 2012/01/31 16:30:40 christos Exp $");
#endif /* not lint */
#include <sys/param.h>
@@ -64,11 +64,9 @@
static time_t expand(u_int);
static char *flagbits(int);
static const char *getdev(dev_t);
-static int requested(char *[], struct acct *);
+static int requested(char *[], const struct acct *);
static void usage(void) __dead;
-int main(int, char **);
-
int
main(int argc, char *argv[])
{
@@ -79,16 +77,21 @@
off_t size;
time_t t;
double delta;
- int ch;
+ int ch, wflag, lwidth;
const char *acctfile = _PATH_ACCT;
setprogname(argv[0]);
+ wflag = 0;
+ lwidth = -6;
- while ((ch = getopt(argc, argv, "f:")) != -1)
+ while ((ch = getopt(argc, argv, "f:w")) != -1)
switch((char)ch) {
case 'f':
acctfile = optarg;
break;
+ case 'w':
+ wflag = 1;
+ break;
case '?':
default:
usage();
@@ -104,22 +107,19 @@
* 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);
+ size = sb.st_size - sb.st_size % sizeof(ab);
/* Check if any records to display. */
- if (size < (off_t)sizeof(struct acct))
- exit(0);
+ if (size < (off_t)sizeof(ab))
+ return 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)
+ size -= sizeof(ab);
+ if (fseeko(fp, size, SEEK_SET) == -1)
err(1, "%s", acctfile);
+ lwidth = (int)fldsiz(acct, ac_comm) - ((wflag)? 0: 6);
for (;;) {
- if (fread(&ab, sizeof(struct acct), 1, fp) != 1)
+ if (fread(&ab, sizeof(ab), 1, fp) != 1)
err(1, "%s", acctfile);
if (ab.ac_comm[0] == '\0') {
@@ -132,32 +132,33 @@
*p = '?';
if (!*argv || requested(argv, &ab)) {
+ if (!wflag)
+ ab.ac_comm[10] = '\0';
t = expand(ab.ac_utime) + expand(ab.ac_stime);
(void)printf(
"%-*.*s %-7s %-*.*s %-*.*s %6.2f secs %.16s",
- (int)fldsiz(acct, ac_comm),
- (int)fldsiz(acct, ac_comm),
- ab.ac_comm, flagbits(ab.ac_flag),
- UT_NAMESIZE, UT_NAMESIZE,
- user_from_uid(ab.ac_uid, 0), UT_LINESIZE,
- UT_LINESIZE, getdev(ab.ac_tty),
- t / (double)AHZ, ctime(&ab.ac_btime));
+ lwidth, lwidth,
+ ab.ac_comm, flagbits(ab.ac_flag),
+ UT_NAMESIZE, UT_NAMESIZE,
+ user_from_uid(ab.ac_uid, 0), UT_LINESIZE,
+ UT_LINESIZE, getdev(ab.ac_tty),
+ t / (double)AHZ, ctime(&ab.ac_btime));
delta = expand(ab.ac_etime) / (double)AHZ;
- printf(" (%1.0f:%02.0f:%05.2f)\n",
- floor(delta / SECSPERHOUR),
- floor(fmod(delta, SECSPERHOUR) / SECSPERMIN),
- fmod(delta, SECSPERMIN));
+ (void)printf(" (%1.0f:%02.0f:%05.2f)\n",
+ floor(delta / SECSPERHOUR),
+ floor(fmod(delta, SECSPERHOUR) / SECSPERMIN),
+ fmod(delta, SECSPERMIN));
}
/* are we at the beginning of the file yet? */
if (size == 0)
break;
/* seek backward over the one we read and the next to read */
- if (fseek(fp, 2 * -(long)sizeof(struct acct), SEEK_CUR) == -1)
+ if (fseeko(fp, 2 * -(off_t)sizeof(ab), SEEK_CUR) == -1)
err(1, "%s", acctfile);
/* and account for its size */
- size -= sizeof(struct acct);
+ size -= sizeof(ab);
}
- exit(0);
+ return 0;
}
static time_t
@@ -171,7 +172,7 @@
t--;
nt <<= 3;
}
- return (nt);
+ return nt;
}
static char *
@@ -189,44 +190,43 @@
BIT(ACORE, 'D');
BIT(AXSIG, 'X');
*p = '\0';
- return (flags);
+ return flags;
}
static int
-requested(char *argv[], struct acct *acp)
+requested(char *argv[], const struct acct *acp)
{
do {
if (!strcmp(user_from_uid(acp->ac_uid, 0), *argv))
- return (1);
+ return 1;
if (!strcmp(getdev(acp->ac_tty), *argv))
- return (1);
+ return 1;
if (!strncmp(acp->ac_comm, *argv, fldsiz(acct, ac_comm)))
- return (1);
+ return 1;
} while (*++argv);
- return (0);
+ return 0;
}
static const char *
getdev(dev_t dev)
{
- static dev_t lastdev = (dev_t)-1;
+ static dev_t lastdev = NODEV;
static const char *lastname;
if (dev == NODEV) /* Special case. */
- return ("__");
+ return "__";
if (dev == lastdev) /* One-element cache. */
- return (lastname);
- lastdev = dev;
- if ((lastname = devname(dev, S_IFCHR)) == NULL)
- lastname = "??";
- return (lastname);
+ return lastname;
+ if ((lastname = devname(dev, S_IFCHR)) != NULL)
+ return lastname;
+ return "??";
}
static void
usage(void)
{
(void)fprintf(stderr,
- "Usage: %s [ -f file ] [command ...] [user ...] [tty ...]\n",
+ "Usage: %s [ -f file ] [-w] [command ...] [user ...] [tty ...]\n",
getprogname());
exit(1);
}
Home |
Main Index |
Thread Index |
Old Index