summaryrefslogtreecommitdiffstats
path: root/usr.bin/who
diff options
context:
space:
mode:
authorpluknet <pluknet@FreeBSD.org>2011-10-28 12:47:37 +0000
committerpluknet <pluknet@FreeBSD.org>2011-10-28 12:47:37 +0000
commite43df010f926df8b6b55d562c7ed2d96f4acc5fc (patch)
tree5c534d2d89a4c193cba9178c987adfba369f216f /usr.bin/who
parent97fe037955ae3ed7129ea7459805ae3b946315c3 (diff)
downloadFreeBSD-src-e43df010f926df8b6b55d562c7ed2d96f4acc5fc.zip
FreeBSD-src-e43df010f926df8b6b55d562c7ed2d96f4acc5fc.tar.gz
Add the XSI option -b to show date of the last reboot.
That required to increase the LINE field to fit the output of -b. While here, change the row() function to take a const argument. In collaboration with: ed
Diffstat (limited to 'usr.bin/who')
-rw-r--r--usr.bin/who/who.16
-rw-r--r--usr.bin/who/who.c33
2 files changed, 31 insertions, 8 deletions
diff --git a/usr.bin/who/who.1 b/usr.bin/who/who.1
index 8a40396..aadee18 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 May 8, 2002
+.Dd Oct 28, 2011
.Dt WHO 1
.Os
.Sh NAME
@@ -36,7 +36,7 @@
.Nd display who is on the system
.Sh SYNOPSIS
.Nm
-.Op Fl HmqsTu
+.Op Fl bHmqsTu
.Op Cm am I
.Op Ar file
.Sh DESCRIPTION
@@ -48,6 +48,8 @@ remote hostname if not local.
.Pp
The options are as follows:
.Bl -tag -width indent
+.It Fl b
+Write the time and date of the last system reboot.
.It Fl H
Write column headings above the output.
.It Fl m
diff --git a/usr.bin/who/who.c b/usr.bin/who/who.c
index d6f38dd..18467f3 100644
--- a/usr.bin/who/who.c
+++ b/usr.bin/who/who.c
@@ -48,14 +48,16 @@ __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(struct utmpx *);
+static void row(const struct utmpx *);
static int ttywidth(void);
static void usage(void);
static void whoami(void);
static int Hflag; /* Write column headings */
+static int bflag; /* Show date of the last reboot */
static int mflag; /* Show info about current terminal */
static int qflag; /* "Quick" mode */
static int sflag; /* Show name, line, time */
@@ -69,7 +71,7 @@ main(int argc, char *argv[])
setlocale(LC_TIME, "");
- while ((ch = getopt(argc, argv, "HTmqsu")) != -1) {
+ while ((ch = getopt(argc, argv, "HTbmqsu")) != -1) {
switch (ch) {
case 'H': /* Write column headings */
Hflag = 1;
@@ -77,6 +79,9 @@ main(int argc, char *argv[])
case 'T': /* Show terminal state */
Tflag = 1;
break;
+ case 'b': /* Show date of the last reboot */
+ bflag = 1;
+ break;
case 'm': /* Show info about current terminal */
mflag = 1;
break;
@@ -121,6 +126,8 @@ main(int argc, char *argv[])
heading();
if (mflag)
whoami();
+ else if (bflag)
+ boottime();
else
process_utmp();
}
@@ -134,7 +141,7 @@ static void
usage(void)
{
- fprintf(stderr, "usage: who [-HmqsTu] [am I] [file]\n");
+ fprintf(stderr, "usage: who [-bHmqsTu] [am I] [file]\n");
exit(1);
}
@@ -145,14 +152,14 @@ heading(void)
printf("%-16s ", "NAME");
if (Tflag)
printf("S ");
- printf("%-8s %-12s ", "LINE", "TIME");
+ printf("%-12s %-12s ", "LINE", "TIME");
if (uflag)
printf("IDLE ");
printf("%-16s\n", "FROM");
}
static void
-row(struct utmpx *ut)
+row(const struct utmpx *ut)
{
char buf[80], tty[PATH_MAX];
struct stat sb;
@@ -178,7 +185,10 @@ row(struct utmpx *ut)
printf("%-16s ", ut->ut_user);
if (Tflag)
printf("%c ", state);
- printf("%-8s ", ut->ut_line);
+ if (ut->ut_type == BOOT_TIME)
+ printf("%-12s ", "system boot");
+ else
+ printf("%-12s ", ut->ut_line);
t = ut->ut_tv.tv_sec;
tm = localtime(&t);
strftime(buf, sizeof(buf), d_first ? "%e %b %R" : "%b %e %R", tm);
@@ -225,6 +235,17 @@ process_utmp(void)
}
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;
OpenPOWER on IntegriCloud