From nobody@FreeBSD.org  Mon Jul 10 09:35:35 2006
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id 0850F16A4E5
	for <freebsd-gnats-submit@FreeBSD.org>; Mon, 10 Jul 2006 09:35:35 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (www.freebsd.org [216.136.204.117])
	by mx1.FreeBSD.org (Postfix) with ESMTP id C8B4043D46
	for <freebsd-gnats-submit@FreeBSD.org>; Mon, 10 Jul 2006 09:35:34 +0000 (GMT)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (localhost [127.0.0.1])
	by www.freebsd.org (8.13.1/8.13.1) with ESMTP id k6A9ZY16005541
	for <freebsd-gnats-submit@FreeBSD.org>; Mon, 10 Jul 2006 09:35:34 GMT
	(envelope-from nobody@www.freebsd.org)
Received: (from nobody@localhost)
	by www.freebsd.org (8.13.1/8.13.1/Submit) id k6A9ZYU4005540;
	Mon, 10 Jul 2006 09:35:34 GMT
	(envelope-from nobody)
Message-Id: <200607100935.k6A9ZYU4005540@www.freebsd.org>
Date: Mon, 10 Jul 2006 09:35:34 GMT
From: Arne Woerner <arne_woerner@yahoo.com>
To: freebsd-gnats-submit@FreeBSD.org
Subject: newsyslog does not check size if time_at is used
X-Send-Pr-Version: www-2.3

>Number:         100018
>Category:       bin
>Synopsis:       [patch] newsyslog(8) does not check size if time_at is used
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    glebius
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Mon Jul 10 09:40:18 GMT 2006
>Closed-Date:    Wed Apr 25 07:05:55 UTC 2012
>Last-Modified:  Wed Apr 25 07:10:09 UTC 2012
>Originator:     Arne Woerner
>Release:        R6.1
>Organization:
>Environment:
FreeBSD neo.riddick.homeunix.org 6.1-RELEASE FreeBSD 6.1-RELEASE #4: Sun Jul  9 19:31:19 UTC 2006     aw@neo.riddick.homeunix.org:/opt/src/sys/i386/compile/NEO  i386

>Description:
I had the line
  /var/log/messages                       644  80   30000 @T12 JC
in my /etc/newsyslog.conf yesterday.

/var/log/messages's size was over 33,000,000 bytes.

But when I called "newsyslog" nothing happened...

-Arne
>How-To-Repeat:
Should work like this:
1. Create a large file
2. put an appropriate line into newsyslog.conf
3. call newsyslog
>Fix:

>Release-Note:
>Audit-Trail:
State-Changed-From-To: open->feedback 
State-Changed-By: gavin 
State-Changed-When: Thu Jul 17 11:22:53 UTC 2008 
State-Changed-Why:  
To submitter: Can you try the following patch please? 
It works for me, and I've been running it on a couple of machines for a few 
weeks without problem, but more testers would be beneficial! 

Index: src/usr.sbin/newsyslog/newsyslog.c 
=================================================================== 
RCS file: /home/ncvs/src/usr.sbin/newsyslog/newsyslog.c,v 
retrieving revision 1.108 
diff -u -r1.108 newsyslog.c 
--- src/usr.sbin/newsyslog/newsyslog.c	30 Jan 2008 22:11:59 -0000	1.108 
+++ src/usr.sbin/newsyslog/newsyslog.c	17 Jul 2008 12:06:53 -0000 
@@ -424,11 +424,13 @@ 
{ 
#define	REASON_MAX	80 
int modtime; 
+	int check_time_rotate; 
fk_entry free_or_keep; 
double diffsecs; 
char temp_reason[REASON_MAX]; 

free_or_keep = FREE_ENT; 
+	check_time_rotate = 0; 
if (verbose) { 
if (ent->flags & CE_COMPACT) 
printf("%s <%dZ>: ", ent->log, ent->numlogs); 
@@ -476,7 +478,6 @@ 
printf("--> will trim at %s", 
ptimeget_ctime(ent->trim_at)); 
} 
-				return (free_or_keep); 
} else if (diffsecs >= 3600.0) { 
/* 
* trim_at is more than an hour in the past, 
@@ -491,7 +492,6 @@ 
printf("--> will trim at %s", 
ptimeget_ctime(ent->trim_at)); 
} 
-				return (free_or_keep); 
} else if (verbose && noaction && dbg_at_times) { 
/* 
* If we are just debugging at-times, then 
@@ -501,9 +501,10 @@ 
*/ 
printf("nt--> timematch at %s", 
ptimeget_ctime(ent->trim_at)); 
-				return (free_or_keep); 
-			} else if (verbose && ent->hours <= 0) { 
-				printf("--> time is upn"); 
+			} else if (ent->hours <= 0) { 
+				if (verbose) 
+					printf("--> time is upn"); 
+				check_time_rotate = 1; 
} 
} 
if (verbose && (ent->trsize > 0)) 
@@ -526,7 +527,8 @@ 
ent->rotate = 1; 
snprintf(temp_reason, REASON_MAX, " due to size>%dK", 
ent->trsize); 
-		} else if (ent->hours <= 0 && (ent->flags & CE_TRIMAT)) { 
+		} else if ((ent->hours <= 0 && (ent->flags & CE_TRIMAT)) && 
+		    check_time_rotate) { 
ent->rotate = 1; 
} else if ((ent->hours > 0) && ((modtime >= ent->hours) || 
(modtime < 0))) { 


Responsible-Changed-From-To: freebsd-bugs->gavin 
Responsible-Changed-By: gavin 
Responsible-Changed-When: Thu Jul 17 11:22:53 UTC 2008 
Responsible-Changed-Why:  
Track 

http://www.freebsd.org/cgi/query-pr.cgi?pr=100018 
State-Changed-From-To: feedback->open 
State-Changed-By: gavin 
State-Changed-When: Thu Jul 17 14:38:04 UTC 2008 
State-Changed-Why:  
Back to open, user is unable to test the patch 

http://www.freebsd.org/cgi/query-pr.cgi?pr=100018 
Responsible-Changed-From-To: gavin->freebsd-bugs 
Responsible-Changed-By: gavin 
Responsible-Changed-When: Mon Dec 1 12:26:50 UTC 2008 
Responsible-Changed-Why:  
Cast back into the pool.  I've created a patch for it which seems to work 
fine for me, hopefully someone else will take this up. 

Patch is at http://people.freebsd.org/~gavin/PRs/100018.diff 

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


Responsible-Changed-From-To: freebsd-bugs->glebius 
Responsible-Changed-By: glebius 
Responsible-Changed-When: Wed Mar 21 06:52:24 UTC 2012 
Responsible-Changed-Why:  
Fix committed to head/. 

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

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/100018: commit references a PR
Date: Wed, 21 Mar 2012 06:51:55 +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:05:21 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=100018 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/100018: 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:
