zsh-workers
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: zsh-workers@zsh.org
Subject: Re: Deadlock when receiving kill-signal from child process
Date: Wed, 5 Aug 2015 08:52:58 -0700	[thread overview]
Message-ID: <150805085258.ZM17673@torch.brasslantern.com> (raw)
In-Reply-To: <CA+=GgY5826pmKzn=WHUKCVWOEfRbP=sCN873arRsYHvGgEUb7A@mail.gmail.com>

On Aug 5,  1:37pm, Mathias Fredriksson wrote:
} Subject: Re: Deadlock when receiving kill-signal from child process
}
} Of course, here's the output (as I see it in the terminal) with the
} applied patch:
} 
} TRAPUSR1:1: no job table entry for pid 61571

Aha.  Well, we can't leave that zwarn() in there because there are
legitimate cases where we fork without creating a job table entry,
but none of those cases should have occurred with your test script.

However, don't you delete it just yet from your test build.  Instead,
add this patch and see what you get.


diff --git a/Src/exec.c b/Src/exec.c
index 7612d43..29cc5cb 100644
--- a/Src/exec.c
+++ b/Src/exec.c
@@ -1456,6 +1456,14 @@ execpline(Estate state, wordcode slcode, int how, int last1)
     else if (slflags & WC_SUBLIST_NOT)
 	last1 = 0;
 
+    /* If trap handlers are allowed to run here, they may start another
+     * external job in the middle of us starting this one, which can
+     * result in jobs being reaped before their job table entries have
+     * been initialized, which in turn leads to waiting forever for
+     * jobs that no longer exist.  So don't do that.
+     */
+    queue_signals();
+
     pj = thisjob;
     ipipe[0] = ipipe[1] = opipe[0] = opipe[1] = 0;
     child_block();
@@ -1468,6 +1476,7 @@ execpline(Estate state, wordcode slcode, int how, int last1)
      */
     if ((thisjob = newjob = initjob()) == -1) {
 	child_unblock();
+	unqueue_signals();
 	return 1;
     }
     if (how & Z_TIMED)
@@ -1523,6 +1532,7 @@ execpline(Estate state, wordcode slcode, int how, int last1)
 	else
 	    spawnjob();
 	child_unblock();
+	unqueue_signals();
 	/* Executing background code resets shell status */
 	return lastval = 0;
     } else {
@@ -1580,7 +1590,7 @@ execpline(Estate state, wordcode slcode, int how, int last1)
 		}
 		if (!(jn->stat & STAT_LOCKED)) {
 		    updated = hasprocs(thisjob);
-		    waitjobs();
+		    waitjobs();		/* deals with signal queue */
 		    child_block();
 		} else
 		    updated = 0;
@@ -1588,6 +1598,8 @@ execpline(Estate state, wordcode slcode, int how, int last1)
 		    list_pipe_job && hasprocs(list_pipe_job) &&
 		    !(jobtab[list_pipe_job].stat & STAT_STOPPED)) {
 		    child_unblock();
+		    unqueue_signals();
+		    queue_signals();
 		    child_block();
 		}
 		if (list_pipe_child &&
@@ -1672,6 +1684,7 @@ execpline(Estate state, wordcode slcode, int how, int last1)
 		    break;
 	    }
 	    child_unblock();
+	    unqueue_signals();
 
 	    if (list_pipe && (lastval & 0200) && pj >= 0 &&
 		(!(jn->stat & STAT_INUSE) || (jn->stat & STAT_DONE))) {

-- 
Barton E. Schaefer


  reply	other threads:[~2015-08-05 15:53 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-08-03 11:25 Mathias Fredriksson
2015-08-03 15:52 ` Bart Schaefer
2015-08-03 20:36   ` Mathias Fredriksson
2015-08-03 20:58     ` Bart Schaefer
2015-08-04 21:52       ` Mathias Fredriksson
2015-08-05  0:05         ` Mathias Fredriksson
2015-08-05  6:53         ` Bart Schaefer
2015-08-05 10:37           ` Mathias Fredriksson
2015-08-05 15:52             ` Bart Schaefer [this message]
2015-08-05 16:05               ` Mathias Fredriksson
2015-08-05 18:52                 ` Bart Schaefer
2015-08-05 19:11                   ` Mathias Fredriksson
2015-08-05 20:20                     ` Bart Schaefer
2015-08-05 21:49                       ` Mathias Fredriksson
2015-08-06  5:06                         ` Bart Schaefer
2015-08-06  8:24                           ` Mathias Fredriksson
2015-08-06 15:54                             ` Bart Schaefer
2015-08-07  0:45                               ` Mathias Fredriksson
2015-08-07  5:39                                 ` Bart Schaefer
2015-08-09 13:53                                   ` Mathias Fredriksson
2015-08-09 23:42                                     ` Bart Schaefer
2015-08-10  0:02                                       ` Mikael Magnusson
2015-08-10  0:16                                         ` Mathias Fredriksson
2015-08-10  1:47                                           ` Bart Schaefer
2015-08-10  2:02                                             ` Mikael Magnusson
2015-08-10 15:59                                               ` Bart Schaefer
2015-08-10 17:30                                                 ` Mathias Fredriksson
2015-08-10  0:36                                         ` Bart Schaefer
2015-08-10  0:29                                       ` Bart Schaefer
2015-08-10 19:34                                     ` Bart Schaefer
2015-08-10 21:17                                       ` Mathias Fredriksson
2015-08-10 22:53                                         ` Mathias Fredriksson
2015-08-11  0:53                                           ` Bart Schaefer
2015-08-11 12:17                                             ` Mathias Fredriksson
2015-08-11 14:38                                               ` Mathias Fredriksson
2015-08-11 15:07                                               ` Bart Schaefer
2015-08-11 15:22                                                 ` Mathias Fredriksson
2015-08-11  4:06                                           ` Running commands in a zpty worker Bart Schaefer
2015-08-11 13:14                                             ` Mathias Fredriksson
2015-08-11 14:35                                               ` Mathias Fredriksson
2015-08-11 14:37                                               ` 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=150805085258.ZM17673@torch.brasslantern.com \
    --to=schaefer@brasslantern.com \
    --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).