diff options
| author | Ron Yorston <rmy@pobox.com> | 2026-07-16 13:46:08 +0100 |
|---|---|---|
| committer | Ron Yorston <rmy@pobox.com> | 2026-07-16 14:09:16 +0100 |
| commit | d49a90b998ca8d381fead3ac8060071bec46c393 (patch) | |
| tree | b8bce59e83c7ebcbeb4b81f0564f68b29dd143b3 /shell | |
| parent | dfb473921952e6c049aa7a591efca78db7a4720d (diff) | |
| download | busybox-w32-waitfor.tar.gz busybox-w32-waitfor.tar.bz2 busybox-w32-waitfor.zip | |
ash: allow wait to handle more than 64 processeswaitfor
WaitForMultipleObjects() can only handle 64 processes (actually,
MAXIMUM_WAIT_OBJECTS) in a single call. Using the 'wait' shell
built-in after a command like:
for i in $(seq 1 70); do echo $i; sleep 10 & done
resulted in an uninterruptible 'wait'.
Handle processes in batches of MAXIMUM_WAIT_OBJECTS.
The problem was noted by Morgan Bartlett, who also supplied a
fix which I claim to have 'improved'.
Adds 32-48 bytes.
Signed-off-by: Ron Yorston <rmy@pobox.com>
Diffstat (limited to '')
| -rw-r--r-- | shell/ash.c | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/shell/ash.c b/shell/ash.c index a114fdbb0..72cdf5f59 100644 --- a/shell/ash.c +++ b/shell/ash.c | |||
| @@ -4928,7 +4928,18 @@ waitpid_child(int *status, DWORD blocking) | |||
| 4928 | 4928 | ||
| 4929 | if (pid_nr) { | 4929 | if (pid_nr) { |
| 4930 | do { | 4930 | do { |
| 4931 | idx = WaitForMultipleObjects(pid_nr, proclist, FALSE, blocking); | 4931 | for (i = 0; i < pid_nr; i += MAXIMUM_WAIT_OBJECTS) { |
| 4932 | DWORD nr; | ||
| 4933 | TRACE(("poll many: i %d, pidnr: %d, maxwait: %d, blocking: %d\n", i, pid_nr, MAXIMUM_WAIT_OBJECTS, blocking)); | ||
| 4934 | nr = i + MAXIMUM_WAIT_OBJECTS > pid_nr ? | ||
| 4935 | (DWORD)(pid_nr - i) : MAXIMUM_WAIT_OBJECTS; | ||
| 4936 | idx = WaitForMultipleObjects(nr, proclist + i, FALSE, blocking); | ||
| 4937 | TRACE(("poll result: %d\n", idx)); | ||
| 4938 | if (idx != WAIT_TIMEOUT) { | ||
| 4939 | idx += i; | ||
| 4940 | break; | ||
| 4941 | } | ||
| 4942 | } | ||
| 4932 | if (idx < pid_nr) { | 4943 | if (idx < pid_nr) { |
| 4933 | GetExitCodeProcess(proclist[idx], &win_status); | 4944 | GetExitCodeProcess(proclist[idx], &win_status); |
| 4934 | *status = exit_code_to_wait_status(win_status); | 4945 | *status = exit_code_to_wait_status(win_status); |
