Index | Thread | Search

From:
Jan Klemkow <jan@openbsd.org>
Subject:
Re: newsyslog: fix time and size logic
To:
tech@openbsd.org
Date:
Wed, 18 Sep 2024 23:36:54 +0200

Download raw body.

Thread
On Mon, Sep 09, 2024 at 01:05:14PM +0200, Jan Klemkow wrote:
> if we use time and size parameter for logfile rotation, just the time
> parameter is used.  Caused by the return next to the debug print (see
> below).  If we removed the return statement, the logic changed to (time
> || size).  The manpage is also adjusted to clarify this behavior.

Last diff always rotates logs.  This diff fixes this issue and rotates
when time is up or log it too big.

Of course, this should be committed after the 7.6 release.

ok?

bye,
Jan

Index: newsyslog.8
===================================================================
RCS file: /cvs/src/usr.bin/newsyslog/newsyslog.8,v
diff -u -p -r1.55 newsyslog.8
--- newsyslog.8	22 Apr 2024 14:16:14 -0000	1.55
+++ newsyslog.8	18 Sep 2024 21:29:32 -0000
@@ -253,6 +253,14 @@ If an interval is specified, the log fil
 many hours have passed since the last rotation.
 When both a time and an interval are specified, both conditions
 must be satisfied for the rotation to take place.
+If the
+.Ar size
+field is set and not
+.Ql *
+or
+.Ql 0 ,
+the file will be rotated either if the size is
+exceeded or the specified time or interval is reached.
 .Pp
 There is no provision for the specification of a time zone.
 There is little point in specifying an explicit minutes or seconds
Index: newsyslog.c
===================================================================
RCS file: /cvs/src/usr.bin/newsyslog/newsyslog.c,v
diff -u -p -r1.114 newsyslog.c
--- newsyslog.c	22 Apr 2024 14:20:35 -0000	1.114
+++ newsyslog.c	18 Sep 2024 21:27:36 -0000
@@ -313,7 +313,8 @@ do_entry(struct conf_entry *ent)
 		    difftime(timenow, ent->trim_at) >= 60 * 60) {
 			DPRINTF(("--> will trim at %s",
 			    ctime(&ent->trim_at)));
-			return;
+			if (ent->size <= 0 || size < ent->size)
+				return;
 		} else if (ent->hours <= 0) {
 			DPRINTF(("--> time is up\n"));
 		}