From: Mike Yuan Date: Sat, 4 Jan 2025 13:43:07 +0000 (+0100) Subject: signal-util: generalize sigaction_nop_nocldstop X-Git-Tag: v258-rc1~1706^2~3 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=bed4386e2946c483ddd762f01d742f5b45d18612;p=thirdparty%2Fsystemd.git signal-util: generalize sigaction_nop_nocldstop --- diff --git a/src/basic/signal-util.c b/src/basic/signal-util.c index ad9ed049f1e..32d37e68dd1 100644 --- a/src/basic/signal-util.c +++ b/src/basic/signal-util.c @@ -302,6 +302,11 @@ const struct sigaction sigaction_default = { .sa_flags = SA_RESTART, }; +const struct sigaction sigaction_nop_nocldstop = { + .sa_handler = nop_signal_handler, + .sa_flags = SA_NOCLDSTOP|SA_RESTART, +}; + int parse_signo(const char *s, int *ret) { int sig, r; diff --git a/src/basic/signal-util.h b/src/basic/signal-util.h index 559ce429498..dc2b9de1479 100644 --- a/src/basic/signal-util.h +++ b/src/basic/signal-util.h @@ -68,5 +68,6 @@ void propagate_signal(int sig, siginfo_t *siginfo); extern const struct sigaction sigaction_ignore; extern const struct sigaction sigaction_default; +extern const struct sigaction sigaction_nop_nocldstop; int parse_signo(const char *s, int *ret); diff --git a/src/core/crash-handler.c b/src/core/crash-handler.c index 68bc96e517e..e964c897d22 100644 --- a/src/core/crash-handler.c +++ b/src/core/crash-handler.c @@ -69,13 +69,8 @@ _noreturn_ static void crash(int sig, siginfo_t *siginfo, void *context) { LOG_MESSAGE("Caught <%s>, not dumping core.", signal_to_string(sig)), "MESSAGE_ID=" SD_MESSAGE_CRASH_NO_COREDUMP_STR); else { - sa = (struct sigaction) { - .sa_handler = nop_signal_handler, - .sa_flags = SA_NOCLDSTOP|SA_RESTART, - }; - /* We want to wait for the core process, hence let's enable SIGCHLD */ - (void) sigaction(SIGCHLD, &sa, NULL); + (void) sigaction(SIGCHLD, &sigaction_nop_nocldstop, NULL); pid = raw_clone(SIGCHLD); if (pid < 0) diff --git a/src/nspawn/nspawn.c b/src/nspawn/nspawn.c index c2f232ae790..cc037c078f3 100644 --- a/src/nspawn/nspawn.c +++ b/src/nspawn/nspawn.c @@ -5175,11 +5175,6 @@ static int run_container( pid_t *pid, int *ret) { - static const struct sigaction sa = { - .sa_handler = nop_signal_handler, - .sa_flags = SA_NOCLDSTOP|SA_RESTART, - }; - _cleanup_(release_lock_file) LockFile uid_shift_lock = LOCK_FILE_INIT; _cleanup_close_ int etc_passwd_lock = -EBADF; _cleanup_close_pair_ int @@ -5240,7 +5235,7 @@ static int run_container( if (r < 0) return log_error_errno(errno, "Failed to change the signal mask: %m"); - r = sigaction(SIGCHLD, &sa, NULL); + r = sigaction(SIGCHLD, &sigaction_nop_nocldstop, NULL); if (r < 0) return log_error_errno(errno, "Failed to install SIGCHLD handler: %m"); diff --git a/src/tty-ask-password-agent/tty-ask-password-agent.c b/src/tty-ask-password-agent/tty-ask-password-agent.c index c6097c41202..9bd7ba452f3 100644 --- a/src/tty-ask-password-agent/tty-ask-password-agent.c +++ b/src/tty-ask-password-agent/tty-ask-password-agent.c @@ -571,13 +571,9 @@ static int parse_argv(int argc, char *argv[]) { * terminated. */ static int ask_on_this_console(const char *tty, pid_t *ret_pid, char **arguments) { - static const struct sigaction sigchld = { - .sa_handler = nop_signal_handler, - .sa_flags = SA_NOCLDSTOP | SA_RESTART, - }; int r; - assert_se(sigaction(SIGCHLD, &sigchld, NULL) >= 0); + assert_se(sigaction(SIGCHLD, &sigaction_nop_nocldstop, NULL) >= 0); assert_se(sigaction(SIGHUP, &sigaction_default, NULL) >= 0); assert_se(sigprocmask_many(SIG_UNBLOCK, NULL, SIGHUP, SIGCHLD) >= 0);