newsyslog.conf: allow to configure the signal using the signal name.

Submitted by:	Alexandre Perrin <alex@kaworu.ch>
MFC after:	1 week
Relnotes:	yes
Differential Revision:	https://reviews.freebsd.org/D3961
This commit is contained in:
bapt 2015-10-24 13:55:12 +00:00
parent 79d3d4c428
commit a0408328fb
2 changed files with 48 additions and 16 deletions

View File

@ -280,6 +280,7 @@ static int age_old_log(const char *file);
static void savelog(char *from, char *to); static void savelog(char *from, char *to);
static void createdir(const struct conf_entry *ent, char *dirpart); static void createdir(const struct conf_entry *ent, char *dirpart);
static void createlog(const struct conf_entry *ent); 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 * All the following take a parameter of 'int', but expect values in the
@ -1338,12 +1339,13 @@ parse_file(FILE *cf, struct cflist *work_p, struct cflist *glob_p,
if (q && *q) { if (q && *q) {
if (*q == '/') if (*q == '/')
working->pid_cmd_file = strdup(q); working->pid_cmd_file = strdup(q);
else if (isdigit(*q)) else if (isalnum(*q))
goto got_sig; goto got_sig;
else else {
errx(1, errx(1,
"illegal pid file or signal number in config file:\n%s", "illegal pid file or signal in config file:\n%s",
errline); errline);
}
} }
if (eol) if (eol)
q = NULL; q = NULL;
@ -1354,17 +1356,13 @@ parse_file(FILE *cf, struct cflist *work_p, struct cflist *glob_p,
working->sig = SIGHUP; working->sig = SIGHUP;
if (q && *q) { if (q && *q) {
if (isdigit(*q)) { got_sig:
got_sig: working->sig = parse_signal(q);
working->sig = atoi(q); if (working->sig < 1 || working->sig >= sys_nsig) {
} else {
err_sig:
errx(1, errx(1,
"illegal signal number in config file:\n%s", "illegal signal in config file:\n%s",
errline); errline);
} }
if (working->sig < 1 || working->sig >= NSIG)
goto err_sig;
} }
/* /*
@ -2662,3 +2660,28 @@ change_attrs(const char *fname, const struct conf_entry *ent)
warn("can't chflags %s NODUMP", fname); 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);
}

View File

@ -21,7 +21,7 @@
.\" the suitability of this software for any purpose. It is .\" the suitability of this software for any purpose. It is
.\" provided "as is" without express or implied warranty. .\" provided "as is" without express or implied warranty.
.\" .\"
.Dd March 21, 2012 .Dd October 24, 2015
.Dt NEWSYSLOG.CONF 5 .Dt NEWSYSLOG.CONF 5
.Os .Os
.Sh NAME .Sh NAME
@ -337,7 +337,7 @@ process ID or to find a group process ID if the
.Cm U .Cm U
flag was specified. flag was specified.
If this field is present, a If this field is present, a
.Ar signal_number .Ar signal
is sent to the process ID contained in this file. is sent to the process ID contained in this file.
If this field is not present and the If this field is not present and the
.Cm N .Cm N
@ -358,14 +358,23 @@ flag, the file is treated as a path to a binary to be executed
by the by the
.Xr newsyslog 8 .Xr newsyslog 8
after rotation instead of sending the signal out. after rotation instead of sending the signal out.
.It Ar signal_number .It Ar signal
This optional field specifies the signal number that will be sent This optional field specifies the signal that will be sent to the daemon
to the daemon process (or to all processes in a process group, if the process (or to all processes in a process group, if the
.Cm U .Cm U
flag was specified). flag was specified).
If this field is not present, then a If this field is not present, then a
.Dv SIGHUP .Dv SIGHUP
signal will be sent. signal will be sent.
Signal names
must start with
.Dq SIG
and be the signal name, e.g.,
.Dv SIGUSR1 .
Alternatively,
.Ar signal
can be the signal number, e.g., 30 for
.Dv SIGUSR1 .
.El .El
.Sh EXAMPLES .Sh EXAMPLES
The following is an example of the The following is an example of the