From 240a63375697be8f3ff0fb97aea35ef2fecf1f4d Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Sat, 16 Jul 2011 12:07:46 -0700 Subject: timeout: treat seconds counts like 'sleep' does Treat fractions as a request to round up to the next representable value, and treat out-of-range values as maximal ones. This is consistent with how "sleep" works. And this way, "timeout 999999999999999999d FOO" and "timeout 4.5 foo" are more likely to do what the user wants. * src/timeout.c: Include c-strtod.h and xstrtod.h, not xstrtol.h. (apply_time_suffix): Change it to the way sleep.c's time_suffix does things. Maybe this function (identical in both programs, other than its name) should be moved to a library? (parse_duration): Return a maximal value on overflow. Return unsigned int, not unsigned long. Allow fractions, which round up to the next integer value. * tests/misc/timeout-parameters: Adjust tests to match new behavior. Add a very large number. --- tests/misc/timeout-parameters | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'tests/misc') diff --git a/tests/misc/timeout-parameters b/tests/misc/timeout-parameters index 6e9152b96..56804a808 100755 --- a/tests/misc/timeout-parameters +++ b/tests/misc/timeout-parameters @@ -37,11 +37,23 @@ test $? = 125 || fail=1 # timeout overflow timeout $UINT_OFLOW sleep 0 -test $? = 125 || fail=1 +test $? = 0 || fail=1 # timeout overflow timeout $(expr $UINT_MAX / 86400 + 1)d sleep 0 -test $? = 125 || fail=1 +test $? = 0 || fail=1 + +# timeout overflow +timeout 999999999999999999999999999999999999999999999999999999999999d sleep 0 +test $? = 0 || fail=1 + +# floating point notation +timeout 2.34 sleep 0 +test $? = 0 || fail=1 + +# floating point notation +timeout 2.34e+5d sleep 0 +test $? = 0 || fail=1 # invalid signal spec timeout --signal=invalid 1 sleep 0 -- cgit v1.2.3-54-g00ecf