aboutsummaryrefslogtreecommitdiff
path: root/coreutils/timeout.c
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2017-08-22 08:53:11 +0100
committerRon Yorston <rmy@pobox.com>2017-08-22 08:53:11 +0100
commitc170026700eabb10147dd848c45c06995b43a32e (patch)
treeb8aefe40bd2b2d5e463b7ea2ce9199b94c703fa2 /coreutils/timeout.c
parentcebf20d1a5ca9ccf4c17830b60567427df746872 (diff)
downloadbusybox-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.
Diffstat (limited to 'coreutils/timeout.c')
-rw-r--r--coreutils/timeout.c35
1 files changed, 35 insertions, 0 deletions
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;
50int timeout_main(int argc UNUSED_PARAM, char **argv) 50int 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}