From 4f5124cb794f91b64f7f5bd4e2c64ba89230f4d8 Mon Sep 17 00:00:00 2001 From: Joachim Nilsson Date: Tue, 29 Oct 2019 06:37:55 +0100 Subject: [PATCH] Change command line option for log rotation, from -b/-c --> -R b:c We want to use -b for binding to an address:port, like FreeBSD/NetBSD supports using this option. Unfortunately breaks existing setups in the wild already. Signed-off-by: Joachim Nilsson --- man/sysklogd.8 | 52 +++++++++++++++++++------------------------------- src/compat.h | 20 +++++++++++++++++++ src/logger.c | 20 ------------------- src/syslogd.c | 18 +++++++---------- 4 files changed, 47 insertions(+), 63 deletions(-) diff --git a/man/sysklogd.8 b/man/sysklogd.8 index 83de619..2c8fdf0 100644 --- a/man/sysklogd.8 +++ b/man/sysklogd.8 @@ -11,12 +11,6 @@ sysklogd \- Linux system logging utilities. .RB [ " \-a " .I socket ] -.RB [ " \-b " -.I size -] -.RB [ " \-c " -.I count -] .RB [ " \-d " ] .RB [ " \-f " .I config file @@ -32,6 +26,9 @@ sysklogd \- Linux system logging utilities. .RB [ " \-p" .IB socket ] +.RB [ " \-R " +.I size:count +] .RB [ " \-r " ] .RB [ " \-s " .I domainlist @@ -111,32 +108,6 @@ within the syslogd.c source file. An example for a chroot() daemon is described by the people from OpenBSD at . .TP -.BI "\-b " "size" -This option controls the max size of files in the built-in log-rotation. -When present on the command line it activates log rotation of all files -with the given maximum size. It is also possible to control log rotate -per log file, see -.BR syslog.conf (5) -for details. - -The size argument takes optional modifiers; k, M, G. E.g., 100M is -100MB, 42k is 42 kB, etc. - -Default: disabled (0). -.TP -.BI "\-c " "count" -This option controls the max number of files kept by the built-in -log-rotation. To activate the built-in log rotation this option must be -combined with the -.BI "\-b" -option. The number of files kept include both gzipped files and the -first rotated (not zipped) file. It is also possible to control log -rotate per log file, see -.BR syslog.conf (5) -for details. - -Default: 5. -.TP .B "\-d" Turns on debug mode. Using this the daemon will not proceed a .BR fork (2) @@ -187,6 +158,23 @@ is started and controlled by You can specify an alternative unix domain socket instead of .IR /dev/log "." .TP +.BI "\-R " "size[:count]" +This option controls the max size and number of backup files kept by the +built-in log-rotation. When present on the command line it activates +log rotation of all files with the given maximum size. It is also +possible to control log rotate per log file, see +.BR syslog.conf (5) +for details. + +The size argument takes optional modifiers; k, M, G. E.g., 100M is +100MB, 42k is 42 kB, etc. + +The optional number of files kept include both gzipped files and the +first rotated (not zipped) file. The default for this, when omitted, +is 5. + +Default: disabled. +.TP .B "\-r" This option will enable the facility to receive message from the network using an internet domain socket with the syslog service (see diff --git a/src/compat.h b/src/compat.h index 56b414e..0e93946 100644 --- a/src/compat.h +++ b/src/compat.h @@ -100,4 +100,24 @@ static inline int strtobytes(char *arg) return bytes; } +static inline void parse_rotation(char *optarg, off_t *size, int *num) +{ + char buf[100]; + char *c; + int sz = 0, cnt = 0; + + strlcpy(buf, optarg, sizeof(buf)); + c = strchr(buf, ':'); + if (c) { + *c++ = 0; + cnt = atoi(c); + } + + sz = strtobytes(buf); + if (sz > 0) + *size = sz; + if (cnt) + *num = cnt; +} + #endif /* SYSKLOGD_COMPAT_H_ */ diff --git a/src/logger.c b/src/logger.c index c59a0a5..d2200ed 100644 --- a/src/logger.c +++ b/src/logger.c @@ -219,26 +219,6 @@ static int usage(int code) return code; } -static void parse_rotation(char *optarg, off_t *size, int *num) -{ - char buf[100]; - char *c; - int sz = 0, cnt = 0; - - strlcpy(buf, optarg, sizeof(buf)); - c = strchr(buf, ':'); - if (c) { - *c++ = 0; - cnt = atoi(c); - } - - sz = strtobytes(buf); - if (sz > 0) - *size = sz; - if (cnt) - *num = cnt; -} - int main(int argc, char *argv[]) { int c, rc, num = 5; diff --git a/src/syslogd.c b/src/syslogd.c index 9f7b01b..ebb0654 100644 --- a/src/syslogd.c +++ b/src/syslogd.c @@ -353,8 +353,8 @@ int AcceptRemote = 0; /* receive messages that come via UDP */ char **StripDomains = NULL; /* these domains may be stripped before writing logs */ char **LocalHosts = NULL; /* these hosts are logged with their hostname */ int NoHops = 1; /* Can we bounce syslog messages through an intermediate host. */ -int RotateSz = 0; /* Max file size (bytes) before rotating, disabled by default */ -int RotateCnt = 5; /* Max number (count) of log files to keep, set with -c */ +static off_t RotateSz = 0; /* Max file size (bytes) before rotating, disabled by default */ +static int RotateCnt = 5; /* Max number (count) of log files to keep, set with -c */ extern int errno; /* Function prototypes. */ @@ -413,7 +413,7 @@ int main(int argc, char *argv[]) funix[i] = -1; } - while ((ch = getopt(argc, argv, "46Aa:b:c:dhf:l:m:np:rs:v?")) != EOF) { + while ((ch = getopt(argc, argv, "46Aa:dhf:l:m:np:R:rs:v?")) != EOF) { switch ((char)ch) { case '4': family = PF_INET; @@ -434,14 +434,6 @@ int main(int argc, char *argv[]) fprintf(stderr, "Out of descriptors, ignoring %s\n", optarg); break; - case 'b': /* Max file size (bytes) before rotating log file. */ - RotateSz = strtobytes(optarg); - break; - - case 'c': /* Number (count) of log files to keep. */ - RotateCnt = atoi(optarg); - break; - case 'd': /* debug */ Debug = 1; break; @@ -475,6 +467,10 @@ int main(int argc, char *argv[]) funixn[0] = optarg; break; + case 'R': + parse_rotation(optarg, &RotateSz, &RotateCnt); + break; + case 'r': /* accept remote messages */ AcceptRemote = 1; break;