aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--coreutils/timeout.c19
1 files changed, 7 insertions, 12 deletions
diff --git a/coreutils/timeout.c b/coreutils/timeout.c
index 0d6a2c612..ff58a753a 100644
--- a/coreutils/timeout.c
+++ b/coreutils/timeout.c
@@ -59,18 +59,13 @@ static void kill_child(void)
59} 59}
60 60
61/* Return TRUE if child exits before timeout expires */ 61/* Return TRUE if child exits before timeout expires */
62/* NB timeout is in milliseconds */
62static NOINLINE int timeout_wait(int timeout, HANDLE proc, DWORD *status) 63static NOINLINE int timeout_wait(int timeout, HANDLE proc, DWORD *status)
63{ 64{
64 /* Just sleep(HUGE_NUM); kill(parent) may kill wrong process! */ 65 if (WaitForSingleObject(proc, timeout) == WAIT_OBJECT_0) {
65 while (1) { 66 /* process is gone */
66 sleep1(); 67 GetExitCodeProcess(proc, status);
67 if (--timeout <= 0) 68 return TRUE;
68 break;
69 if (WaitForSingleObject(proc, 0) == WAIT_OBJECT_0) {
70 /* process is gone */
71 GetExitCodeProcess(proc, status);
72 return TRUE;
73 }
74 } 69 }
75 return FALSE; 70 return FALSE;
76} 71}
@@ -136,11 +131,11 @@ int timeout_main(int argc UNUSED_PARAM, char **argv)
136 131
137 kill_timeout = 0; 132 kill_timeout = 0;
138 if (opt_k) 133 if (opt_k)
139 kill_timeout = parse_duration_str(opt_k); 134 kill_timeout = parse_duration_str(opt_k) IF_PLATFORM_MINGW32(* 1000);
140 135
141 if (!argv[optind]) 136 if (!argv[optind])
142 bb_show_usage(); 137 bb_show_usage();
143 timeout = parse_duration_str(argv[optind++]); 138 timeout = parse_duration_str(argv[optind++]) IF_PLATFORM_MINGW32(* 1000);
144 if (!argv[optind]) /* no PROG? */ 139 if (!argv[optind]) /* no PROG? */
145 bb_show_usage(); 140 bb_show_usage();
146 141