Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: [BUG] zsystem:34: flock: invalid timeout value: '0'
- X-seq: zsh-workers 46152
- From: Cedric Ware <cedric.ware__bml@xxxxxxxxxxxxxx>
- To: Roman Perepelitsa <roman.perepelitsa@xxxxxxxxx>
- Subject: Re: [BUG] zsystem:34: flock: invalid timeout value: '0'
- Date: Sat, 27 Jun 2020 22:38:26 +0200
- Cc: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>, Daniel Shahaf <d.s@xxxxxxxxxxxxxxxxxx>, Sebastian Gniazdowski <sgniazdowski@xxxxxxxxx>, Zsh hackers list <zsh-workers@xxxxxxx>
- In-reply-to: <CAN=4vMpFpaQg03JbY_B3ktXAEmiUhXH4crdwyc1Ups8Cf=nf8A@mail.gmail.com>
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- List-unsubscribe: <mailto:zsh-workers-unsubscribe@zsh.org>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
- References: <CAKc7PVAm3Wp9Gme42qNQeLo=QE8A2ZvcjcyQqw=aRQa2UDNX0w@mail.gmail.com> <20200626141644.7cb5e511@tarpaulin.shahaf.local2> <CAKc7PVCtHg1Pq1qBWBUwdiNe_8w9LXS_3t-2eBSuCg-ZoZnUgw@mail.gmail.com> <20200627014717.68986199@tarpaulin.shahaf.local2> <CAH+w=7YuMOOSbsgop53ZpCGQZ=COGBSS_nMAyS7m6aQ_YmpukA@mail.gmail.com> <20200627071350.zqkdhzbk3mfej2tz@phare.normalesup.org> <CAN=4vMpFpaQg03JbY_B3ktXAEmiUhXH4crdwyc1Ups8Cf=nf8A@mail.gmail.com>
- Sender: zsh-workers@xxxxxxx
Roman Perepelitsa (Saturday 2020-06-27):
> Timeout strictly between 0 and 1 microsecond is not much different
> from timeout between 1 and 2 microseconds. You can either round up or
> down in both cases. Rounding up is the right thing to do for sleeps
> and timeouts because it allows you to provide a guarantee.
That's a good point. I don't think we can offer an actual guarantee
(or at least I don't have time to really think it through), but
rounding up can be done, alternative patch below.
Best,
Cedric Ware.
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.
Messages sorted by:
Reverse Date,
Date,
Thread,
Author