zsh-workers
 help / color / mirror / code / Atom feed
From: Cedric Ware <cedric.ware__bml@normalesup.org>
To: Roman Perepelitsa <roman.perepelitsa@gmail.com>
Cc: Bart Schaefer <schaefer@brasslantern.com>,
	Daniel Shahaf <d.s@daniel.shahaf.name>,
	Sebastian Gniazdowski <sgniazdowski@gmail.com>,
	Zsh hackers list <zsh-workers@zsh.org>
Subject: Re: [BUG] zsystem:34: flock: invalid timeout value: '0'
Date: Sat, 27 Jun 2020 22:38:26 +0200	[thread overview]
Message-ID: <20200627203826.fd7sygqg5o3b7hgc@phare.normalesup.org> (raw)
In-Reply-To: <CAN=4vMpFpaQg03JbY_B3ktXAEmiUhXH4crdwyc1Ups8Cf=nf8A@mail.gmail.com>


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.

  parent reply	other threads:[~2020-06-27 20:39 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-25 17:49 Sebastian Gniazdowski
2020-06-26 14:16 ` Daniel Shahaf
2020-06-26 19:42   ` Sebastian Gniazdowski
2020-06-27  1:47     ` Daniel Shahaf
2020-06-27  2:04       ` Bart Schaefer
2020-06-27  7:13         ` Cedric Ware
2020-06-27  7:27           ` Roman Perepelitsa
2020-06-27 17:01             ` Bart Schaefer
2020-06-27 17:12               ` Roman Perepelitsa
2020-06-27 17:58                 ` Bart Schaefer
2020-06-27 18:09                   ` Roman Perepelitsa
2020-06-27 20:38             ` Cedric Ware [this message]
2020-06-28  9:27               ` Roman Perepelitsa
2020-07-10 15:28                 ` Sebastian Gniazdowski
2020-07-11  5:18                   ` dana
2020-06-27 17:25           ` Sebastian Gniazdowski

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200627203826.fd7sygqg5o3b7hgc@phare.normalesup.org \
    --to=cedric.ware__bml@normalesup.org \
    --cc=d.s@daniel.shahaf.name \
    --cc=roman.perepelitsa@gmail.com \
    --cc=schaefer@brasslantern.com \
    --cc=sgniazdowski@gmail.com \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).