When the command completes, make the monitor the foreground process

group before informing the main sudo process of the command's exit
status.  This will prevent processes started by the command (which
runs in a different process group) from receiving SIGHUP since the
kernel sends SIGHUP to the foreground process group associated with
the terminal session.  The monitor has a SIGHUP handler installed
so the signal is effectively ignored.
This commit is contained in:
Todd C. Miller
2017-12-01 13:43:06 -07:00
parent 4168668f53
commit b561d0d7dd

View File

@@ -630,6 +630,17 @@ exec_monitor(struct command_details *details, sigset_t *oset,
} while (pid == -1 && errno == EINTR);
/* XXX - update cstat with wait status? */
}
/*
* Take the controlling tty. This prevents processes spawned by the
* command from receiving SIGHUP when the session leader (us) exits.
*/
if (tcsetpgrp(io_fds[SFD_SLAVE], mc.mon_pgrp) == -1) {
sudo_debug_printf(SUDO_DEBUG_ERROR|SUDO_DEBUG_ERRNO,
"%s: unable to set foreground pgrp to %d (monitor)",
__func__, (int)mc.mon_pgrp);
}
/* Send parent status. */
send_status(backchannel, &cstat);