From owner-svn-src-all@FreeBSD.ORG Fri Oct 28 12:47:37 2011 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id D39B2106564A; Fri, 28 Oct 2011 12:47:37 +0000 (UTC) (envelope-from pluknet@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id B9D5C8FC08; Fri, 28 Oct 2011 12:47:37 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.4/8.14.4) with ESMTP id p9SClba5061057; Fri, 28 Oct 2011 12:47:37 GMT (envelope-from pluknet@svn.freebsd.org) Received: (from pluknet@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id p9SClb9u061054; Fri, 28 Oct 2011 12:47:37 GMT (envelope-from pluknet@svn.freebsd.org) Message-Id: <201110281247.p9SClb9u061054@svn.freebsd.org> From: Sergey Kandaurov Date: Fri, 28 Oct 2011 12:47:37 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r226881 - head/usr.bin/who X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 28 Oct 2011 12:47:38 -0000 Author: pluknet Date: Fri Oct 28 12:47:37 2011 New Revision: 226881 URL: http://svn.freebsd.org/changeset/base/226881 Log: 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 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 Fri Oct 28 11:45:24 2011 (r226880) +++ head/usr.bin/who/who.1 Fri Oct 28 12:47:37 2011 (r226881) @@ -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 Modified: head/usr.bin/who/who.c ============================================================================== --- head/usr.bin/who/who.c Fri Oct 28 11:45:24 2011 (r226880) +++ head/usr.bin/who/who.c Fri Oct 28 12:47:37 2011 (r226881) @@ -48,14 +48,16 @@ __FBSDID("$FreeBSD$"); #include 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;