aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2016-11-08 00:59:29 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2016-11-08 00:59:29 +0100
commit02affb4afd4a71b0c1ca6286f9b0f6bf3b10e0a1 (patch)
tree8588590d1bc78e3d8117816eb6dfeed882166814
parent26ad94bedcc6a4aa3feb07ea032709bcd517ee46 (diff)
downloadbusybox-w32-02affb4afd4a71b0c1ca6286f9b0f6bf3b10e0a1.tar.gz
busybox-w32-02affb4afd4a71b0c1ca6286f9b0f6bf3b10e0a1.tar.bz2
busybox-w32-02affb4afd4a71b0c1ca6286f9b0f6bf3b10e0a1.zip
hush: rework "wait %jobspec" to work in non-interactive shells too
Also add tests. wait5.tests so far fails (but works for ash and dash). function old new delta builtin_wait 305 283 -22 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--shell/ash_test/ash-misc/wait4.right1
-rwxr-xr-xshell/ash_test/ash-misc/wait4.tests2
-rw-r--r--shell/ash_test/ash-misc/wait5.right2
-rwxr-xr-xshell/ash_test/ash-misc/wait5.tests5
-rw-r--r--shell/hush.c21
-rw-r--r--shell/hush_test/hush-misc/wait4.right1
-rwxr-xr-xshell/hush_test/hush-misc/wait4.tests2
-rw-r--r--shell/hush_test/hush-misc/wait5.right2
-rwxr-xr-xshell/hush_test/hush-misc/wait5.tests5
9 files changed, 28 insertions, 13 deletions
diff --git a/shell/ash_test/ash-misc/wait4.right b/shell/ash_test/ash-misc/wait4.right
new file mode 100644
index 000000000..f7987db32
--- /dev/null
+++ b/shell/ash_test/ash-misc/wait4.right
@@ -0,0 +1 @@
Three:3
diff --git a/shell/ash_test/ash-misc/wait4.tests b/shell/ash_test/ash-misc/wait4.tests
new file mode 100755
index 000000000..cc34059ac
--- /dev/null
+++ b/shell/ash_test/ash-misc/wait4.tests
@@ -0,0 +1,2 @@
1sleep 1 | (sleep 1;exit 3) & wait %1
2echo Three:$?
diff --git a/shell/ash_test/ash-misc/wait5.right b/shell/ash_test/ash-misc/wait5.right
new file mode 100644
index 000000000..82c9d5696
--- /dev/null
+++ b/shell/ash_test/ash-misc/wait5.right
@@ -0,0 +1,2 @@
1Zero:0
2Three:3
diff --git a/shell/ash_test/ash-misc/wait5.tests b/shell/ash_test/ash-misc/wait5.tests
new file mode 100755
index 000000000..1b4762d89
--- /dev/null
+++ b/shell/ash_test/ash-misc/wait5.tests
@@ -0,0 +1,5 @@
1sleep 0 | (sleep 0;exit 3) &
2sleep 1
3echo Zero:$?
4wait %1
5echo Three:$?
diff --git a/shell/hush.c b/shell/hush.c
index 7683a3749..ddbf2f7d8 100644
--- a/shell/hush.c
+++ b/shell/hush.c
@@ -9586,7 +9586,6 @@ static int FAST_FUNC builtin_wait(char **argv)
9586{ 9586{
9587 int ret; 9587 int ret;
9588 int status; 9588 int status;
9589 struct pipe *wait_pipe = NULL;
9590 9589
9591 argv = skip_dash_dash(argv); 9590 argv = skip_dash_dash(argv);
9592 if (argv[0] == NULL) { 9591 if (argv[0] == NULL) {
@@ -9614,10 +9613,13 @@ static int FAST_FUNC builtin_wait(char **argv)
9614 if (errno || pid <= 0) { 9613 if (errno || pid <= 0) {
9615#if ENABLE_HUSH_JOB 9614#if ENABLE_HUSH_JOB
9616 if (argv[0][0] == '%') { 9615 if (argv[0][0] == '%') {
9616 struct pipe *wait_pipe;
9617 wait_pipe = parse_jobspec(*argv); 9617 wait_pipe = parse_jobspec(*argv);
9618 if (wait_pipe) { 9618 if (wait_pipe) {
9619 pid = - wait_pipe->pgrp; 9619 ret = job_exited_or_stopped(wait_pipe);
9620 goto do_wait; 9620 if (ret < 0)
9621 ret = wait_for_child_or_signal(wait_pipe, 0);
9622 continue;
9621 } 9623 }
9622 } 9624 }
9623#endif 9625#endif
@@ -9626,7 +9628,7 @@ static int FAST_FUNC builtin_wait(char **argv)
9626 ret = EXIT_FAILURE; 9628 ret = EXIT_FAILURE;
9627 continue; /* bash checks all argv[] */ 9629 continue; /* bash checks all argv[] */
9628 } 9630 }
9629 IF_HUSH_JOB(do_wait:) 9631
9630 /* Do we have such child? */ 9632 /* Do we have such child? */
9631 ret = waitpid(pid, &status, WNOHANG); 9633 ret = waitpid(pid, &status, WNOHANG);
9632 if (ret < 0) { 9634 if (ret < 0) {
@@ -9652,20 +9654,13 @@ static int FAST_FUNC builtin_wait(char **argv)
9652 } 9654 }
9653 if (ret == 0) { 9655 if (ret == 0) {
9654 /* Yes, and it still runs */ 9656 /* Yes, and it still runs */
9655 ret = wait_for_child_or_signal(wait_pipe, wait_pipe ? 0 : pid); 9657 ret = wait_for_child_or_signal(NULL, pid);
9656 } else { 9658 } else {
9657 /* Yes, and it just exited */ 9659 /* Yes, and it just exited */
9658 process_wait_result(NULL, ret, status); 9660 process_wait_result(NULL, pid, status);
9659 ret = WEXITSTATUS(status); 9661 ret = WEXITSTATUS(status);
9660 if (WIFSIGNALED(status)) 9662 if (WIFSIGNALED(status))
9661 ret = 128 + WTERMSIG(status); 9663 ret = 128 + WTERMSIG(status);
9662#if ENABLE_HUSH_JOB
9663 if (wait_pipe) {
9664 ret = job_exited_or_stopped(wait_pipe);
9665 if (ret < 0)
9666 goto do_wait;
9667 }
9668#endif
9669 } 9664 }
9670 } while (*++argv); 9665 } while (*++argv);
9671 9666
diff --git a/shell/hush_test/hush-misc/wait4.right b/shell/hush_test/hush-misc/wait4.right
new file mode 100644
index 000000000..f7987db32
--- /dev/null
+++ b/shell/hush_test/hush-misc/wait4.right
@@ -0,0 +1 @@
Three:3
diff --git a/shell/hush_test/hush-misc/wait4.tests b/shell/hush_test/hush-misc/wait4.tests
new file mode 100755
index 000000000..cc34059ac
--- /dev/null
+++ b/shell/hush_test/hush-misc/wait4.tests
@@ -0,0 +1,2 @@
1sleep 1 | (sleep 1;exit 3) & wait %1
2echo Three:$?
diff --git a/shell/hush_test/hush-misc/wait5.right b/shell/hush_test/hush-misc/wait5.right
new file mode 100644
index 000000000..82c9d5696
--- /dev/null
+++ b/shell/hush_test/hush-misc/wait5.right
@@ -0,0 +1,2 @@
1Zero:0
2Three:3
diff --git a/shell/hush_test/hush-misc/wait5.tests b/shell/hush_test/hush-misc/wait5.tests
new file mode 100755
index 000000000..1b4762d89
--- /dev/null
+++ b/shell/hush_test/hush-misc/wait5.tests
@@ -0,0 +1,5 @@
1sleep 0 | (sleep 0;exit 3) &
2sleep 1
3echo Zero:$?
4wait %1
5echo Three:$?