#else
sa.sa_handler = handler;
#endif
+ if (sudo_sigaction(SIGCHLD, &sa, NULL) != 0)
+ sudo_warn(U_("unable to set handler for signal %d"), SIGCHLD);
if (sudo_sigaction(SIGCONT, &sa, NULL) != 0)
sudo_warn(U_("unable to set handler for signal %d"), SIGCONT);
#ifdef SA_SIGINFO
if (sudo_sigaction(SIGTSTP, &sa, NULL) != 0)
sudo_warn(U_("unable to set handler for signal %d"), SIGTSTP);
- /*
- * The policy plugin's session init must be run before we fork
- * or certain pam modules won't be able to track their state.
- */
- if (policy_init_session(details) != true)
- sudo_fatalx(U_("policy plugin failed session initialization"));
-
cmnd_pid = sudo_debug_fork();
switch (cmnd_pid) {
case -1:
sudo_fatal(U_("unable to create sockets"));
/*
- * Signals to forward to the child process (excluding SIGALRM and SIGCHLD).
+ * Signals to forward to the child process (excluding SIGALRM).
* We block all other signals while running the signal handler.
* Note: HP-UX select() will not be interrupted if SA_RESTART set.
*/
sudo_warn(U_("unable to set handler for signal %d"), SIGTERM);
if (sudo_sigaction(SIGALRM, &sa, NULL) != 0)
sudo_warn(U_("unable to set handler for signal %d"), SIGALRM);
- if (sudo_sigaction(SIGCHLD, &sa, NULL) != 0)
- sudo_warn(U_("unable to set handler for signal %d"), SIGCHLD);
if (sudo_sigaction(SIGPIPE, &sa, NULL) != 0)
sudo_warn(U_("unable to set handler for signal %d"), SIGPIPE);
if (sudo_sigaction(SIGUSR1, &sa, NULL) != 0)
if (sudo_sigaction(SIGQUIT, &sa, NULL) != 0)
sudo_warn(U_("unable to set handler for signal %d"), SIGQUIT);
+ /*
+ * The policy plugin's session init must be run before we fork
+ * or certain pam modules won't be able to track their state.
+ */
+ if (policy_init_session(details) != true)
+ sudo_fatalx(U_("policy plugin failed session initialization"));
+
/*
* Child will run the command in the pty, parent will pass data
* to and from pty.
#else
sa.sa_handler = handler;
#endif
+ if (sudo_sigaction(SIGCHLD, &sa, NULL) != 0)
+ sudo_warn(U_("unable to set handler for signal %d"), SIGCHLD);
if (sudo_sigaction(SIGTSTP, &sa, NULL) != 0)
sudo_warn(U_("unable to set handler for signal %d"), SIGTSTP);
}
}
- /*
- * The policy plugin's session init must be run before we fork
- * or certain pam modules won't be able to track their state.
- */
- if (policy_init_session(details) != true)
- sudo_fatalx(U_("policy plugin failed session initialization"));
-
/*
* Block some signals until cmnd_pid is set in the parent to avoid a
* race between exec of the command and receipt of a fatal signal from it.
#include <config.h>
#include <sys/types.h>
+#include <sys/wait.h>
#include <stdio.h>
#ifdef STDC_HEADERS
# include <stdlib.h>
{
static char buf[SUDO_CONV_REPL_MAX + 1], *pass;
sigaction_t sa, saved_sa_pipe;
- int pfd[2];
- pid_t pid;
+ int pfd[2], status;
+ pid_t child;
debug_decl(sudo_askpass, SUDO_DEBUG_CONV, sudo_debug_instance)
if (pipe(pfd) == -1)
sudo_fatal(U_("unable to create pipe"));
- if ((pid = fork()) == -1)
+ child = sudo_debug_fork();
+ if (child == -1)
sudo_fatal(U_("unable to fork"));
- if (pid == 0) {
+ if (child == 0) {
/* child, point stdout to output side of the pipe and exec askpass */
if (dup2(pfd[1], STDOUT_FILENO) == -1) {
sudo_warn("dup2");
(void) close(pfd[0]);
(void) sigaction(SIGPIPE, &saved_sa_pipe, NULL);
+ /* Wait for child to exit. */
+ while (waitpid(child, &status, 0) == -1 && errno == EINTR)
+ continue;
+
if (pass == NULL)
errno = EINTR; /* make cancel button simulate ^C */