diff options
-rw-r--r-- | shell/ash.c | 25 |
1 files changed, 19 insertions, 6 deletions
diff --git a/shell/ash.c b/shell/ash.c index ac25866ec..13470b2fa 100644 --- a/shell/ash.c +++ b/shell/ash.c | |||
@@ -4453,15 +4453,28 @@ waitone(int block, struct job *job) | |||
4453 | static int | 4453 | static int |
4454 | dowait(int block, struct job *jp) | 4454 | dowait(int block, struct job *jp) |
4455 | { | 4455 | { |
4456 | int pid = block == DOWAIT_NONBLOCK ? got_sigchld : 1; | 4456 | smallint gotchld = *(volatile smallint *)&got_sigchld; |
4457 | int rpid; | ||
4458 | int pid; | ||
4459 | |||
4460 | if (jp && jp->state != JOBRUNNING) | ||
4461 | block = DOWAIT_NONBLOCK; | ||
4462 | |||
4463 | if (block == DOWAIT_NONBLOCK && !gotchld) | ||
4464 | return 1; | ||
4465 | |||
4466 | rpid = 1; | ||
4457 | 4467 | ||
4458 | while (jp ? jp->state == JOBRUNNING : pid > 0) { | 4468 | do { |
4459 | if (!jp) | 4469 | got_sigchld = 0; |
4460 | got_sigchld = 0; | ||
4461 | pid = waitone(block, jp); | 4470 | pid = waitone(block, jp); |
4462 | } | 4471 | rpid &= !!pid; |
4463 | 4472 | ||
4464 | return pid; | 4473 | if (!pid || (jp && jp->state != JOBRUNNING)) |
4474 | block = DOWAIT_NONBLOCK; | ||
4475 | } while (pid >= 0); | ||
4476 | |||
4477 | return rpid; | ||
4465 | } | 4478 | } |
4466 | 4479 | ||
4467 | #if JOBS | 4480 | #if JOBS |