From 5d019f426af8b2a600ee03e43782c24b357d1401 Mon Sep 17 00:00:00 2001 From: "Barton E. Schaefer" Date: Sat, 15 Aug 2015 10:15:30 -0700 Subject: 36180: avoid infinite job stop/continue loop on "wait PID" for a background job --- Src/jobs.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'Src') 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; -- cgit 1.4.1