Date: Fri, 08 Jun 2012 12:08:20 +0100 From: Matthew Seaman <m.seaman@infracaninophile.co.uk> To: FreeBSD - <freebsd-questions@freebsd.org> Subject: Re: find date of last boot Message-ID: <4FD1DD24.4060908@infracaninophile.co.uk> In-Reply-To: <4FD19973.5040802@infracaninophile.co.uk> References: <4FD1360D.1060208@a1poweruser.com> <alpine.BSF.2.00.1206072110350.67420@tripel.monochrome.org> <4FD15461.6090109@makeworld.com> <86obou7fly.fsf@red.stonehenge.com> <5E0240CD-6B6C-4221-A656-0006254132F9@mac.com> <86ipf276g7.fsf@red.stonehenge.com> <4FD19973.5040802@infracaninophile.co.uk>
next in thread | previous in thread | raw e-mail | index | archive | help
This is an OpenPGP/MIME signed message (RFC 2440 and 3156) --------------enigC2B7A5D73E1FA9E15275A6CA Content-Type: multipart/mixed; boundary="------------090907090006040305040407" This is a multi-part message in MIME format. --------------090907090006040305040407 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable On 08/06/2012 07:19, Matthew Seaman wrote: > On 08/06/2012 05:50, Randal L. Schwartz wrote: >> Sure, but the question was likely involving a stock system, so yes, yo= ur >> mileage may vary, but let's consider a solution that works for a defau= lt >> system. "last reboot" isn't it. >=20 > It's not that. 'last reboot' seems to be broken at the moment, at leas= t > on stable/9: >=20 > lucid-nonsense:~:% uname -a > 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-N= ONSENSE > amd64 >=20 > I rebooted a few days ago: >=20 > lucid-nonsense:~:% uptime > 7:14AM up 3 days, 8:18, 1 user, load averages: 0.03, 0.01, 0.01 >=20 > And the utx.log file was last rotated over a week ago: >=20 > lucid-nonsense:~:% ls -la /var/log/utx* > -rw-r--r-- 1 root wheel 394 Jun 7 17:51 /var/log/utx.lastlogin > -rw-r--r-- 1 root wheel 16841 Jun 8 07:06 /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 >=20 > but last(1) isn't coming up with the goods: >=20 > lucid-nonsense:~:% last reboot >=20 > wtmp begins Fri Jun 1 06:14:46 BST 2012 >=20 > (nor does it work if I tell last to use the older utx.log files) Having investigated, the problem appears to be that wtmp used to use the literal string 'reboot' in the username field of its records, while in struct utmpx, that field is left blank but the record type field indicates if this is the time the system shutdown or rebooted. The attached patch fixes the problem for me. Or see http://www.freebsd.org/cgi/query-pr.cgi?pr=3D168844 lucid-nonsense:~:% /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 In passing, apparently it seems that creating a user with a username of 'reboot' is probably not recommended. Cheers, Matthew --=20 Dr Matthew J Seaman MA, D.Phil. 7 Priory Courtyard Flat 3 PGP: http://www.infracaninophile.co.uk/pgpkey Ramsgate JID: matthew@infracaninophile.co.uk Kent, CT11 9PW --------------090907090006040305040407 Content-Type: text/plain; charset=UTF-8; x-mac-type="0"; x-mac-creator="0"; name="last.diff" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="last.diff" Index: usr.bin/last/last.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- usr.bin/last/last.c (revision 236465) +++ usr.bin/last/last.c (working copy) @@ -64,6 +64,7 @@ =20 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 +=3D optind; *argv; ++argv) { + if (strcmp(*argv, "reboot") =3D=3D 0) + addarg(REBOOT_TYPE, *argv); #define COMPATIBILITY #ifdef COMPATIBILITY /* code to allow "last p5" to work */ @@ -391,6 +394,11 @@ =20 for (step =3D arglist; step; step =3D step->next) switch(step->type) { + case REBOOT_TYPE: + if (bp->ut_type =3D=3D BOOT_TIME || + bp->ut_type =3D=3D SHUTDOWN_TIME) + return (YES); + break; case HOST_TYPE: if (!strcasecmp(step->name, bp->ut_host)) return (YES); --------------090907090006040305040407-- --------------enigC2B7A5D73E1FA9E15275A6CA Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG/MacGPG2 v2.0.16 (Darwin) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iEYEARECAAYFAk/R3SsACgkQ8Mjk52CukIwjpACbBKm85yIGgz9peO9u6nd+oYXU WvIAniLo342WBfdNQEqRX2tPyjDhH/89 =PC63 -----END PGP SIGNATURE----- --------------enigC2B7A5D73E1FA9E15275A6CA--
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?4FD1DD24.4060908>