Index | Thread | Search

From:
Alexander Bluhm <bluhm@openbsd.org>
Subject:
Re: newsyslog: fix time and size logic
To:
Jan Klemkow <jan@openbsd.org>
Cc:
tech@openbsd.org
Date:
Fri, 18 Oct 2024 16:03:51 +0200

Download raw body.

Thread
On Thu, Oct 17, 2024 at 10:06:28AM +0200, Jan Klemkow wrote:
> ping
> 
> On Wed, Sep 18, 2024 at 11:36:54PM GMT, Jan Klemkow wrote:
> > 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.

FreeBSD has fixed this in 2012.  Maybe we should use their logic
as it keeps debug messages consistent.

https://cgit.freebsd.org/src/commit/?id=7be124b0a87db08a0dae97dc3797df168b2b913c

bluhm

> 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"));
>  		}