summaryrefslogtreecommitdiffstats
path: root/usr.sbin/newsyslog/newsyslog.c
diff options
context:
space:
mode:
Diffstat (limited to 'usr.sbin/newsyslog/newsyslog.c')
-rw-r--r--usr.sbin/newsyslog/newsyslog.c45
1 files changed, 34 insertions, 11 deletions
diff --git a/usr.sbin/newsyslog/newsyslog.c b/usr.sbin/newsyslog/newsyslog.c
index b63234b..24e4882 100644
--- a/usr.sbin/newsyslog/newsyslog.c
+++ b/usr.sbin/newsyslog/newsyslog.c
@@ -280,6 +280,7 @@ 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
@@ -1338,12 +1339,13 @@ no_trimat:
if (q && *q) {
if (*q == '/')
working->pid_cmd_file = strdup(q);
- else if (isdigit(*q))
+ else if (isalnum(*q))
goto got_sig;
- else
+ else {
errx(1,
- "illegal pid file or signal number in config file:\n%s",
+ "illegal pid file or signal in config file:\n%s",
errline);
+ }
}
if (eol)
q = NULL;
@@ -1354,17 +1356,13 @@ no_trimat:
working->sig = SIGHUP;
if (q && *q) {
- if (isdigit(*q)) {
- got_sig:
- working->sig = atoi(q);
- } else {
- err_sig:
+got_sig:
+ working->sig = parse_signal(q);
+ if (working->sig < 1 || working->sig >= sys_nsig) {
errx(1,
- "illegal signal number in config file:\n%s",
+ "illegal signal in config file:\n%s",
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);
}
}
+
+/*
+ * 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);
+}
OpenPOWER on IntegriCloud