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

Re: Deadlock when receiving kill-signal from child process



On Aug 11,  3:17pm, Mathias Fredriksson wrote:
}
} #0  0x00007fff8abfe72a in __sigsuspend ()
} #1  0x00000001013bc3e9 in signal_suspend ()
} #2  0x0000000101392fc1 in zwaitjob ()
} #3  0x0000000101392e0c in waitjobs ()
} #4  0x0000000101374314 in execpline ()

This looks like we're waiting for a non-existent job again.  Last time
it was the strace output that pointed to the culprit, because here the
call stack has most likely grown and shrunk several times before the
blocking waitjobs() is finally called.

execpline() already does queue_signals() around its only waitjobs(),
and zwaitjob() runs the signal queue before checking the status of
jobs, so the following is a bit of a shot in the dark, rearranging
the order in which SIGCHILD and the queues are managed.  I think it's
probably better to do it in this order anyway, I was undecided about
it when I initially made the patches.


diff --git a/Src/exec.c b/Src/exec.c
index a635c18..45f1c66 100644
--- a/Src/exec.c
+++ b/Src/exec.c
@@ -1607,8 +1607,8 @@ execpline(Estate state, wordcode slcode, int how, int last1)
 		    !(jobtab[list_pipe_job].stat & STAT_STOPPED)) {
 		    int q = queue_signal_level();
 		    child_unblock();
-		    dont_queue_signals();
 		    child_block();
+		    dont_queue_signals();
 		    restore_queue_signals(q);
 		}
 		if (list_pipe_child &&
diff --git a/Src/jobs.c b/Src/jobs.c
index 9333488..ed647b8 100644
--- a/Src/jobs.c
+++ b/Src/jobs.c
@@ -1420,9 +1420,9 @@ zwaitjob(int job, int wait_cmd)
     int q = queue_signal_level();
     Job jn = jobtab + job;
 
-    dont_queue_signals();
     child_block();		 /* unblocked during signal_suspend() */
     queue_traps(wait_cmd);
+    dont_queue_signals();
     if (jn->procs || jn->auxprocs) { /* if any forks were done         */
 	jn->stat |= STAT_LOCKED;
 	if (jn->stat & STAT_CHANGED)
@@ -1478,9 +1478,9 @@ zwaitjob(int job, int wait_cmd)
 	pipestats[0] = lastval;
 	numpipestats = 1;
     }
+    restore_queue_signals(q);
     unqueue_traps();
     child_unblock();
-    restore_queue_signals(q);
 
     return 0;
 }

-- 
Barton E. Schaefer



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