aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2019-03-26 18:34:06 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2019-03-26 18:34:06 +0100
commit4d1c5149a09722cd6dcf718812a347db60110706 (patch)
treecb95c5ea875d5a66dac60c304e449e7bb743d5e0
parent3c6f3336e124be483e4852f022b1d07c1d2f7f2c (diff)
downloadbusybox-w32-4d1c5149a09722cd6dcf718812a347db60110706.tar.gz
busybox-w32-4d1c5149a09722cd6dcf718812a347db60110706.tar.bz2
busybox-w32-4d1c5149a09722cd6dcf718812a347db60110706.zip
hush: add "wait -n" bashism
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--shell/hush.c18
1 files changed, 17 insertions, 1 deletions
diff --git a/shell/hush.c b/shell/hush.c
index 920a85299..7c907686e 100644
--- a/shell/hush.c
+++ b/shell/hush.c
@@ -8763,7 +8763,11 @@ static int checkjobs(struct pipe *fg_pipe, pid_t waitfor_pid)
8763 /* fg_pipe exited or stopped */ 8763 /* fg_pipe exited or stopped */
8764 break; 8764 break;
8765 } 8765 }
8766 if (childpid == waitfor_pid) { 8766 if (childpid == waitfor_pid /* "wait PID" */
8767#if ENABLE_HUSH_BASH_COMPAT
8768 || -1 == waitfor_pid /* "wait -n" (wait for any one child) */
8769#endif
8770 ) {
8767 debug_printf_exec("childpid==waitfor_pid:%d status:0x%08x\n", childpid, status); 8771 debug_printf_exec("childpid==waitfor_pid:%d status:0x%08x\n", childpid, status);
8768 rcode = WEXITSTATUS(status); 8772 rcode = WEXITSTATUS(status);
8769 if (WIFSIGNALED(status)) 8773 if (WIFSIGNALED(status))
@@ -11471,6 +11475,12 @@ static int wait_for_child_or_signal(struct pipe *waitfor_pipe, pid_t waitfor_pid
11471 ret--; 11475 ret--;
11472 if (ret < 0) /* if ECHILD, may need to fix "ret" */ 11476 if (ret < 0) /* if ECHILD, may need to fix "ret" */
11473 ret = 0; 11477 ret = 0;
11478#if ENABLE_HUSH_BASH_COMPAT
11479 if (waitfor_pid == -1 && errno == ECHILD) {
11480 /* exitcode of "wait -n" with no children is 127, not 0 */
11481 ret = 127;
11482 }
11483#endif
11474 sigprocmask(SIG_SETMASK, &oldset, NULL); 11484 sigprocmask(SIG_SETMASK, &oldset, NULL);
11475 break; 11485 break;
11476 } 11486 }
@@ -11499,6 +11509,12 @@ static int FAST_FUNC builtin_wait(char **argv)
11499 int status; 11509 int status;
11500 11510
11501 argv = skip_dash_dash(argv); 11511 argv = skip_dash_dash(argv);
11512#if ENABLE_HUSH_BASH_COMPAT
11513 if (argv[0] && !argv[1] && strcmp(argv[0], "-n") == 0) {
11514 /* wait -n */
11515 return wait_for_child_or_signal(NULL, -1 /*(no job, wait for one child)*/);
11516 }
11517#endif
11502 if (argv[0] == NULL) { 11518 if (argv[0] == NULL) {
11503 /* Don't care about wait results */ 11519 /* Don't care about wait results */
11504 /* Note 1: must wait until there are no more children */ 11520 /* Note 1: must wait until there are no more children */