]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
ntp: log added and removed sources
authorMiroslav Lichvar <mlichvar@redhat.com>
Tue, 15 Nov 2022 15:38:50 +0000 (16:38 +0100)
committerMiroslav Lichvar <mlichvar@redhat.com>
Wed, 16 Nov 2022 16:00:39 +0000 (17:00 +0100)
Log a message when a single NTP source or pool of sources is added or
removed. Use the INFO severity if it's a result of a chronyc command or
(re)load of sourcefiles (which are assumed to change over time), and
DEBUG for other contexts, e.g. sources loaded from the config, sources
removed when pruning pools after reaching maxsources, and other parts of
normal operation.

ntp_sources.c

index d46c211dd0537b0fcbd40a0d35f86f32c943e7bb..fa562a1685570c3ba43ca89b897c8596cebfa905 100644 (file)
@@ -317,6 +317,31 @@ rehash_records(void)
 
 /* ================================================== */
 
+static void
+log_source(SourceRecord *record, int addition, int once_per_pool)
+{
+  int pool, log_addr;
+  char *ip_str;
+
+  if (once_per_pool && record->pool_id != INVALID_POOL) {
+    if (get_pool(record->pool_id)->sources > 1)
+      return;
+    pool = 1;
+    log_addr = 0;
+  } else {
+    ip_str = UTI_IPToString(&record->remote_addr->ip_addr);
+    pool = 0;
+    log_addr = strcmp(record->name, ip_str) != 0;
+  }
+
+  LOG(LOG_GetContextSeverity(LOGC_Command | LOGC_SourceFile), "%s %s %s%s%s%s",
+      addition ? "Added" : "Removed", pool ? "pool" : "source",
+      log_addr ? ip_str : record->name,
+      log_addr ? " (" : "", log_addr ? record->name : "", log_addr ? ")" : "");
+}
+
+/* ================================================== */
+
 /* Procedure to add a new source */
 static NSR_Status
 add_source(NTP_Remote_Address *remote_addr, char *name, NTP_Source_Type type,
@@ -371,6 +396,8 @@ add_source(NTP_Remote_Address *remote_addr, char *name, NTP_Source_Type type,
       if (auto_start_sources && UTI_IsIPReal(&remote_addr->ip_addr))
         NCR_StartInstance(record->data);
 
+      log_source(record, 1, 1);
+
       /* The new instance is allowed to change its address immediately */
       handle_saved_address_update();
 
@@ -884,6 +911,7 @@ NSR_RemoveSource(IPAddr *address)
   if (find_slot(address, &slot) == 0)
     return NSR_NoSuchSource;
 
+  log_source(get_record(slot), 0, 0);
   clean_source_record(get_record(slot));
 
   /* Rehash the table to make sure there are no broken probe sequences.
@@ -906,6 +934,7 @@ NSR_RemoveSourcesById(uint32_t conf_id)
     record = get_record(i);
     if (!record->remote_addr || record->conf_id != conf_id)
       continue;
+    log_source(record, 0, 1);
     clean_source_record(record);
   }