Download raw body.
newsyslog: fix time and size logic
On Fri, Oct 18, 2024 at 04:03:51PM GMT, Alexander Bluhm wrote:
> On Thu, Oct 17, 2024 at 10:06:28AM +0200, Jan Klemkow wrote:
> > 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
Like this, OK?
Thanks,
Jan
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 21 Oct 2024 08:26:07 -0000
@@ -284,6 +284,7 @@ do_entry(struct conf_entry *ent)
struct stat sb;
int modhours;
off_t size;
+ int oversized;
if (lstat(ent->log, &sb) != 0)
return;
@@ -307,8 +308,9 @@ do_entry(struct conf_entry *ent)
(ent->flags & CE_FOLLOW) ? "F" : "",
(ent->flags & CE_MONITOR) && monitormode ? "M" : ""));
size = sizefile(&sb);
+ oversized = (ent->size > 0 && size >= ent->size);
modhours = age_old_log(ent);
- if (ent->flags & CE_TRIMAT && !force) {
+ if (ent->flags & CE_TRIMAT && !force && !oversized) {
if (timenow < ent->trim_at ||
difftime(timenow, ent->trim_at) >= 60 * 60) {
DPRINTF(("--> will trim at %s",
@@ -326,7 +328,7 @@ do_entry(struct conf_entry *ent)
if (monitormode && (ent->flags & CE_MONITOR) && domonitor(ent))
DPRINTF(("--> monitored\n"));
else if (!monitormode &&
- (force || (ent->size > 0 && size >= ent->size) ||
+ (force || oversized ||
(ent->hours <= 0 && (ent->flags & CE_TRIMAT)) ||
(ent->hours > 0 && (modhours >= ent->hours || modhours < 0)
&& ((ent->flags & CE_BINARY) || size >= MIN_SIZE)))) {
newsyslog: fix time and size logic