bin/115486: newsyslog(8) -- provide ability to compress Nth rotated file

David Wolfskill david at catwhisker.org
Mon Aug 13 16:30:05 PDT 2007


>Number:         115486
>Category:       bin
>Synopsis:       newsyslog(8) -- provide ability to compress Nth rotated file
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Mon Aug 13 23:30:01 GMT 2007
>Closed-Date:
>Last-Modified:
>Originator:     David Wolfskill
>Release:        FreeBSD 7.0-CURRENT i386
>Organization:
Wolfskill & Dowling Residence
>Environment:
System: FreeBSD catmint.mail-abuse.org 7.0-CURRENT FreeBSD 7.0-CURRENT #94: Sun Aug 12 09:27:33 PDT 2007     root at catmint.mail-abuse.org:/common/S4/obj/usr/src/sys/CATMINT  i386

>Description:
	As it stands, newsyslog(8) provides for optional compression for
	rotated files.

	However, that compression only takes place for the newly-created
	".0" file.

	Artis Caune <Artis.Caune at latnet.lv> suggested (in -hackers@)
	that providing an ability to defer the compression to the
	".1" file might be useful for certain applications, such
	as apache.

	Dirk GOUDERS <gouders at et.bocholt.fh-ge.de> followed up,
	suggesting the use of the "0" flag, which is an enhancement
	available in another implementation of newsyslog(8).

	I mentioned that while this might be useful, it would still fall
	short of something I needed to do at work recently: leave the
	newest N rotated log files uncompressed, while compressing the
	others.

	After a small amount of additional discussion, Dirk volunteered
	to supply patches; I volunteered to test (and later, to hack the
	man page).

	Dirk supplied the patches; I tested to my satisfaction, and
	attacked the man page.  The attached patches are the result.

>How-To-Repeat:
	Try to figure out  how to get newsyslog(8) to only compress a
	rotated log file if it exceeds a certain "age" (or "generation
	number").  If you figure out a way, please document it. :-}
>Fix:
	Apply the following patches in /usr/src/usr.sbin/newsyslog,
	then make  && make install.  That done, the "generation number"
	of the rotated file that is to be compressed may be specified in
	the "flags" field of a newsyslog.conf entry:


Index: newsyslog.c
===================================================================
RCS file: /cvs/freebsd/src/usr.sbin/newsyslog/newsyslog.c,v
retrieving revision 1.107
diff -u -r1.107 newsyslog.c
--- newsyslog.c	17 Aug 2006 18:15:43 -0000	1.107
+++ newsyslog.c	12 Aug 2007 17:26:08 -0000
@@ -127,6 +127,8 @@
 	struct ptime_data *trim_at;	/* Specific time to do trimming */
 	unsigned int permissions;	/* File permissions on the log */
 	int flags;		/* CE_COMPACT, CE_BZCOMPACT, CE_BINARY */
+	int nuncompact;		/* number of rotations that should not
+				 * be compressed; -1 turns this off */
 	int sig;		/* Signal to send */
 	int def_cfg;		/* Using the <default> rule for this file */
 	struct conf_entry *next;/* Linked list pointer */
@@ -1187,6 +1189,11 @@
 		}
 
 		for (; q && *q && !isspacech(*q); q++) {
+			if (isdigit(*q)) {
+				working->nuncompact = strtol(q, NULL, 10);
+				while(isdigit(*(q+1))) q++;
+				continue;
+			}
 			switch (tolowerch(*q)) {
 			case 'b':
 				working->flags |= CE_BINARY;
@@ -1456,6 +1463,12 @@
 			(void)rename(zfile1, zfile2);
 		}
 		change_attrs(zfile2, ent);
+		if ((flags & (CE_COMPACT | CE_BZCOMPACT)) &&
+		    (ent->nuncompact != -1) &&
+		    (numlogs_c == ent->nuncompact)) {
+			free_or_keep = KEEP_ENT;
+			save_zipwork(ent, NULL, ent->fsize, file2);
+		}
 	}
 
 	if (ent->numlogs > 0) {
@@ -1494,7 +1507,8 @@
 	swork = NULL;
 	if (ent->pid_file != NULL)
 		swork = save_sigwork(ent);
-	if (ent->numlogs > 0 && (flags & (CE_COMPACT | CE_BZCOMPACT))) {
+	if (ent->numlogs > 0 && (flags & (CE_COMPACT | CE_BZCOMPACT))
+	    && ent->nuncompact == -1) {
 		/*
 		 * The zipwork_entry will include a pointer to this
 		 * conf_entry, so the conf_entry should not be freed.
Index: newsyslog.conf.5
===================================================================
RCS file: /cvs/freebsd/src/usr.sbin/newsyslog/newsyslog.conf.5,v
retrieving revision 1.6
diff -u -r1.6 newsyslog.conf.5
--- newsyslog.conf.5	29 Sep 2006 17:57:03 -0000	1.6
+++ newsyslog.conf.5	13 Aug 2007 18:08:03 -0000
@@ -242,6 +242,16 @@
 files matched by this line.
 The following are valid flags:
 .Bl -tag -width indent
+.It Ar number
+In combination with one of the compression flags
+.Cm J
+or
+.Cm Z
+, this selects which one of the already-rotated archives will be
+subject to the requested compression.  If it is omitted and compression
+is specified, the most recently-rotated archive file will be compressed.
+(Compression is done subsequent to rotation, but the selection
+specified here is done prior to the rotation.)
 .It Cm B
 indicates that the log file is a binary file, or has some
 special format.
>Release-Note:
>Audit-Trail:
>Unformatted:


More information about the freebsd-bugs mailing list