diff --git a/usr.sbin/newsyslog/Makefile b/usr.sbin/newsyslog/Makefile index 0afbe3b814a7..26ff30d4a0b3 100644 --- a/usr.sbin/newsyslog/Makefile +++ b/usr.sbin/newsyslog/Makefile @@ -6,7 +6,7 @@ CONFS= newsyslog.conf PROG= newsyslog MAN= newsyslog.8 newsyslog.conf.5 SRCS= newsyslog.c ptimes.c -LIBADD= sbuf +LIBADD= sbuf util HAS_TESTS= SUBDIR.${MK_TESTS}+= tests diff --git a/usr.sbin/newsyslog/newsyslog.c b/usr.sbin/newsyslog/newsyslog.c index e9b84bae342d..d07f302fd24f 100644 --- a/usr.sbin/newsyslog/newsyslog.c +++ b/usr.sbin/newsyslog/newsyslog.c @@ -77,6 +77,7 @@ #include #include #include +#include #include #include #include @@ -1335,9 +1336,21 @@ parse_file(FILE *cf, struct cflist *work_p, struct cflist *glob_p, badline("malformed line (missing fields):\n%s", errline); *parse = '\0'; - if (isdigitch(*q)) - working->trsize = atoi(q); - else if (strcmp(q, "*") == 0) + if (isdigitch(*q)) { + char last_digit = q[strlen(q) - 1]; + if (isdigitch(last_digit)) + working->trsize = atoi(q); + else { + uint64_t trsize = 0; + if (expand_number(q, &trsize) == 0) + working->trsize = trsize / 1024; + else { + working->trsize = -1; + warnx("Invalid value of '%s' for 'size' in line:\n%s", + q, errline); + } + } + } else if (strcmp(q, "*") == 0) working->trsize = -1; else { warnx("Invalid value of '%s' for 'size' in line:\n%s", diff --git a/usr.sbin/newsyslog/newsyslog.conf.5 b/usr.sbin/newsyslog/newsyslog.conf.5 index a8ab132edaa8..a9deb079e294 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 December 25, 2023 +.Dd November 11, 2024 .Dt NEWSYSLOG.CONF 5 .Os .Sh NAME @@ -116,8 +116,10 @@ Specify the maximum number of archive files which may exist. This does not consider the current log file. .It Ar size When the size of the log file reaches -.Ar size -in kilobytes, the log file will be trimmed as described above. +.Ar size , +in kilobytes by default, or with suffix suffixes like k, M, G, ... as supported by +.Xr expand_number 3 , +the log file will be trimmed as described above. If this field contains an asterisk .Pq Ql * , the log file will not be trimmed based on size. @@ -438,6 +440,7 @@ entry: .Xr gzip 1 , .Xr xz 1 , .Xr zstd 1 , +.Xr expand_number 3 , .Xr syslog 3 , .Xr chown 8 , .Xr newsyslog 8 ,