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.
This commit is contained in:
Ed Schouten 2012-02-11 21:49:23 +00:00
parent c0b3cf0676
commit 79625d00a2
2 changed files with 16 additions and 22 deletions

View File

@ -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

View File

@ -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,25 +227,13 @@ 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)
{