diff --git a/Src/jobs.c b/Src/jobs.c index 707374297..2c4f41547 100644 --- a/Src/jobs.c +++ b/Src/jobs.c @@ -566,6 +566,12 @@ update_job(Job jn) * when the job is finally deleted. */ jn->stat |= STAT_ATTACH; + /* + * If we're in shell jobs on the right side of a pipeline + * we should treat it like a job in the current shell. + */ + if (inforeground == 2) + inforeground = 1; } /* If we have `foo|while true; (( x++ )); done', and hit * ^C, we have to stop the loop, too. */ @@ -1488,10 +1494,7 @@ addproc(pid_t pid, char *text, int aux, struct timeval *bgtime, * set it for that, too. */ if (gleader != -1) { - if (jobtab[thisjob].stat & STAT_CURSH) - jobtab[thisjob].gleader = gleader; - else - jobtab[thisjob].gleader = pid; + jobtab[thisjob].gleader = gleader; if (list_pipe_job_used != -1) jobtab[list_pipe_job_used].gleader = gleader; /* @@ -1500,7 +1503,7 @@ addproc(pid_t pid, char *text, int aux, struct timeval *bgtime, */ last_attached_pgrp = gleader; } else if (!jobtab[thisjob].gleader) - jobtab[thisjob].gleader = pid; + jobtab[thisjob].gleader = pid; /* attach this process to end of process list of current job */ pnlist = &jobtab[thisjob].procs; } @@ -2506,6 +2509,7 @@ bin_fg(char *name, char **argv, Options ops, int func) jobtab[job].stat &= ~STAT_CURSH; } if ((stopped = (jobtab[job].stat & STAT_STOPPED))) { + /* WIFCONTINUED will makerunning() again at killjb() */ makerunning(jobtab + job); if (func == BIN_BG) { /* Set $! to indicate this was backgrounded */