diff options
author | Ron Yorston <rmy@pobox.com> | 2024-07-14 10:11:45 +0100 |
---|---|---|
committer | Ron Yorston <rmy@pobox.com> | 2024-07-14 10:11:45 +0100 |
commit | 6198a0ff055751d5cda4017a3d4821dc93ad77d1 (patch) | |
tree | e637781f4d186a6c39e9f6c9aa42b8ad97f978bb /coreutils/timeout.c | |
parent | b18891bba511d4fc4fcd0a6ff5cd2df31a086f1b (diff) | |
parent | 371fe9f71d445d18be28c82a2a6d82115c8af19d (diff) | |
download | busybox-w32-6198a0ff055751d5cda4017a3d4821dc93ad77d1.tar.gz busybox-w32-6198a0ff055751d5cda4017a3d4821dc93ad77d1.tar.bz2 busybox-w32-6198a0ff055751d5cda4017a3d4821dc93ad77d1.zip |
Merge branch 'busybox' into merge
Diffstat (limited to 'coreutils/timeout.c')
-rw-r--r-- | coreutils/timeout.c | 23 |
1 files changed, 14 insertions, 9 deletions
diff --git a/coreutils/timeout.c b/coreutils/timeout.c index 802ddfc07..764927a12 100644 --- a/coreutils/timeout.c +++ b/coreutils/timeout.c | |||
@@ -61,10 +61,10 @@ static void kill_child(void) | |||
61 | } | 61 | } |
62 | 62 | ||
63 | /* Return TRUE if child exits before timeout expires */ | 63 | /* Return TRUE if child exits before timeout expires */ |
64 | /* NB timeout is in milliseconds */ | 64 | static NOINLINE int timeout_wait(duration_t timeout, HANDLE proc, DWORD *status) |
65 | static NOINLINE int timeout_wait(int timeout, HANDLE proc, DWORD *status) | ||
66 | { | 65 | { |
67 | if (WaitForSingleObject(proc, timeout) == WAIT_OBJECT_0) { | 66 | DWORD t = (DWORD)(timeout * 1000); |
67 | if (WaitForSingleObject(proc, t) == WAIT_OBJECT_0) { | ||
68 | /* process is gone */ | 68 | /* process is gone */ |
69 | GetExitCodeProcess(proc, status); | 69 | GetExitCodeProcess(proc, status); |
70 | return TRUE; | 70 | return TRUE; |
@@ -72,11 +72,16 @@ static NOINLINE int timeout_wait(int timeout, HANDLE proc, DWORD *status) | |||
72 | return FALSE; | 72 | return FALSE; |
73 | } | 73 | } |
74 | #else | 74 | #else |
75 | static NOINLINE int timeout_wait(int timeout, pid_t pid) | 75 | static NOINLINE int timeout_wait(duration_t timeout, pid_t pid) |
76 | { | 76 | { |
77 | /* Just sleep(HUGE_NUM); kill(parent) may kill wrong process! */ | 77 | /* Just sleep(HUGE_NUM); kill(parent) may kill wrong process! */ |
78 | while (1) { | 78 | while (1) { |
79 | sleep1(); | 79 | #if ENABLE_FLOAT_DURATION |
80 | if (timeout < 1) | ||
81 | sleep_for_duration(timeout); | ||
82 | else | ||
83 | #endif | ||
84 | sleep1(); | ||
80 | if (--timeout <= 0) | 85 | if (--timeout <= 0) |
81 | break; | 86 | break; |
82 | if (kill(pid, 0)) { | 87 | if (kill(pid, 0)) { |
@@ -99,8 +104,8 @@ int timeout_main(int argc UNUSED_PARAM, char **argv) | |||
99 | intptr_t ret; | 104 | intptr_t ret; |
100 | DWORD status = EXIT_SUCCESS; | 105 | DWORD status = EXIT_SUCCESS; |
101 | #endif | 106 | #endif |
102 | int timeout; | 107 | duration_t timeout; |
103 | int kill_timeout; | 108 | duration_t kill_timeout; |
104 | pid_t pid; | 109 | pid_t pid; |
105 | #if !BB_MMU | 110 | #if !BB_MMU |
106 | char *sv1, *sv2; | 111 | char *sv1, *sv2; |
@@ -133,11 +138,11 @@ int timeout_main(int argc UNUSED_PARAM, char **argv) | |||
133 | 138 | ||
134 | kill_timeout = 0; | 139 | kill_timeout = 0; |
135 | if (opt_k) | 140 | if (opt_k) |
136 | kill_timeout = parse_duration_str(opt_k) IF_PLATFORM_MINGW32(* 1000); | 141 | kill_timeout = parse_duration_str(opt_k); |
137 | 142 | ||
138 | if (!argv[optind]) | 143 | if (!argv[optind]) |
139 | bb_show_usage(); | 144 | bb_show_usage(); |
140 | timeout = parse_duration_str(argv[optind++]) IF_PLATFORM_MINGW32(* 1000); | 145 | timeout = parse_duration_str(argv[optind++]); |
141 | if (!argv[optind]) /* no PROG? */ | 146 | if (!argv[optind]) /* no PROG? */ |
142 | bb_show_usage(); | 147 | bb_show_usage(); |
143 | 148 | ||