Skip to content

Commit

Permalink
newsyslog.conf(5): Accept human unit suffix in the size filed
Browse files Browse the repository at this point in the history
  • Loading branch information
laffer1 committed Dec 1, 2024
1 parent d53bcfd commit e6fc4d5
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
2 changes: 1 addition & 1 deletion usr.sbin/newsyslog/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,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
Expand Down
19 changes: 16 additions & 3 deletions usr.sbin/newsyslog/newsyslog.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
#include <signal.h>
#include <stdio.h>
#include <libgen.h>
#include <libutil.h>
#include <stdlib.h>
#include <string.h>
#include <syslog.h>
Expand Down Expand Up @@ -1223,9 +1224,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",
Expand Down
9 changes: 6 additions & 3 deletions usr.sbin/newsyslog/newsyslog.conf.5
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
.\" the suitability of this software for any purpose. It is
.\" provided "as is" without express or implied warranty.
.\"
.Dd February 26, 2021
.Dd November 11, 2024
.Dt NEWSYSLOG.CONF 5
.Os
.Sh NAME
Expand Down Expand Up @@ -105,8 +105,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 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.
Expand Down Expand Up @@ -414,6 +416,7 @@ entry:
.Xr bzip2 1 ,
.Xr gzip 1 ,
.Xr xz 1 ,
.Xr expand_number 3 ,
.Xr syslog 3 ,
.Xr chown 8 ,
.Xr newsyslog 8 ,
Expand Down

0 comments on commit e6fc4d5

Please sign in to comment.