Bug 168844 - [patch] last(1) doesn't show reboot times with struct utmpx
Summary: [patch] last(1) doesn't show reboot times with struct utmpx
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: 9.0-STABLE
Hardware: Any Any
: Normal Affects Only Me
Assignee: Ed Schouten
URL:
Keywords:
: 183962 (view as bug list)
Depends on:
Blocks:
 
Reported: 2012-06-08 12:00 UTC by Matthew Seaman
Modified: 2015-08-20 08:35 UTC (History)
2 users (show)

See Also:


Attachments
last.diff (898 bytes, patch)
2012-06-08 12:00 UTC, Matthew Seaman
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Matthew Seaman freebsd_committer freebsd_triage 2012-06-08 12:00:29 UTC
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
Comment 1 Ed Schouten freebsd_committer freebsd_triage 2012-07-01 17:02:23 UTC
Responsible Changed
From-To: freebsd-bugs->ed

I'll take it.
Comment 2 Jilles Tjoelker freebsd_committer freebsd_triage 2015-03-31 21:23:01 UTC
Linux and Solaris put "reboot" in the username field for BOOT_TIME and SHUTDOWN_TIME at least, the type of event going into a different field. This may not be strictly necessary, but makes it such that the man page text remains correct. The attached patch only makes "reboot" special as a filter.

The patch looks good to me otherwise.
Comment 3 Jilles Tjoelker freebsd_committer freebsd_triage 2015-03-31 21:25:00 UTC
*** Bug 183962 has been marked as a duplicate of this bug. ***
Comment 4 commit-hook freebsd_committer freebsd_triage 2015-07-21 10:52:17 UTC
A commit references this bug:

Author: ed
Date: Tue Jul 21 10:52:07 UTC 2015
New revision: 285742
URL: https://svnweb.freebsd.org/changeset/base/285742

Log:
  Unbreak "last reboot".

  According to the last(1) man page, the "reboot" pseudo-user should print
  all system reboot entries. This got broken by the utmpx import, as
  records are typed.

  Re-add support for "last reboot" by specifically matching against
  SHUTDOWN_TIME and BOOT_TIME records.

  PR:		168844
  Submitted by:	matthew@
  MFC after:	1 month

Changes:
  head/usr.bin/last/last.c
Comment 5 commit-hook freebsd_committer freebsd_triage 2015-08-20 08:35:11 UTC
A commit references this bug:

Author: ed
Date: Thu Aug 20 08:34:14 UTC 2015
New revision: 286952
URL: https://svnweb.freebsd.org/changeset/base/286952

Log:
  MFC r285742:

    Unbreak "last reboot".

    According to the last(1) man page, the "reboot" pseudo-user should print
    all system reboot entries. This got broken by the utmpx import, as
    records are typed.

    Re-add support for "last reboot" by specifically matching against
    SHUTDOWN_TIME and BOOT_TIME records.

  PR:           168844
  Submitted by: matthew@

Changes:
_U  stable/10/
  stable/10/usr.bin/last/last.c