Add tcsetpgrp_nobg() which acts like tcsetpgrp() but returns -1
for a background process. This is safer than blocking SIGTTOU which would cause tcsetpgrp() to succeed in the background.
This commit is contained in:
@@ -394,18 +394,12 @@ dispatch_signal(struct exec_closure_nopty *ec, int signo, char *signame)
|
||||
* Restore foreground process group, if different.
|
||||
* 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.
|
||||
* It is possible that we are no longer the foreground
|
||||
* process so use tcsetpgrp_nobg() to avoid sudo
|
||||
* receiving SIGTTOU.
|
||||
*/
|
||||
if (saved_pgrp != ppgrp) {
|
||||
sigset_t set, oset;
|
||||
sigemptyset(&set);
|
||||
sigaddset(&set, SIGTTOU);
|
||||
sigprocmask(SIG_BLOCK, &set, &oset);
|
||||
(void)tcsetpgrp(fd, saved_pgrp);
|
||||
sigprocmask(SIG_SETMASK, &oset, NULL);
|
||||
}
|
||||
if (saved_pgrp != ppgrp)
|
||||
tcsetpgrp_nobg(fd, saved_pgrp);
|
||||
close(fd);
|
||||
}
|
||||
} else {
|
||||
|
Reference in New Issue
Block a user