]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
tree-wide: make sigactions static const
authorMike Yuan <me@yhndnzj.com>
Sat, 4 Jan 2025 13:49:14 +0000 (14:49 +0100)
committerMike Yuan <me@yhndnzj.com>
Sat, 4 Jan 2025 15:40:53 +0000 (16:40 +0100)
src/basic/sigbus.c
src/core/crash-handler.c
src/core/manager.c
src/coredump/coredumpctl.c

index e8d2fdb79a05ce5b9fd693ed6e9ae1549acf13cc..307e879bf59aaaf15543c419bd58690c719ca86f 100644 (file)
@@ -121,7 +121,7 @@ static void sigbus_handler(int sn, siginfo_t *si, void *data) {
 }
 
 void sigbus_install(void) {
-        struct sigaction sa = {
+        static const struct sigaction sa = {
                 .sa_sigaction = sigbus_handler,
                 .sa_flags = SA_SIGINFO,
         };
index e964c897d223e789bdc0962e958f7bfe4876399e..056ac4b347c64523bcc1cda1418613e9432ba6f6 100644 (file)
@@ -52,8 +52,13 @@ _noreturn_ void freeze_or_exit_or_reboot(void) {
 }
 
 _noreturn_ static void crash(int sig, siginfo_t *siginfo, void *context) {
-        struct sigaction sa;
+        static const struct sigaction sa_nocldwait = {
+                .sa_handler = SIG_IGN,
+                .sa_flags = SA_NOCLDSTOP|SA_NOCLDWAIT|SA_RESTART,
+        };
+
         pid_t pid;
+        int r;
 
         /* NB: ðŸ’£ ðŸ’£ ðŸ’£ This is a signal handler, most likely executed in a situation where we have corrupted
          * memory. Thus: please avoid any libc memory allocation here, or any functions that internally use
@@ -94,7 +99,6 @@ _noreturn_ static void crash(int sig, siginfo_t *siginfo, void *context) {
                         _exit(EXIT_EXCEPTION);
                 } else {
                         siginfo_t status;
-                        int r;
 
                         if (siginfo) {
                                 if (siginfo->si_pid == 0)
@@ -141,13 +145,8 @@ _noreturn_ static void crash(int sig, siginfo_t *siginfo, void *context) {
         if (arg_crash_chvt >= 0)
                 (void) chvt(arg_crash_chvt);
 
-        sa = (struct sigaction) {
-                .sa_handler = SIG_IGN,
-                .sa_flags = SA_NOCLDSTOP|SA_NOCLDWAIT|SA_RESTART,
-        };
-
         /* Let the kernel reap children for us */
-        (void) sigaction(SIGCHLD, &sa, NULL);
+        (void) sigaction(SIGCHLD, &sa_nocldwait, NULL);
 
         if (arg_crash_shell) {
                 log_notice("Executing crash shell...");
index e75c760b6fd7b08dc6877b52ae2d1093dada328b..f4fbeaa142cc4adc6d53ce66a88b75b9a3688646 100644 (file)
@@ -517,7 +517,7 @@ static int manager_enable_special_signals(Manager *m) {
 #define RTSIG_IF_AVAILABLE(signum) (signum <= SIGRTMAX ? signum : -1)
 
 static int manager_setup_signals(Manager *m) {
-        struct sigaction sa = {
+        static const struct sigaction sa = {
                 .sa_handler = SIG_DFL,
                 .sa_flags = SA_NOCLDSTOP|SA_RESTART,
         };
index e7d0dd34c0d104d88f8db615c1ce41af41dd750a..f01db21f88e0844eb91e4d9c16f547b2857f9ba1 100644 (file)
@@ -1170,13 +1170,14 @@ static void sigterm_handler(int signal, siginfo_t *info, void *ucontext) {
 }
 
 static int run_debug(int argc, char **argv, void *userdata) {
-        _cleanup_(sd_journal_closep) sd_journal *j = NULL;
-        _cleanup_free_ char *exe = NULL, *path = NULL;
-        _cleanup_strv_free_ char **debugger_call = NULL;
-        struct sigaction sa = {
+        static const struct sigaction sa = {
                 .sa_sigaction = sigterm_handler,
                 .sa_flags = SA_SIGINFO,
         };
+
+        _cleanup_(sd_journal_closep) sd_journal *j = NULL;
+        _cleanup_free_ char *exe = NULL, *path = NULL;
+        _cleanup_strv_free_ char **debugger_call = NULL;
         bool unlink_path = false;
         const char *data, *fork_name;
         size_t len;