mirror of
https://codeberg.org/dnkl/foot.git
synced 2026-02-04 04:06:06 -05:00
spawn: call setsid() in child process
This commit is contained in:
parent
8365fde980
commit
4e57711012
1 changed files with 13 additions and 9 deletions
22
spawn.c
22
spawn.c
|
|
@ -35,15 +35,14 @@ spawn(struct reaper *reaper, const char *cwd, char *const argv[],
|
|||
/* Child */
|
||||
close(pipe_fds[0]);
|
||||
|
||||
if (setsid() < 0)
|
||||
goto child_err;
|
||||
|
||||
/* Clear signal mask */
|
||||
sigset_t mask;
|
||||
sigemptyset(&mask);
|
||||
if (sigprocmask(SIG_SETMASK, &mask, NULL) < 0) {
|
||||
const int errno_copy = errno;
|
||||
LOG_ERRNO("failed to restore signals");
|
||||
(void)!write(pipe_fds[1], &errno_copy, sizeof(errno_copy));
|
||||
_exit(errno_copy);
|
||||
}
|
||||
if (sigprocmask(SIG_SETMASK, &mask, NULL) < 0)
|
||||
goto child_err;
|
||||
|
||||
bool close_stderr = stderr_fd >= 0;
|
||||
bool close_stdout = stdout_fd >= 0 && stdout_fd != stderr_fd;
|
||||
|
|
@ -58,12 +57,17 @@ spawn(struct reaper *reaper, const char *cwd, char *const argv[],
|
|||
(cwd != NULL && chdir(cwd) < 0) ||
|
||||
execvp(argv[0], argv) < 0)
|
||||
{
|
||||
const int errno_copy = errno;
|
||||
(void)!write(pipe_fds[1], &errno_copy, sizeof(errno_copy));
|
||||
_exit(errno_copy);
|
||||
goto child_err;
|
||||
}
|
||||
|
||||
xassert(false);
|
||||
_exit(errno);
|
||||
|
||||
child_err:
|
||||
;
|
||||
const int errno_copy = errno;
|
||||
(void)!write(pipe_fds[1], &errno_copy, sizeof(errno_copy));
|
||||
_exit(errno_copy);
|
||||
}
|
||||
|
||||
/* Parent */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue