mirror of
https://github.com/systemd/systemd.git
synced 2024-11-05 06:52:22 +03:00
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:
parent
08d3fdc37e
commit
29a3db75fd
@ -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 */
|
||||
}
|
||||
|
@ -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) {
|
||||
|
@ -4042,7 +4042,7 @@ int config_parse_set_status(
|
||||
|
||||
r = safe_atoi(temp, &val);
|
||||
if (r < 0) {
|
||||
val = signal_from_string_try_harder(temp);
|
||||
val = signal_from_string(temp);
|
||||
|
||||
if (val <= 0) {
|
||||
log_syntax(unit, LOG_ERR, filename, line, 0, "Failed to parse value, ignoring: %s", word);
|
||||
|
@ -1465,7 +1465,7 @@ static int parse_argv(int argc, char *argv[]) {
|
||||
break;
|
||||
|
||||
case 's':
|
||||
arg_signal = signal_from_string_try_harder(optarg);
|
||||
arg_signal = signal_from_string(optarg);
|
||||
if (arg_signal < 0) {
|
||||
log_error("Failed to parse signal string %s.", optarg);
|
||||
return -EINVAL;
|
||||
|
@ -2879,7 +2879,7 @@ static int parse_argv(int argc, char *argv[]) {
|
||||
break;
|
||||
|
||||
case 's':
|
||||
arg_signal = signal_from_string_try_harder(optarg);
|
||||
arg_signal = signal_from_string(optarg);
|
||||
if (arg_signal < 0) {
|
||||
log_error("Failed to parse signal string %s.", optarg);
|
||||
return -EINVAL;
|
||||
|
@ -972,7 +972,7 @@ static int parse_argv(int argc, char *argv[]) {
|
||||
break;
|
||||
|
||||
case ARG_KILL_SIGNAL:
|
||||
arg_kill_signal = signal_from_string_try_harder(optarg);
|
||||
arg_kill_signal = signal_from_string(optarg);
|
||||
if (arg_kill_signal < 0) {
|
||||
log_error("Cannot parse signal: %s", optarg);
|
||||
return -EINVAL;
|
||||
|
@ -109,7 +109,7 @@ DEFINE_BUS_APPEND_PARSE("i", log_level_from_string);
|
||||
DEFINE_BUS_APPEND_PARSE("i", parse_errno);
|
||||
DEFINE_BUS_APPEND_PARSE("i", sched_policy_from_string);
|
||||
DEFINE_BUS_APPEND_PARSE("i", secure_bits_from_string);
|
||||
DEFINE_BUS_APPEND_PARSE("i", signal_from_string_try_harder);
|
||||
DEFINE_BUS_APPEND_PARSE("i", signal_from_string);
|
||||
DEFINE_BUS_APPEND_PARSE("i", socket_protocol_from_name);
|
||||
DEFINE_BUS_APPEND_PARSE_PTR("i", int32_t, int, ioprio_parse_priority);
|
||||
DEFINE_BUS_APPEND_PARSE_PTR("i", int32_t, int, parse_nice);
|
||||
@ -1189,7 +1189,7 @@ static int bus_append_kill_property(sd_bus_message *m, const char *field, const
|
||||
|
||||
if (streq(field, "KillSignal"))
|
||||
|
||||
return bus_append_signal_from_string_try_harder(m, field, eq);
|
||||
return bus_append_signal_from_string(m, field, eq);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -1298,7 +1298,7 @@ static int bus_append_service_property(sd_bus_message *m, const char *field, con
|
||||
|
||||
r = safe_atoi(word, &val);
|
||||
if (r < 0) {
|
||||
val = signal_from_string_try_harder(word);
|
||||
val = signal_from_string(word);
|
||||
if (val < 0)
|
||||
return log_error_errno(r, "Invalid status or signal %s in %s: %m", word, field);
|
||||
|
||||
|
@ -927,7 +927,7 @@ int config_parse_signal(
|
||||
assert(rvalue);
|
||||
assert(sig);
|
||||
|
||||
r = signal_from_string_try_harder(rvalue);
|
||||
r = signal_from_string(rvalue);
|
||||
if (r <= 0) {
|
||||
log_syntax(unit, LOG_ERR, filename, line, 0, "Failed to parse signal name, ignoring: %s", rvalue);
|
||||
return 0;
|
||||
|
@ -7601,7 +7601,7 @@ static int systemctl_parse_argv(int argc, char *argv[]) {
|
||||
break;
|
||||
|
||||
case 's':
|
||||
arg_signal = signal_from_string_try_harder(optarg);
|
||||
arg_signal = signal_from_string(optarg);
|
||||
if (arg_signal < 0) {
|
||||
log_error("Failed to parse signal string %s.", optarg);
|
||||
return -EINVAL;
|
||||
|
Loading…
Reference in New Issue
Block a user