From m.seaman@infracaninophile.co.uk  Fri Jun  8 10:53:15 2012
Return-Path: <m.seaman@infracaninophile.co.uk>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id 390331065670
	for <FreeBSD-gnats-submit@freebsd.org>; Fri,  8 Jun 2012 10:53:15 +0000 (UTC)
	(envelope-from m.seaman@infracaninophile.co.uk)
Received: from smtp.infracaninophile.co.uk (smtp6.infracaninophile.co.uk [IPv6:2001:8b0:151:1:3cd3:cd67:fafa:3d78])
	by mx1.freebsd.org (Postfix) with ESMTP id B6AE88FC08
	for <FreeBSD-gnats-submit@freebsd.org>; Fri,  8 Jun 2012 10:53:14 +0000 (UTC)
Received: from lucid-nonsense.infracaninophile.co.uk (localhost [IPv6:::1])
	by smtp.infracaninophile.co.uk (8.14.5/8.14.5) with ESMTP id q58Ar6iV046317
	for <FreeBSD-gnats-submit@freebsd.org>; Fri, 8 Jun 2012 11:53:06 +0100 (BST)
	(envelope-from matthew@lucid-nonsense.infracaninophile.co.uk)
Received: (from matthew@localhost)
	by lucid-nonsense.infracaninophile.co.uk (8.14.5/8.14.5/Submit) id q58Ar6GJ046316;
	Fri, 8 Jun 2012 11:53:06 +0100 (BST)
	(envelope-from matthew)
Message-Id: <201206081053.q58Ar6GJ046316@lucid-nonsense.infracaninophile.co.uk>
Date: Fri, 8 Jun 2012 11:53:06 +0100 (BST)
From: Matthew Seaman <matthew@freebsd.org>
Reply-To: Matthew Seaman <matthew@freebsd.org>
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: [patch] last(1) doesn't show reboot times with struct utmpx
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         168844
>Category:       bin
>Synopsis:       [patch] last(1) doesn't show reboot times with struct utmpx
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    ed
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Fri Jun 08 11:00:29 UTC 2012
>Closed-Date:    
>Last-Modified:  Sun Jul 01 18:02:32 CEST 2012
>Originator:     Matthew Seaman
>Release:        FreeBSD 9.0-STABLE amd64
>Organization:
>Environment:
System: FreeBSD lucid-nonsense.infracaninophile.co.uk 9.0-STABLE FreeBSD 9.0-STABLE #15 r236465: Sat Jun 2 23:14:59 BST 2012 root@lucid-nonsense.infracaninophile.co.uk:/usr/obj/usr/src/sys/LUCID-NONSENSE amd64


	
>Description:

last(1) when invoked as 'last reboot' should show the time and date of
reboots.  As the man page says:

     The pseudo-user reboot logs in at reboots of the system, thus ``last
     reboot'' will give an indication of mean time between reboot.

However, with the switch from /var/log/wtmp to /var/log/utx.log this
functionality no longer works.

>How-To-Repeat:

I last rebooted about 3 days ago:

lucid-nonsense:~/work:%	uptime
11:47AM  up 3 days, 12:51, 1 user, load averages: 0.05, 0.03, 0.00

... and utx.log hasn't been recycled during that time:

lucid-nonsense:~/work:%	   ls -l /var/log/utx.log*
-rw-r--r--  1 root  wheel  17047 Jun  8 11:41 /var/log/utx.log
-rw-r--r--  1 root  wheel  24878 May 31 22:41 /var/log/utx.log.0
-rw-r--r--  1 root  wheel  13741 Apr 30 08:50 /var/log/utx.log.1
-rw-r--r--  1 root  wheel  27886 Mar 31 22:52 /var/log/utx.log.2

but no information about system reboots is shown by 'last reboot'

lucid-nonsense:~/work:%	   last reboot

wtmp begins Fri Jun  1 06:14:46 BST 2012

With the patch below, the result is:

lucid-nonsense:~/work:%	  /usr/obj/usr/src/usr.bin/last/last reboot
boot time                                  Mon Jun  4 22:58
shutdown time                              Mon Jun  4 22:54
boot time                                  Sun Jun  3 09:43
shutdown time                              Sun Jun  3 09:39

wtmp begins Fri Jun  1 06:14:46 BST 2012

>Fix:

	

--- last.diff begins here ---
Index: usr.bin/last/last.c
===================================================================
--- usr.bin/last/last.c	(revision 236465)
+++ usr.bin/last/last.c	(working copy)
@@ -64,6 +64,7 @@
 
 typedef struct arg {
 	char	*name;				/* argument */
+#define	REBOOT_TYPE	-1
 #define	HOST_TYPE	-2
 #define	TTY_TYPE	-3
 #define	USER_TYPE	-4
@@ -180,6 +181,8 @@
 	if (argc) {
 		setlinebuf(stdout);
 		for (argv += optind; *argv; ++argv) {
+			if (strcmp(*argv, "reboot") == 0)
+				addarg(REBOOT_TYPE, *argv);
 #define	COMPATIBILITY
 #ifdef	COMPATIBILITY
 			/* code to allow "last p5" to work */
@@ -391,6 +394,11 @@
 
 	for (step = arglist; step; step = step->next)
 		switch(step->type) {
+		case REBOOT_TYPE:
+			if (bp->ut_type == BOOT_TIME ||
+			    bp->ut_type == SHUTDOWN_TIME)
+				return (YES);
+			break;
 		case HOST_TYPE:
 			if (!strcasecmp(step->name, bp->ut_host))
 				return (YES);
--- last.diff ends here ---


>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->ed 
Responsible-Changed-By: ed 
Responsible-Changed-When: Sun Jul 1 18:02:23 CEST 2012 
Responsible-Changed-Why:  
I'll take it. 


http://www.freebsd.org/cgi/query-pr.cgi?pr=168844 
>Unformatted:
