From owner-svn-src-stable-10@freebsd.org Sat Oct 31 09:32:41 2015 Return-Path: Delivered-To: svn-src-stable-10@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 6A230A220DB; Sat, 31 Oct 2015 09:32:41 +0000 (UTC) (envelope-from bapt@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 4137C161A; Sat, 31 Oct 2015 09:32:41 +0000 (UTC) (envelope-from bapt@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id t9V9WeMs081599; Sat, 31 Oct 2015 09:32:40 GMT (envelope-from bapt@FreeBSD.org) Received: (from bapt@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id t9V9We4R081597; Sat, 31 Oct 2015 09:32:40 GMT (envelope-from bapt@FreeBSD.org) Message-Id: <201510310932.t9V9We4R081597@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: bapt set sender to bapt@FreeBSD.org using -f From: Baptiste Daroussin Date: Sat, 31 Oct 2015 09:32:40 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org Subject: svn commit: r290225 - stable/10/usr.sbin/newsyslog X-SVN-Group: stable-10 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-10@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: SVN commit messages for only the 10-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 31 Oct 2015 09:32:41 -0000 Author: bapt Date: Sat Oct 31 09:32:39 2015 New Revision: 290225 URL: https://svnweb.freebsd.org/changeset/base/290225 Log: MFC: 289879 newsyslog.conf: allow to configure the signal using the signal name. Submitted by: Alexandre Perrin Relnotes: yes Differential Revision: https://reviews.freebsd.org/D3961 Modified: stable/10/usr.sbin/newsyslog/newsyslog.c stable/10/usr.sbin/newsyslog/newsyslog.conf.5 Directory Properties: stable/10/ (props changed) Modified: stable/10/usr.sbin/newsyslog/newsyslog.c ============================================================================== --- stable/10/usr.sbin/newsyslog/newsyslog.c Sat Oct 31 04:53:07 2015 (r290224) +++ stable/10/usr.sbin/newsyslog/newsyslog.c Sat Oct 31 09:32:39 2015 (r290225) @@ -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 st 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); +} Modified: stable/10/usr.sbin/newsyslog/newsyslog.conf.5 ============================================================================== --- stable/10/usr.sbin/newsyslog/newsyslog.conf.5 Sat Oct 31 04:53:07 2015 (r290224) +++ stable/10/usr.sbin/newsyslog/newsyslog.conf.5 Sat Oct 31 09:32:39 2015 (r290225) @@ -21,7 +21,7 @@ .\" the suitability of this software for any purpose. It is .\" provided "as is" without express or implied warranty. .\" -.Dd March 21, 2012 +.Dd October 24, 2015 .Dt NEWSYSLOG.CONF 5 .Os .Sh NAME @@ -337,7 +337,7 @@ process ID or to find a group process ID .Cm U flag was specified. If this field is present, a -.Ar signal_number +.Ar signal is sent to the process ID contained in this file. If this field is not present and the .Cm N @@ -358,14 +358,23 @@ flag, the file is treated as a path to a by the .Xr newsyslog 8 after rotation instead of sending the signal out. -.It Ar signal_number -This optional field specifies the signal number that will be sent -to the daemon process (or to all processes in a process group, if the +.It Ar signal +This optional field specifies the signal that will be sent to the daemon +process (or to all processes in a process group, if the .Cm U flag was specified). If this field is not present, then a .Dv SIGHUP 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 .Sh EXAMPLES The following is an example of the