]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
cmdmon: rename reset command to reset sources
authorMiroslav Lichvar <mlichvar@redhat.com>
Tue, 12 May 2020 08:52:46 +0000 (10:52 +0200)
committerMiroslav Lichvar <mlichvar@redhat.com>
Thu, 14 May 2020 13:37:38 +0000 (15:37 +0200)
Add a sources option for the reset command in case there are other
components that would need to be reset.

candm.h
client.c
cmdmon.c
doc/chronyc.adoc
pktlength.c
test/simulation/110-chronyc

diff --git a/candm.h b/candm.h
index e0d5140cf20d03bc4397f6407774744f027c1aac..9f584472bbaa70f3c52308e95173d0c4fb2437a8 100644 (file)
--- a/candm.h
+++ b/candm.h
 #define REQ_ONOFFLINE 63
 #define REQ_ADD_SOURCE 64
 #define REQ_NTP_SOURCE_NAME 65
-#define REQ_RESET 66
+#define REQ_RESET_SOURCES 66
 #define N_REQUEST_TYPES 67
 
 /* Structure used to exchange timespecs independent of time_t size */
index c557040339951c0258338d471133c1737d085670..9e64c6d9b704e7a4f43420affd9cd4f17f70465e 100644 (file)
--- a/client.c
+++ b/client.c
@@ -1269,7 +1269,7 @@ give_help(void)
     "cyclelogs\0Close and re-open log files\0"
     "dump\0Dump measurements and NTS keys/cookies\0"
     "rekey\0Re-read keys\0"
-    "reset\0Drop all measurements\0"
+    "reset sources\0Drop all measurements\0"
     "shutdown\0Stop daemon\0"
     "\0\0"
     "Client commands:\0\0"
@@ -1299,6 +1299,7 @@ enum {
   TAB_COMPLETE_BASE_CMDS,
   TAB_COMPLETE_ADD_OPTS,
   TAB_COMPLETE_MANUAL_OPTS,
+  TAB_COMPLETE_RESET_OPTS,
   TAB_COMPLETE_SOURCES_OPTS,
   TAB_COMPLETE_SOURCESTATS_OPTS,
   TAB_COMPLETE_MAX_INDEX
@@ -1324,6 +1325,7 @@ command_name_generator(const char *text, int state)
   };
   const char *add_options[] = { "peer", "pool", "server", NULL };
   const char *manual_options[] = { "on", "off", "delete", "list", "reset", NULL };
+  const char *reset_options[] = { "sources", NULL };
   const char *sources_options[] = { "-a", "-v", NULL };
   const char *sourcestats_options[] = { "-a", "-v", NULL };
   static int list_index, len;
@@ -1331,6 +1333,7 @@ command_name_generator(const char *text, int state)
   names[TAB_COMPLETE_BASE_CMDS] = base_commands;
   names[TAB_COMPLETE_ADD_OPTS] = add_options;
   names[TAB_COMPLETE_MANUAL_OPTS] = manual_options;
+  names[TAB_COMPLETE_RESET_OPTS] = reset_options;
   names[TAB_COMPLETE_SOURCES_OPTS] = sources_options;
   names[TAB_COMPLETE_SOURCESTATS_OPTS] = sourcestats_options;
 
@@ -1362,6 +1365,8 @@ command_name_completion(const char *text, int start, int end)
     tab_complete_index = TAB_COMPLETE_ADD_OPTS;
   } else if (!strcmp(first, "manual ")) {
     tab_complete_index = TAB_COMPLETE_MANUAL_OPTS;
+  } else if (!strcmp(first, "reset ")) {
+    tab_complete_index = TAB_COMPLETE_RESET_OPTS;
   } else if (!strcmp(first, "sources ")) {
     tab_complete_index = TAB_COMPLETE_SOURCES_OPTS;
   } else if (!strcmp(first, "sourcestats ")) {
@@ -2836,10 +2841,17 @@ process_cmd_shutdown(CMD_Request *msg, char *line)
 
 /* ================================================== */
 
-static void
+static int
 process_cmd_reset(CMD_Request *msg, char *line)
 {
-  msg->command = htons(REQ_RESET);
+  if (!strcmp(line, "sources")) {
+    msg->command = htons(REQ_RESET_SOURCES);
+  } else {
+    LOG(LOGS_ERR, "Invalid syntax for reset command");
+    return 0;
+  }
+
+  return 1;
 }
 
 /* ================================================== */
@@ -3139,7 +3151,7 @@ process_line(char *line)
   } else if (!strcmp(command, "reselectdist")) {
     do_normal_submit = process_cmd_reselectdist(&tx_message, line);
   } else if (!strcmp(command, "reset")) {
-    process_cmd_reset(&tx_message, line);
+    do_normal_submit = process_cmd_reset(&tx_message, line);
   } else if (!strcmp(command, "retries")) {
     ret = process_cmd_retries(line);
     do_normal_submit = 0;
index c43e10cf453456283533706188a32d9101094c72..13a0fad6e9ec0c95898bd4f047b0d05efab4f7e2 100644 (file)
--- a/cmdmon.c
+++ b/cmdmon.c
@@ -135,7 +135,7 @@ static const char permissions[] = {
   PERMIT_AUTH, /* ONOFFLINE */
   PERMIT_AUTH, /* ADD_SOURCE */
   PERMIT_OPEN, /* NTP_SOURCE_NAME */
-  PERMIT_AUTH, /* RESET */
+  PERMIT_AUTH, /* RESET_SOURCES */
 };
 
 /* ================================================== */
@@ -1226,7 +1226,7 @@ handle_ntp_source_name(CMD_Request *rx_message, CMD_Reply *tx_message)
 /* ================================================== */
 
 static void
-handle_reset(CMD_Request *rx_message, CMD_Reply *tx_message)
+handle_reset_sources(CMD_Request *rx_message, CMD_Reply *tx_message)
 {
   struct timespec cooked_now, now;
 
@@ -1613,8 +1613,8 @@ read_from_cmd_socket(int sock_fd, int event, void *anything)
           handle_ntp_source_name(&rx_message, &tx_message);
           break;
 
-        case REQ_RESET:
-          handle_reset(&rx_message, &tx_message);
+        case REQ_RESET_SOURCES:
+          handle_reset_sources(&rx_message, &tx_message);
           break;
 
         default:
index 5d884a852c75d3f4e86f6e797d214535fc77dff3..1b7513f840fb1760751887f1a2a61bc68975d9fb 100644 (file)
@@ -1177,12 +1177,12 @@ also re-reads the server NTS keys if
 <<chrony.conf.adoc#ntsrotate,automatic rotation>> is disabled in the
 configuration file.
 
-[[reset]]*reset*::
-The *reset* command causes *chronyd* to drop all measurements and switch to the
-unsynchronised state. This command can help *chronyd* with recovery when the
-measurements are known to be no longer valid or accurate, e.g. due to moving
-the computer to a different network, or resuming the computer from a low-power
-state (which resets the system clock).
+[[reset]]*reset* *sources*::
+The *reset sources* command causes *chronyd* to drop all measurements and
+switch to the unsynchronised state. This command can help *chronyd* with
+recovery when the measurements are known to be no longer valid or accurate,
+e.g. due to moving the computer to a different network, or resuming the
+computer from a low-power state (which resets the system clock).
 
 [[shutdown]]*shutdown*::
 The *shutdown* command causes *chronyd* to exit. This is equivalent to sending
index 911f725e5c2a009e761075980f44b25d8608b968..83f848f43718987ea79b6d12238c4e05e219f301 100644 (file)
@@ -123,7 +123,7 @@ static const struct request_length request_lengths[] = {
   REQ_LENGTH_ENTRY(ntp_source, null),           /* ADD_SOURCE */
   REQ_LENGTH_ENTRY(ntp_source_name,
                    ntp_source_name),            /* NTP_SOURCE_NAME */
-  REQ_LENGTH_ENTRY(null, null),                 /* RESET */
+  REQ_LENGTH_ENTRY(null, null),                 /* RESET_SOURCES */
 };
 
 static const uint16_t reply_lengths[] = {
index e20cf3d50d04a92ddd6da09c50e674ca836b860e..40df0871148d365c92826d964407c5b7efd78449 100755 (executable)
@@ -138,7 +138,7 @@ for chronyc_conf in \
        "rekey" \
        "reselect" \
        "reselectdist 1e-3" \
-       "reset" \
+       "reset sources" \
        "settime 16:30" \
        "settime 16:30:05" \
        "settime Nov 21, 2015 16:30:05" \