Package: debianutils
Version: 2.30

Hi,

The version of savelog shipped with lenny does not correctly handle
the target file not existing, which is a common case when /var/log is
a tmpfs. In this situation, /etc/init.d/bootmisc.sh uses savelog to
rotate /var/log/dmesg on boot, which does not exist, producing the
errors below on every boot and creating the spurious file
/var/log/dmesg.new.

To reproduce, run:
/usr/bin/savelog -q -p foo

where foo is a file that does not exist.

Expected behaviour:

The command completes with no output, and the empty files 'foo' and
'foo.0' are created (-p implies touch the target file which creates
'foo', and the default is to rotate even if the file does not exist,
producing 'foo.0').

Actual behaviour; The following error messages are printed:

chown: failed to get attributes of `foo': No such file or directory
chmod: failed to get attributes of `foo': No such file or directory

and the empty files 'foo.0' and 'foo.new' are created.

The attached patch fixes this bug.

Cheers,

Patrick


-- 
http://www.labyrinthdata.net.au - WA Backup, Web and VPS Hosting
--- /usr/bin/savelog	2009-02-17 06:27:53.000000000 +0900
+++ savelog	2009-11-14 23:36:12.000000000 +0800
@@ -185,9 +185,9 @@
 		continue
 	fi
 
-	# if not a file or empty, do nothing major
-	# (in the Debian version, we rotate even if empty by default)
-	if [ ! -s "$filename" ] && [ "$rotateifempty" != "yes" ]; then
+	# if file does not exist or is empty, and we've been told to not rotate
+	# empty files, create if requested and skip to the next file.
+	if [ ! -s "$filename" ] && [ "$rotateifempty" = "no" ]; then
 		# if -t was given and it does not exist, create it
 		if test -n "$touch" && [ ! -f "$filename" ]; then 
 			touch -- "$filename"
@@ -199,6 +199,16 @@
 			fixfile "$filename"
 		fi
 		continue
+	# otherwise if the file does not exist and we've been told to rotate it
+	# anyway, create an empty file to rotate.
+	elif [ ! -e "$filename" ]; then
+		touch -- "$filename"
+		if [ "$?" -ne 0 ]; then
+			echo "$prog: could not touch $filename" 1>&2
+			exitcode=4
+			continue
+		fi
+		fixfile "$filename"
 	fi
 
  	# be sure that the savedir exists and is writable

Reply via email to