From andre.albsmeier@siemens.com  Wed Jan 26 06:58:54 2005
Return-Path: <andre.albsmeier@siemens.com>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id 2338816A4CE
	for <FreeBSD-gnats-submit@freebsd.org>; Wed, 26 Jan 2005 06:58:54 +0000 (GMT)
Received: from goliath.siemens.de (goliath.siemens.de [192.35.17.28])
	by mx1.FreeBSD.org (Postfix) with ESMTP id 45BF043D31
	for <FreeBSD-gnats-submit@freebsd.org>; Wed, 26 Jan 2005 06:58:53 +0000 (GMT)
	(envelope-from andre.albsmeier@siemens.com)
Received: from mail3.siemens.de (mail3.siemens.de [139.25.208.14])
	by goliath.siemens.de (8.12.6/8.12.6) with ESMTP id j0Q6wq07003763
	for <FreeBSD-gnats-submit@freebsd.org>; Wed, 26 Jan 2005 07:58:52 +0100
Received: from mars.cert.siemens.com (mars.cert.siemens.com [139.25.19.9])
	by mail3.siemens.de (8.12.6/8.12.6) with ESMTP id j0Q6wpfs015359
	for <FreeBSD-gnats-submit@freebsd.org>; Wed, 26 Jan 2005 07:58:52 +0100
Received: from curry.mchp.siemens.de (curry.mchp.siemens.de [139.25.42.7])
	by mars.cert.siemens.com (8.13.3/8.13.3/$SiemensCERT: mail/cert.mc.pre,v 1.65 2004/10/29 21:53:46 mailadm Exp $) with ESMTP id j0Q6wp93054517
	for <FreeBSD-gnats-submit@freebsd.org>; Wed, 26 Jan 2005 07:58:51 +0100 (CET)
Received: (from localhost)
	by curry.mchp.siemens.de (8.13.1/8.13.1) id j0Q6wpKM004455
	for FreeBSD-gnats-submit@freebsd.org; Wed, 26 Jan 2005 07:58:51 +0100 (CET)
Message-Id: <200501260658.j0Q6wpCe057787@curry.mchp.siemens.de>
Date: Wed, 26 Jan 2005 07:58:51 +0100 (CET)
From: Andre Albsmeier <andre.albsmeier@siemens.com>
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: newsyslog keeps one more archive files than documented
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         76697
>Category:       bin
>Synopsis:       newsyslog(8) keeps one more archive files than documented
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    simon
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Wed Jan 26 07:00:42 GMT 2005
>Closed-Date:    Fri Mar 15 23:41:42 UTC 2013
>Last-Modified:  Fri Mar 15 23:41:42 UTC 2013
>Originator:     Andre Albsmeier
>Release:        FreeBSD 4.10-STABLE i386
>Organization:
>Environment:

	verified on 4.10-STABLE and 5.2.1-RELEASE but probably
	all FreeBSD versions are affected

>Description:

	man newsyslog.conf (on a FreeBSD 4.10-STABLE box) says:

     count   Specify the maximum number of archive files which may exist.
             This does not consider the current log file.

	However, it seems that newsyslog actually keeps count+1
	archive files.

>How-To-Repeat:

	On a machine which had been running for at least one
	week and which has an unmodifed /etc/newsyslog.conf do
	(only checked on 4.10-STABLE):

	egrep 'count|/var/log/messages' /etc/newsyslog.conf
	ls -l /var/log/messages.* | wc -l

	and compare the output of the two commands :-).

>Fix:

	Either fix the manpage or the code :-)
>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->edwin 
Responsible-Changed-By: edwin 
Responsible-Changed-When: Wed Aug 13 01:25:27 UTC 2008 
Responsible-Changed-Why:  
Handle with mentor. 

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

From: "Matt Koivisto" <mkoivisto@sandvine.com>
To: <bug-followup@FreeBSD.org>,
	<andre.albsmeier@siemens.com>
Cc: <emaste@freebsd.org>
Subject: Re: bin/76697: newsyslog(8) keeps one more archive files than documented
Date: Tue, 16 Dec 2008 10:49:02 -0500

 This is a multi-part message in MIME format.
 
 ------_=_NextPart_001_01C95F95.D20E59F9
 Content-Type: text/plain;
 	charset="us-ascii"
 Content-Transfer-Encoding: quoted-printable
 
 The attached patch fixes the behavior to match the manpage's
 description. Newsyslog will keep "count" rotated logs instead of the
 current "count+1". This patch is against HEAD
 (src/usr.sbin/newsyslog/newsyslog.c 1.108)
 
 
 ------_=_NextPart_001_01C95F95.D20E59F9
 Content-Type: text/plain;
 	name="newsyslog.c.patch.txt"
 Content-Transfer-Encoding: base64
 Content-Description: newsyslog.c.patch.txt
 Content-Disposition: attachment;
 	filename="newsyslog.c.patch.txt"
 
 LS0tIG5ld3N5c2xvZy5jLjEuMTA4CisrKyBuZXdzeXNsb2cuYwpAQCAtMTM5Myw3ICsxMzkzLDcg
 QEAKIAogCQkvKiBuYW1lIG9mIG9sZGVzdCBsb2cgKi8KIAkJKHZvaWQpIHNucHJpbnRmKGZpbGUx
 LCBzaXplb2YoZmlsZTEpLCAiJXMvJXMuJWQiLCBkaXJwYXJ0LAotCQkgICAgbmFtZXBhcnQsIGVu
 dC0+bnVtbG9ncyk7CisJCSAgICBuYW1lcGFydCwgZW50LT5udW1sb2dzLTEpOwogCQkodm9pZCkg
 c25wcmludGYoemZpbGUxLCBzaXplb2YoemZpbGUxKSwgIiVzJXMiLCBmaWxlMSwKIAkJICAgIENP
 TVBSRVNTX1BPU1RGSVgpOwogCQlzbnByaW50ZihqZmlsZTEsIHNpemVvZihqZmlsZTEpLCAiJXMl
 cyIsIGZpbGUxLApAQCAtMTQwMSw3ICsxNDAxLDcgQEAKIAl9IGVsc2UgewogCQkvKiBuYW1lIG9m
 IG9sZGVzdCBsb2cgKi8KIAkJKHZvaWQpIHNucHJpbnRmKGZpbGUxLCBzaXplb2YoZmlsZTEpLCAi
 JXMuJWQiLCBlbnQtPmxvZywKLQkJICAgIGVudC0+bnVtbG9ncyk7CisJCSAgICBlbnQtPm51bWxv
 Z3MtMSk7CiAJCSh2b2lkKSBzbnByaW50Zih6ZmlsZTEsIHNpemVvZih6ZmlsZTEpLCAiJXMlcyIs
 IGZpbGUxLAogCQkgICAgQ09NUFJFU1NfUE9TVEZJWCk7CiAJCXNucHJpbnRmKGpmaWxlMSwgc2l6
 ZW9mKGpmaWxlMSksICIlcyVzIiwgZmlsZTEsCkBAIC0xNDE5LDggKzE0MTksOCBAQAogCX0KIAog
 CS8qIE1vdmUgZG93biBsb2cgZmlsZXMgKi8KLQludW1sb2dzX2MgPSBlbnQtPm51bWxvZ3M7CQkv
 KiBjb3B5IGZvciBjb3VudGRvd24gKi8KLQl3aGlsZSAobnVtbG9nc19jLS0pIHsKKwludW1sb2dz
 X2MgPSBlbnQtPm51bWxvZ3MtMTsJCS8qIGNvcHkgZm9yIGNvdW50ZG93biAqLworCXdoaWxlIChu
 dW1sb2dzX2MtLSA+IDApIHsKIAogCQkodm9pZCkgc3RybGNweShmaWxlMiwgZmlsZTEsIHNpemVv
 ZihmaWxlMikpOwogCg==
 
 ------_=_NextPart_001_01C95F95.D20E59F9--

From: Andre Albsmeier <Andre.Albsmeier@siemens.com>
To: Matt Koivisto <mkoivisto@sandvine.com>
Cc: bug-followup@FreeBSD.org, andre.albsmeier@siemens.com, emaste@FreeBSD.org
Subject: Re: bin/76697: newsyslog(8) keeps one more archive files than
	documented
Date: Mon, 29 Dec 2008 13:18:49 +0100

 On Tue, 16-Dec-2008 at 10:49:02 -0500, Matt Koivisto wrote:
 > The attached patch fixes the behavior to match the manpage's
 > description. Newsyslog will keep "count" rotated logs instead of the
 > current "count+1". This patch is against HEAD
 > (src/usr.sbin/newsyslog/newsyslog.c 1.108)
 
 Well, I can't test it at the moment but I think it looks good...
 
 	-Andre
 
 > 
 
 Content-Description: newsyslog.c.patch.txt
 > --- newsyslog.c.1.108
 > +++ newsyslog.c
 > @@ -1393,7 +1393,7 @@
 >  
 >  		/* name of oldest log */
 >  		(void) snprintf(file1, sizeof(file1), "%s/%s.%d", dirpart,
 > -		    namepart, ent->numlogs);
 > +		    namepart, ent->numlogs-1);
 >  		(void) snprintf(zfile1, sizeof(zfile1), "%s%s", file1,
 >  		    COMPRESS_POSTFIX);
 >  		snprintf(jfile1, sizeof(jfile1), "%s%s", file1,
 > @@ -1401,7 +1401,7 @@
 >  	} else {
 >  		/* name of oldest log */
 >  		(void) snprintf(file1, sizeof(file1), "%s.%d", ent->log,
 > -		    ent->numlogs);
 > +		    ent->numlogs-1);
 >  		(void) snprintf(zfile1, sizeof(zfile1), "%s%s", file1,
 >  		    COMPRESS_POSTFIX);
 >  		snprintf(jfile1, sizeof(jfile1), "%s%s", file1,
 > @@ -1419,8 +1419,8 @@
 >  	}
 >  
 >  	/* Move down log files */
 > -	numlogs_c = ent->numlogs;		/* copy for countdown */
 > -	while (numlogs_c--) {
 > +	numlogs_c = ent->numlogs-1;		/* copy for countdown */
 > +	while (numlogs_c-- > 0) {
 >  
 >  		(void) strlcpy(file2, file1, sizeof(file2));
 >  
 
 
 -- 
 Micro$oft: When will your system crash today?

Date: Thu, 22 Jul 2010 18:41:10 +0200
From: "Simon L. Nielsen" <simon@FreeBSD.org>
To: Edwin Groothuis <edwin@FreeBSD.org>
Subject: Take PR bin/76697?

 Hey,
 
 Do you have any plans to get bin/76697 committed/fixed?  If not I'm
 going to get it fixed while working on newsyslog anyway...
 
 -- 
 Simon L. Nielsen

Responsible-Changed-From-To: edwin->simon 
Responsible-Changed-By: emaste 
Responsible-Changed-When: Thu Jul 22 21:19:42 UTC 2010 
Responsible-Changed-Why:  
I believe I've managed to talk Simon into taking care of this. 

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

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/76697: commit references a PR
Date: Thu, 21 Apr 2011 16:31:17 +0000 (UTC)

 Author: simon
 Date: Thu Apr 21 16:31:05 2011
 New Revision: 220926
 URL: http://svn.freebsd.org/changeset/base/220926
 
 Log:
   Fix an old bug in newsyslog where we kept one log file more than was
   requested in newsyslog.conf.  This was only the case using the non-time
   based filenames (.0, .1, .2 etc.).
   
   The change also makes newsyslog clean clean up the old extra logfile so
   users don't end up with a single stale logfile which won't be rotated
   out.
   
   This change also cleans up some code a bit to avoid more copy / paste
   code and removes some old copy / paste code in the process.
   
   PR:		bin/76697
   MFC after:	2 weeks
 
 Modified:
   head/usr.sbin/newsyslog/newsyslog.c
 
 Modified: head/usr.sbin/newsyslog/newsyslog.c
 ==============================================================================
 --- head/usr.sbin/newsyslog/newsyslog.c	Thu Apr 21 14:39:33 2011	(r220925)
 +++ head/usr.sbin/newsyslog/newsyslog.c	Thu Apr 21 16:31:05 2011	(r220926)
 @@ -1592,6 +1592,43 @@ delete_oldest_timelog(const struct conf_
  }
  
  /*
 + * Generate a log filename, when using clasic filenames.
 + */
 +static void
 +gen_clasiclog_fname(char *fname, size_t fname_sz, const char *archive_dir,
 +    const char *namepart, int numlogs_c)
 +{
 +
 +	if (archive_dir[0] != '\0')
 +		(void) snprintf(fname, fname_sz, "%s/%s.%d", archive_dir,
 +		    namepart, numlogs_c);
 +	else
 +		(void) snprintf(fname, fname_sz, "%s.%d", namepart, numlogs_c);
 +}
 +
 +/*
 + * Delete a rotated logfiles, when using clasic filenames.
 + */
 +static void
 +delete_clasiclog(const char *archive_dir, const char *namepart, int numlog_c)
 +{
 +	char file1[MAXPATHLEN], zfile1[MAXPATHLEN];
 +	int c;
 +
 +	gen_clasiclog_fname(file1, sizeof(file1), archive_dir, namepart,
 +	    numlog_c);
 +
 +	for (c = 0; c < COMPRESS_TYPES; c++) {
 +		(void) snprintf(zfile1, sizeof(zfile1), "%s%s", file1,
 +		    compress_type[c].suffix);
 +		if (noaction)
 +			printf("\trm -f %s\n", zfile1);
 +		else
 +			(void) unlink(zfile1);
 +	}
 +}
 +
 +/*
   * Only add to the queue if the file hasn't already been added. This is
   * done to prevent circular include loops.
   */
 @@ -1655,7 +1692,6 @@ do_rotate(const struct conf_entry *ent)
  	struct stat st;
  	struct tm tm;
  	time_t now;
 -	int c;
  
  	flags = ent->flags;
  	free_or_keep = FREE_ENT;
 @@ -1685,35 +1721,29 @@ do_rotate(const struct conf_entry *ent)
  			strlcpy(namepart, ent->log, sizeof(namepart));
  		else
  			strlcpy(namepart, p + 1, sizeof(namepart));
 -
 -		/* name of oldest log */
 -		(void) snprintf(file1, sizeof(file1), "%s/%s.%d", dirpart,
 -		    namepart, ent->numlogs);
  	} else {
  		/*
 -		 * Tell delete_oldest_timelog() we are not using an
 -		 * archive dir.
 +		 * Tell utility functions we are not using an archive
 +		 * dir.
  		 */
  		dirpart[0] = '\0';
 -
 -		/* name of oldest log */
 -		(void) snprintf(file1, sizeof(file1), "%s.%d", ent->log,
 -		    ent->numlogs);
 +		strlcpy(namepart, ent->log, sizeof(namepart));
  	}
  
  	/* Delete old logs */
  	if (timefnamefmt != NULL)
  		delete_oldest_timelog(ent, dirpart);
  	else {
 -		/* name of oldest log */
 -		for (c = 0; c < COMPRESS_TYPES; c++) {
 -			(void) snprintf(zfile1, sizeof(zfile1), "%s%s", file1,
 -			    compress_type[c].suffix);
 -			if (noaction)
 -				printf("\trm -f %s\n", zfile1);
 -			else
 -				(void) unlink(zfile1);
 -		}
 +		/*
 +		 * Handle cleaning up after legacy newsyslog where we
 +		 * kept ent->numlogs + 1 files.  This code can go away
 +		 * at some point in the future.
 +		 */
 +		delete_clasiclog(dirpart, namepart, ent->numlogs);
 +
 +		if (ent->numlogs > 0)
 +			delete_clasiclog(dirpart, namepart, ent->numlogs - 1);
 +
  	}
  
  	if (timefnamefmt != NULL) {
 @@ -1731,21 +1761,19 @@ do_rotate(const struct conf_entry *ent)
  			    ent->log, datetimestr);
  
  		/* Don't run the code to move down logs */
 -		numlogs_c = 0;
 -	} else
 -		numlogs_c = ent->numlogs;		/* copy for countdown */
 +		numlogs_c = -1;
 +	} else {
 +		gen_clasiclog_fname(file1, sizeof(file1), dirpart, namepart,
 +		    ent->numlogs - 1);
 +		numlogs_c = ent->numlogs - 2;		/* copy for countdown */
 +	}
  
  	/* Move down log files */
 -	while (numlogs_c--) {
 -
 +	for (; numlogs_c >= 0; numlogs_c--) {
  		(void) strlcpy(file2, file1, sizeof(file2));
  
 -		if (archtodir)
 -			(void) snprintf(file1, sizeof(file1), "%s/%s.%d",
 -			    dirpart, namepart, numlogs_c);
 -		else
 -			(void) snprintf(file1, sizeof(file1), "%s.%d",
 -			    ent->log, numlogs_c);
 +		gen_clasiclog_fname(file1, sizeof(file1), dirpart, namepart,
 +		    numlogs_c);
  
  		logfile_suffix = get_logfile_suffix(file1);
  		if (logfile_suffix == NULL)
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 
State-Changed-From-To: open->patched 
State-Changed-By: simon 
State-Changed-When: Thu Apr 21 16:48:15 UTC 2011 
State-Changed-Why:  
Fixed in FreeBSD 9-CURRENT / head.  Will MFC to FreeBSD 8 later. 

I didn't use the patch in the PR as I wanted to clean out old log files, 
and the patch did not apply anymore. 

Thanks for the report, and sorry about it taking so long to be fixed. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=76697 
State-Changed-From-To: patched->closed 
State-Changed-By: eadler 
State-Changed-When: Fri Mar 15 23:41:41 UTC 2013 
State-Changed-Why:  
MFCed/fixed by now or it will never be MFCed 

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