From owner-freebsd-audit Thu Oct 4 15:25:53 2001 Delivered-To: freebsd-audit@freebsd.org Received: from robin.mail.pas.earthlink.net (robin.mail.pas.earthlink.net [207.217.120.65]) by hub.freebsd.org (Postfix) with ESMTP id 7CD2B37B405 for ; Thu, 4 Oct 2001 15:25:49 -0700 (PDT) Received: from blossom.cjclark.org (dialup-209.245.132.25.Dial1.SanJose1.Level3.net [209.245.132.25]) by robin.mail.pas.earthlink.net (8.11.5/8.9.3) with ESMTP id f94MPk911140; Thu, 4 Oct 2001 15:25:46 -0700 (PDT) Received: (from cjc@localhost) by blossom.cjclark.org (8.11.6/8.11.3) id f94MPhH02084; Thu, 4 Oct 2001 15:25:43 -0700 (PDT) (envelope-from cjc) Date: Thu, 4 Oct 2001 15:25:41 -0700 From: "Crist J. Clark" To: Dag-Erling Smorgrav Cc: freebsd-audit@FreeBSD.ORG Subject: Re: dmesg.boot Gets Overwritten without Reboot Message-ID: <20011004152541.I297@blossom.cjclark.org> Reply-To: cjclark@alum.mit.edu References: <20011003221310.Q8391@blossom.cjclark.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.2.5i In-Reply-To: ; from des@ofug.org on Thu, Oct 04, 2001 at 02:00:23PM +0200 Sender: owner-freebsd-audit@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG On Thu, Oct 04, 2001 at 02:00:23PM +0200, Dag-Erling Smorgrav wrote: > "Crist J. Clark" writes: > > Any comments on the patch or the concept? > > Is there any way you can compare the timestamp on /var/run/dmesg.boot > with `sysctl -n kern.boottime`? This would DTRT in almost all cases > (the exception being the case where you set the clock back before > returning from single-user mode) Right, but is there a more graceful way than, # Not too bad LASTBOOT=`sysctl -n kern.boottime | sed 's/^{ sec = \([0-9]*\), .*/\1/'` # Gack! LASTDMESG=`ls -lT /var/run/dmesg.boot | awk '{ print $6 " " $7 " " $8 " " $9; }'` LASTDMESG=`date -j -f "%Ef %T %Y" "$LASTDMESG" +%s` To get those two secs numbers to compare. I've looked for a utility that will return the [acm]time of a file in UNIX Epoch seconds before, but I don't think I've ever found one in the base system. Here's the rc(8) patch, Index: src/etc/rc =================================================================== RCS file: /export/ncvs/src/etc/rc,v retrieving revision 1.283 diff -u -r1.283 rc --- src/etc/rc 2001/10/02 12:00:39 1.283 +++ src/etc/rc 2001/10/04 22:23:18 @@ -339,10 +339,28 @@ clean_var() { if [ ! -f /var/run/clean_var ]; then + # We may wish to save the boot messages. + if [ -f /var/run/dmesg.boot ]; then + mv -f /var/run/dmesg.boot /tmp/dmesg.boot + fi purgedir /var/run /var/spool/lock rm -rf /var/spool/uucp/.Temp/* - # Keep a copy of the boot messages around - dmesg >/var/run/dmesg.boot + # Check if the dmesg.boot is from (younger than) + # the most recent reboot. + if [ -f /tmp/dmesg.boot ]; then + LASTBOOT=`sysctl -n kern.boottime | \ + sed 's/^{ sec = \([0-9]*\), .*/\1/'` + LASTDMESG=`ls -lT /tmp/dmesg.boot | \ + awk '{ print $6 " " $7 " " $8 " " $9; }'` + LASTDMESG=`date -j -f "%Ef %T %Y" "$LASTDMESG" +%s` + if [ $LASTBOOT -lt $LASTDMESG ]; then + mv -f /tmp/dmesg.boot /var/run/dmesg.boot + fi + rm -f /tmp/dmesg.boot + fi + if [ ! -f /var/run/dmesg.boot ]; then + dmesg >/var/run/dmesg.boot + fi # And an initial utmp file (cd /var/run && cp /dev/null utmp && chmod 644 utmp;) >/var/run/clean_var -- Crist J. Clark cjclark@alum.mit.edu cjclark@jhu.edu cjc@freebsd.org To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-audit" in the body of the message