summaryrefslogtreecommitdiff
path: root/usr.bin
diff options
context:
space:
mode:
authorJan Klemkow <jan@cvs.openbsd.org>2024-10-30 09:16:25 +0000
committerJan Klemkow <jan@cvs.openbsd.org>2024-10-30 09:16:25 +0000
commit2da4331b3e4cce769fe27376ff81cf68fd3b2eb7 (patch)
tree06beafda9ba2df46765afca6392bd0c9085423ad /usr.bin
parent5d27090a1566275457d5c1f280b4f150db65f739 (diff)
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@
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/newsyslog/newsyslog.812
-rw-r--r--usr.bin/newsyslog/newsyslog.c8
2 files changed, 15 insertions, 5 deletions
diff --git a/usr.bin/newsyslog/newsyslog.8 b/usr.bin/newsyslog/newsyslog.8
index 9e3f84a0b26..391c7c3d99d 100644
--- a/usr.bin/newsyslog/newsyslog.8
+++ b/usr.bin/newsyslog/newsyslog.8
@@ -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
diff --git a/usr.bin/newsyslog/newsyslog.c b/usr.bin/newsyslog/newsyslog.c
index 852f1dfac87..9274ecf83fb 100644
--- a/usr.bin/newsyslog/newsyslog.c
+++ b/usr.bin/newsyslog/newsyslog.c
@@ -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)))) {