]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
Add reselect command
authorMiroslav Lichvar <mlichvar@redhat.com>
Tue, 7 Dec 2010 15:21:24 +0000 (16:21 +0100)
committerMiroslav Lichvar <mlichvar@redhat.com>
Tue, 7 Dec 2010 15:47:58 +0000 (16:47 +0100)
candm.h
chrony.texi
client.c
cmdmon.c
pktlength.c
sources.c
sources.h

diff --git a/candm.h b/candm.h
index ac8e4cb5e17493d66983ac8305e418c6e2fa67a4..d79b00c1be58cda0349ad838e82ae8398cfe4437 100644 (file)
--- a/candm.h
+++ b/candm.h
@@ -89,7 +89,8 @@
 #define REQ_MODIFY_MINSTRATUM 45
 #define REQ_MODIFY_POLLTARGET 46
 #define REQ_MODIFY_MAXDELAYDEVRATIO 47
-#define N_REQUEST_TYPES 48
+#define REQ_RESELECT 48
+#define N_REQUEST_TYPES 49
 
 /* Special utoken value used to log on with first exchange being the
    password.  (This time value has long since gone by) */
@@ -338,6 +339,10 @@ typedef struct {
   int32_t EOR;
 } REQ_Activity;
 
+typedef struct {
+  int32_t EOR;
+} REQ_Reselect;
+
 /* ================================================== */
 
 #define PKT_TYPE_CMD_REQUEST 1
@@ -423,6 +428,7 @@ typedef struct {
     REQ_ManualDelete manual_delete;
     REQ_MakeStep make_step;
     REQ_Activity activity;
+    REQ_Reselect reselect;
   } data; /* Command specific parameters */
 
 } CMD_Request;
index 823e20cf8383840b4ae1b2dc5046bef70359900d..f52729a93cf394850fce19b98e631c8e5e787c07 100644 (file)
@@ -2883,6 +2883,7 @@ interface.
 * password command::            Provide password needed for most commands
 * polltarget command::          Set poll target for a source
 * quit command::                Exit from chronyc
+* reselect command::            Reselect synchronisation source
 * retries command::             Set maximum number of retries
 * rtcdata command::             Display RTC parameters
 * settime command::             Provide a manual input of the current time
@@ -3695,6 +3696,16 @@ to 12.
 The quit command exits from chronyc and returns the user to the shell
 (same as the exit command).
 @c }}}
+@c {{{ reselect command
+@node reselect command
+@subsubsection reselect
+To avoid excessive switching between sources, @code{chronyd} may stay
+synchronised to a source even when it is not currently the best one among the
+available sources.
+
+The @code{reselect} command can be used to force @code{chronyd} to
+reselect the best synchronisation source.
+@c }}}
 @c {{{ retries
 @node retries command
 @subsubsection retries
index ecea90ca5e25a683f07560bb80c824236341cd58..e6dbd61e4141b922736d1ffb2477587238e3a337 100644 (file)
--- a/client.c
+++ b/client.c
@@ -1231,6 +1231,7 @@ give_help(void)
   printf("online [<mask>/<masked-address>] : Set sources in subnet to online status\n");
   printf("password [<new-password>] : Set command authentication password\n");
   printf("polltarget <address> <new-poll-target> : Modify poll target of source\n");
+  printf("reselect : Reselect synchronisation source\n");
   printf("rtcdata : Print current RTC performance parameters\n");
   printf("settime <date/time (e.g. Nov 21, 1997 16:30:05 or 16:30:05)> : Manually set the daemon time\n");
   printf("sources [-v] : Display information about current sources\n");
@@ -2372,6 +2373,14 @@ process_cmd_activity(const char *line)
 
 /* ================================================== */
 
+static void
+process_cmd_reselect(CMD_Request *msg, char *line)
+{
+  msg->command = htons(REQ_RESELECT);
+}
+
+/* ================================================== */
+
 static int
 process_cmd_dns(const char *line)
 {
@@ -2545,6 +2554,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, "reselect", 8)) {
+    process_cmd_reselect(&tx_message, p+8);
   } else if (!strncmp(p, "dns ", 4)) {
     ret = process_cmd_dns(p+4);
     do_normal_submit = 0;
index e5a6f4330b251d91b4fbdb72c733a9390749cd40..c8fc5b08adf20b57edb7bb432c925e3d2a2f86d2 100644 (file)
--- a/cmdmon.c
+++ b/cmdmon.c
@@ -161,7 +161,8 @@ static int permissions[] = {
   PERMIT_OPEN, /* ACTIVITY */
   PERMIT_AUTH, /* MODIFY_MINSTRATUM */
   PERMIT_AUTH, /* MODIFY_POLLTARGET */
-  PERMIT_AUTH  /* MODIFY_MAXDELAYDEVRATIO */
+  PERMIT_AUTH, /* MODIFY_MAXDELAYDEVRATIO */
+  PERMIT_AUTH  /* RESELECT */
 };
 
 /* ================================================== */
@@ -1709,6 +1710,16 @@ handle_activity(CMD_Request *rx_message, CMD_Reply *tx_message)
 
 /* ================================================== */
 
+static void
+handle_reselect(CMD_Request *rx_message, CMD_Reply *tx_message)
+{
+  SRC_ReselectSource();
+  tx_message->status = htons(STT_SUCCESS);
+  return;
+}
+
+/* ================================================== */
+
 #if 0
 /* ================================================== */
 
@@ -2236,6 +2247,10 @@ read_from_cmd_socket(void *anything)
           handle_activity(&rx_message, &tx_message);
           break;
 
+        case REQ_RESELECT:
+          handle_reselect(&rx_message, &tx_message);
+          break;
+
         case REQ_MODIFY_MINSTRATUM:
           handle_modify_minstratum(&rx_message, &tx_message);
           break;
index dc1d059ed451548635eb041a4e3e1169533be8d4..788a36715b3e4ef0ecea155c8db20f3888b566f9 100644 (file)
@@ -149,6 +149,8 @@ PKL_CommandLength(CMD_Request *r)
         return offsetof(CMD_Request, data.make_step.EOR);
       case REQ_ACTIVITY:
         return offsetof(CMD_Request, data.activity.EOR);
+      case REQ_RESELECT:
+        return offsetof(CMD_Request, data.reselect.EOR);
       case REQ_MODIFY_MINSTRATUM:
         return offsetof(CMD_Request, data.modify_minstratum.EOR);
       case REQ_MODIFY_POLLTARGET:
index 20c0855971df3bef2bdc76e8102c90b265d97449..3dcfc4207a7016ffb5c1d58b61a8ae4cf0769758 100644 (file)
--- a/sources.c
+++ b/sources.c
@@ -778,6 +778,16 @@ SRC_SelectSource(unsigned long match_addr)
 
 }
 
+/* ================================================== */
+/* Force reselecting the best source */
+
+void
+SRC_ReselectSource(void)
+{
+  selected_source_index = INVALID_SOURCE;
+  SRC_SelectSource(0);
+}
+
 /* ================================================== */
 
 double
index b731191edeaf40dd618d6c1e59a3d7b6be7ac299..4351e13c2edb1cbe8899124469c5c569ab74a183 100644 (file)
--- a/sources.h
+++ b/sources.h
@@ -136,6 +136,9 @@ extern void SRC_UnsetReachable(SRC_Instance instance);
    selected reference make a difference) */
 extern void SRC_SelectSource(unsigned long match_addr);
 
+/* Force reselecting the best source */
+extern void SRC_ReselectSource(void);
+
 /* 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. */