From 7f0a48f231c7a1bfcfce8b585abc54a3c48d3297 Mon Sep 17 00:00:00 2001 From: Ron Yorston Date: Sat, 24 Mar 2018 10:07:02 +0000 Subject: 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. --- coreutils/timeout.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'coreutils/timeout.c') 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) #else intptr_t ret; HANDLE h; + DWORD status = EXIT_SUCCESS; #endif int parent = 0; int timeout = 10; @@ -131,6 +132,7 @@ int timeout_main(int argc UNUSED_PARAM, char **argv) #endif BB_EXECVP_or_die(argv); #else /* ENABLE_PLATFORM_MINGW32 */ + xfunc_error_retval = 125; if (signo != SIGTERM && signo != SIGKILL && signo != 0) bb_error_msg_and_die("unknown signal '%s'", opt_s); @@ -138,16 +140,21 @@ int timeout_main(int argc UNUSED_PARAM, char **argv) if (argv[0] == NULL) bb_show_usage(); - if ((ret=mingw_spawn_proc((const char **)argv)) == -1) + if ((ret=mingw_spawn_proc((const char **)argv)) == -1) { + xfunc_error_retval = errno == EACCES ? 126 : 127; bb_perror_msg_and_die("can't execute '%s'", argv[0]); + } h = (HANDLE)ret; while (1) { sleep(1); - if (--timeout <= 0) + if (--timeout <= 0) { + status = signo == SIGKILL ? 137 : 124; break; + } if (WaitForSingleObject(h, 0) == WAIT_OBJECT_0) { /* process is gone */ + GetExitCodeProcess(h, &status); goto finish; } } @@ -156,6 +163,6 @@ int timeout_main(int argc UNUSED_PARAM, char **argv) kill(pid, signo); finish: CloseHandle(h); - return EXIT_SUCCESS; + return status; #endif } -- cgit v1.2.3-55-g6feb