Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: zsh hangs sometimes continued.



On Thu, 31 Mar 2011 20:32:58 +0200
VAN VLIERBERGHE Stef <stef.van-vlierberghe@xxxxxxxxxxxxxxx> wrote:
> After adding more and more debug info to the zsh-4.3.10 sources I
> figured out that the problem is in the findjob returning the pid of
> a terminated process.

Thanks for the investigation and the explanation.  I agree the uses of
findproc() all appear to assume the process is still marked as running,
since they are all about to update it.  Here's the patch I'll apply.

Index: Src/jobs.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/jobs.c,v
retrieving revision 1.79
diff -p -u -r1.79 jobs.c
--- Src/jobs.c	22 Aug 2010 20:08:57 -0000	1.79
+++ Src/jobs.c	1 Apr 2011 09:09:54 -0000
@@ -173,11 +173,28 @@ findproc(pid_t pid, Job *jptr, Process *
 
 	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;

-- 
Peter Stephenson <pws@xxxxxxx>            Software Engineer
Tel: +44 (0)1223 692070                   Cambridge Silicon Radio Limited
Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, UK


Member of the CSR plc group of companies. CSR plc registered in England and Wales, registered number 4187346, registered office Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, United Kingdom



Messages sorted by: Reverse Date, Date, Thread, Author