diff options
author | Ron Yorston <rmy@pobox.com> | 2023-04-27 07:39:00 +0100 |
---|---|---|
committer | Ron Yorston <rmy@pobox.com> | 2023-04-27 07:39:00 +0100 |
commit | 8e6e5aa81c3bb7ce0b6a7f85ed0d01fc15604e5a (patch) | |
tree | c4ac725922861b638107e0c4a5a3669b21636dbd | |
parent | 99c93b79228bb986cdeaa706f71bb1da0ec8a5fc (diff) | |
download | busybox-w32-8e6e5aa81c3bb7ce0b6a7f85ed0d01fc15604e5a.tar.gz busybox-w32-8e6e5aa81c3bb7ce0b6a7f85ed0d01fc15604e5a.tar.bz2 busybox-w32-8e6e5aa81c3bb7ce0b6a7f85ed0d01fc15604e5a.zip |
xargs: reinstate use of nofork applets
Commit 99402ca92 (xargs: kill children when interrupted by Ctrl-C)
caused all child processes to be spawned, losing the advantage of
running nofork applets without spawning.
Costs 64 bytes.
-rw-r--r-- | findutils/xargs.c | 60 |
1 files changed, 38 insertions, 22 deletions
diff --git a/findutils/xargs.c b/findutils/xargs.c index 1023f80a3..bc47a869f 100644 --- a/findutils/xargs.c +++ b/findutils/xargs.c | |||
@@ -76,6 +76,8 @@ | |||
76 | 76 | ||
77 | #if ENABLE_PLATFORM_MINGW32 | 77 | #if ENABLE_PLATFORM_MINGW32 |
78 | #include <conio.h> | 78 | #include <conio.h> |
79 | #include "busybox.h" | ||
80 | #include "NUM_APPLETS.h" | ||
79 | #endif | 81 | #endif |
80 | #include "libbb.h" | 82 | #include "libbb.h" |
81 | #include "common_bufsiz.h" | 83 | #include "common_bufsiz.h" |
@@ -282,32 +284,10 @@ static int xargs_exec(void) | |||
282 | #if !ENABLE_PLATFORM_MINGW32 | 284 | #if !ENABLE_PLATFORM_MINGW32 |
283 | if (option_mask32 & OPT_STDIN_TTY) | 285 | if (option_mask32 & OPT_STDIN_TTY) |
284 | xdup2(G.fd_tty, STDIN_FILENO); | 286 | xdup2(G.fd_tty, STDIN_FILENO); |
285 | #endif | ||
286 | 287 | ||
287 | #if !ENABLE_FEATURE_XARGS_SUPPORT_PARALLEL | 288 | #if !ENABLE_FEATURE_XARGS_SUPPORT_PARALLEL |
288 | status = spawn_and_wait(G.args); | 289 | status = spawn_and_wait(G.args); |
289 | #else | 290 | #else |
290 | #if ENABLE_PLATFORM_MINGW32 | ||
291 | if (G.max_procs == 1) { | ||
292 | G.pid = spawn(G.args); | ||
293 | status = G.pid < 0 ? -1 : wait4pid(G.pid); | ||
294 | } else { | ||
295 | int idx; | ||
296 | status = !G.running_procs && !G.max_procs ? 0 : wait_for_slot(&idx); | ||
297 | if (G.max_procs) { | ||
298 | HANDLE p = (HANDLE)mingw_spawn_proc((const char **)G.args); | ||
299 | if (p < 0) | ||
300 | status = -1; | ||
301 | else | ||
302 | G.procs[idx] = p; | ||
303 | } else { | ||
304 | while (G.running_procs) { | ||
305 | int status2 = wait_for_slot(&idx); | ||
306 | if (status2 && !status) | ||
307 | status = status2; | ||
308 | } | ||
309 | } | ||
310 | #else | ||
311 | if (G.max_procs == 1) { | 291 | if (G.max_procs == 1) { |
312 | status = spawn_and_wait(G.args); | 292 | status = spawn_and_wait(G.args); |
313 | } else { | 293 | } else { |
@@ -351,8 +331,44 @@ static int xargs_exec(void) | |||
351 | /* final waitpid() loop: must be ECHILD "no more children" */ | 331 | /* final waitpid() loop: must be ECHILD "no more children" */ |
352 | status = 0; | 332 | status = 0; |
353 | } | 333 | } |
334 | } | ||
335 | #endif | ||
354 | #endif | 336 | #endif |
337 | |||
338 | #if ENABLE_PLATFORM_MINGW32 | ||
339 | # if ENABLE_FEATURE_XARGS_SUPPORT_PARALLEL | ||
340 | if (G.max_procs == 1) { | ||
341 | # endif | ||
342 | # if ENABLE_FEATURE_PREFER_APPLETS && (NUM_APPLETS > 1) | ||
343 | int applet = find_applet_by_name(G.args[0]); | ||
344 | if (applet >= 0 && APPLET_IS_NOFORK(applet)) { | ||
345 | status = run_nofork_applet(applet, G.args); | ||
346 | } else | ||
347 | # endif | ||
348 | { | ||
349 | G.pid = spawn(G.args); | ||
350 | status = G.pid < 0 ? -1 : wait4pid(G.pid); | ||
351 | } | ||
352 | # if ENABLE_FEATURE_XARGS_SUPPORT_PARALLEL | ||
353 | } | ||
354 | else { | ||
355 | int idx; | ||
356 | status = !G.running_procs && !G.max_procs ? 0 : wait_for_slot(&idx); | ||
357 | if (G.max_procs) { | ||
358 | HANDLE p = (HANDLE)mingw_spawn_proc((const char **)G.args); | ||
359 | if (p < 0) | ||
360 | status = -1; | ||
361 | else | ||
362 | G.procs[idx] = p; | ||
363 | } else { | ||
364 | while (G.running_procs) { | ||
365 | int status2 = wait_for_slot(&idx); | ||
366 | if (status2 && !status) | ||
367 | status = status2; | ||
368 | } | ||
369 | } | ||
355 | } | 370 | } |
371 | # endif | ||
356 | #endif | 372 | #endif |
357 | /* Manpage: | 373 | /* Manpage: |
358 | * """xargs exits with the following status: | 374 | * """xargs exits with the following status: |