]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
client: add second form of makestep command
authorMiroslav Lichvar <mlichvar@redhat.com>
Mon, 8 Dec 2014 16:54:08 +0000 (17:54 +0100)
committerMiroslav Lichvar <mlichvar@redhat.com>
Tue, 9 Dec 2014 11:31:56 +0000 (12:31 +0100)
The second form configures the automatic stepping, similarly to the
makestep directive. It has two parameters, stepping threshold (in
seconds) and number of future clock updates for which will be the
threshold active. This can be used with the burst command to quickly
make a new measurement and correct the clock by stepping if needed,
without waiting for chronyd to complete the measurement and update the
clock.

candm.h
chrony.texi.in
client.c
cmdmon.c
pktlength.c
reference.c
reference.h

diff --git a/candm.h b/candm.h
index f3eb433b28a155e53ca7da1aed72e115c26483e2..eceb3052074b3aae6388d2fd7ba40af66709e25d 100644 (file)
--- a/candm.h
+++ b/candm.h
@@ -88,7 +88,8 @@
 #define REQ_MODIFY_MAXDELAYDEVRATIO 47
 #define REQ_RESELECT 48
 #define REQ_RESELECTDISTANCE 49
-#define N_REQUEST_TYPES 50
+#define REQ_MODIFY_MAKESTEP 50
+#define N_REQUEST_TYPES 51
 
 /* Special utoken value used to log on with first exchange being the
    password.  (This time value has long since gone by) */
@@ -187,6 +188,12 @@ typedef struct {
   int32_t EOR;
 } REQ_Modify_Maxupdateskew;
 
+typedef struct {
+  int32_t limit;
+  Float threshold;
+  int32_t EOR;
+} REQ_Modify_Makestep;
+
 typedef struct {
   Timeval ts;
   int32_t EOR;
@@ -362,7 +369,8 @@ typedef struct {
    subnets accessed and client accesses
 
    Version 6 : added padding to requests to prevent amplification attack,
-   changed maximum number of samples in manual list to 16
+   changed maximum number of samples in manual list to 16, new commands: modify
+   makestep
  */
 
 #define PROTO_VERSION_NUMBER 6
@@ -407,6 +415,7 @@ typedef struct {
     REQ_Modify_Minstratum modify_minstratum;
     REQ_Modify_Polltarget modify_polltarget;
     REQ_Modify_Maxupdateskew modify_maxupdateskew;
+    REQ_Modify_Makestep modify_makestep;
     REQ_Logon logon;
     REQ_Settime settime;
     REQ_Local local;
index cb81ef183c859566fc6b07abbb815ecdaf62a37d..c8f66cab69d233586f6d78a6417af91043288cca 100644 (file)
@@ -3231,7 +3231,7 @@ interface.
 * exit command::                Exit from chronyc
 * help command::                Generate help summary
 * local command::               Let computer be a server when it is unsynchronised
-* makestep command::            Immediately correct the system clock instead of slewing
+* makestep command::            Correct the system clock by stepping instead of slewing
 * manual command::              Enable/disable/configure options for settime
 * maxdelay command::            Set max measurement delay for a source
 * maxdelaydevratio command::    Set max measurement delay for a source as ratio to deviation
@@ -3702,17 +3702,27 @@ offset, by slowing down or speeding up the clock as required.  In
 certain situations, the system clock may be so far adrift that this
 slewing process would take a very long time to correct the system clock.
 
-The @code{makestep} command can be used in this situation.  It cancels
-any remaining correction that was being slewed, and jumps the system
-clock by the equivalent amount, making it correct immediately.
+The @code{makestep} command can be used in this situation.  There are two forms
+of the command.  The first form has no parameters.  It tells @code{chronyd} to
+cancel any remaining correction that was being slewed and jump the system clock
+by the equivalent amount, making it correct immediately.
+
+The second form configures the automatic stepping, similarly to the
+@code{makestep} directive (@pxref{makestep directive}).  It has two parameters,
+stepping threshold (in seconds) and number of future clock updates for which
+will be the threshold active.  This can be used with the @code{burst} command
+to quickly make a new measurement and correct the clock by stepping if needed,
+without waiting for @code{chronyd} to complete the measurement and update the
+clock.
+
+@example
+makestep 0.1 1
+burst 1/2
+@end example
 
 BE WARNED - certain software will be seriously affected by such jumps to
 the system time.  (That is the reason why chronyd uses slewing
 normally.)
-
-The @code{makestep} directive in the configuration file can be used
-to step the clock automatically when the adjustment is larger than a
-specified threshold, see @ref{makestep directive}.
 @c }}}
 @c {{{ manual
 @node manual command
index 3822dd4d1eb91122cec237bc7aabe2d11eaceca8..2de99c011e3fb39dee8153ba248b48d76bfc2c10 100644 (file)
--- a/client.c
+++ b/client.c
@@ -1210,7 +1210,7 @@ give_help(void)
   printf("dump : Dump all measurements to save files\n");
   printf("local off : Disable server capability for unsynchronised clock\n");
   printf("local stratum <stratum> : Enable server capability for unsynchronised clock\n");
-  printf("makestep : Jump the time to remove any correction being slewed\n");
+  printf("makestep [<threshold> <updates>] : Correct clock by stepping\n");
   printf("manual off|on|reset : Disable/enable/reset settime command and statistics\n");
   printf("manual list : Show previous settime entries\n");
   printf("maxdelay <address> <new-max-delay> : Modify maximum round-trip valid sample delay for source\n");
@@ -2230,10 +2230,25 @@ process_cmd_rekey(CMD_Request *msg, char *line)
 
 /* ================================================== */
 
-static void
+static int
 process_cmd_makestep(CMD_Request *msg, char *line)
 {
-  msg->command = htons(REQ_MAKESTEP);
+  int limit;
+  double threshold;
+
+  if (*line) {
+    if (sscanf(line, "%lf %d", &threshold, &limit) != 2) {
+      fprintf(stderr, "Bad syntax for makestep command\n");
+      return 0;
+    }
+    msg->command = htons(REQ_MODIFY_MAKESTEP);
+    msg->data.modify_makestep.limit = htonl(limit);
+    msg->data.modify_makestep.threshold = UTI_FloatHostToNetwork(threshold);
+  } else {
+    msg->command = htons(REQ_MAKESTEP);
+  }
+
+  return 1;
 }
 
 /* ================================================== */
@@ -2512,7 +2527,7 @@ process_line(char *line, int *quit)
   } else if (!strcmp(command, "local")) {
     do_normal_submit = process_cmd_local(&tx_message, line);
   } else if (!strcmp(command, "makestep")) {
-    process_cmd_makestep(&tx_message, line);
+    do_normal_submit = process_cmd_makestep(&tx_message, line);
   } else if (!strcmp(command, "manual")) {
     if (!strncmp(line, "list", 4)) {
       do_normal_submit = 0;
index 74e1ee463b233d03a35e0fcff273e703c41987f9..0db4f1fd2d992eb4eb5100bbf913e08d1f9f5e08 100644 (file)
--- a/cmdmon.c
+++ b/cmdmon.c
@@ -160,7 +160,8 @@ static const char permissions[] = {
   PERMIT_AUTH, /* MODIFY_POLLTARGET */
   PERMIT_AUTH, /* MODIFY_MAXDELAYDEVRATIO */
   PERMIT_AUTH, /* RESELECT */
-  PERMIT_AUTH  /* RESELECTDISTANCE */
+  PERMIT_AUTH, /* RESELECTDISTANCE */
+  PERMIT_AUTH, /* MODIFY_MAKESTEP */
 };
 
 /* ================================================== */
@@ -908,6 +909,16 @@ handle_modify_maxupdateskew(CMD_Request *rx_message, CMD_Reply *tx_message)
 
 /* ================================================== */
 
+static void
+handle_modify_makestep(CMD_Request *rx_message, CMD_Reply *tx_message)
+{
+  REF_ModifyMakestep(ntohl(rx_message->data.modify_makestep.limit),
+                     UTI_FloatNetworkToHost(rx_message->data.modify_makestep.threshold));
+  tx_message->status = htons(STT_SUCCESS);
+}
+
+/* ================================================== */
+
 static void
 handle_settime(CMD_Request *rx_message, CMD_Reply *tx_message)
 {
@@ -1940,6 +1951,10 @@ read_from_cmd_socket(void *anything)
           handle_modify_maxupdateskew(&rx_message, &tx_message);
           break;
 
+        case REQ_MODIFY_MAKESTEP:
+          handle_modify_makestep(&rx_message, &tx_message);
+          break;
+
         case REQ_LOGON:
           /* If the log-on fails, record the reason why */
           if (!issue_token) {
index 03a5a7e335c6413d6dc8d08c97e77ee70845fcac..2bd03b002b8da6dac269b911dcc857512b485dda 100644 (file)
@@ -67,6 +67,8 @@ command_unpadded_length(CMD_Request *r)
         return offsetof(CMD_Request, data.modify_maxdelaydevratio.EOR);
       case REQ_MODIFY_MAXUPDATESKEW:
         return offsetof(CMD_Request, data.modify_maxupdateskew.EOR);
+      case REQ_MODIFY_MAKESTEP:
+        return offsetof(CMD_Request, data.modify_makestep.EOR);
       case REQ_LOGON :
         return offsetof(CMD_Request, data.logon.EOR);
       case REQ_SETTIME :
@@ -215,6 +217,8 @@ PKL_CommandPaddingLength(CMD_Request *r)
       return PADDING_LENGTH(data.modify_maxdelaydevratio.EOR, data.null.EOR);
     case REQ_MODIFY_MAXUPDATESKEW:
       return PADDING_LENGTH(data.modify_maxupdateskew.EOR, data.null.EOR);
+    case REQ_MODIFY_MAKESTEP:
+      return PADDING_LENGTH(data.modify_makestep.EOR, data.null.EOR);
     case REQ_LOGON:
       return PADDING_LENGTH(data.logon.EOR, data.null.EOR);
     case REQ_SETTIME:
index 62489f0db98507f0ca01ae1f526d58dd61a7f01b..0103c38d67f2a8888f3cdbb99eab6d1f90a07c97 100644 (file)
@@ -1125,6 +1125,15 @@ REF_ModifyMaxupdateskew(double new_max_update_skew)
 
 /* ================================================== */
 
+void
+REF_ModifyMakestep(int limit, double threshold)
+{
+  make_step_limit = limit;
+  make_step_threshold = threshold;
+}
+
+/* ================================================== */
+
 void
 REF_EnableLocal(int stratum)
 {
index fc918400abc0a870a524d3845953c588ad795b19..287a4c10e7f5ed39be04b496c1e861c7e15d3973 100644 (file)
@@ -157,6 +157,9 @@ extern int REF_GetOurStratum(void);
 /* Modify the setting for the maximum skew we are prepared to allow updates on (in ppm). */
 extern void REF_ModifyMaxupdateskew(double new_max_update_skew);
 
+/* Modify makestep settings */
+extern void REF_ModifyMakestep(int limit, double threshold);
+
 extern void REF_EnableLocal(int stratum);
 extern void REF_DisableLocal(void);
 extern int REF_IsLocalActive(void);