]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
client: make waitsync check interval configurable
authorMiroslav Lichvar <mlichvar@redhat.com>
Wed, 7 Oct 2015 10:44:25 +0000 (12:44 +0200)
committerMiroslav Lichvar <mlichvar@redhat.com>
Wed, 7 Oct 2015 13:52:37 +0000 (15:52 +0200)
chrony.texi.in
client.c

index fe8c1a407ba37f8b8f176423fdce8b7d3959f4cf..95ae47d47307e764ae314261db9d77aaf5ee91e0 100644 (file)
@@ -4687,10 +4687,10 @@ with the @code{rtcautotrim} directive (@pxref{rtcautotrim directive}).
 @subsubsection waitsync
 The @code{waitsync} command waits for @code{chronyd} to synchronise.
 
-Up to three optional arguments can be specified, the first is the maximum
-number of tries in 10 second intervals before giving up and returning a
-non-zero error code.  When 0 is specified, or there are no arguments, the
-number of tries will not be limited.
+Up to four optional arguments can be specified, the first is the maximum
+number of tries before giving up and returning a non-zero error code.  When 0
+is specified, or there are no arguments, the number of tries will not be
+limited.
 
 The second and third arguments are the maximum allowed remaining correction of
 the system clock and the maximum allowed skew (in ppm) as reported by the
@@ -4698,14 +4698,18 @@ the system clock and the maximum allowed skew (in ppm) as reported by the
 and @code{Skew} fields.  If not specified or zero, the value will not be
 checked.
 
+The fourth argument is the interval in which the check is repeated.  The
+interval is 10 seconds by default.
+
 An example is
 
 @example
 waitsync 60 0.01
 @end example
 
-which will wait up to about 10 minutes for @code{chronyd} to synchronise to a
-source and the remaining correction to be less than 10 milliseconds.
+which will wait up to about 10 minutes (60 times 10 seconds) for @code{chronyd}
+to synchronise to a source and the remaining correction to be less than 10
+milliseconds.
 @c }}}
 @c {{{ writertc
 @node writertc command
index 967d70ff18eb31018500885479516844a0c74dbe..8dba0c6a654716a20a3865a28a688835ccb75af0 100644 (file)
--- a/client.c
+++ b/client.c
@@ -1191,7 +1191,7 @@ give_help(void)
     "makestep\0Correct clock by stepping immediately\0"
     "makestep <threshold> <updates>\0Configure automatic clock stepping\0"
     "maxupdateskew <skew>\0Modify maximum valid skew to update frequency\0"
-    "waitsync [max-tries [max-correction [max-skew]]]\0"
+    "waitsync [max-tries [max-correction [max-skew [interval]]]]\0"
                           "Wait until synchronised in specified limits\0"
     "\0\0"
     "Time sources:\0\0"
@@ -2313,14 +2313,20 @@ process_cmd_waitsync(char *line)
   CMD_Request request;
   CMD_Reply reply;
   uint32_t ref_id, a, b, c, d;
-  double correction, skew_ppm, max_correction, max_skew_ppm;
+  double correction, skew_ppm, max_correction, max_skew_ppm, interval;
   int ret = 0, max_tries, i;
+  struct timeval timeout;
 
   max_tries = 0;
   max_correction = 0.0;
   max_skew_ppm = 0.0;
+  interval = 10.0;
 
-  sscanf(line, "%d %lf %lf", &max_tries, &max_correction, &max_skew_ppm);
+  sscanf(line, "%d %lf %lf %lf", &max_tries, &max_correction, &max_skew_ppm, &interval);
+
+  /* Don't allow shorter interval than 0.1 seconds */
+  if (interval < 0.1)
+    interval = 0.1;
 
   request.command = htons(REQ_TRACKING);
 
@@ -2347,7 +2353,9 @@ process_cmd_waitsync(char *line)
     }
 
     if (!ret && (!max_tries || i < max_tries) && !quit) {
-      sleep(10);
+      UTI_DoubleToTimeval(interval, &timeout);
+      if (select(0, NULL, NULL, NULL, &timeout))
+        break;
     } else {
       break;
     }