From: Pádraig Brady Date: Fri, 4 Apr 2025 19:40:26 +0000 (+0100) Subject: timeout: ensure infinitesimal timeouts timeout quickly X-Git-Tag: v9.7~16 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=026d0d7c40d2b585d153bb597b336442c14f2d18;p=thirdparty%2Fcoreutils.git timeout: ensure infinitesimal timeouts timeout quickly * src/timeout.c (parse_duration): Clamp infinitesimal values to 1ns. * tests/timeout/timeout-large-parameters.sh: Add a test case. * NEWS: Mention the bug fix. Fixes https://bugs.gnu.org/77535 --- diff --git a/NEWS b/NEWS index a77a49f74f..b4559cefce 100644 --- a/NEWS +++ b/NEWS @@ -23,6 +23,10 @@ GNU coreutils NEWS -*- outline -*- like with dangling symlinks on cygwin. [bug introduced in coreutils-9.6] + timeout would fail to timeout commands with infinitesimal timeouts. + For example `timeout 1e-5000 sleep inf` would never timeout. + [bug introduced with timeout in coreutils-7.0] + 'who -m' now outputs entries for remote logins. Previously login entries prefixed with the service (like "sshd") were not matched. [bug introduced in coreutils-9.4] diff --git a/src/timeout.c b/src/timeout.c index 578d71070d..6756cd8881 100644 --- a/src/timeout.c +++ b/src/timeout.c @@ -371,6 +371,10 @@ parse_duration (char const *str) usage (EXIT_CANCELED); } + /* Clamp underflow to 1ns, as 0 disables the timeout. */ + if (duration == 0 && errno == ERANGE) + duration = 1e-9; + return duration; } diff --git a/tests/timeout/timeout-large-parameters.sh b/tests/timeout/timeout-large-parameters.sh index 5669810e8a..a5395d153f 100755 --- a/tests/timeout/timeout-large-parameters.sh +++ b/tests/timeout/timeout-large-parameters.sh @@ -43,4 +43,7 @@ timeout 2.34e+5d sleep 0 || fail=1 timeout $LDBL_MAX sleep 0 || fail=1 returns_ 125 timeout -- -$LDBL_MAX sleep 0 || fail=1 +# Ensure underflow times out immediately +returns_ 124 timeout 1e-5000 sleep 10 || fail=1 + Exit $fail