diff options
author | Ron Yorston <rmy@pobox.com> | 2018-03-24 10:07:02 +0000 |
---|---|---|
committer | Ron Yorston <rmy@pobox.com> | 2018-03-24 10:16:44 +0000 |
commit | 7f0a48f231c7a1bfcfce8b585abc54a3c48d3297 (patch) | |
tree | cbe4fead9a28947182b572797135487af5c60f5f /coreutils/timeout.c | |
parent | 36065f083a7eba3e0c6a9047c835b7efd1c61e9d (diff) | |
download | busybox-w32-7f0a48f231c7a1bfcfce8b585abc54a3c48d3297.tar.gz busybox-w32-7f0a48f231c7a1bfcfce8b585abc54a3c48d3297.tar.bz2 busybox-w32-7f0a48f231c7a1bfcfce8b585abc54a3c48d3297.zip |
timeout: bring exit status into line with coreutils
Coreutils documentation says of the exit status:
124 if command times out
125 if timeout itself fails
126 if command is found but cannot be invoked
127 if command cannot be found
137 if command is sent the KILL(9) signal (128+9)
the exit status of command otherwise
Make busybox-w32 'timeout' behaviour match this. Upstream BusyBox
is unaffected.
See GitHub issue #105.
Diffstat (limited to 'coreutils/timeout.c')
-rw-r--r-- | coreutils/timeout.c | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/coreutils/timeout.c b/coreutils/timeout.c index 6db3e1bc8..ecdf1633c 100644 --- a/coreutils/timeout.c +++ b/coreutils/timeout.c | |||
@@ -55,6 +55,7 @@ int timeout_main(int argc UNUSED_PARAM, char **argv) | |||
55 | #else | 55 | #else |
56 | intptr_t ret; | 56 | intptr_t ret; |
57 | HANDLE h; | 57 | HANDLE h; |
58 | DWORD status = EXIT_SUCCESS; | ||
58 | #endif | 59 | #endif |
59 | int parent = 0; | 60 | int parent = 0; |
60 | int timeout = 10; | 61 | int timeout = 10; |
@@ -131,6 +132,7 @@ int timeout_main(int argc UNUSED_PARAM, char **argv) | |||
131 | #endif | 132 | #endif |
132 | BB_EXECVP_or_die(argv); | 133 | BB_EXECVP_or_die(argv); |
133 | #else /* ENABLE_PLATFORM_MINGW32 */ | 134 | #else /* ENABLE_PLATFORM_MINGW32 */ |
135 | xfunc_error_retval = 125; | ||
134 | if (signo != SIGTERM && signo != SIGKILL && signo != 0) | 136 | if (signo != SIGTERM && signo != SIGKILL && signo != 0) |
135 | bb_error_msg_and_die("unknown signal '%s'", opt_s); | 137 | bb_error_msg_and_die("unknown signal '%s'", opt_s); |
136 | 138 | ||
@@ -138,16 +140,21 @@ int timeout_main(int argc UNUSED_PARAM, char **argv) | |||
138 | if (argv[0] == NULL) | 140 | if (argv[0] == NULL) |
139 | bb_show_usage(); | 141 | bb_show_usage(); |
140 | 142 | ||
141 | if ((ret=mingw_spawn_proc((const char **)argv)) == -1) | 143 | if ((ret=mingw_spawn_proc((const char **)argv)) == -1) { |
144 | xfunc_error_retval = errno == EACCES ? 126 : 127; | ||
142 | bb_perror_msg_and_die("can't execute '%s'", argv[0]); | 145 | bb_perror_msg_and_die("can't execute '%s'", argv[0]); |
146 | } | ||
143 | 147 | ||
144 | h = (HANDLE)ret; | 148 | h = (HANDLE)ret; |
145 | while (1) { | 149 | while (1) { |
146 | sleep(1); | 150 | sleep(1); |
147 | if (--timeout <= 0) | 151 | if (--timeout <= 0) { |
152 | status = signo == SIGKILL ? 137 : 124; | ||
148 | break; | 153 | break; |
154 | } | ||
149 | if (WaitForSingleObject(h, 0) == WAIT_OBJECT_0) { | 155 | if (WaitForSingleObject(h, 0) == WAIT_OBJECT_0) { |
150 | /* process is gone */ | 156 | /* process is gone */ |
157 | GetExitCodeProcess(h, &status); | ||
151 | goto finish; | 158 | goto finish; |
152 | } | 159 | } |
153 | } | 160 | } |
@@ -156,6 +163,6 @@ int timeout_main(int argc UNUSED_PARAM, char **argv) | |||
156 | kill(pid, signo); | 163 | kill(pid, signo); |
157 | finish: | 164 | finish: |
158 | CloseHandle(h); | 165 | CloseHandle(h); |
159 | return EXIT_SUCCESS; | 166 | return status; |
160 | #endif | 167 | #endif |
161 | } | 168 | } |