]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
sources: improve no majority log message
authorMiroslav Lichvar <mlichvar@redhat.com>
Thu, 6 Mar 2025 11:46:09 +0000 (12:46 +0100)
committerMiroslav Lichvar <mlichvar@redhat.com>
Thu, 6 Mar 2025 14:22:36 +0000 (15:22 +0100)
Add the number of sources that form an agreement (overlapping
intervals), if at least two agree with each other, and number of
reachable sources to the "Can't synchronize: no majority" log message to
better explain why synchronization is failing and hint that adding more
sources might help.

sources.c
test/simulation/009-sourceselection
test/simulation/148-replacement

index 2ba595b5ae67ba62f03b281f1ccc51e60afd9577..3b1766bef39f5dbe0b29313506cf2540c9617742 100644 (file)
--- a/sources.c
+++ b/sources.c
@@ -1222,12 +1222,23 @@ SRC_SelectSource(SRC_Instance updated_inst)
   assert(depth == 0 && trust_depth == 0);
   assert(2 * n_sel_sources == n_endpoints);
 
-  if ((best_trust_depth == 0 && best_depth <= n_sel_sources / 2) ||
-      (best_trust_depth > 0 && best_trust_depth <= n_sel_trust_sources / 2)) {
+  if (best_trust_depth > 0) {
+    best_depth = best_trust_depth;
+    n_sel_sources = n_sel_trust_sources;
+  }
+
+  if (best_depth <= n_sel_sources / 2) {
     /* Could not even get half the reachable (trusted) sources to agree */
 
     if (!reported_no_majority) {
-      log_selection_message(LOGS_WARN, "Can't synchronise: no majority");
+      if (best_depth < 2)
+        log_selection_message(LOGS_WARN, "%s (no agreement among %d %ssources)",
+                              "Can't synchronise: no majority", n_sel_sources,
+                              best_trust_depth > 0 ? "trusted " : "");
+      else
+        log_selection_message(LOGS_WARN, "%s (only %d of %d %ssources agree)",
+                              "Can't synchronise: no majority", best_depth,
+                              n_sel_sources, best_trust_depth > 0 ? "trusted " : "");
       reported_no_majority = 1;
       report_selection_loss = 0;
     }
index 547c376c6981ce513063f6cce9edfa4b65923712..139b6aa2f03b096571854b24916350d67c55830d 100755 (executable)
@@ -24,6 +24,12 @@ for falsetickers in 3 4; do
        # These check are expected to fail
        check_source_selection && test_fail
        check_sync && test_fail
+
+       if [ $falsetickers = 3 ]; then
+               check_log_messages "Can't synchronise: no majority (only 2 of 5 sources agree)" 1 1 || test_fail
+       else
+               check_log_messages "Can't synchronise: no majority (no agreement among 5 sources)" 1 1 || test_fail
+       fi
 done
 
 # Sources with large asymmetric delay should be excluded
index d09fba6edff301dd1dcbcf3601fb7453e2193173..ee8b2e232b176b10afdb9e5e510ee273f95080df 100755 (executable)
@@ -68,7 +68,7 @@ check_source_selection && test_fail
 check_packet_interval || test_fail
 check_sync || test_fail
 
-check_log_messages "Can't synchronise: no majority" 1 1 || test_fail
+check_log_messages "Can't synchronise: no majority (no agreement among 2 sources)" 1 1 || test_fail
 check_log_messages "Detected falseticker" 0 2 || test_fail
 check_log_messages "Source 192.168.123.. replaced with" 3 60 || test_fail
 check_log_messages "Source 192.168.123.1 replaced with" 1 25 || test_fail