diff options
-rw-r--r-- | ChangeLog | 7 | ||||
-rw-r--r-- | Src/exec.c | 13 | ||||
-rw-r--r-- | Src/jobs.c | 10 | ||||
-rw-r--r-- | Src/signals.c | 5 | ||||
-rw-r--r-- | Src/utils.c | 4 |
5 files changed, 31 insertions, 8 deletions
diff --git a/ChangeLog b/ChangeLog index c3bce99cd..b83c4e86e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2018-09-16 Peter Stephenson <p.w.stephenson@ntlworld.com> + + * 43464: Src/exec.c, Src/jobs.c, Src/signals.c, Src/utils.c: + Remember the last process group to attach to the terminal, not + just the set of running processes which did. Don't + record process groups for ESUB_ASYNC subshells. + 2018-09-14 Daniel Shahaf <d.s@daniel.shahaf.name> * unposted: Completion/Unix/Command/_subversion: _svn: Allow diff --git a/Src/exec.c b/Src/exec.c index b9af9ea63..a667b078d 100644 --- a/Src/exec.c +++ b/Src/exec.c @@ -1036,7 +1036,7 @@ entersubsh(int flags, struct entersubsh_ret *retp) if (!(flags & ESUB_ASYNC)) attachtty(jobtab[thisjob].gleader); } - if (retp) { + if (retp && !(flags & ESUB_ASYNC)) { retp->gleader = jobtab[list_pipe_job].gleader; retp->list_pipe_job = list_pipe_job; } @@ -1058,12 +1058,13 @@ entersubsh(int flags, struct entersubsh_ret *retp) !jobtab[list_pipe_job].gleader) jobtab[list_pipe_job].gleader = jobtab[thisjob].gleader; setpgrp(0L, jobtab[thisjob].gleader); - if (!(flags & ESUB_ASYNC)) + if (!(flags & ESUB_ASYNC)) { attachtty(jobtab[thisjob].gleader); - if (retp) { - retp->gleader = jobtab[thisjob].gleader; - if (list_pipe_job != thisjob) - retp->list_pipe_job = list_pipe_job; + if (retp) { + retp->gleader = jobtab[thisjob].gleader; + if (list_pipe_job != thisjob) + retp->list_pipe_job = list_pipe_job; + } } } } diff --git a/Src/jobs.c b/Src/jobs.c index db2e87ec1..2d58319a8 100644 --- a/Src/jobs.c +++ b/Src/jobs.c @@ -40,6 +40,11 @@ mod_export pid_t origpgrp; /**/ mod_export pid_t mypgrp; + +/* the last process group to attach to the terminal */ + +/**/ +pid_t last_attached_pgrp; /* the job we are working on */ @@ -1405,6 +1410,11 @@ addproc(pid_t pid, char *text, int aux, struct timeval *bgtime, jobtab[thisjob].gleader = gleader; if (list_pipe_job_used != -1) jobtab[list_pipe_job_used].gleader = gleader; + /* + * Record here this is the latest process group to grab the + * terminal as attachtty() was run in the subshell. + */ + last_attached_pgrp = gleader; } else if (!jobtab[thisjob].gleader) jobtab[thisjob].gleader = pid; /* attach this process to end of process list of current job */ diff --git a/Src/signals.c b/Src/signals.c index 99aad0fab..26d88abc2 100644 --- a/Src/signals.c +++ b/Src/signals.c @@ -540,8 +540,8 @@ wait_for_processes(void) if (WIFEXITED(status) && pn->pid == jn->gleader && killpg(pn->pid, 0) == -1) { - jn->gleader = 0; - if (!(jn->stat & STAT_NOSTTY)) { + if (last_attached_pgrp == jn->gleader && + !(jn->stat & STAT_NOSTTY)) { /* * This PID was in control of the terminal; * reclaim terminal now it has exited. @@ -552,6 +552,7 @@ wait_for_processes(void) attachtty(mypgrp); adjustwinsize(0); } + jn->gleader = 0; } } update_job(jn); diff --git a/Src/utils.c b/Src/utils.c index 075d27241..5a9fbdd32 100644 --- a/Src/utils.c +++ b/Src/utils.c @@ -4670,6 +4670,10 @@ attachtty(pid_t pgrp) ep = 1; } } + else + { + last_attached_pgrp = pgrp; + } } } |