summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBarton E. Schaefer <schaefer@zsh.org>2015-08-15 10:15:30 -0700
committerBarton E. Schaefer <schaefer@zsh.org>2015-08-15 10:15:30 -0700
commit5d019f426af8b2a600ee03e43782c24b357d1401 (patch)
treefc17f855bcdd278ae725ccf191fe95b8ad90466c
parent0204f5e17fd5a3e2448bcacb446bd11a497f63e2 (diff)
downloadzsh-5d019f426af8b2a600ee03e43782c24b357d1401.tar.gz
zsh-5d019f426af8b2a600ee03e43782c24b357d1401.zip
36180: avoid infinite job stop/continue loop on "wait PID" for a background job
-rw-r--r--ChangeLog5
-rw-r--r--Src/jobs.c9
2 files changed, 13 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index a13e05d08..2966957fb 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2015-08-15 Barton E. Schaefer <schaefer@zsh.org>
+
+ * 36180: Src/jobs.c: avoid infinite job stop/continue loop on
+ "wait PID" for a background job
+
2015-08-15 Mikael Magnusson <mikachu@gmail.com>
* Eric Cook: 36091: Completion/Unix/Command/_ncftp: search
diff --git a/Src/jobs.c b/Src/jobs.c
index ed647b87e..b47ba8c60 100644
--- a/Src/jobs.c
+++ b/Src/jobs.c
@@ -1384,10 +1384,17 @@ waitforpid(pid_t pid, int wait_cmd)
dont_queue_signals();
child_block(); /* unblocked in signal_suspend() */
queue_traps(wait_cmd);
+
+ /* This function should never be called with a pid that is not a
+ * child of the current shell. Consequently, if kill(0, pid)
+ * fails here with ESRCH, the child has already been reaped. In
+ * the loop body, we expect this to happen in signal_suspend()
+ * via zhandler(), after which this test terminates the loop.
+ */
while (!errflag && (kill(pid, 0) >= 0 || errno != ESRCH)) {
if (first)
first = 0;
- else
+ else if (!wait_cmd)
kill(pid, SIGCONT);
last_signal = -1;