Prevent sudo from receiving SIGTTOU when it tries to restore the

controlling terminal.  There appears to be a race with the shell
(bash) which we may lose.
This commit is contained in:
Todd C. Miller
2017-03-06 13:05:17 -07:00
parent 00b4732c9d
commit 2f074d33ab

View File

@@ -391,11 +391,21 @@ dispatch_signal(struct exec_closure_nopty *ec, int signo, char *signame)
} }
if (saved_pgrp != -1) { if (saved_pgrp != -1) {
/* /*
* Restore command's process group if different. * Restore foreground process group, if different.
* Otherwise, we cannot resume some shells. * Otherwise, we cannot resume some shells (pdksh).
*
* There appears to be a race with shells that do restore
* the controlling group. Sudo can receive SIGTTOU
* if the shell has already changed the controlling tty.
*/ */
if (saved_pgrp != ppgrp) if (saved_pgrp != ppgrp) {
sigset_t set, oset;
sigemptyset(&set);
sigaddset(&set, SIGTTOU);
sigprocmask(SIG_BLOCK, &set, &oset);
(void)tcsetpgrp(fd, saved_pgrp); (void)tcsetpgrp(fd, saved_pgrp);
sigprocmask(SIG_SETMASK, &oset, NULL);
}
close(fd); close(fd);
} }
} else { } else {