zsh-workers
 help / color / mirror / code / Atom feed
From: Peter Stephenson <Peter.Stephenson@csr.com>
To: VAN VLIERBERGHE Stef <stef.van-vlierberghe@eurocontrol.int>,
	<zsh-workers@zsh.org>
Cc: LORANG Geert <geert.lorang@eurocontrol.int>
Subject: Re: zsh hangs sometimes continued.
Date: Fri, 1 Apr 2011 10:28:46 +0100	[thread overview]
Message-ID: <20110401102846.482a9165@pwslap01u.europe.root.pri> (raw)
In-Reply-To: <1B2B2EF98D55CB41BD16F13B18B9B0080EA2084C@FFBRUE001.cfmu.corp.eurocontrol.int>

On Thu, 31 Mar 2011 20:32:58 +0200
VAN VLIERBERGHE Stef <stef.van-vlierberghe@eurocontrol.int> 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@csr.com>            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


  reply	other threads:[~2011-04-01 10:04 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <1301593035.6016.ezmlm@zsh.org>
2011-03-31 18:32 ` VAN VLIERBERGHE Stef
2011-04-01  9:28   ` Peter Stephenson [this message]
2011-04-01 14:18     ` Bart Schaefer
2011-04-01 21:33       ` VAN VLIERBERGHE Stef
2011-04-01 21:48       ` Phil Pennock
2011-04-01 23:40         ` Bart Schaefer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20110401102846.482a9165@pwslap01u.europe.root.pri \
    --to=peter.stephenson@csr.com \
    --cc=geert.lorang@eurocontrol.int \
    --cc=stef.van-vlierberghe@eurocontrol.int \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).