diff options
author | Ed Schouten <ed@FreeBSD.org> | 2012-02-11 21:49:23 +0000 |
---|---|---|
committer | Ed Schouten <ed@FreeBSD.org> | 2012-02-11 21:49:23 +0000 |
commit | 79625d00a29291807039192671e0dee5020e43d8 (patch) | |
tree | c883665f1510635a0138b03c67dd17d7d59f45b9 /usr.bin/who | |
parent | c0b3cf0676b6dbfa5c9f580af9f083eb0c0263f2 (diff) |
Attempt to implement who -a.
According to POSIX, -a is equal to -bdlprtTu. It seems this is not true
in practice, as -b normally restricts the output to BOOT_TIME entries
and all implementations that I know of don't.
Notes
Notes:
svn path=/head/; revision=231536
Diffstat (limited to 'usr.bin/who')
-rw-r--r-- | usr.bin/who/who.1 | 9 | ||||
-rw-r--r-- | usr.bin/who/who.c | 29 |
2 files changed, 16 insertions, 22 deletions
diff --git a/usr.bin/who/who.1 b/usr.bin/who/who.1 index aadee185b74d..d4e0da937957 100644 --- a/usr.bin/who/who.1 +++ b/usr.bin/who/who.1 @@ -28,7 +28,7 @@ .\" @(#)who.1 8.2 (Berkeley) 12/30/93 .\" $FreeBSD$ .\" -.Dd Oct 28, 2011 +.Dd February 11, 2012 .Dt WHO 1 .Os .Sh NAME @@ -36,7 +36,7 @@ .Nd display who is on the system .Sh SYNOPSIS .Nm -.Op Fl bHmqsTu +.Op Fl abHmqsTu .Op Cm am I .Op Ar file .Sh DESCRIPTION @@ -48,6 +48,11 @@ remote hostname if not local. .Pp The options are as follows: .Bl -tag -width indent +.It Fl a +Equivalent to +.Fl bTu , +with the exception that output isn't restricted to the time and date of +the last system reboot. .It Fl b Write the time and date of the last system reboot. .It Fl H diff --git a/usr.bin/who/who.c b/usr.bin/who/who.c index 18467f3c5a24..18b866d2c59a 100644 --- a/usr.bin/who/who.c +++ b/usr.bin/who/who.c @@ -48,7 +48,6 @@ __FBSDID("$FreeBSD$"); #include <utmpx.h> static void heading(void); -static void boottime(void); static void process_utmp(void); static void quick(void); static void row(const struct utmpx *); @@ -57,6 +56,7 @@ static void usage(void); static void whoami(void); static int Hflag; /* Write column headings */ +static int aflag; /* Print all entries */ static int bflag; /* Show date of the last reboot */ static int mflag; /* Show info about current terminal */ static int qflag; /* "Quick" mode */ @@ -71,7 +71,7 @@ main(int argc, char *argv[]) setlocale(LC_TIME, ""); - while ((ch = getopt(argc, argv, "HTbmqsu")) != -1) { + while ((ch = getopt(argc, argv, "HTabmqsu")) != -1) { switch (ch) { case 'H': /* Write column headings */ Hflag = 1; @@ -79,6 +79,9 @@ main(int argc, char *argv[]) case 'T': /* Show terminal state */ Tflag = 1; break; + case 'a': /* Same as -bdlprtTu */ + aflag = bflag = Tflag = uflag = 1; + break; case 'b': /* Show date of the last reboot */ bflag = 1; break; @@ -126,8 +129,6 @@ main(int argc, char *argv[]) heading(); if (mflag) whoami(); - else if (bflag) - boottime(); else process_utmp(); } @@ -226,26 +227,14 @@ process_utmp(void) struct utmpx *utx; while ((utx = getutxent()) != NULL) { - if (utx->ut_type != USER_PROCESS) - continue; - if (ttystat(utx->ut_line) != 0) - continue; - row(utx); + if (((aflag || !bflag) && utx->ut_type == USER_PROCESS) || + (bflag && utx->ut_type == BOOT_TIME)) + if (ttystat(utx->ut_line) == 0) + row(utx); } } static void -boottime(void) -{ - struct utmpx u1, *u2; - - u1.ut_type = BOOT_TIME; - if ((u2 = getutxid(&u1)) == NULL) - return; - row(u2); -} - -static void quick(void) { struct utmpx *utx; |