diff options
author | Ron Yorston <rmy@pobox.com> | 2017-08-22 08:53:11 +0100 |
---|---|---|
committer | Ron Yorston <rmy@pobox.com> | 2017-08-22 08:53:11 +0100 |
commit | c170026700eabb10147dd848c45c06995b43a32e (patch) | |
tree | b8aefe40bd2b2d5e463b7ea2ce9199b94c703fa2 | |
parent | cebf20d1a5ca9ccf4c17830b60567427df746872 (diff) | |
download | busybox-w32-c170026700eabb10147dd848c45c06995b43a32e.tar.gz busybox-w32-c170026700eabb10147dd848c45c06995b43a32e.tar.bz2 busybox-w32-c170026700eabb10147dd848c45c06995b43a32e.zip |
timeout: provide a basic implementation for WIN32
Only the TERM signal is supported.
-rw-r--r-- | configs/mingw32_defconfig | 2 | ||||
-rw-r--r-- | configs/mingw64_defconfig | 2 | ||||
-rw-r--r-- | coreutils/timeout.c | 35 |
3 files changed, 37 insertions, 2 deletions
diff --git a/configs/mingw32_defconfig b/configs/mingw32_defconfig index 8d331acfe..8f5a2e701 100644 --- a/configs/mingw32_defconfig +++ b/configs/mingw32_defconfig | |||
@@ -314,7 +314,7 @@ CONFIG_TEST=y | |||
314 | CONFIG_TEST1=y | 314 | CONFIG_TEST1=y |
315 | CONFIG_TEST2=y | 315 | CONFIG_TEST2=y |
316 | CONFIG_FEATURE_TEST_64=y | 316 | CONFIG_FEATURE_TEST_64=y |
317 | # CONFIG_TIMEOUT is not set | 317 | CONFIG_TIMEOUT=y |
318 | CONFIG_TOUCH=y | 318 | CONFIG_TOUCH=y |
319 | # CONFIG_FEATURE_TOUCH_NODEREF is not set | 319 | # CONFIG_FEATURE_TOUCH_NODEREF is not set |
320 | CONFIG_FEATURE_TOUCH_SUSV3=y | 320 | CONFIG_FEATURE_TOUCH_SUSV3=y |
diff --git a/configs/mingw64_defconfig b/configs/mingw64_defconfig index 8fa05cd05..1ccb47268 100644 --- a/configs/mingw64_defconfig +++ b/configs/mingw64_defconfig | |||
@@ -314,7 +314,7 @@ CONFIG_TEST=y | |||
314 | CONFIG_TEST1=y | 314 | CONFIG_TEST1=y |
315 | CONFIG_TEST2=y | 315 | CONFIG_TEST2=y |
316 | CONFIG_FEATURE_TEST_64=y | 316 | CONFIG_FEATURE_TEST_64=y |
317 | # CONFIG_TIMEOUT is not set | 317 | CONFIG_TIMEOUT=y |
318 | CONFIG_TOUCH=y | 318 | CONFIG_TOUCH=y |
319 | # CONFIG_FEATURE_TOUCH_NODEREF is not set | 319 | # CONFIG_FEATURE_TOUCH_NODEREF is not set |
320 | CONFIG_FEATURE_TOUCH_SUSV3=y | 320 | CONFIG_FEATURE_TOUCH_SUSV3=y |
diff --git a/coreutils/timeout.c b/coreutils/timeout.c index 4a6117f59..4cdde4366 100644 --- a/coreutils/timeout.c +++ b/coreutils/timeout.c | |||
@@ -50,10 +50,17 @@ int timeout_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | |||
50 | int timeout_main(int argc UNUSED_PARAM, char **argv) | 50 | int timeout_main(int argc UNUSED_PARAM, char **argv) |
51 | { | 51 | { |
52 | int signo; | 52 | int signo; |
53 | #if !ENABLE_PLATFORM_MINGW32 | ||
53 | int status; | 54 | int status; |
55 | #endif | ||
54 | int parent = 0; | 56 | int parent = 0; |
55 | int timeout = 10; | 57 | int timeout = 10; |
58 | #if !ENABLE_PLATFORM_MINGW32 | ||
56 | pid_t pid; | 59 | pid_t pid; |
60 | #else | ||
61 | intptr_t ret; | ||
62 | HANDLE h; | ||
63 | #endif | ||
57 | #if !BB_MMU | 64 | #if !BB_MMU |
58 | char *sv1, *sv2; | 65 | char *sv1, *sv2; |
59 | #endif | 66 | #endif |
@@ -66,6 +73,7 @@ int timeout_main(int argc UNUSED_PARAM, char **argv) | |||
66 | getopt32(argv, "+s:t:+" USE_FOR_NOMMU("p:+"), &opt_s, &timeout, &parent); | 73 | getopt32(argv, "+s:t:+" USE_FOR_NOMMU("p:+"), &opt_s, &timeout, &parent); |
67 | /*argv += optind; - no, wait for bb_daemonize_or_rexec! */ | 74 | /*argv += optind; - no, wait for bb_daemonize_or_rexec! */ |
68 | signo = get_signum(opt_s); | 75 | signo = get_signum(opt_s); |
76 | #if !ENABLE_PLATFORM_MINGW32 | ||
69 | if (signo < 0) | 77 | if (signo < 0) |
70 | bb_error_msg_and_die("unknown signal '%s'", opt_s); | 78 | bb_error_msg_and_die("unknown signal '%s'", opt_s); |
71 | 79 | ||
@@ -124,4 +132,31 @@ int timeout_main(int argc UNUSED_PARAM, char **argv) | |||
124 | argv[1] = sv2; | 132 | argv[1] = sv2; |
125 | #endif | 133 | #endif |
126 | BB_EXECVP_or_die(argv); | 134 | BB_EXECVP_or_die(argv); |
135 | #else /* ENABLE_PLATFORM_MINGW32 */ | ||
136 | if (signo != SIGTERM) | ||
137 | bb_error_msg_and_die("unknown signal '%s'", opt_s); | ||
138 | |||
139 | argv += optind; | ||
140 | if (argv[0] == NULL) | ||
141 | bb_show_usage(); | ||
142 | |||
143 | if ((ret=mingw_spawn_proc(argv)) == -1) | ||
144 | bb_perror_msg_and_die("can't execute '%s'", argv[0]); | ||
145 | |||
146 | h = (HANDLE)ret; | ||
147 | while (1) { | ||
148 | sleep(1); | ||
149 | if (--timeout <= 0) | ||
150 | break; | ||
151 | if (WaitForSingleObject(h, 0) == WAIT_OBJECT_0) { | ||
152 | /* process is gone */ | ||
153 | goto finish; | ||
154 | } | ||
155 | } | ||
156 | |||
157 | TerminateProcess(h, 0); | ||
158 | finish: | ||
159 | CloseHandle(h); | ||
160 | return EXIT_SUCCESS; | ||
161 | #endif | ||
127 | } | 162 | } |