diff options
author | ed <ed@FreeBSD.org> | 2012-02-11 21:49:23 +0000 |
---|---|---|
committer | ed <ed@FreeBSD.org> | 2012-02-11 21:49:23 +0000 |
commit | fbfd1ac8bcebefee6a59b357000a5c226311fe1a (patch) | |
tree | c883665f1510635a0138b03c67dd17d7d59f45b9 | |
parent | 0458d57ea3cd173f7a4e71d67ee628f844dbdd70 (diff) | |
download | FreeBSD-src-fbfd1ac8bcebefee6a59b357000a5c226311fe1a.zip FreeBSD-src-fbfd1ac8bcebefee6a59b357000a5c226311fe1a.tar.gz |
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.
-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 aadee18..d4e0da9 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 18467f3..18b866d 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; |