Save signal state before changing handlers and restore before

we execute the command.
This commit is contained in:
Todd C. Miller
2011-02-02 12:44:35 -05:00
parent af2ac7ccc6
commit c18468d1a5
3 changed files with 51 additions and 17 deletions

View File

@@ -824,6 +824,7 @@ exec_monitor(struct command_details *details, char *argv[], char *envp[],
error(1, "cannot create pipe");
/* Reset SIGWINCH and SIGALRM. */
/* XXX - restore all signals except SIGPIPE? */
zero_bytes(&sa, sizeof(sa));
sigemptyset(&sa.sa_mask);
sa.sa_flags = SA_RESTART;
@@ -885,6 +886,7 @@ exec_monitor(struct command_details *details, char *argv[], char *envp[],
close(signal_pipe[1]);
close(errpipe[0]);
fcntl(errpipe[1], F_SETFD, FD_CLOEXEC);
restore_signals();
/* setup tty and exec command */
exec_pty(details, argv, envp);
@@ -1082,25 +1084,8 @@ flush_output(void)
static void
exec_pty(struct command_details *details, char *argv[], char *envp[])
{
sigaction_t sa;
pid_t self = getpid();
/* Reset signal handlers. */
zero_bytes(&sa, sizeof(sa));
sigemptyset(&sa.sa_mask);
sa.sa_flags = SA_RESTART;
sa.sa_handler = SIG_DFL;
sigaction(SIGHUP, &sa, NULL);
sigaction(SIGTERM, &sa, NULL);
sigaction(SIGINT, &sa, NULL);
sigaction(SIGQUIT, &sa, NULL);
sigaction(SIGTSTP, &sa, NULL);
sigaction(SIGTTIN, &sa, NULL);
sigaction(SIGTTOU, &sa, NULL);
sigaction(SIGUSR1, &sa, NULL);
sigaction(SIGUSR2, &sa, NULL);
sigaction(SIGCHLD, &sa, NULL);
/* Set child process group here too to avoid a race. */
setpgid(0, self);