Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Deadlock when receiving kill-signal from child process
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
Messages sorted by:
Reverse Date,
Date,
Thread,
Author