Merge branch 'restore-sighup-handler'

This commit is contained in:
Daniel Eklöf 2021-06-02 20:13:26 +02:00
commit 6671d53859
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F
3 changed files with 9 additions and 2 deletions

View file

@ -151,6 +151,7 @@
in the right-most column.
* Multi-column characters being cut in half when resizing the
alternate screen.
* Restore `SIGHUP` in spawned processes.
### Security

View file

@ -274,10 +274,12 @@ slave_spawn(int ptmx, int argc, const char *cwd, char *const *argv,
_exit(errno_copy);
}
/* Restore signal mask */
/* Restore signal mask, and SIG_IGN'd signals */
sigset_t mask;
sigemptyset(&mask);
if (sigprocmask(SIG_SETMASK, &mask, NULL) < 0) {
if (sigprocmask(SIG_SETMASK, &mask, NULL) < 0 ||
sigaction(SIGHUP, &(struct sigaction){.sa_handler = SIG_DFL}, NULL) < 0)
{
const int errno_copy = errno;
LOG_ERRNO_P(errno, "failed to restore signals");
(void)!write(fork_pipe[1], &errno_copy, sizeof(errno_copy));

View file

@ -44,6 +44,10 @@ spawn(struct reaper *reaper, const char *cwd, char *const argv[],
if (sigprocmask(SIG_SETMASK, &mask, NULL) < 0)
goto child_err;
/* Restore ignored (SIG_IGN) signals */
if (sigaction(SIGHUP, &(struct sigaction){.sa_handler = SIG_DFL}, NULL) < 0)
goto child_err;
bool close_stderr = stderr_fd >= 0;
bool close_stdout = stdout_fd >= 0 && stdout_fd != stderr_fd;
bool close_stdin = stdin_fd >= 0 && stdin_fd != stdout_fd && stdin_fd != stderr_fd;