From 47d1215cb43a8b6388b1f6e3f8368676e6f2aa93 Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Fri, 1 Apr 2011 11:02:15 +0000 Subject: Stef van Vlierberghe: 28965 (as posted in 28967): findproc() should not return processes not marked as SP_RUNNING --- ChangeLog | 8 +++++++- Src/jobs.c | 19 ++++++++++++++++++- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 5368f0a18..a8175b28f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2011-04-01 Peter Stephenson + + * Stef van Vlierberghe: 28965 (as posted in 28967): + findproc() should not return processes not marked as SP_RUNNING + since findproc() is used find processes still known to the OS. + 2011-03-30 Frank Terbeck * Mike Meyer: 28956, 28957: @@ -14414,5 +14420,5 @@ ***************************************************** * This is used by the shell to define $ZSH_PATCHLEVEL -* $Revision: 1.5239 $ +* $Revision: 1.5240 $ ***************************************************** diff --git a/Src/jobs.c b/Src/jobs.c index fd785a0e9..9a8dc8fea 100644 --- a/Src/jobs.c +++ b/Src/jobs.c @@ -173,11 +173,28 @@ findproc(pid_t pid, Job *jptr, Process *pptr, int aux) for (pn = aux ? jobtab[i].auxprocs : jobtab[i].procs; pn; pn = pn->next) - if (pn->pid == pid) { + { + /* + * Make sure we match a process that's still running. + * + * When a job contains two pids, one terminated pid and one + * running pid, then the condition (jobtab[i].stat & + * STAT_DONE) will not stop these pids from being candidates + * for the findproc result (which is supposed to be a + * RUNNING pid), and if the terminated pid is an identical + * process number for the pid identifying the running + * process we are trying to find (after pid number + * wrapping), then we need to avoid returning the terminated + * pid, otherwise the shell would block and wait forever for + * the termination of the process which pid we were supposed + * to return in a different job. + */ + if (pn->pid == pid && pn->status == SP_RUNNING) { *pptr = pn; *jptr = jobtab + i; return 1; } + } } return 0; -- cgit 1.4.1