From peter@tesseract.demon.co.uk  Mon Apr 28 13:41:42 2003
Return-Path: <peter@tesseract.demon.co.uk>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id 5F86D37B401
	for <FreeBSD-gnats-submit@freebsd.org>; Mon, 28 Apr 2003 13:41:42 -0700 (PDT)
Received: from tesseract.demon.co.uk (tesseract.demon.co.uk [194.222.237.220])
	by mx1.FreeBSD.org (Postfix) with SMTP id 3A93B43F75
	for <FreeBSD-gnats-submit@freebsd.org>; Mon, 28 Apr 2003 13:41:40 -0700 (PDT)
	(envelope-from peter@tesseract.demon.co.uk)
Received: (qmail 1429 invoked by uid 1000); 28 Apr 2003 20:41:17 -0000
Message-Id: <20030428204117.1428.qmail@tesseract.demon.co.uk>
Date: 28 Apr 2003 20:41:17 -0000
From: Peter Grimshaw <peter@tesseract.demon.co.uk>
Reply-To: Peter Grimshaw <peter@tesseract.demon.co.uk>
To: FreeBSD-gnats-submit@freebsd.org
Subject: newsyslog handles bzip2-compressed files incorrectly
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         51519
>Category:       bin
>Synopsis:       newsyslog handles bzip2-compressed files incorrectly
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    gad
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Mon Apr 28 13:50:11 PDT 2003
>Closed-Date:    Mon May 12 16:50:59 PDT 2003
>Last-Modified:  Mon May 12 16:50:59 PDT 2003
>Originator:     Peter Grimshaw
>Release:        FreeBSD 5.0-RELEASE i386
>Organization:
N/A
>Environment:
System: FreeBSD tesseract.demon.co.uk 5.0-RELEASE FreeBSD 5.0-RELEASE #0: Fri Mar 7 15:46:41 GMT 2003 peter@tesseract.demon.co.uk:/usr/obj/usr/src/sys/TESSERACT i386

>Description:
Function age_old_log in /usr/src/usr.sbin/newsyslog/newsyslog.c does
not check for a .bz2 file name suffix on the old log file name.  This
causes time-based rotation of bzip2-compressed log files to work
incorrectly - a new log is started each time newsyslog is run.

>How-To-Repeat:
In /etc/newsyslog.conf specify a 'when' value of, say, 168 and a '[ZJB]'
value of J.  This causes newsyslog to unconditionally start a new log
file, rather than weekly as you would expect.

>Fix:
Make function age_old_log also check for a .bz2 suffix on the old log
file name.

A workaround is to switch to gzip compression for old log files.
>Release-Note:
>Audit-Trail:

From: Lukas Ertl <l.ertl@univie.ac.at>
To: freebsd-gnats-submit@FreeBSD.org, peter@tesseract.demon.co.uk
Cc:  
Subject: Re: bin/51519: newsyslog handles bzip2-compressed files incorrectly
Date: Thu, 1 May 2003 19:36:28 +0200 (CEST)

 Hi Peter,
 
 could you try this patch? It is against rev. 1.67 of newsyslog.c.
 
 --- newsyslog.c.diff begins here ---
 Index: usr.sbin/newsyslog/newsyslog.c
 ===================================================================
 RCS file: /u/cvs/cvs/src/usr.sbin/newsyslog/newsyslog.c,v
 retrieving revision 1.67
 diff -u -r1.67 newsyslog.c
 --- usr.sbin/newsyslog/newsyslog.c	27 Apr 2003 23:37:31 -0000	1.67
 +++ usr.sbin/newsyslog/newsyslog.c	1 May 2003 17:30:25 -0000
 @@ -143,7 +143,7 @@
  static void compress_log(char *log, int dowait);
  static void bzcompress_log(char *log, int dowait);
  static int sizefile(char *file);
 -static int age_old_log(char *file);
 +static int age_old_log(char *file, int flags);
  static int send_signal(const struct conf_entry *ent);
  static time_t parse8601(char *s, char *errline);
  static void movefile(char *from, char *to, int perm, uid_t owner_uid,
 @@ -301,7 +301,7 @@
  			printf("%s <%d>: ", ent->log, ent->numlogs);
  	}
  	size = sizefile(ent->log);
 -	modtime = age_old_log(ent->log);
 +	modtime = age_old_log(ent->log, ent->flags);
  	ent->rotate = 0;
  	ent->firstcreate = 0;
  	if (size < 0) {
 @@ -1461,40 +1461,53 @@
  
  /* Return the age of old log file (file.0) */
  static int
 -age_old_log(char *file)
 +age_old_log(char *file, int flags)
  {
  	struct stat sb;
 -	char tmp[MAXPATHLEN + sizeof(".0") + sizeof(COMPRESS_POSTFIX) + 1];
 +	char *suffix, *tmp;
 +	int size;
 +
 +	if (flags & CE_COMPACT)
 +		suffix = COMPRESS_POSTFIX;
 +	else if (flags & CE_BZCOMPACT)
 +		suffix = BZCOMPRESS_POSTFIX;
 +	else
 +		suffix = "";
 +
 +	size = MAXPATHLEN + sizeof(".0") + sizeof(suffix) + 1;
 +
 +	if ((tmp = (char *) malloc(size)) == NULL)
 +		err(1, "malloc failed");
  
  	if (archtodir) {
  		char *p;
  
  		/* build name of archive directory into tmp */
  		if (*archdirname == '/') {	/* absolute */
 -			strlcpy(tmp, archdirname, sizeof(tmp));
 +			strlcpy(tmp, archdirname, size);
  		} else {	/* relative */
  			/* get directory part of logfile */
 -			strlcpy(tmp, file, sizeof(tmp));
 +			strlcpy(tmp, file, size);
  			if ((p = rindex(tmp, '/')) == NULL)
  				tmp[0] = '\0';
  			else
  				*(p + 1) = '\0';
 -			strlcat(tmp, archdirname, sizeof(tmp));
 +			strlcat(tmp, archdirname, size);
  		}
  
 -		strlcat(tmp, "/", sizeof(tmp));
 +		strlcat(tmp, "/", size);
  
  		/* get filename part of logfile */
  		if ((p = rindex(file, '/')) == NULL)
 -			strlcat(tmp, file, sizeof(tmp));
 +			strlcat(tmp, file, size);
  		else
 -			strlcat(tmp, p + 1, sizeof(tmp));
 +			strlcat(tmp, p + 1, size);
  	} else {
 -		(void) strlcpy(tmp, file, sizeof(tmp));
 +		(void) strlcpy(tmp, file, size);
  	}
  
  	if (stat(strcat(tmp, ".0"), &sb) < 0)
 -		if (stat(strcat(tmp, COMPRESS_POSTFIX), &sb) < 0)
 +		if (stat(strcat(tmp, suffix), &sb) < 0)
  			return (-1);
  	return ((int)(timenow - sb.st_mtime + 1800) / 3600);
  }
 --- newsyslog.c.diff ends here ---
 
Responsible-Changed-From-To: freebsd-bugs->gad 
Responsible-Changed-By: gad 
Responsible-Changed-When: Mon May 5 15:56:03 PDT 2003 
Responsible-Changed-Why:  
I've been working on newsyslog for the past month or so, so I should 
probably look into this too.  The patch suggested by Lukas Ertl does 
not look too good to me, so I doubt I would go with that. 
Unfortunately we're just a few hours away from a code-freeze for 
freebsd-current.  If I can come up with a likely patch in that time, 
then I'll try to commit it tonight.  Otherwise it will probably have 
to wait a few weeks. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=51519 

From: Garance A Drosehn <gad@FreeBSD.org>
To: freebsd-gnats-submit@FreeBSD.org, peter@tesseract.demon.co.uk
Cc: Lukas Ertl <l.ertl@univie.ac.at>
Subject: Re: bin/51519: newsyslog handles bzip2-compressed files incorrectly
Date: Mon, 5 May 2003 19:47:00 -0400

 I noticed your bug report as I was checking some other PR's for 
 newsyslog, and I wanted to get a fix in before the code freeze for 
 5.1-release.  I have now committed a change to 5.0-stable branch, which 
 means it should be included in the official 5.1-release.
 
 Since I was doing this in a rush, I wanted to make the "least invasive" 
 change, so I just changed the code such that if the .gz file is not 
 found, then age_old_log just looks for a '.bz2' file.  I did about ten 
 minutes worth of testing with 'J' entries, and that seems to be enough 
 to solve the problem.
 
 Assuming this change does not cause any problems, I will also MFC it 
 into the freebsd-stable branch.
 
 Thanks for noticing this.  Given that freebsd does prefer the J (bzip2) 
 compression over the gzip compression, it is certainly important that 
 time-intervals work with 'J' entries!
 
 -- 
 Garance Alistair Drosehn     =      gad@gilead.netel.rpi.edu
 Senior Systems Programmer               or   gad@FreeBSD.org
 
State-Changed-From-To: open->closed 
State-Changed-By: gad 
State-Changed-When: Mon May 12 16:49:51 PDT 2003 
State-Changed-Why:  
A fix for this has been committed to both -current and -stable. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=51519 
>Unformatted:
