volatile pid_t cmnd_pid = -1;
-static int handle_signals(int sv[2], pid_t child, int log_io,
+static int dispatch_signals(int sv[2], pid_t child, int log_io,
struct command_status *cstat);
static void forward_signals(int fd);
static void schedule_signal(int signo);
* we don't need to (e.g. command pgrp == parent pgrp).
*/
zero_bytes(&sa, sizeof(sa));
- sigemptyset(&sa.sa_mask);
+ sigfillset(&sa.sa_mask);
sa.sa_flags = SA_INTERRUPT; /* do not restart syscalls */
#ifdef SA_SIGINFO
sa.sa_flags |= SA_SIGINFO;
if (pipe_nonblock(signal_pipe) != 0)
error(1, _("unable to create pipe"));
- zero_bytes(&sa, sizeof(sa));
- sigemptyset(&sa.sa_mask);
-
/*
* Signals to forward to the child process (excluding SIGALRM and SIGCHLD).
+ * We block all other signals while running the signal handler.
* Note: HP-UX select() will not be interrupted if SA_RESTART set.
*/
+ zero_bytes(&sa, sizeof(sa));
+ sigfillset(&sa.sa_mask);
sa.sa_flags = SA_INTERRUPT; /* do not restart syscalls */
#ifdef SA_SIGINFO
sa.sa_flags |= SA_SIGINFO;
forward_signals(sv[0]);
}
if (FD_ISSET(signal_pipe[0], fdsr)) {
- n = handle_signals(sv, child, log_io, cstat);
+ n = dispatch_signals(sv, child, log_io, cstat);
if (n == 0) {
/* Child has exited, cstat is set, we are done. */
break;
* Returns -1 on error, 0 on child exit, else 1.
*/
static int
-handle_signals(int sv[2], pid_t child, int log_io, struct command_status *cstat)
+dispatch_signals(int sv[2], pid_t child, int log_io, struct command_status *cstat)
{
char signame[SIG2STR_MAX];
unsigned char signo;
ssize_t nread;
int status;
pid_t pid;
- debug_decl(handle_signals, SUDO_DEBUG_EXEC)
+ debug_decl(dispatch_signals, SUDO_DEBUG_EXEC)
for (;;) {
/* read signal pipe */
sigset_t mask;
pid_t child;
debug_decl(fork_pty, SUDO_DEBUG_EXEC);
-
+
ppgrp = getpgrp(); /* parent's pgrp, so child can signal us */
-
+
zero_bytes(&sa, sizeof(sa));
sigemptyset(&sa.sa_mask);
-
+
if (io_fds[SFD_USERTTY] != -1) {
sa.sa_flags = SA_RESTART;
sa.sa_handler = sigwinch;
io_fds[SFD_STDERR] = io_pipe[STDERR_FILENO][1];
}
+ /* We don't want to receive SIGTTIN/SIGTTOU, getting EIO is preferable. */
+ sa.sa_handler = SIG_IGN;
+ sigaction(SIGTTIN, &sa, NULL);
+ sigaction(SIGTTOU, &sa, NULL);
+
/* Job control signals to relay from parent to child. */
+ sigfillset(&sa.sa_mask);
sa.sa_flags = SA_INTERRUPT; /* do not restart syscalls */
#ifdef SA_SIGINFO
sa.sa_flags |= SA_SIGINFO;
#endif
sigaction(SIGTSTP, &sa, NULL);
- /* We don't want to receive SIGTTIN/SIGTTOU, getting EIO is preferable. */
- sa.sa_handler = SIG_IGN;
- sigaction(SIGTTIN, &sa, NULL);
- sigaction(SIGTTOU, &sa, NULL);
-
if (foreground) {
/* Copy terminal attrs from user tty -> pty slave. */
if (term_copy(io_fds[SFD_USERTTY], io_fds[SFD_SLAVE])) {
close(io_pipe[STDIN_FILENO][0]);
if (io_pipe[STDOUT_FILENO][1])
close(io_pipe[STDOUT_FILENO][1]);
- if (io_pipe[STDERR_FILENO][1])
+ if (io_pipe[STDERR_FILENO][1])
close(io_pipe[STDERR_FILENO][1]);
for (iob = iobufs; iob; iob = iob->next) {
sigaction(SIGTTIN, &sa, NULL);
sigaction(SIGTTOU, &sa, NULL);
+ /* Block all signals in mon_handler(). */
+ sigfillset(&sa.sa_mask);
+
/* Note: HP-UX select() will not be interrupted if SA_RESTART set */
sa.sa_flags = SA_INTERRUPT;
#ifdef SA_SIGINFO