From ilepore@damnhippie.dyndns.org  Sat Sep  3 17:40:34 2011
Return-Path: <ilepore@damnhippie.dyndns.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id 367BC106566B
	for <freebsd-gnats-submit@freebsd.org>; Sat,  3 Sep 2011 17:40:34 +0000 (UTC)
	(envelope-from ilepore@damnhippie.dyndns.org)
Received: from qmta12.emeryville.ca.mail.comcast.net (qmta12.emeryville.ca.mail.comcast.net [76.96.27.227])
	by mx1.freebsd.org (Postfix) with ESMTP id 1BA6F8FC0C
	for <freebsd-gnats-submit@freebsd.org>; Sat,  3 Sep 2011 17:40:33 +0000 (UTC)
Received: from omta16.emeryville.ca.mail.comcast.net ([76.96.30.72])
	by qmta12.emeryville.ca.mail.comcast.net with comcast
	id UHe91h0041ZMdJ4ACHgUVa; Sat, 03 Sep 2011 17:40:28 +0000
Received: from damnhippie.dyndns.org ([24.8.232.202])
	by omta16.emeryville.ca.mail.comcast.net with comcast
	id UHg61h00L4NgCEG8cHg6rp; Sat, 03 Sep 2011 17:40:07 +0000
Received: from revolution.hippie.lan (revolution.hippie.lan [172.22.42.240])
	by damnhippie.dyndns.org (8.14.3/8.14.3) with ESMTP id p83HeVOl034008
	for <FreeBSD-gnats-submit@freebsd.org>; Sat, 3 Sep 2011 11:40:31 -0600 (MDT)
	(envelope-from ilepore@damnhippie.dyndns.org)
Received: (from ilepore@localhost)
	by revolution.hippie.lan (8.14.4/8.14.4/Submit) id p83HeVWS098843;
	Sat, 3 Sep 2011 11:40:31 -0600 (MDT)
	(envelope-from ilepore)
Message-Id: <201109031740.p83HeVWS098843@revolution.hippie.lan>
Date: Sat, 3 Sep 2011 11:40:31 -0600 (MDT)
From: Ian Lepore <freebsd@damnhippie.dyndns.org>
Reply-To: Ian Lepore <freebsd@damnhippie.dyndns.org>
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: [patch] Allow both size and at-time specifications for log rotation.
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         160432
>Category:       bin
>Synopsis:       [patch] newsyslog(8): Allow both size and at-time specifications for log rotation.
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    glebius
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Sat Sep 03 17:50:08 UTC 2011
>Closed-Date:    Wed Apr 25 07:06:19 UTC 2012
>Last-Modified:  Wed Apr 25 07:10:11 UTC 2012
>Originator:     Ian Lepore <freebsd@damnhippie.dyndns.org>
>Release:        FreeBSD 8.2-RC3 arm
>Organization:
none
>Environment:
FreeBSD dvb 8.2-RC3 FreeBSD 8.2-RC3 #49: Tue Feb 15 22:52:14 UTC 2011     root@revolution.hippie.lan:/usr/obj/arm/usr/src/sys/DVB  arm

>Description:
If both size-based and time-based rotation parameters are specified for the
same log file in newsyslog.conf, the size specification is effectively 
ignored because the rotation-decision logic returns early if the at-time 
test isn't satisfied.

>How-To-Repeat:
Specify both a size limit and a time specification for the same file.  The
log will not be rotated until the designated time regardless of how large 
it becomes before then.

>Fix:
This patch allows both size and time to be specified in a useful way.  The
log file will be rotated when either the size is exceeded or the designated
time arrives.


--- diff.tmp begins here ---
--- newsyslog.c.orig	2011-09-03 11:26:46.000000000 -0600
+++ newsyslog.c	2011-08-31 16:06:09.000000000 -0600
@@ -516,7 +516,12 @@ do_entry(struct conf_entry * ent)
 			printf("does not exist, skipped%s.\n", temp_reason);
 		}
 	} else {
-		if (ent->flags & CE_TRIMAT && !force && !rotatereq) {
+		if (ent->trsize > 0 && ent->fsize >= ent->trsize) {
+			if (verbose) {
+				printf("(size overrides at-time) ");
+			}
+			/* not returning here is how size overrides at-time */
+		} else if (ent->flags & CE_TRIMAT && !force && !rotatereq) {
 			diffsecs = ptimeget_diff(timenow, ent->trim_at);
 			if (diffsecs < 0.0) {
 				/* trim_at is some time in the future. */
--- diff.tmp ends here ---
>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->glebius 
Responsible-Changed-By: glebius 
Responsible-Changed-When: Mon Mar 19 19:03:16 UTC 2012 
Responsible-Changed-Why:  
Take it, so that I won't forget to handle this. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=160432 
State-Changed-From-To: open->patched 
State-Changed-By: glebius 
State-Changed-When: Wed Mar 21 06:52:01 UTC 2012 
State-Changed-Why:  
Fix committed to head/. 

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

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/160432: commit references a PR
Date: Wed, 21 Mar 2012 06:51:56 +0000 (UTC)

 Author: glebius
 Date: Wed Mar 21 06:51:45 2012
 New Revision: 233257
 URL: http://svn.freebsd.org/changeset/base/233257
 
 Log:
   Don't run through time checks when entry is definitely oversized. This
   leads to newsyslog rotating on (size OR time) if both are specified.
   
   PR:		100018, 160432
 
 Modified:
   head/usr.sbin/newsyslog/newsyslog.c
 
 Modified: head/usr.sbin/newsyslog/newsyslog.c
 ==============================================================================
 --- head/usr.sbin/newsyslog/newsyslog.c	Wed Mar 21 04:00:58 2012	(r233256)
 +++ head/usr.sbin/newsyslog/newsyslog.c	Wed Mar 21 06:51:45 2012	(r233257)
 @@ -484,12 +484,14 @@ do_entry(struct conf_entry * ent)
  	fk_entry free_or_keep;
  	double diffsecs;
  	char temp_reason[REASON_MAX];
 +	int oversized;
  
  	free_or_keep = FREE_ENT;
  	if (verbose)
  		printf("%s <%d%s>: ", ent->log, ent->numlogs,
  		    compress_type[ent->compress].flag);
  	ent->fsize = sizefile(ent->log);
 +	oversized = ((ent->trsize > 0) && (ent->fsize >= ent->trsize));
  	modtime = age_old_log(ent->log);
  	ent->rotate = 0;
  	ent->firstcreate = 0;
 @@ -518,7 +520,8 @@ do_entry(struct conf_entry * ent)
  			printf("does not exist, skipped%s.\n", temp_reason);
  		}
  	} else {
 -		if (ent->flags & CE_TRIMAT && !force && !rotatereq) {
 +		if (ent->flags & CE_TRIMAT && !force && !rotatereq &&
 +		    !oversized) {
  			diffsecs = ptimeget_diff(timenow, ent->trim_at);
  			if (diffsecs < 0.0) {
  				/* trim_at is some time in the future. */
 @@ -574,7 +577,7 @@ do_entry(struct conf_entry * ent)
  		} else if (force) {
  			ent->rotate = 1;
  			snprintf(temp_reason, REASON_MAX, " due to -F request");
 -		} else if ((ent->trsize > 0) && (ent->fsize >= ent->trsize)) {
 +		} else if (oversized) {
  			ent->rotate = 1;
  			snprintf(temp_reason, REASON_MAX, " due to size>%dK",
  			    ent->trsize);
 _______________________________________________
 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: patched->closed 
State-Changed-By: glebius 
State-Changed-When: Wed Apr 25 07:06:04 UTC 2012 
State-Changed-Why:  
Merged to stable/9, would be available in 9.1-RELEASE. 

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

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/160432: commit references a PR
Date: Wed, 25 Apr 2012 07:04:59 +0000 (UTC)

 Author: glebius
 Date: Wed Apr 25 07:04:48 2012
 New Revision: 234674
 URL: http://svn.freebsd.org/changeset/base/234674
 
 Log:
   Merge r233257, r233258 from head:
     Don't run through time checks when entry is definitely oversized. This
     leads to newsyslog rotating on (size OR time) if both are specified.
   
     Fix a sentence in a paragraph that describes time and interval based
     trimming. This sentence vaguely can be interpreted as if it was speaking
     about time and size interaction, while it wasn't about it.
   
   PR:	100018, 160432
 
 Modified:
   stable/9/usr.sbin/newsyslog/newsyslog.c
   stable/9/usr.sbin/newsyslog/newsyslog.conf.5
 Directory Properties:
   stable/9/usr.sbin/newsyslog/   (props changed)
 
 Modified: stable/9/usr.sbin/newsyslog/newsyslog.c
 ==============================================================================
 --- stable/9/usr.sbin/newsyslog/newsyslog.c	Wed Apr 25 06:52:26 2012	(r234673)
 +++ stable/9/usr.sbin/newsyslog/newsyslog.c	Wed Apr 25 07:04:48 2012	(r234674)
 @@ -484,12 +484,14 @@ do_entry(struct conf_entry * ent)
  	fk_entry free_or_keep;
  	double diffsecs;
  	char temp_reason[REASON_MAX];
 +	int oversized;
  
  	free_or_keep = FREE_ENT;
  	if (verbose)
  		printf("%s <%d%s>: ", ent->log, ent->numlogs,
  		    compress_type[ent->compress].flag);
  	ent->fsize = sizefile(ent->log);
 +	oversized = ((ent->trsize > 0) && (ent->fsize >= ent->trsize));
  	modtime = age_old_log(ent->log);
  	ent->rotate = 0;
  	ent->firstcreate = 0;
 @@ -518,7 +520,8 @@ do_entry(struct conf_entry * ent)
  			printf("does not exist, skipped%s.\n", temp_reason);
  		}
  	} else {
 -		if (ent->flags & CE_TRIMAT && !force && !rotatereq) {
 +		if (ent->flags & CE_TRIMAT && !force && !rotatereq &&
 +		    !oversized) {
  			diffsecs = ptimeget_diff(timenow, ent->trim_at);
  			if (diffsecs < 0.0) {
  				/* trim_at is some time in the future. */
 @@ -574,7 +577,7 @@ do_entry(struct conf_entry * ent)
  		} else if (force) {
  			ent->rotate = 1;
  			snprintf(temp_reason, REASON_MAX, " due to -F request");
 -		} else if ((ent->trsize > 0) && (ent->fsize >= ent->trsize)) {
 +		} else if (oversized) {
  			ent->rotate = 1;
  			snprintf(temp_reason, REASON_MAX, " due to size>%dK",
  			    ent->trsize);
 
 Modified: stable/9/usr.sbin/newsyslog/newsyslog.conf.5
 ==============================================================================
 --- stable/9/usr.sbin/newsyslog/newsyslog.conf.5	Wed Apr 25 06:52:26 2012	(r234673)
 +++ stable/9/usr.sbin/newsyslog/newsyslog.conf.5	Wed Apr 25 07:04:48 2012	(r234674)
 @@ -21,7 +21,7 @@
  .\" the suitability of this software for any purpose.  It is
  .\" provided "as is" without express or implied warranty.
  .\"
 -.Dd February 25, 2011
 +.Dd March 21, 2012
  .Dt NEWSYSLOG.CONF 5
  .Os
  .Sh NAME
 @@ -130,7 +130,7 @@ Additionally, the format may also be con
  sign along with a rotation time specification of once
  a day, once a week, or once a month.
  .Pp
 -If a time is specified, the log file will only be trimmed if
 +Time based trimming happens only if
  .Xr newsyslog 8
  is run within one hour of the specified time.
  If an interval is specified, the log file will be trimmed if that many
 _______________________________________________
 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"
 
>Unformatted:
