Subject: misc/27274: Keep RCS backups of dmesg.boot
To: None <gnats-bugs@gnats.NetBSD.org>
From: Alan Barrett <apb@cequrux.com>
List: netbsd-bugs
Date: 10/16/2004 09:23:14
>Number:         27274
>Category:       misc
>Synopsis:       Keep RCS backups of dmesg.boot
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    misc-bug-people
>State:          open
>Class:          change-request
>Submitter-Id:   net
>Arrival-Date:   Sat Oct 16 07:24:00 UTC 2004
>Closed-Date:
>Last-Modified:
>Originator:     Alan Barrett
>Release:        NetBSD 2.99.9
>Organization:
	Not much
>Environment:
Architecture: i386
Machine: i386
>Description:
	I have been using a modified version of /etc/rc.d/dmesg for
	about 20 months, to keep RCS backups of /var/run/dmesg.boot.

        It works, but it needs a bit of cleanup, and it would be better
        if some of the logic that is used by both this script and
        /etc/security were abstracted into functions in /etc/rc.subr.

>How-To-Repeat:
	Observe that /etc/security makes daily RCS backups of lots of
	stuff.

	Wish that similar backups of /var/run/dmesg.boot were made at
	every boot.

>Fix:
	Apply this patch.

Index: etc/rc.d/dmesg
--- etc/rc.d/dmesg	13 Aug 2004 18:08:03 -0000	1.9
+++ etc/rc.d/dmesg	16 Oct 2004 07:18:28 -0000
@@ -12,13 +12,48 @@
 name="dmesg"
 rcvar=$name
 dmesg_file="/var/run/dmesg.boot"
+backup_dir="${backup_dir:-/var/backups}"
+#work_dir="${backup_dir}/work"
+work_dir="${backup_dir}/${dmesg_file%/*}"
 start_cmd="do_dmesg"
 stop_cmd=":"
 
 do_dmesg()
 {
+	mkdir -p ${work_dir}
+	BASE=${dmesg_file##*/}
+	CUR=${work_dir}/${BASE}.current
+	BACK=${work_dir}/${BASE}.backup
+	#echo "start"
+	#ls -ld ${dmesg_file} ${CUR} ${CUR},v
+	# Backup the old file left over from the previous boot,
+	# if it was not already backed up.
+	if [ -f ${dmesg_file} ]; then
+		if [ -f $CUR ] && cmp -s ${dmesg_file} $CUR; then
+		    : OK
+		else
+		    echo "Backing up old ${dmesg_file} from previous boot."
+		    backup_file update ${dmesg_file} $CUR $BACK
+		fi
+	fi
+	#echo "saved old"
+	#ls -ld ${dmesg_file} ${CUR} ${CUR},v
+	# Create the new file.
 	rm -f ${dmesg_file}
 	( umask 022 ; /sbin/dmesg $rc_flags > ${dmesg_file} )
+	#echo "new"
+	#ls -ld ${dmesg_file} ${CUR} ${CUR},v
+	# Backup the new file, if it has changed.
+	if [ -f $CUR ] && cmp -s ${dmesg_file} $CUR; then
+	    : No changes
+	    echo "Not backing up unchanged ${dmesg_file}"
+	else
+	    #diff -u2 ${CUR} ${dmesg_file}
+	    echo "Backing up new ${dmesg_file}"
+	    backup_file update ${dmesg_file} $CUR $BACK
+	fi
+	#echo "end"
+	#ls -ld ${dmesg_file} ${CUR} ${CUR},v
 }
 
 load_rc_config $name
>Release-Note:
>Audit-Trail:
>Unformatted: