aboutsummaryrefslogtreecommitdiff
path: root/usr.sbin/newsyslog/newsyslog.c
diff options
context:
space:
mode:
authorJuraj Lutter <otis@FreeBSD.org>2021-02-28 22:07:14 +0000
committerJuraj Lutter <otis@FreeBSD.org>2021-05-23 13:35:51 +0000
commit7e863cb9893b96f4ca6e0597572e3df218dd3830 (patch)
tree924318c788b0aaae4adc1034099b062305d72850 /usr.sbin/newsyslog/newsyslog.c
parent6bc3535519f7206f844c3ffd0ee282e8875dceb4 (diff)
downloadsrc-7e863cb9893b96f4ca6e0597572e3df218dd3830.tar.gz
src-7e863cb9893b96f4ca6e0597572e3df218dd3830.zip
newsyslog(8): Implement a new 'E' flag to not rotate empty log files
Based on an idea from dvl's coworker, László DANIELISZ, implement a new flag, 'E', that prevents newsyslog(8) from rotating the empty log files. This 'E' flag ist mostly usable in conjunction with 'B' flag that instructs newsyslog(8) to not insert an informational message into the log file after rotation, keeping it still empty. Reviewed by: markj, ian, manpages (rpokala) Approved by: markj, ian, manpages (rpokala) MFC after: 2 weeks Differential Revision: https://reviews.freebsd.org/D28940 (cherry picked from commit c7d27b225df8d7fb36a31a21737d4309593c4604)
Diffstat (limited to 'usr.sbin/newsyslog/newsyslog.c')
-rw-r--r--usr.sbin/newsyslog/newsyslog.c11
1 files changed, 10 insertions, 1 deletions
diff --git a/usr.sbin/newsyslog/newsyslog.c b/usr.sbin/newsyslog/newsyslog.c
index d850b0af9f53..c20a36cf31c0 100644
--- a/usr.sbin/newsyslog/newsyslog.c
+++ b/usr.sbin/newsyslog/newsyslog.c
@@ -129,7 +129,8 @@ __FBSDID("$FreeBSD$");
#define CE_PID2CMD 0x0400 /* Replace PID file with a shell command.*/
#define CE_PLAIN0 0x0800 /* Do not compress zero'th history file */
#define CE_RFC5424 0x1000 /* Use RFC5424 format rotation message */
-
+#define CE_NOEMPTY 0x2000 /* Do not rotate the file when its size */
+ /* is zero */
#define MIN_PID 5 /* Don't touch pids lower than this */
#define MAX_PID 99999 /* was lower, see /usr/include/sys/proc.h */
@@ -538,6 +539,11 @@ do_entry(struct conf_entry * ent)
printf("does not exist, skipped%s.\n", temp_reason);
}
} else {
+ if (ent->flags & CE_NOEMPTY && ent->fsize == 0) {
+ if (verbose)
+ printf("--> Not rotating empty file\n");
+ return (free_or_keep);
+ }
if (ent->flags & CE_TRIMAT && !force && !rotatereq &&
!oversized) {
diffsecs = ptimeget_diff(timenow, ent->trim_at);
@@ -1292,6 +1298,9 @@ no_trimat:
case 'd':
working->flags |= CE_NODUMP;
break;
+ case 'e':
+ working->flags |= CE_NOEMPTY;
+ break;
case 'g':
working->flags |= CE_GLOB;
break;