diff options
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 | } |