1
0
mirror of https://github.com/openbsd/src.git synced 2024-12-22 07:27:59 -08:00

Don't run through time checks when entry is definitely oversized.

This leads to newsyslog rotating on (size OR time) if both are
specified.

Reported from Matthias Pitzl.
with tweak from bluhm@

ok millert@
This commit is contained in:
jan 2024-10-30 09:16:24 +00:00
parent e22ff83ad5
commit a910e6e541
2 changed files with 15 additions and 5 deletions

View File

@ -1,4 +1,4 @@
.\" $OpenBSD: newsyslog.8,v 1.55 2024/04/22 14:16:14 jmc Exp $
.\" $OpenBSD: newsyslog.8,v 1.56 2024/10/30 09:16:24 jan Exp $
.\"
.\" Copyright (c) 1997, Jason Downs. All rights reserved.
.\"
@ -41,7 +41,7 @@
.\" the suitability of this software for any purpose. It is
.\" provided "as is" without express or implied warranty.
.\"
.Dd $Mdocdate: April 22 2024 $
.Dd $Mdocdate: October 30 2024 $
.Dt NEWSYSLOG 8
.Os
.Sh NAME
@ -253,6 +253,14 @@ If an interval is specified, the log file will be trimmed if that
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

View File

@ -1,4 +1,4 @@
/* $OpenBSD: newsyslog.c,v 1.114 2024/04/22 14:20:35 millert Exp $ */
/* $OpenBSD: newsyslog.c,v 1.115 2024/10/30 09:16:24 jan Exp $ */
/*
* Copyright (c) 1999, 2002, 2003 Todd C. Miller <millert@openbsd.org>
@ -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)))) {