diff options
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | Src/Modules/system.c | 6 | ||||
-rw-r--r-- | Test/V14system.ztst | 21 |
3 files changed, 18 insertions, 14 deletions
diff --git a/ChangeLog b/ChangeLog index d8da32500..a05703cbb 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2020-07-11 dana <dana@dana.is> + + * Cedric Ware: 46152: Src/Modules/system.c, Test/V14system.ztst: + Re-allow '0' timeout in zsystem flock + 2020-07-09 Jun-ichi Takimoto <takimoto-j@kba.biglobe.ne.jp> * 46215 (w/ minor tweak): Test/E01options.ztst: make the test diff --git a/Src/Modules/system.c b/Src/Modules/system.c index 972aa0767..ecd4e2546 100644 --- a/Src/Modules/system.c +++ b/Src/Modules/system.c @@ -597,7 +597,7 @@ bin_zsystem_flock(char *nam, char **args, UNUSED(Options ops), UNUSED(int func)) * a 32-bit int and CLOCK_MONOTONIC is not supported, in which * case there is a Y2038 problem anyway. */ - if (timeout < 1e-6 || timeout > 1073741823.) { + if (timeout > 1073741823.) { zwarnnam(nam, "flock: invalid timeout value: '%s'", optarg); return 1; @@ -623,7 +623,7 @@ bin_zsystem_flock(char *nam, char **args, UNUSED(Options ops), UNUSED(int func)) timeout_param.type = MN_FLOAT; timeout_param.u.d = (double)timeout_param.u.l; } - timeout_param.u.d *= 1e6; + timeout_param.u.d = ceil(timeout_param.u.d * 1e6); if (timeout_param.u.d < 1 || timeout_param.u.d > 0.999 * LONG_MAX) { zwarnnam(nam, "flock: invalid interval value: '%s'", @@ -704,7 +704,7 @@ bin_zsystem_flock(char *nam, char **args, UNUSED(Options ops), UNUSED(int func)) zgettime_monotonic_if_available(&now); end.tv_sec = now.tv_sec; end.tv_nsec = now.tv_nsec; - end.tv_nsec += modf(timeout, &timeout_s) * 1000000000L; + end.tv_nsec += ceil(modf(timeout, &timeout_s) * 1000000000L); end.tv_sec += timeout_s; if (end.tv_nsec >= 1000000000L) { end.tv_nsec -= 1000000000L; diff --git a/Test/V14system.ztst b/Test/V14system.ztst index b8af96cda..100daab08 100644 --- a/Test/V14system.ztst +++ b/Test/V14system.ztst @@ -13,27 +13,26 @@ %test ( - zsystem flock -t 0.1 -i 0.000001 $tst_dir/file + zsystem flock -t 0 -i 0.000001 $tst_dir/file && + zsystem flock -t 0.1 -i 0.000001 $tst_dir/file && + zsystem flock -t 0.1 -i 0.0000001 $tst_dir/file && + zsystem flock -t 1 -i 0.000001 $tst_dir/file ) 0:zsystem flock valid time arguments ( - zsystem flock -t -1 $tst_dir/file || - zsystem flock -t 0.49e-6 $tst_dir/file || zsystem flock -t 1073741824 $tst_dir/file || zsystem flock -t 1e100 $tst_dir/file || zsystem flock -i -1 $tst_dir/file || - zsystem flock -i 0.49e-6 $tst_dir/file || + zsystem flock -i 0 $tst_dir/file || zsystem flock -i 1e100 $tst_dir/file ) 1:zsystem flock invalid time arguments -?(eval):zsystem:2: flock: invalid timeout value: '-1' -?(eval):zsystem:3: flock: invalid timeout value: '0.49e-6' -?(eval):zsystem:4: flock: invalid timeout value: '1073741824' -?(eval):zsystem:5: flock: invalid timeout value: '1e100' -?(eval):zsystem:6: flock: invalid interval value: '-1' -?(eval):zsystem:7: flock: invalid interval value: '0.49e-6' -?(eval):zsystem:8: flock: invalid interval value: '1e100' +?(eval):zsystem:2: flock: invalid timeout value: '1073741824' +?(eval):zsystem:3: flock: invalid timeout value: '1e100' +?(eval):zsystem:4: flock: invalid interval value: '-1' +?(eval):zsystem:5: flock: invalid interval value: '0' +?(eval):zsystem:6: flock: invalid interval value: '1e100' ( # Lock file for 1 second in the background. |