]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
Add reselectdist command
authorMiroslav Lichvar <mlichvar@redhat.com>
Thu, 7 Apr 2011 16:16:39 +0000 (18:16 +0200)
committerMiroslav Lichvar <mlichvar@redhat.com>
Thu, 7 Apr 2011 16:16:39 +0000 (18:16 +0200)
candm.h
chrony.texi
client.c
cmdmon.c
pktlength.c
sources.c
sources.h

diff --git a/candm.h b/candm.h
index 49822b038c9ea008c2a62980fb036fc7163f1851..51549460338d92a2fd5173d17ae1c508c8dd0ec9 100644 (file)
--- a/candm.h
+++ b/candm.h
@@ -86,7 +86,8 @@
 #define REQ_MODIFY_POLLTARGET 46
 #define REQ_MODIFY_MAXDELAYDEVRATIO 47
 #define REQ_RESELECT 48
-#define N_REQUEST_TYPES 49
+#define REQ_RESELECTDISTANCE 49
+#define N_REQUEST_TYPES 50
 
 /* Special utoken value used to log on with first exchange being the
    password.  (This time value has long since gone by) */
@@ -339,6 +340,11 @@ typedef struct {
   int32_t EOR;
 } REQ_Reselect;
 
+typedef struct {
+  Float distance;
+  int32_t EOR;
+} REQ_ReselectDistance;
+
 /* ================================================== */
 
 #define PKT_TYPE_CMD_REQUEST 1
@@ -425,6 +431,7 @@ typedef struct {
     REQ_MakeStep make_step;
     REQ_Activity activity;
     REQ_Reselect reselect;
+    REQ_ReselectDistance reselect_distance;
   } data; /* Command specific parameters */
 
 } CMD_Request;
index ec755a1f4c34d8d3e31ef2794f61162e0336e433..f0931b8073af558a7da23e793f0bb92f290ad26a 100644 (file)
@@ -2934,6 +2934,7 @@ interface.
 * polltarget command::          Set poll target for a source
 * quit command::                Exit from chronyc
 * reselect command::            Reselect synchronisation source
+* reselectdist command::        Set improvement in distance needed to reselect a source
 * retries command::             Set maximum number of retries
 * rtcdata command::             Display RTC parameters
 * settime command::             Provide a manual input of the current time
@@ -3756,6 +3757,13 @@ available sources.
 The @code{reselect} command can be used to force @code{chronyd} to
 reselect the best synchronisation source.
 @c }}}
+@c {{{ reselectdist command
+@node reselectdist command
+@subsubsection reselectdist
+The @code{reselectdist} command sets the reselect distance.  It is equivalent
+to the @code{reselectdist} directive in the configuration file
+(@pxref{reselectdist directive}).
+@c }}}
 @c {{{ retries
 @node retries command
 @subsubsection retries
index 43a9b7c32dec0c14ce0516e25a89ecf7614e9a83..b8d93bf41ddfc18cefc6c9b61eb73d43387f91be 100644 (file)
--- a/client.c
+++ b/client.c
@@ -2377,6 +2377,23 @@ process_cmd_activity(const char *line)
 
 /* ================================================== */
 
+static int
+process_cmd_reselectdist(CMD_Request *msg, char *line)
+{
+  double dist;
+  int ok;
+  msg->command = htons(REQ_RESELECTDISTANCE);
+  if (sscanf(line, "%lf", &dist) == 1) {
+    msg->data.reselect_distance.distance = UTI_FloatHostToNetwork(dist);
+    ok = 1;
+  } else {
+    ok = 0;
+  }
+  return ok;
+}
+
+/* ================================================== */
+
 static void
 process_cmd_reselect(CMD_Request *msg, char *line)
 {
@@ -2558,6 +2575,8 @@ process_line(char *line, int *quit)
   } else if (!strncmp(p, "activity", 8)) {
     ret = process_cmd_activity(p+8);
     do_normal_submit = 0;
+  } else if (!strncmp(p, "reselectdist", 12)) {
+    do_normal_submit = process_cmd_reselectdist(&tx_message, p+12);
   } else if (!strncmp(p, "reselect", 8)) {
     process_cmd_reselect(&tx_message, p+8);
   } else if (!strncmp(p, "dns ", 4)) {
index 561cb40bbf87ba8451e9f04c13f5917f96d93051..4aea031f2c41a709779223e537242be91221fca0 100644 (file)
--- a/cmdmon.c
+++ b/cmdmon.c
@@ -158,7 +158,8 @@ static int permissions[] = {
   PERMIT_AUTH, /* MODIFY_MINSTRATUM */
   PERMIT_AUTH, /* MODIFY_POLLTARGET */
   PERMIT_AUTH, /* MODIFY_MAXDELAYDEVRATIO */
-  PERMIT_AUTH  /* RESELECT */
+  PERMIT_AUTH, /* RESELECT */
+  PERMIT_AUTH  /* RESELECTDISTANCE */
 };
 
 /* ================================================== */
@@ -1711,6 +1712,18 @@ handle_activity(CMD_Request *rx_message, CMD_Reply *tx_message)
 
 /* ================================================== */
 
+static void
+handle_reselect_distance(CMD_Request *rx_message, CMD_Reply *tx_message)
+{
+  double dist;
+  dist = UTI_FloatNetworkToHost(rx_message->data.reselect_distance.distance);
+  SRC_SetReselectDistance(dist);
+  tx_message->status = htons(STT_SUCCESS);
+  return;
+}
+
+/* ================================================== */
+
 static void
 handle_reselect(CMD_Request *rx_message, CMD_Reply *tx_message)
 {
@@ -2258,6 +2271,10 @@ read_from_cmd_socket(void *anything)
           handle_activity(&rx_message, &tx_message);
           break;
 
+        case REQ_RESELECTDISTANCE:
+          handle_reselect_distance(&rx_message, &tx_message);
+          break;
+
         case REQ_RESELECT:
           handle_reselect(&rx_message, &tx_message);
           break;
index 7bde64c562c7b1a9d63f4200d820fd90e3c5d525..74f35dbd8549353964074caa7c39044f2fcc73ca 100644 (file)
@@ -147,6 +147,8 @@ PKL_CommandLength(CMD_Request *r)
         return offsetof(CMD_Request, data.activity.EOR);
       case REQ_RESELECT:
         return offsetof(CMD_Request, data.reselect.EOR);
+      case REQ_RESELECTDISTANCE:
+        return offsetof(CMD_Request, data.reselect_distance.EOR);
       case REQ_MODIFY_MINSTRATUM:
         return offsetof(CMD_Request, data.modify_minstratum.EOR);
       case REQ_MODIFY_POLLTARGET:
index 01b0f46e4264f37a2f3a33f6ea4bdbebd36fcdf0..b596ed9716f7a94cfc7c6d0da0f0a674d614b81e 100644 (file)
--- a/sources.c
+++ b/sources.c
@@ -901,6 +901,17 @@ SRC_ReselectSource(void)
 
 /* ================================================== */
 
+void
+SRC_SetReselectDistance(double distance)
+{
+  if (reselect_distance != distance) {
+    reselect_distance = distance;
+    LOG(LOGS_INFO, LOGF_Sources, "New reselect distance %f", distance);
+  }
+}
+
+/* ================================================== */
+
 double
 SRC_PredictOffset(SRC_Instance inst, struct timeval *when)
 {
index 8aeee020a88fed4468417269b40b46531d488321..ec9833823b03dd5225d7294586324d9a8328a740 100644 (file)
--- a/sources.h
+++ b/sources.h
@@ -140,6 +140,9 @@ extern void SRC_SelectSource(unsigned long match_addr);
 /* Force reselecting the best source */
 extern void SRC_ReselectSource(void);
 
+/* Set reselect distance */
+extern void SRC_SetReselectDistance(double distance);
+
 /* Predict the offset of the local clock relative to a given source at
    a given local cooked time. Positive indicates local clock is FAST
    relative to reference. */