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 --- ChangeLog | 5 +++++ Src/jobs.c | 9 ++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index a13e05d08..2966957fb 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2015-08-15 Barton E. Schaefer + + * 36180: Src/jobs.c: avoid infinite job stop/continue loop on + "wait PID" for a background job + 2015-08-15 Mikael Magnusson * 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; -- cgit 1.4.1