diff options
author | Mike Frysinger <vapier@gentoo.org> | 2009-03-28 20:01:58 +0000 |
---|---|---|
committer | Mike Frysinger <vapier@gentoo.org> | 2009-03-28 20:01:58 +0000 |
commit | 56bdea1b43eda3f5ec7073736f5381e9c0017af4 (patch) | |
tree | a1d4b0c479375a96790f1af39dbc850879fa4ee2 | |
parent | e61f07f03661b8e75a54e50d8a2c948c0e215531 (diff) | |
download | busybox-w32-56bdea1b43eda3f5ec7073736f5381e9c0017af4.tar.gz busybox-w32-56bdea1b43eda3f5ec7073736f5381e9c0017af4.tar.bz2 busybox-w32-56bdea1b43eda3f5ec7073736f5381e9c0017af4.zip |
implement `wait` builtin
-rw-r--r-- | shell/hush.c | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/shell/hush.c b/shell/hush.c index 6f34ce1c3..498b14e72 100644 --- a/shell/hush.c +++ b/shell/hush.c | |||
@@ -524,6 +524,7 @@ static int builtin_shift(char **argv); | |||
524 | static int builtin_source(char **argv); | 524 | static int builtin_source(char **argv); |
525 | static int builtin_umask(char **argv); | 525 | static int builtin_umask(char **argv); |
526 | static int builtin_unset(char **argv); | 526 | static int builtin_unset(char **argv); |
527 | static int builtin_wait(char **argv); | ||
527 | #if ENABLE_HUSH_LOOPS | 528 | #if ENABLE_HUSH_LOOPS |
528 | static int builtin_break(char **argv); | 529 | static int builtin_break(char **argv); |
529 | static int builtin_continue(char **argv); | 530 | static int builtin_continue(char **argv); |
@@ -582,6 +583,7 @@ static const struct built_in_command bltins[] = { | |||
582 | // BLTIN("ulimit", builtin_not_written, "Control resource limits"), | 583 | // BLTIN("ulimit", builtin_not_written, "Control resource limits"), |
583 | BLTIN("umask" , builtin_umask, "Set file creation mask"), | 584 | BLTIN("umask" , builtin_umask, "Set file creation mask"), |
584 | BLTIN("unset" , builtin_unset, "Unset environment variable"), | 585 | BLTIN("unset" , builtin_unset, "Unset environment variable"), |
586 | BLTIN("wait" , builtin_wait, "Wait for process"), | ||
585 | #if ENABLE_HUSH_HELP | 587 | #if ENABLE_HUSH_HELP |
586 | BLTIN("help" , builtin_help, "List shell built-in commands"), | 588 | BLTIN("help" , builtin_help, "List shell built-in commands"), |
587 | #endif | 589 | #endif |
@@ -4895,6 +4897,39 @@ static int builtin_unset(char **argv) | |||
4895 | return EXIT_SUCCESS; | 4897 | return EXIT_SUCCESS; |
4896 | } | 4898 | } |
4897 | 4899 | ||
4900 | /* http://www.opengroup.org/onlinepubs/9699919799/utilities/wait.html */ | ||
4901 | static int builtin_wait(char **argv) | ||
4902 | { | ||
4903 | int ret = EXIT_SUCCESS; | ||
4904 | int status; | ||
4905 | |||
4906 | if (argv[1] == NULL) | ||
4907 | /* don't care about exit status */ | ||
4908 | wait(&status); | ||
4909 | |||
4910 | while (argv[1]) { | ||
4911 | char *endp; | ||
4912 | pid_t pid = bb_strtou(argv[1], &endp, 10); | ||
4913 | if (*endp) { | ||
4914 | bb_perror_msg("wait %s", argv[1]); | ||
4915 | return EXIT_FAILURE; | ||
4916 | } else if (waitpid(pid, &status, 0) == pid) { | ||
4917 | if (WIFSIGNALED(status)) | ||
4918 | ret = 128 + WTERMSIG(status); | ||
4919 | else if (WIFEXITED(status)) | ||
4920 | ret = WEXITSTATUS(status); | ||
4921 | else | ||
4922 | ret = EXIT_FAILURE; | ||
4923 | } else { | ||
4924 | bb_perror_msg("wait %s", argv[1]); | ||
4925 | ret = 127; | ||
4926 | } | ||
4927 | ++argv; | ||
4928 | } | ||
4929 | |||
4930 | return ret; | ||
4931 | } | ||
4932 | |||
4898 | #if ENABLE_HUSH_LOOPS | 4933 | #if ENABLE_HUSH_LOOPS |
4899 | static int builtin_break(char **argv) | 4934 | static int builtin_break(char **argv) |
4900 | { | 4935 | { |