]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
cmdmon: add reload sources command
authorMiroslav Lichvar <mlichvar@redhat.com>
Wed, 10 Jun 2020 09:20:43 +0000 (11:20 +0200)
committerMiroslav Lichvar <mlichvar@redhat.com>
Wed, 10 Jun 2020 11:56:43 +0000 (13:56 +0200)
Add the command which reloads the files from the directories specified
by the sourcedirs directive.

candm.h
client.c
cmdmon.c
doc/chrony.conf.adoc
doc/chronyc.adoc
pktlength.c

diff --git a/candm.h b/candm.h
index 6530f146b2d39a3ed2a5d13326980741566c1592..a786ae74f0c4d2c91f2753e478ea2176d1dcd726 100644 (file)
--- a/candm.h
+++ b/candm.h
 #define REQ_AUTH_DATA 67
 #define REQ_CLIENT_ACCESSES_BY_INDEX3 68
 #define REQ_SELECT_DATA 69
-#define N_REQUEST_TYPES 70
+#define REQ_RELOAD_SOURCES 70
+#define N_REQUEST_TYPES 71
 
 /* Structure used to exchange timespecs independent of time_t size */
 typedef struct {
index 6a9ef185da02feae6672d63cc9e4c099d0620ec4..f6652ba659ed1b98dce633499fe49ca84d939b9b 100644 (file)
--- a/client.c
+++ b/client.c
@@ -1234,6 +1234,7 @@ give_help(void)
     "\0according to network configuration\0"
     "polltarget <address> <target>\0Modify poll target\0"
     "refresh\0Refresh IP addresses\0"
+    "reload sources\0Re-read *.sources files\0"
     "sourcename <address>\0Display original name\0"
     "\0\0"
     "Manual time input:\0\0"
@@ -1301,6 +1302,7 @@ enum {
   TAB_COMPLETE_BASE_CMDS,
   TAB_COMPLETE_ADD_OPTS,
   TAB_COMPLETE_MANUAL_OPTS,
+  TAB_COMPLETE_RELOAD_OPTS,
   TAB_COMPLETE_RESET_OPTS,
   TAB_COMPLETE_SOURCES_OPTS,
   TAB_COMPLETE_SOURCESTATS_OPTS,
@@ -1321,7 +1323,7 @@ command_name_generator(const char *text, int state)
     "deny", "dns", "dump", "exit", "help", "keygen", "local", "makestep",
     "manual", "maxdelay", "maxdelaydevratio", "maxdelayratio", "maxpoll",
     "maxupdateskew", "minpoll", "minstratum", "ntpdata", "offline", "online", "onoffline",
-    "polltarget", "quit", "refresh", "rekey", "reselect", "reselectdist", "reset",
+    "polltarget", "quit", "refresh", "rekey", "reload", "reselect", "reselectdist", "reset",
     "retries", "rtcdata", "selectdata", "serverstats", "settime", "shutdown", "smoothing",
     "smoothtime", "sourcename", "sources", "sourcestats",
     "timeout", "tracking", "trimrtc", "waitsync", "writertc",
@@ -1330,12 +1332,14 @@ 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 *reload_options[] = { "sources", NULL };
   const char *common_source_options[] = { "-a", "-v", NULL };
   static int list_index, len;
 
   names[TAB_COMPLETE_BASE_CMDS] = base_commands;
   names[TAB_COMPLETE_ADD_OPTS] = add_options;
   names[TAB_COMPLETE_MANUAL_OPTS] = manual_options;
+  names[TAB_COMPLETE_RELOAD_OPTS] = reload_options;
   names[TAB_COMPLETE_RESET_OPTS] = reset_options;
   names[TAB_COMPLETE_AUTHDATA_OPTS] = common_source_options;
   names[TAB_COMPLETE_SELECTDATA_OPTS] = common_source_options;
@@ -1372,6 +1376,8 @@ command_name_completion(const char *text, int start, int end)
     tab_complete_index = TAB_COMPLETE_AUTHDATA_OPTS;
   } else if (!strcmp(first, "manual ")) {
     tab_complete_index = TAB_COMPLETE_MANUAL_OPTS;
+  } else if (!strcmp(first, "reload ")) {
+    tab_complete_index = TAB_COMPLETE_RELOAD_OPTS;
   } else if (!strcmp(first, "reset ")) {
     tab_complete_index = TAB_COMPLETE_RESET_OPTS;
   } else if (!strcmp(first, "selectdata ")) {
@@ -3043,6 +3049,21 @@ process_cmd_shutdown(CMD_Request *msg, char *line)
 
 /* ================================================== */
 
+static int
+process_cmd_reload(CMD_Request *msg, char *line)
+{
+  if (!strcmp(line, "sources")) {
+    msg->command = htons(REQ_RELOAD_SOURCES);
+  } else {
+    LOG(LOGS_ERR, "Invalid syntax for reload command");
+    return 0;
+  }
+
+  return 1;
+}
+
+/* ================================================== */
+
 static int
 process_cmd_reset(CMD_Request *msg, char *line)
 {
@@ -3351,6 +3372,8 @@ process_line(char *line)
     process_cmd_refresh(&tx_message, line);
   } else if (!strcmp(command, "rekey")) {
     process_cmd_rekey(&tx_message, line);
+  } else if (!strcmp(command, "reload")) {
+    do_normal_submit = process_cmd_reload(&tx_message, line);
   } else if (!strcmp(command, "reselect")) {
     process_cmd_reselect(&tx_message, line);
   } else if (!strcmp(command, "reselectdist")) {
index ee6a25d560f42ffbdbddfe014c2080fe8e9e17bd..bdaf711340e4337b7ead2e37708379dc06d31134 100644 (file)
--- a/cmdmon.c
+++ b/cmdmon.c
@@ -139,6 +139,7 @@ static const char permissions[] = {
   PERMIT_AUTH, /* AUTH_DATA */
   PERMIT_AUTH, /* CLIENT_ACCESSES_BY_INDEX3 */
   PERMIT_AUTH, /* SELECT_DATA */
+  PERMIT_AUTH, /* RELOAD_SOURCES */
 };
 
 /* ================================================== */
@@ -1232,6 +1233,14 @@ handle_ntp_source_name(CMD_Request *rx_message, CMD_Reply *tx_message)
 
 /* ================================================== */
 
+static void
+handle_reload_sources(CMD_Request *rx_message, CMD_Reply *tx_message)
+{
+  CNF_ReloadSources();
+}
+
+/* ================================================== */
+
 static void
 handle_reset_sources(CMD_Request *rx_message, CMD_Reply *tx_message)
 {
@@ -1710,6 +1719,10 @@ read_from_cmd_socket(int sock_fd, int event, void *anything)
           handle_select_data(&rx_message, &tx_message);
           break;
 
+        case REQ_RELOAD_SOURCES:
+          handle_reload_sources(&rx_message, &tx_message);
+          break;
+
         default:
           DEBUG_LOG("Unhandled command %d", rx_command);
           tx_message.status = htons(STT_FAILED);
index a3c432187432c59185590815c63baf7fcda2202b..b03862945d4659b898566cb3b540bcffdce5cccd 100644 (file)
@@ -2152,8 +2152,12 @@ confdirs @SYSCONFDIR@/chrony.d /var/run/chrony.d /usr/lib/chrony.d
 
 [[sourcedirs]]*sourcedirs* _directory_...::
 The *sourcedirs* directive is identical to the *confdirs* directive, except the
-configuration files have the _.sources_ suffix and they can only specify NTP
-sources (i.e. use the *server*, *pool*, and *peer* directive).
+configuration files have the _.sources_ suffix, they can only specify NTP
+sources (i.e. use the *server*, *pool*, and *peer* directive), and can be
+reloaded by the <<chronyc.adoc#reload,*reload sources*>> command in
+*chronyc*. It is particularly useful with dynamic sources like NTP servers
+received from a DHCP server, which can be written to a file specific to the
+network interface by a networking script.
 +
 An example of the directive is:
 +
index 3e32f13ca01976c431a7d476797f3b3247b366b4..eb7db633ad6b5a1b97f5307471339c64f1b593cb 100644 (file)
@@ -928,6 +928,11 @@ Sources that stop responding will be replaced with newly resolved addresses
 automatically after 8 polling intervals, but this command can still be useful
 to replace them immediately and not wait until they are marked as unreachable.
 
+[[reload]]*reload* *sources*::
+The *reload sources* command causes *chronyd* to re-read all _*.sources_ files
+from the directories specified by the
+<<chrony.conf.adoc#sourcedirs,*sourcedirs*>> directive.
+
 [[sourcename]]*sourcename* _address_::
 The *sourcename* command prints the original hostname or address that was
 specified for an NTP source in the configuration file, or the *add* command.
index bc0055fe33bd379e5125c5d4810ab3085098d6c8..25476898d1c9db7ef26e07f421994cd02d1c92ec 100644 (file)
@@ -127,6 +127,7 @@ static const struct request_length request_lengths[] = {
   REQ_LENGTH_ENTRY(client_accesses_by_index,
                    client_accesses_by_index),   /* CLIENT_ACCESSES_BY_INDEX3 */
   REQ_LENGTH_ENTRY(select_data, select_data),   /* SELECT_DATA */
+  REQ_LENGTH_ENTRY(null, null),                 /* RELOAD_SOURCES */
 };
 
 static const uint16_t reply_lengths[] = {