Check return value of sigaction(), even though it should never fail.

This commit is contained in:
Todd C. Miller
2014-09-04 10:13:26 -06:00
parent 111136dc8b
commit 328c563791
3 changed files with 90 additions and 41 deletions

View File

@@ -456,7 +456,8 @@ suspend_parent(int signo)
sigemptyset(&sa.sa_mask);
sa.sa_flags = SA_RESTART;
sa.sa_handler = SIG_DFL;
sudo_sigaction(signo, &sa, &osa);
if (sudo_sigaction(signo, &sa, &osa) != 0)
sudo_warn(U_("unable to set handler for signal %d"), signo);
}
sudo_debug_printf(SUDO_DEBUG_INFO, "kill parent SIG%s", signame);
if (killpg(ppgrp, signo) != 0)
@@ -488,8 +489,10 @@ suspend_parent(int signo)
ttymode = TERM_COOKED;
}
if (signo != SIGSTOP)
sudo_sigaction(signo, &osa, NULL);
if (signo != SIGSTOP) {
if (sudo_sigaction(signo, &osa, NULL) != 0)
sudo_warn(U_("unable to restore handler for signal %d"), signo);
}
rval = ttymode == TERM_RAW ? SIGCONT_FG : SIGCONT_BG;
break;
}
@@ -709,7 +712,8 @@ fork_pty(struct command_details *details, int sv[], sigset_t *omask)
if (io_fds[SFD_USERTTY] != -1) {
sa.sa_flags = SA_RESTART;
sa.sa_handler = sigwinch;
sudo_sigaction(SIGWINCH, &sa, NULL);
if (sudo_sigaction(SIGWINCH, &sa, NULL) != 0)
sudo_warn(U_("unable to set handler for signal %d"), SIGWINCH);
}
/* So we can block tty-generated signals */
@@ -778,8 +782,10 @@ fork_pty(struct command_details *details, int sv[], sigset_t *omask)
/* We don't want to receive SIGTTIN/SIGTTOU, getting EIO is preferable. */
sa.sa_handler = SIG_IGN;
sudo_sigaction(SIGTTIN, &sa, NULL);
sudo_sigaction(SIGTTOU, &sa, NULL);
if (sudo_sigaction(SIGTTIN, &sa, NULL) != 0)
sudo_warn(U_("unable to set handler for signal %d"), SIGTTIN);
if (sudo_sigaction(SIGTTOU, &sa, NULL) != 0)
sudo_warn(U_("unable to set handler for signal %d"), SIGTTOU);
/* Job control signals to relay from parent to child. */
sigfillset(&sa.sa_mask);
@@ -790,7 +796,8 @@ fork_pty(struct command_details *details, int sv[], sigset_t *omask)
#else
sa.sa_handler = handler;
#endif
sudo_sigaction(SIGTSTP, &sa, NULL);
if (sudo_sigaction(SIGTSTP, &sa, NULL) != 0)
sudo_warn(U_("unable to set handler for signal %d"), SIGTSTP);
if (foreground) {
/* Copy terminal attrs from user tty -> pty slave. */
@@ -1277,13 +1284,17 @@ exec_monitor(struct command_details *details, int backchannel)
sigemptyset(&sa.sa_mask);
sa.sa_flags = SA_RESTART;
sa.sa_handler = SIG_DFL;
sudo_sigaction(SIGWINCH, &sa, NULL);
sudo_sigaction(SIGALRM, &sa, NULL);
if (sudo_sigaction(SIGWINCH, &sa, NULL) != 0)
sudo_warn(U_("unable to set handler for signal %d"), SIGWINCH);
if (sudo_sigaction(SIGALRM, &sa, NULL) != 0)
sudo_warn(U_("unable to set handler for signal %d"), SIGALRM);
/* Ignore any SIGTTIN or SIGTTOU we get. */
sa.sa_handler = SIG_IGN;
sudo_sigaction(SIGTTIN, &sa, NULL);
sudo_sigaction(SIGTTOU, &sa, NULL);
if (sudo_sigaction(SIGTTIN, &sa, NULL) != 0)
sudo_warn(U_("unable to set handler for signal %d"), SIGTTIN);
if (sudo_sigaction(SIGTTOU, &sa, NULL) != 0)
sudo_warn(U_("unable to set handler for signal %d"), SIGTTOU);
/* Block all signals in mon_handler(). */
sigfillset(&sa.sa_mask);
@@ -1296,7 +1307,8 @@ exec_monitor(struct command_details *details, int backchannel)
#else
sa.sa_handler = mon_handler;
#endif
sudo_sigaction(SIGCHLD, &sa, NULL);
if (sudo_sigaction(SIGCHLD, &sa, NULL) != 0)
sudo_warn(U_("unable to set handler for signal %d"), SIGCHLD);
/* Catch common signals so we can cleanup properly. */
sa.sa_flags = SA_RESTART;
@@ -1306,13 +1318,20 @@ exec_monitor(struct command_details *details, int backchannel)
#else
sa.sa_handler = mon_handler;
#endif
sudo_sigaction(SIGHUP, &sa, NULL);
sudo_sigaction(SIGINT, &sa, NULL);
sudo_sigaction(SIGQUIT, &sa, NULL);
sudo_sigaction(SIGTERM, &sa, NULL);
sudo_sigaction(SIGTSTP, &sa, NULL);
sudo_sigaction(SIGUSR1, &sa, NULL);
sudo_sigaction(SIGUSR2, &sa, NULL);
if (sudo_sigaction(SIGHUP, &sa, NULL) != 0)
sudo_warn(U_("unable to set handler for signal %d"), SIGHUP);
if (sudo_sigaction(SIGINT, &sa, NULL) != 0)
sudo_warn(U_("unable to set handler for signal %d"), SIGINT);
if (sudo_sigaction(SIGQUIT, &sa, NULL) != 0)
sudo_warn(U_("unable to set handler for signal %d"), SIGQUIT);
if (sudo_sigaction(SIGTERM, &sa, NULL) != 0)
sudo_warn(U_("unable to set handler for signal %d"), SIGTERM);
if (sudo_sigaction(SIGTSTP, &sa, NULL) != 0)
sudo_warn(U_("unable to set handler for signal %d"), SIGTSTP);
if (sudo_sigaction(SIGUSR1, &sa, NULL) != 0)
sudo_warn(U_("unable to set handler for signal %d"), SIGUSR1);
if (sudo_sigaction(SIGUSR2, &sa, NULL) != 0)
sudo_warn(U_("unable to set handler for signal %d"), SIGUSR2);
/*
* Start a new session with the parent as the session leader