mirror of https://github.com/mirror/busybox.git
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>master
parent
b20b3790b4
commit
e4b5ccd13b
|
@ -47,10 +47,15 @@
|
||||||
|
|
||||||
#include "libbb.h"
|
#include "libbb.h"
|
||||||
|
|
||||||
static NOINLINE int timeout_wait(int timeout, pid_t pid)
|
static NOINLINE int timeout_wait(duration_t timeout, pid_t pid)
|
||||||
{
|
{
|
||||||
/* Just sleep(HUGE_NUM); kill(parent) may kill wrong process! */
|
/* Just sleep(HUGE_NUM); kill(parent) may kill wrong process! */
|
||||||
while (1) {
|
while (1) {
|
||||||
|
#if ENABLE_FLOAT_DURATION
|
||||||
|
if (timeout < 1)
|
||||||
|
sleep_for_duration(timeout);
|
||||||
|
else
|
||||||
|
#endif
|
||||||
sleep1();
|
sleep1();
|
||||||
if (--timeout <= 0)
|
if (--timeout <= 0)
|
||||||
break;
|
break;
|
||||||
|
@ -68,8 +73,8 @@ int timeout_main(int argc UNUSED_PARAM, char **argv)
|
||||||
int signo;
|
int signo;
|
||||||
int status;
|
int status;
|
||||||
int parent = 0;
|
int parent = 0;
|
||||||
int timeout;
|
duration_t timeout;
|
||||||
int kill_timeout;
|
duration_t kill_timeout;
|
||||||
pid_t pid;
|
pid_t pid;
|
||||||
#if !BB_MMU
|
#if !BB_MMU
|
||||||
char *sv1, *sv2;
|
char *sv1, *sv2;
|
||||||
|
|
Loading…
Reference in New Issue