]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
sources: include hostname in selection log message
authorMiroslav Lichvar <mlichvar@redhat.com>
Mon, 1 Jun 2020 15:22:58 +0000 (17:22 +0200)
committerMiroslav Lichvar <mlichvar@redhat.com>
Thu, 4 Jun 2020 12:50:17 +0000 (14:50 +0200)
When selecting an NTP source, include the hostname in the log message.

sources.c
test/unit/sources.c

index 160977bfb39bf7e323cc919502fbe51ca08b68ab..6ae77142610020ff0c1f45fe1fa98aae9ebc84d0 100644 (file)
--- a/sources.c
+++ b/sources.c
@@ -573,6 +573,24 @@ log_selection_message(const char *format, const char *arg)
 
 /* ================================================== */
 
+static void
+log_selection_source(const char *format, SRC_Instance inst)
+{
+  char buf[320], *name, *ntp_name;
+
+  name = source_to_string(inst);
+  ntp_name = inst->type == SRC_NTP ? NSR_GetName(inst->ip_addr) : NULL;
+
+  if (ntp_name && strcmp(name, ntp_name) != 0)
+    snprintf(buf, sizeof (buf), "%s (%s)", name, ntp_name);
+  else
+    snprintf(buf, sizeof (buf), "%s", name);
+
+  log_selection_message(format, buf);
+}
+
+/* ================================================== */
+
 static int
 compare_sort_elements(const void *a, const void *b)
 {
@@ -1166,8 +1184,7 @@ SRC_SelectSource(SRC_Instance updated_inst)
     }
 
     selected_source_index = max_score_index;
-    log_selection_message("Selected source %s",
-                          source_to_string(sources[selected_source_index]));
+    log_selection_source("Selected source %s", sources[selected_source_index]);
 
     /* New source has been selected, reset all scores */
     for (i = 0; i < n_sources; i++) {
index 1c666297506630582f5699f49751d4660c9a4f18..a314a2eb3e24278dcdbc7c7aa59c179060061517 100644 (file)
@@ -49,6 +49,7 @@ test_unit(void)
   SCH_Initialise();
   SRC_Initialise();
   REF_Initialise();
+  NSR_Initialise();
 
   REF_SetMode(REF_ModeIgnore);
 
@@ -224,6 +225,7 @@ test_unit(void)
     }
   }
 
+  NSR_Finalise();
   REF_Finalise();
   SRC_Finalise();
   SCH_Finalise();