From: Yu Watanabe Date: Thu, 3 May 2018 07:38:57 +0000 (+0900) Subject: util: rename signal_from_string_try_harder() to signal_from_string() X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=333a751b30147389972db335fb9e18c15c7e9a78;p=elogind.git util: rename signal_from_string_try_harder() to signal_from_string() Also this makes the new `signal_from_string()` function reject e.g, `SIG3` or `SIG+5`. --- diff --git a/src/basic/signal-util.c b/src/basic/signal-util.c index bf4816fd6..5bd5c71ce 100644 --- a/src/basic/signal-util.c +++ b/src/basic/signal-util.c @@ -234,11 +234,7 @@ int signal_from_string(const char *s) { const char *p; int signo, r; - /* Check that the input is a signal name. */ - signo = __signal_from_string(s); - if (signo > 0) - return signo; - + /* Check that the input is a signal number. */ if (safe_atoi(s, &signo) >= 0) { if (SIGNAL_VALID(signo)) return signo; @@ -246,6 +242,15 @@ int signal_from_string(const char *s) { return -ERANGE; } + /* Drop "SIG" prefix. */ + if (startswith(s, "SIG")) + s += 3; + + /* Check that the input is a signal name. */ + signo = __signal_from_string(s); + if (signo > 0) + return signo; + /* Check that the input is RTMIN or * RTMIN+n (0 <= n <= SIGRTMAX-SIGRTMIN). */ p = startswith(s, "RTMIN"); @@ -287,17 +292,6 @@ int signal_from_string(const char *s) { return -EINVAL; } -int signal_from_string_try_harder(const char *s) { - int signo; - assert(s); - - signo = signal_from_string(s); - if (signo <= 0) - if (startswith(s, "SIG")) - return signal_from_string(s+3); - - return signo; -} #if 0 /// UNNEEDED by elogind void nop_signal_handler(int sig) {