Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 11 Feb 2012 21:49:24 +0000 (UTC)
From:      Ed Schouten <ed@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r231536 - head/usr.bin/who
Message-ID:  <201202112149.q1BLnOfT049510@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: ed
Date: Sat Feb 11 21:49:23 2012
New Revision: 231536
URL: http://svn.freebsd.org/changeset/base/231536

Log:
  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.

Modified:
  head/usr.bin/who/who.1
  head/usr.bin/who/who.c

Modified: head/usr.bin/who/who.1
==============================================================================
--- head/usr.bin/who/who.1	Sat Feb 11 21:06:45 2012	(r231535)
+++ head/usr.bin/who/who.1	Sat Feb 11 21:49:23 2012	(r231536)
@@ -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

Modified: head/usr.bin/who/who.c
==============================================================================
--- head/usr.bin/who/who.c	Sat Feb 11 21:06:45 2012	(r231535)
+++ head/usr.bin/who/who.c	Sat Feb 11 21:49:23 2012	(r231536)
@@ -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;



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201202112149.q1BLnOfT049510>