chiark / gitweb /
tree-wide: whenever we fork off a foreign child process reset signal mask/handlers
authorLennart Poettering <lennart@poettering.net>
Sun, 31 May 2015 21:55:55 +0000 (23:55 +0200)
committerSven Eden <yamakuzure@gmx.net>
Tue, 14 Mar 2017 09:01:17 +0000 (10:01 +0100)
Also, when the child is potentially long-running make sure to set a
death signal.

Also, ignore the result of the reset operations explicitly by casting
them to (void).

src/libelogind/sd-bus/bus-socket.c
src/login/inhibit.c
src/shared/machine-pool.c
src/shared/pager.c
src/shared/pty.c
src/shared/util.c

index 4fffc6581d5eedd586e22202c40ed3bd34eab810..93ebe80b07747c62d8da36bbc39a9e6dfd804c93 100644 (file)
@@ -738,7 +738,8 @@ int bus_socket_exec(sd_bus *b) {
         if (pid == 0) {
                 /* Child */
 
         if (pid == 0) {
                 /* Child */
 
-                reset_all_signal_handlers();
+                (void) reset_all_signal_handlers();
+                (void) reset_signal_mask();
 
                 close_all_fds(s+1, 1);
 
 
                 close_all_fds(s+1, 1);
 
index 1f78e4b883d565179a354da6ffe19196e6fd403e..0e5dce59258c47ae797a668af8dcc3d57be5ee6d 100644 (file)
@@ -32,6 +32,8 @@
 #include "build.h"
 #include "strv.h"
 #include "formats-util.h"
 #include "build.h"
 #include "strv.h"
 #include "formats-util.h"
+#include "process-util.h"
+#include "signal-util.h"
 
 static const char* arg_what = "idle:sleep:shutdown";
 static const char* arg_who = NULL;
 
 static const char* arg_what = "idle:sleep:shutdown";
 static const char* arg_who = NULL;
@@ -273,6 +275,9 @@ int main(int argc, char *argv[]) {
                 if (pid == 0) {
                         /* Child */
 
                 if (pid == 0) {
                         /* Child */
 
+                        (void) reset_all_signal_handlers();
+                        (void) reset_signal_mask();
+
                         close_all_fds(NULL, 0);
 
                         execvp(argv[optind], argv + optind);
                         close_all_fds(NULL, 0);
 
                         execvp(argv[optind], argv + optind);
index d27931cb4aaf726c593fbcd81a475225981f4b98..8c64908b1a327a137dbbc0bd700a761a82ee746a 100644 (file)
@@ -109,8 +109,8 @@ static int setup_machine_raw(uint64_t size, sd_bus_error *error) {
 
                 /* Child */
 
 
                 /* Child */
 
-                reset_all_signal_handlers();
-                reset_signal_mask();
+                (void) reset_all_signal_handlers();
+                (void) reset_signal_mask();
                 assert_se(prctl(PR_SET_PDEATHSIG, SIGTERM) == 0);
 
                 fd = safe_close(fd);
                 assert_se(prctl(PR_SET_PDEATHSIG, SIGTERM) == 0);
 
                 fd = safe_close(fd);
index 58b62fdccfab66cd430c5bb304ef4c7dbd3cc2fd..13f03e798b2b83ec030941d1918ac3ab02e25a38 100644 (file)
@@ -30,6 +30,7 @@
 #include "process-util.h"
 #include "macro.h"
 #include "terminal-util.h"
 #include "process-util.h"
 #include "macro.h"
 #include "terminal-util.h"
+#include "signal-util.h"
 
 static pid_t pager_pid = 0;
 
 
 static pid_t pager_pid = 0;
 
@@ -85,6 +86,9 @@ int pager_open(bool jump_to_end) {
         if (pager_pid == 0) {
                 const char* less_opts;
 
         if (pager_pid == 0) {
                 const char* less_opts;
 
+                (void) reset_all_signal_handlers();
+                (void) reset_signal_mask();
+
                 dup2(fd[0], STDIN_FILENO);
                 safe_close_pair(fd);
 
                 dup2(fd[0], STDIN_FILENO);
                 safe_close_pair(fd);
 
@@ -178,6 +182,10 @@ int show_man_page(const char *desc, bool null_stdio) {
 
         if (pid == 0) {
                 /* Child */
 
         if (pid == 0) {
                 /* Child */
+
+                (void) reset_all_signal_handlers();
+                (void) reset_signal_mask();
+
                 if (null_stdio) {
                         r = make_null_stdio();
                         if (r < 0) {
                 if (null_stdio) {
                         r = make_null_stdio();
                         if (r < 0) {
index 119d66e9a2274afcf45a3418a79203fef0186459..a87b3ce6f0ba4efa6ca09b3ef26cdd7834b25c12 100644 (file)
@@ -239,7 +239,7 @@ int pty_setup_child(Pty *pty) {
         assert_return(pty_is_child(pty), -EINVAL);
         assert_return(pty_is_open(pty), -EALREADY);
 
         assert_return(pty_is_child(pty), -EINVAL);
         assert_return(pty_is_open(pty), -EALREADY);
 
-        r = sigprocmask_many(SIG_SETMASK, -1);
+        r = reset_signal_mask();
         if (r < 0)
                 return r;
 
         if (r < 0)
                 return r;
 
index 4eb1d27069a59ce0dfe99b4d490dd3c2503ca1be..28e29ff47851ea105278f1ec51f19147c64d8789 100644 (file)
@@ -2280,8 +2280,8 @@ static int do_execute(char **directories, usec_t timeout, char *argv[]) {
         /* We fork this all off from a child process so that we can
          * somewhat cleanly make use of SIGALRM to set a time limit */
 
         /* We fork this all off from a child process so that we can
          * somewhat cleanly make use of SIGALRM to set a time limit */
 
-        reset_all_signal_handlers();
-        reset_signal_mask();
+        (void) reset_all_signal_handlers();
+        (void) reset_signal_mask();
 
         assert_se(prctl(PR_SET_PDEATHSIG, SIGTERM) == 0);
 
 
         assert_se(prctl(PR_SET_PDEATHSIG, SIGTERM) == 0);
 
@@ -3323,8 +3323,8 @@ int fork_agent(pid_t *pid, const int except[], unsigned n_except, const char *pa
         /* Make sure we actually can kill the agent, if we need to, in
          * case somebody invoked us from a shell script that trapped
          * SIGTERM or so... */
         /* Make sure we actually can kill the agent, if we need to, in
          * case somebody invoked us from a shell script that trapped
          * SIGTERM or so... */
-        reset_all_signal_handlers();
-        reset_signal_mask();
+        (void) reset_all_signal_handlers();
+        (void) reset_signal_mask();
 
         /* Check whether our parent died before we were able
          * to set the death signal and unblock the signals */
 
         /* Check whether our parent died before we were able
          * to set the death signal and unblock the signals */