static int pipeline = FALSE;
static int tty_initialized;
static int ttymode = TERM_COOKED;
-static pid_t ppgrp, child;
+static pid_t ppgrp, child, child_pgrp;
static sigset_t ttyblock;
static struct io_buffer *iobufs;
case SIGCONT_FG:
/* Continue in foreground, grant it controlling tty. */
do {
- status = tcsetpgrp(io_fds[SFD_SLAVE], pid);
+ status = tcsetpgrp(io_fds[SFD_SLAVE], child_pgrp);
} while (status == -1 && errno == EINTR);
killpg(pid, SIGCONT);
break;
if (WIFSTOPPED(status)) {
sudo_debug(8, "command stopped, signal %d",
WSTOPSIG(status));
+ do {
+ child_pgrp = tcgetpgrp(io_fds[SFD_SLAVE]);
+ } while (child_pgrp == -1 && errno == EINTR);
if (send_status(backchannel, cstat) == -1)
return alive; /* XXX */
} else if (WIFSIGNALED(status)) {
* Put child in its own process group. If we are starting the command
* in the foreground, assign its pgrp to the tty.
*/
- setpgid(child, child);
+ child_pgrp = child;
+ setpgid(child, child_pgrp);
if (foreground) {
do {
- status = tcsetpgrp(io_fds[SFD_SLAVE], child);
+ status = tcsetpgrp(io_fds[SFD_SLAVE], child_pgrp);
} while (status == -1 && errno == EINTR);
}