aboutsummaryrefslogtreecommitdiff
path: root/spawn.c
diff options
context:
space:
mode:
authorDaniel Eklöf <daniel@ekloef.se>2021-02-21 19:00:31 +0000
committerDaniel Eklöf <daniel@ekloef.se>2021-02-21 19:00:31 +0000
commit0bda60aacc113d8387831ef86681695f77bcecda (patch)
tree822f90cf94de20b51a36a1d0ca0a7ae8deaa9e29 /spawn.c
parentMerge branch 'refactor-subsurface-creation' (diff)
parentspawn/slave: restore signal mask after fork (diff)
Merge branch 'restore-signals-when-spawning-subprocess'
Closes #366
Diffstat (limited to 'spawn.c')
-rw-r--r--spawn.c11
1 files changed, 11 insertions, 0 deletions
diff --git a/spawn.c b/spawn.c
index e9fb2f96..5f8fc13b 100644
--- a/spawn.c
+++ b/spawn.c
@@ -3,6 +3,7 @@
#include <string.h>
#include <unistd.h>
#include <errno.h>
+#include <signal.h>
#include <sys/types.h>
#include <sys/stat.h>
@@ -34,6 +35,16 @@ spawn(struct reaper *reaper, const char *cwd, char *const argv[],
/* Child */
close(pipe_fds[0]);
+ /* Clear signal mask */
+ sigset_t mask;
+ sigemptyset(&mask);
+ if (sigprocmask(SIG_SETMASK, &mask, NULL) < 0) {
+ const int _errno = errno;
+ LOG_ERRNO_P(errno, "failed to restore signals");
+ (void)!write(pipe_fds[1], &_errno, sizeof(_errno));
+ _exit(_errno);
+ }
+
if ((stdin_fd >= 0 && (dup2(stdin_fd, STDIN_FILENO) < 0 || close(stdin_fd) < 0)) ||
(stdout_fd >= 0 && (dup2(stdout_fd, STDOUT_FILENO) < 0 || close(stdout_fd) < 0)) ||
(stderr_fd >= 0 && (dup2(stderr_fd, STDERR_FILENO) < 0 || close(stderr_fd) < 0)) ||