From dd5c31657ee934c52f24fd77778c56468d668b45 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Sun, 21 Feb 2021 11:57:38 +0100 Subject: spawn/slave: restore signal mask after fork slave: no need to restore signal handlers; they are automatically restored as long as they are not SIG_IGN (which they never are in foot). spawn(): restore signal mask after fork. This fixes an issue where a terminal spawned with ctrl+shift+n did not terminate when its shell exited. Closes #366 --- spawn.c | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'spawn.c') diff --git a/spawn.c b/spawn.c index e9fb2f96..5f8fc13b 100644 --- a/spawn.c +++ b/spawn.c @@ -3,6 +3,7 @@ #include #include #include +#include #include #include @@ -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)) || -- cgit v1.3