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`.
This commit is contained in:
Yu Watanabe
2018-05-03 16:52:49 +09:00
parent 08d3fdc37e
commit 29a3db75fd
9 changed files with 19 additions and 28 deletions
+10 -17
View File
@@ -232,11 +232,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;
@@ -244,6 +240,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");
@@ -285,18 +290,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;
}
void nop_signal_handler(int sig) {
/* nothing here */
}
-2
View File
@@ -24,8 +24,6 @@ int sigprocmask_many(int how, sigset_t *old, ...);
const char *signal_to_string(int i) _const_;
int signal_from_string(const char *s) _pure_;
int signal_from_string_try_harder(const char *s);
void nop_signal_handler(int sig);
static inline void block_signals_reset(sigset_t *ss) {