aboutsummaryrefslogtreecommitdiff
path: root/usr.sbin/newsyslog
diff options
context:
space:
mode:
Diffstat (limited to 'usr.sbin/newsyslog')
-rw-r--r--usr.sbin/newsyslog/newsyslog.829
-rw-r--r--usr.sbin/newsyslog/newsyslog.c76
-rw-r--r--usr.sbin/newsyslog/newsyslog.conf.584
-rw-r--r--usr.sbin/newsyslog/newsyslog.conf.d/Makefile7
-rw-r--r--usr.sbin/newsyslog/tests/legacy_test.sh93
5 files changed, 153 insertions, 136 deletions
diff --git a/usr.sbin/newsyslog/newsyslog.8 b/usr.sbin/newsyslog/newsyslog.8
index 6d4fc378e790..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 December 22, 2023
+.Dd September 22, 2025
.Dt NEWSYSLOG 8
.Os
.Sh NAME
@@ -24,9 +24,9 @@
.Nm
.Op Fl CFNPnrsv
.Op Fl a Ar directory
-.Op Fl c Ar none Ns | Ns Ar legacy Ns | Ns Ar bzip2 Ns | Ns Ar gzip Ns | Ns Ar xz Ns | Ns Ar zstd
.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
@@ -79,25 +79,6 @@ and mode three (above) assumes that this is so.
The following options can be used with
.Nm :
.Bl -tag -width indent
-.It Fl c Ar none Ns | Ns Ar legacy Ns | Ns Ar bzip2 Ns | Ns Ar gzip Ns | Ns Ar xz Ns | Ns Ar zstd
-Instructs
-.Nm
-to use the specified compression method when a file is flagged for compression.
-The default method is
-.Dq legacy ,
-which interprets the
-.Sy J, X, Y, Z
-flags in the configuration file according to their historical meanings.
-This default setting can be overridden by specifying
-.Fl c Ar none ,
-which causes
-.Nm
-to ignore all compression flags.
-Alternatively, specifying one of the compression methods:
-.Sy bzip2 , gzip , xz ,
-or
-.Sy zstd ,
-will apply the chosen method to all files flagged for compression.
.It Fl f Ar config_file
Instruct
.Nm
@@ -152,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
@@ -267,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 d07f302fd24f..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 */
@@ -309,7 +310,6 @@ static int age_old_log(const char *file);
static void savelog(char *from, char *to);
static void createdir(const struct conf_entry *ent, char *dirpart);
static void createlog(const struct conf_entry *ent);
-static int parse_signal(const char *str);
/*
* All the following take a parameter of 'int', but expect values in the
@@ -456,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;
}
@@ -701,19 +701,12 @@ parse_args(int argc, char **argv)
hostname_shortlen = strcspn(hostname, ".");
/* Parse command line options. */
- while ((ch = getopt(argc, argv, "a:c: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++;
archdirname = optarg;
break;
- case 'c':
- if (!parse_compression_type(optarg, &compress_type_override)) {
- warnx("Unrecognized compression method '%s'.", optarg);
- usage();
- }
- compress_type_set = true;
- break;
case 'd':
destdir = optarg;
break;
@@ -756,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;
@@ -844,13 +841,6 @@ parse_doption(const char *doption)
return (1); /* successfully parsed */
}
- /* XXX - This check could probably be dropped. */
- if ((strcmp(doption, "neworder") == 0) || (strcmp(doption, "oldorder")
- == 0)) {
- warnx("NOTE: newsyslog always uses 'neworder'.");
- return (1); /* successfully parsed */
- }
-
warnx("Unknown -D (debug) option: '%s'", doption);
return (0); /* failure */
}
@@ -858,26 +848,10 @@ parse_doption(const char *doption)
static void
usage(void)
{
- int i;
- char *alltypes = NULL, *tmp = NULL;
-
- for (i = 0; i < COMPRESS_TYPES; i++) {
- if (i == COMPRESS_NONE) {
- (void)asprintf(&tmp, "%s|legacy", compress_type[i].name);
- } else {
- (void)asprintf(&tmp, "%s|%s", alltypes, compress_type[i].name);
- }
- if (alltypes)
- free(alltypes);
- alltypes = tmp;
- tmp = NULL;
- }
fprintf(stderr,
- "usage: newsyslog [-CFNPnrsv] [-a directory] [-c %s]\n"
- " [-d directory] [-f config_file]\n"
- " [-S pidfile] [-t timefmt] [[-R tagname] file ...]\n",
- alltypes);
+ "usage: newsyslog [-CFNPnrsv] [-a directory] [-d directory] [-f config_file]\n"
+ " [-I signal] [-S pidfile] [-t timefmt] [[-R tagname] file ...]\n");
exit(1);
}
@@ -1512,11 +1486,10 @@ no_trimat:
*parse = '\0';
}
- working->sig = SIGHUP;
+ working->sig = defsignal;
if (q && *q) {
got_sig:
- working->sig = parse_signal(q);
- if (working->sig < 1 || working->sig >= sys_nsig) {
+ if (str2sig(q, &working->sig) != 0) {
badline(
"illegal signal in config file:\n%s",
errline);
@@ -2642,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 */
@@ -2914,28 +2887,3 @@ change_attrs(const char *fname, const struct conf_entry *ent)
warn("can't chflags %s NODUMP", fname);
}
}
-
-/*
- * Parse a signal number or signal name. Returns the signal number parsed or -1
- * on failure.
- */
-static int
-parse_signal(const char *str)
-{
- int sig, i;
- const char *errstr;
-
- sig = strtonum(str, 1, sys_nsig - 1, &errstr);
-
- if (errstr == NULL)
- return (sig);
- if (strncasecmp(str, "SIG", 3) == 0)
- str += 3;
-
- for (i = 1; i < sys_nsig; i++) {
- if (strcasecmp(str, sys_signame[i]) == 0)
- return (i);
- }
-
- return (-1);
-}
diff --git a/usr.sbin/newsyslog/newsyslog.conf.5 b/usr.sbin/newsyslog/newsyslog.conf.5
index 2887ecb226aa..0a47af7285c6 100644
--- a/usr.sbin/newsyslog/newsyslog.conf.5
+++ b/usr.sbin/newsyslog/newsyslog.conf.5
@@ -18,7 +18,7 @@
.\" the suitability of this software for any purpose. It is
.\" provided "as is" without express or implied warranty.
.\"
-.Dd November 11, 2024
+.Dd September 1, 2025
.Dt NEWSYSLOG.CONF 5
.Os
.Sh NAME
@@ -44,8 +44,7 @@ reads a configuration file,
normally
.Pa /etc/newsyslog.conf ,
to determine which logs may potentially be rotated and archived.
-Each line has five mandatory fields and four optional fields,
-separated with whitespace.
+.Pp
Blank lines or lines beginning with
.Ql #
are ignored.
@@ -63,34 +62,73 @@ in this case preceding
is removed and
.Ql #
is treated as an ordinary character.
+.Pp
+The special
+.Dq Ar <compress>
+and
+.Dq Ar <include>
+lines are defined as follows:
+.Bl -tag -width indent
+.It Ar <compress> Ar none Ns | Ns Ar legacy Ns | Ns Ar bzip2 Ns | Ns Ar gzip Ns | Ns Ar xz Ns | Ns Ar zstd
+This special option sets the global compress method,
+it should be placed before all log file entries in
+.Nm
+configuration file.
+The global compress method applies to all log files flagged as
+compressible
+.Dq Sy J ,
+.Dq Sy X ,
+.Dq Sy Y ,
+.Dq Sy Z
+.Ar flags
+below.
+.Pp
+The following compression methods are available:
+.Bl -tag -width indent
+.It Cm none
+No compression is performed, even when a log file is marked as
+compressible. This is useful for filesystems that have native
+compression support.
+.It Cm legacy
+Interprets the
+.Sy J, X, Y, Z
+flags in the configuration file according to their historical meanings.
+This is the default method.
+.It Cm bzip2
+Use
+.Xr bzip2 1
+for all compressible log files.
+.It Cm gzip
+Use
+.Xr gzip 1
+for all compressible log files.
+.It Cm xz
+Use
+.Xr xz 1
+for all compressible log files.
+.It Cm zstd
+Use
+.Xr zstd 1
+for all compressible log files.
+.El
+.It Ar <include>
+The special <include> entry is used to include other configuration
+files and supports globbing.
+.El
+.Pp
+Each other line has five mandatory fields and four optional fields,
+separated with whitespace.
The fields of the configuration file are as follows:
.Bl -tag -width indent
.It Ar logfile_name
Name of the system log file to be archived,
-or one of the special strings
-.Dq Li <compress> ,
-.Dq Li <default> ,
-or
-.Dq Li <include> .
-The <compress> entry,
-which should be placed at the beginning of the
-.Nm
-configuration file,
-sets the global compress method.
-This method is applied when a log file is flagged as
-compressible,
-which has the same effect of passing a compress method to the
-.Fl c
-option on the
-.Xr newsyslog 8
-command line.
+or the special string
+.Dq Ar <default> .
The special <default> entry will only be used if a log file
name is given as a command line argument to
.Xr newsyslog 8 ,
and if that log file name is not matched by any other
line in the configuration file.
-The include entry is used to include other configuration
-files and supports globbing.
.It Ar owner : Ns Ar group
This optional field specifies the owner and group for the archive file.
The
@@ -432,7 +470,7 @@ can be the signal number, e.g., 30 for
.El
.Sh EXAMPLES
The following is an example of the
-.Dq Aq Li include
+.Dq <include>
entry:
.Dl "<include> /etc/newsyslog-local.conf"
.Sh SEE ALSO
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 5aecdeacd10a..ea0b0c6fc726 100644
--- a/usr.sbin/newsyslog/tests/legacy_test.sh
+++ b/usr.sbin/newsyslog/tests/legacy_test.sh
@@ -206,7 +206,7 @@ tmpdir_clean()
run_newsyslog()
{
- newsyslog -f ../newsyslog.conf -F -r "$@"
+ newsyslog -f ../newsyslog.conf -r "$@"
}
tests_normal_rotate() {
@@ -216,17 +216,17 @@ tests_normal_rotate() {
dir="$2"
if [ -n "$dir" ]; then
- newsyslog_args=" -a ${dir}"
+ newsyslog_args="-F -a ${dir}"
name_postfix="${ext} archive dir"
else
- newsyslog_args=""
+ newsyslog_args="-F"
name_postfix="${ext}"
fi
tmpdir_create
begin "create file ${name_postfix}" -newdir
- run_newsyslog -C
+ run_newsyslog -CF
ckfe $LOGFNAME
cknt ${dir}${LOGFNAME}.0${ext}
end
@@ -294,17 +294,17 @@ tests_normal_rotate_keepn() {
dir="$3"
if [ -n "$dir" ]; then
- newsyslog_args=" -a ${dir}"
+ newsyslog_args="-F -a ${dir}"
name_postfix="${ext} archive dir"
else
- newsyslog_args=""
+ newsyslog_args="-F"
name_postfix="${ext}"
fi
tmpdir_create
begin "create file ${name_postfix}" -newdir
- run_newsyslog -C
+ run_newsyslog -CF
ckfe $LOGFNAME
cknt ${dir}${LOGFNAME}.0${ext}
end
@@ -363,10 +363,10 @@ tests_time_rotate() {
dir="$2"
if [ -n "$dir" ]; then
- newsyslog_args="-t DEFAULT -a ${dir}"
+ newsyslog_args="-F -t DEFAULT -a ${dir}"
name_postfix="${ext} archive dir"
else
- newsyslog_args="-t DEFAULT"
+ newsyslog_args="-F -t DEFAULT"
name_postfix="${ext}"
fi
@@ -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
@@ -424,17 +469,17 @@ tests_rfc5424() {
dir="$2"
if [ -n "$dir" ]; then
- newsyslog_args=" -a ${dir}"
+ newsyslog_args="-F -a ${dir}"
name_postfix="${ext} archive dir"
else
- newsyslog_args=""
+ newsyslog_args="-F"
name_postfix="${ext}"
fi
tmpdir_create
begin "RFC-5424 - create file ${name_postfix}" -newdir
- run_newsyslog -C
+ run_newsyslog -CF
ckfe $LOGFNAME
cknt ${dir}${LOGFNAME}.0${ext}
ckfe $LOGFNAME5424
@@ -466,23 +511,23 @@ tests_p_flag_rotate() {
tmpdir_create
begin "create file"
- run_newsyslog -C
+ run_newsyslog -CF
ckfe $LOGFNAME
cknt ${LOGFNAME}.0
cknt ${LOGFNAME}.0${ext}
end
begin "rotate p flag 1 ${ext}"
- run_newsyslog
+ run_newsyslog -F
ckfe $LOGFNAME
ckfe ${LOGFNAME}.0
cknt ${LOGFNAME}.0${ext}
- run_newsyslog
+ run_newsyslog -F
ckfe $LOGFNAME
ckfe ${LOGFNAME}.0
cknt ${LOGFNAME}.0${ext}
ckfe ${LOGFNAME}.1${ext}
- run_newsyslog
+ run_newsyslog -F
ckfe $LOGFNAME
ckfe ${LOGFNAME}.0
cknt ${LOGFNAME}.0${ext}
@@ -501,13 +546,13 @@ tests_normal_rotate_recompress() {
tmpdir_create
begin "create file recompress"
- run_newsyslog -C
+ run_newsyslog -CF
ckfe $LOGFNAME
cknt ${LOGFNAME}.0${ext}
end
begin "rotate normal 1"
- run_newsyslog
+ run_newsyslog -F
ckfe $LOGFNAME
ckfe ${LOGFNAME}.0${ext}
cknt ${LOGFNAME}.1${ext}
@@ -517,14 +562,16 @@ tests_normal_rotate_recompress() {
gunzip ${LOGFNAME}.0${ext}
ckfe ${LOGFNAME}.0
cknt ${LOGFNAME}.0${ext}
- run_newsyslog
+ run_newsyslog -F
ckfe $LOGFNAME
ckfe ${LOGFNAME}.0${ext}
ckfe ${LOGFNAME}.1${ext}
end
+
+ tmpdir_clean
}
-echo 1..185
+echo 1..193
mkdir -p ${TMPDIR}
cd ${TMPDIR}
@@ -636,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}"