]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
signal-util: generalize sigaction_nop_nocldstop
authorMike Yuan <me@yhndnzj.com>
Sat, 4 Jan 2025 13:43:07 +0000 (14:43 +0100)
committerMike Yuan <me@yhndnzj.com>
Sat, 4 Jan 2025 15:40:53 +0000 (16:40 +0100)
src/basic/signal-util.c
src/basic/signal-util.h
src/core/crash-handler.c
src/nspawn/nspawn.c
src/tty-ask-password-agent/tty-ask-password-agent.c

index ad9ed049f1e3543caebc84aa134cfcb3f9098749..32d37e68dd1f5b9dc92de2e719ef5668193797f0 100644 (file)
@@ -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;
 
index 559ce4294982658c32c35a1b622fa67cbbdb6989..dc2b9de14797926b89cdd5e9a1fe0d607de3f3dd 100644 (file)
@@ -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);
index 68bc96e517e91d854eab9ddeca01dbba63a7a5af..e964c897d223e789bdc0962e958f7bfe4876399e 100644 (file)
@@ -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)
index c2f232ae790fb7be157df0dad5e00bffc13dd691..cc037c078f3661d78369c46148a2547bee4c5e47 100644 (file)
@@ -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");
 
index c6097c412028a7635e129c302c1b3a01f319ffcb..9bd7ba452f397f1b033bd0535560443d5e414a77 100644 (file)
@@ -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);