diff options
author | Ron Yorston <rmy@pobox.com> | 2024-04-08 13:12:25 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2024-07-13 21:34:18 +0200 |
commit | e4b5ccd13bb59eaaec6aa7f22655cc469f8900a2 (patch) | |
tree | 4153f53bf050969ad9f697b36402d0aee57d786d | |
parent | b20b3790b428aab75449995d0866bad15879bc00 (diff) | |
download | busybox-w32-e4b5ccd13bb59eaaec6aa7f22655cc469f8900a2.tar.gz busybox-w32-e4b5ccd13bb59eaaec6aa7f22655cc469f8900a2.tar.bz2 busybox-w32-e4b5ccd13bb59eaaec6aa7f22655cc469f8900a2.zip |
timeout: allow fractional seconds in timeout values
The 'timeout' applet uses parse_duration_str() to obtain its
timeout values. The default configuration enables float durations.
However, the applet silently ignores fractional seconds. This
results in unexpected behaviour:
$ timeout 5.99 sleep 5.1; echo $?
Terminated
143
When float durations are enabled ensure that any fractional seconds
are taken into account.
function old new delta
timeout_wait 44 92 +48
timeout_main 383 365 -18
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/1 up/down: 48/-18) Total: 30 bytes
Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | coreutils/timeout.c | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/coreutils/timeout.c b/coreutils/timeout.c index 18aa9ebeb..84299a0a5 100644 --- a/coreutils/timeout.c +++ b/coreutils/timeout.c | |||
@@ -47,11 +47,16 @@ | |||
47 | 47 | ||
48 | #include "libbb.h" | 48 | #include "libbb.h" |
49 | 49 | ||
50 | static NOINLINE int timeout_wait(int timeout, pid_t pid) | 50 | static NOINLINE int timeout_wait(duration_t timeout, pid_t pid) |
51 | { | 51 | { |
52 | /* Just sleep(HUGE_NUM); kill(parent) may kill wrong process! */ | 52 | /* Just sleep(HUGE_NUM); kill(parent) may kill wrong process! */ |
53 | while (1) { | 53 | while (1) { |
54 | sleep1(); | 54 | #if ENABLE_FLOAT_DURATION |
55 | if (timeout < 1) | ||
56 | sleep_for_duration(timeout); | ||
57 | else | ||
58 | #endif | ||
59 | sleep1(); | ||
55 | if (--timeout <= 0) | 60 | if (--timeout <= 0) |
56 | break; | 61 | break; |
57 | if (kill(pid, 0)) { | 62 | if (kill(pid, 0)) { |
@@ -68,8 +73,8 @@ int timeout_main(int argc UNUSED_PARAM, char **argv) | |||
68 | int signo; | 73 | int signo; |
69 | int status; | 74 | int status; |
70 | int parent = 0; | 75 | int parent = 0; |
71 | int timeout; | 76 | duration_t timeout; |
72 | int kill_timeout; | 77 | duration_t kill_timeout; |
73 | pid_t pid; | 78 | pid_t pid; |
74 | #if !BB_MMU | 79 | #if !BB_MMU |
75 | char *sv1, *sv2; | 80 | char *sv1, *sv2; |