diff options
Diffstat (limited to 'usr.sbin/newsyslog')
| -rw-r--r-- | usr.sbin/newsyslog/newsyslog.8 | 9 | ||||
| -rw-r--r-- | usr.sbin/newsyslog/newsyslog.c | 15 | ||||
| -rw-r--r-- | usr.sbin/newsyslog/newsyslog.conf.d/Makefile | 7 | ||||
| -rw-r--r-- | usr.sbin/newsyslog/tests/legacy_test.sh | 53 |
4 files changed, 69 insertions, 15 deletions
diff --git a/usr.sbin/newsyslog/newsyslog.8 b/usr.sbin/newsyslog/newsyslog.8 index 7429e3b8eb01..aa89ef4b779a 100644 --- a/usr.sbin/newsyslog/newsyslog.8 +++ b/usr.sbin/newsyslog/newsyslog.8 @@ -14,7 +14,7 @@ .\" the suitability of this software for any purpose. It is .\" provided "as is" without express or implied warranty. .\" -.Dd September 1, 2025 +.Dd September 22, 2025 .Dt NEWSYSLOG 8 .Os .Sh NAME @@ -26,6 +26,7 @@ .Op Fl a Ar directory .Op Fl d Ar directory .Op Fl f Ar config_file +.Op Fl I Ar signal .Op Fl S Ar pidfile .Op Fl t Ar timefmt .Op Oo Fl R Ar tagname Oc Ar @@ -132,7 +133,7 @@ Remove the restriction that must be running as root. Of course, .Nm -will not be able to send a HUP signal to +will not be able to send a signal to .Xr syslogd 8 so this option should only be used in debugging. .It Fl s @@ -247,6 +248,10 @@ Skipping the signal step will also mean that will return faster, since .Nm normally waits a few seconds after any signal that is sent. +.It Fl I Ar signal +Specify signal to send for entries that do not have signal configured. +This option accepts either a signal number or a name as argument. +The default value is HUP. .It Fl S Ar pidfile Use .Ar pidfile diff --git a/usr.sbin/newsyslog/newsyslog.c b/usr.sbin/newsyslog/newsyslog.c index e24e2db1155d..084aeb36b052 100644 --- a/usr.sbin/newsyslog/newsyslog.c +++ b/usr.sbin/newsyslog/newsyslog.c @@ -241,6 +241,7 @@ static int norotate = 0; /* Don't rotate */ static int nosignal; /* Do not send any signals */ static int enforcepid = 0; /* If PID file does not exist or empty, do nothing */ static int force = 0; /* Force the trim no matter what */ +static int defsignal = SIGHUP; /* -I Signal to send by default */ static int rotatereq = 0; /* -R = Always rotate the file(s) as given */ /* on the command (this also requires */ /* that a list of files *are* given on */ @@ -455,7 +456,7 @@ init_entry(const char *fname, struct conf_entry *src_entry) tempwork->permissions = 0; tempwork->flags = 0; tempwork->compress = COMPRESS_NONE; - tempwork->sig = SIGHUP; + tempwork->sig = defsignal; tempwork->def_cfg = 0; } @@ -700,7 +701,7 @@ parse_args(int argc, char **argv) hostname_shortlen = strcspn(hostname, "."); /* Parse command line options. */ - while ((ch = getopt(argc, argv, "a:d:f:nrst:vCD:FNPR:S:")) != -1) + while ((ch = getopt(argc, argv, "a:d:f:nrst:vCD:FI:NPR:S:")) != -1) switch (ch) { case 'a': archtodir++; @@ -748,6 +749,10 @@ parse_args(int argc, char **argv) case 'F': force++; break; + case 'I': + if (str2sig(optarg, &defsignal) != 0) + usage(); + break; case 'N': norotate++; break; @@ -846,7 +851,7 @@ usage(void) fprintf(stderr, "usage: newsyslog [-CFNPnrsv] [-a directory] [-d directory] [-f config_file]\n" - " [-S pidfile] [-t timefmt] [[-R tagname] file ...]\n"); + " [-I signal] [-S pidfile] [-t timefmt] [[-R tagname] file ...]\n"); exit(1); } @@ -1481,7 +1486,7 @@ no_trimat: *parse = '\0'; } - working->sig = SIGHUP; + working->sig = defsignal; if (q && *q) { got_sig: if (str2sig(q, &working->sig) != 0) { @@ -2610,7 +2615,7 @@ age_old_log(const char *file) mtime = sb.st_mtime; } - return ((int)(ptimeget_secs(timenow) - mtime + 1800) / 3600); + return ((int)(ptimeget_secs(timenow) - mtime + 180) / 3600); } /* Skip Over Blanks */ diff --git a/usr.sbin/newsyslog/newsyslog.conf.d/Makefile b/usr.sbin/newsyslog/newsyslog.conf.d/Makefile index 8ef3af253a50..81bec81ece6e 100644 --- a/usr.sbin/newsyslog/newsyslog.conf.d/Makefile +++ b/usr.sbin/newsyslog/newsyslog.conf.d/Makefile @@ -6,13 +6,6 @@ CONFSDIR= /etc/newsyslog.conf.d CONFGROUPS= CONFS CONFS= -.if ${MK_FTP} != "no" -CONFGROUPS+= FTP -FTP+= ftp.conf -FTPPACKAGE= ftpd -FTPDIR= /etc/newsyslog.conf.d -.endif - .if ${MK_LPR} != "no" CONFGROUPS+= LP LP+= lpr.conf diff --git a/usr.sbin/newsyslog/tests/legacy_test.sh b/usr.sbin/newsyslog/tests/legacy_test.sh index c8c18a754977..ea0b0c6fc726 100644 --- a/usr.sbin/newsyslog/tests/legacy_test.sh +++ b/usr.sbin/newsyslog/tests/legacy_test.sh @@ -417,6 +417,51 @@ tests_time_rotate() { tmpdir_clean } +tests_interval_rotate() { + local hours ext h + + hours="$1" + ext="$2" + + tmpdir_create + + begin "create file" -newdir + run_newsyslog -C + ckfe ${LOGFNAME} + end + + # old file doesn't exist - forced rotation + begin "rotate interval 0" + run_newsyslog + ckfe ${LOGFNAME} + chkfcnt 1 ${dir}${LOGFNAME}.* + end + + # emulate newsyslog runs every 5 minutes + begin "rotate interval less than ${hours} hours" + m=0 + while [ $(expr ${m} / 60 ) -lt ${hours} ]; do + touch -t $(date -v -${m}M +%Y%m%d%H%M) ${LOGFNAME}.0 + run_newsyslog + ckfe ${LOGFNAME} + chkfcnt 1 ${dir}${LOGFNAME}.* + if [ $OK != 1 ]; then + break; + fi + m=$(expr ${m} + 5) + done + end + + begin "rotate interval ${hours} hours" + touch -t $(date -v -${hours}H +%Y%m%d%H%M) ${LOGFNAME}.0 + run_newsyslog + ckfe ${LOGFNAME} + chkfcnt 2 ${dir}${LOGFNAME}.* + end + + tmpdir_clean +} + tests_rfc5424() { local dir ext name_postfix newsyslog_args @@ -526,7 +571,7 @@ tests_normal_rotate_recompress() { tmpdir_clean } -echo 1..185 +echo 1..193 mkdir -p ${TMPDIR} cd ${TMPDIR} @@ -638,4 +683,10 @@ tests_p_flag_rotate ".gz" echo "$LOGFPATH 640 3 * @T00 NCZ" > newsyslog.conf tests_normal_rotate_recompress +# Interval based rotation +echo "$LOGFPATH 640 3 * 1 NC" > newsyslog.conf +tests_interval_rotate 1 +echo "$LOGFPATH 640 3 * 2 NC" > newsyslog.conf +tests_interval_rotate 2 + rm -rf "${TMPDIR}" |
