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-4d1c5149a09722cd6dcf718812a347db60110706.tar.gz
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)
/* fg_pipe exited or stopped */
break;
}
- if (childpid == waitfor_pid) {
+ if (childpid == waitfor_pid /* "wait PID" */
+#if ENABLE_HUSH_BASH_COMPAT
+ || -1 == waitfor_pid /* "wait -n" (wait for any one child) */
+#endif
+ ) {
debug_printf_exec("childpid==waitfor_pid:%d status:0x%08x\n", childpid, status);
rcode = WEXITSTATUS(status);
if (WIFSIGNALED(status))
@@ -11471,6 +11475,12 @@ static int wait_for_child_or_signal(struct pipe *waitfor_pipe, pid_t waitfor_pid
ret--;
if (ret < 0) /* if ECHILD, may need to fix "ret" */
ret = 0;
+#if ENABLE_HUSH_BASH_COMPAT
+ if (waitfor_pid == -1 && errno == ECHILD) {
+ /* exitcode of "wait -n" with no children is 127, not 0 */
+ ret = 127;
+ }
+#endif
sigprocmask(SIG_SETMASK, &oldset, NULL);
break;
}
@@ -11499,6 +11509,12 @@ static int FAST_FUNC builtin_wait(char **argv)
int status;
argv = skip_dash_dash(argv);
+#if ENABLE_HUSH_BASH_COMPAT
+ if (argv[0] && !argv[1] && strcmp(argv[0], "-n") == 0) {
+ /* wait -n */
+ return wait_for_child_or_signal(NULL, -1 /*(no job, wait for one child)*/);
+ }
+#endif
if (argv[0] == NULL) {
/* Don't care about wait results */
/* Note 1: must wait until there are no more children */