Subject: bin/17235:
To: None <gnats-bugs@gnats.netbsd.org>
From: None <gdt@bbn.com>
List: netbsd-bugs
Date: 06/12/2002 11:24:29
>Number:         17235
>Category:       bin
>Synopsis:       
>Confidential:   yes
>Severity:       non-critical
>Priority:       low
>Responsible:    bin-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Wed Jun 12 08:25:00 PDT 2002
>Closed-Date:
>Last-Modified:
>Originator:     Greg Troxel
>Release:        NetBSD 1.5.3_RC1
>Organization:
BBN Technologies
>Environment:
	
	
System: NetBSD lab.q.bbn.com 1.5.3_RC1 NetBSD 1.5.3_RC1 (QUISTCVS) #9: Thu Mar 14 07:32:28 EST 2002 gdt@lab.q.bbn.com:/home/gdt/QUIST-current/netbsd/src/sys/arch/i386/compile/QUISTCVS i386
Architecture: i386
Machine: i386
>Description:
newsyslog compresses log files (e.g. messages.1 to messages.n-1), even
if Z is not specified

>How-To-Repeat:
remove Z from /etc/newsyslog.conf, and gnzip /var/log/messages*gz.
Wait a while and notice that while messages.0 is not compressed, the
rest are.

Read the source of src/usr.bin/newsyslog/newsyslog.c starting at line
545. Note that CE_COMPRESS is not tested, and log_compress is called
unconditionally for most files.  Note also the use of a logical
expression to initialize a loop index to 0 or 1.  While I can't find
the KNF statement prohibiting this, I find such constructs hard to
follow.

>Fix:
	

The following seems to work for me.  The test is now on CE_COMPRESS0,
and leaves the .0 file alone, partially for CE_PLAIN0, and partially
because the .0 file is handled specially.  The patch only changes the
for initializer and wraps an if; the rest is just KNF-required
whitespace changes resulting from adding the if.

Index: newsyslog.c
===================================================================
RCS file: /QUIST-CVS/netbsd/src/usr.bin/newsyslog/newsyslog.c,v
retrieving revision 1.1.1.2
retrieving revision 1.2
diff -u -r1.1.1.2 -r1.2
--- newsyslog.c	2002/03/13 14:59:01	1.1.1.2
+++ newsyslog.c	2002/06/11 19:22:32	1.2
@@ -537,20 +537,22 @@
 	}
 
 	/*
-	 * If a historical log file isn't compressed, and 'z' has been
+	 * Examine log.1 to log.n-1, and, if 'z' has been specified,
 	 * specified, compress it.  (This is convenient, but is also needed
 	 * if 'p' has been specified.)  It should be noted that gzip(1)
 	 * preserves file ownership and file mode.
 	 */
-	for (i = (log->flags & CE_PLAIN0) != 0; i < log->numhist; i++) {
-		snprintf(file1, sizeof (file1), "%s.%d", log->logfile, i);
-		if (lstat(file1, &st) != 0)
-			continue;
-		snprintf(file2, sizeof (file2), "%s.gz", file1);
-		if (lstat(file2, &st) == 0)
-			continue;
-		log_compress(log, file1);
-	}
+	if ((log->flags & CE_COMPRESS) != 0)
+		for (i = 1; i < log->numhist; i++) {
+			snprintf(file1, sizeof (file1),
+				 "%s.%d", log->logfile, i);
+			if (lstat(file1, &st) != 0)
+				continue;
+			snprintf(file2, sizeof (file2), "%s.gz", file1);
+			if (lstat(file2, &st) == 0)
+				continue;
+			log_compress(log, file1);
+		}
 
 	log_trimmed(log);
 
>Release-Note:
>Audit-Trail:
>Unformatted:
 no
 newsyslog compresses .1 to .n-1, even if Z is not specified
 	
 	
 
 netbsd-1-5 as of 20020510, byt not fixed in netbsd-1-5 head