]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
client: add sourcename command
authorMiroslav Lichvar <mlichvar@redhat.com>
Thu, 5 Dec 2019 12:25:10 +0000 (13:25 +0100)
committerMiroslav Lichvar <mlichvar@redhat.com>
Thu, 12 Dec 2019 15:17:45 +0000 (16:17 +0100)
Add a new command to print the original name of a source specified by
address. This could be useful in scripts to avoid having to run the
sources command with and without -N.

client.c
doc/chronyc.adoc

index 62d0aad3323e3e4cebbe48156bc0b4b1028754ff..e49a25a640a81a4f43bfbb346d4094d6a76ffc38 100644 (file)
--- a/client.c
+++ b/client.c
@@ -1213,6 +1213,7 @@ give_help(void)
     "\0according to network configuration\0"
     "polltarget <address> <target>\0Modify poll target\0"
     "refresh\0Refresh IP addresses\0"
+    "sourcename <address>\0Display original name\0"
     "\0\0"
     "Manual time input:\0\0"
     "manual off|on|reset\0Disable/enable/reset settime command\0"
@@ -2081,6 +2082,27 @@ check_for_verbose_flag(char *line)
 
 /* ================================================== */
 
+static int
+process_cmd_sourcename(char *line)
+{
+  IPAddr ip_addr;
+  char name[256];
+
+  if (!UTI_StringToIP(line, &ip_addr)) {
+    LOG(LOGS_ERR, "Could not read address");
+    return 0;
+  }
+
+  if (!get_source_name(&ip_addr, name, sizeof (name)))
+    return 0;
+
+  print_report("%s\n", name, REPORT_END);
+
+  return 1;
+}
+
+/* ================================================== */
+
 static int
 process_cmd_sources(char *line)
 {
@@ -3093,6 +3115,9 @@ process_line(char *line)
     ret = process_cmd_smoothing(line);
   } else if (!strcmp(command, "smoothtime")) {
     do_normal_submit = process_cmd_smoothtime(&tx_message, line);
+  } else if (!strcmp(command, "sourcename")) {
+    do_normal_submit = 0;
+    ret = process_cmd_sourcename(line);
   } else if (!strcmp(command, "sources")) {
     do_normal_submit = 0;
     ret = process_cmd_sources(line);
index fdb1a98655a0dac13893a513c11932d4f6e2d4eb..3ddf4dea632a1882ef9543f0e67fc904becf1d61 100644 (file)
@@ -761,6 +761,15 @@ 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.
 
+[[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.
+This command is an alternative to the *-N* option, which can be useful in
+scripts.
++
+Note that different NTP sources can share the same name, e.g. servers from a
+pool.
+
 === Manual time input
 
 [[manual]]