]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
sources: improve no-selectable-sources log message
authorMiroslav Lichvar <mlichvar@redhat.com>
Thu, 13 Mar 2025 14:55:32 +0000 (15:55 +0100)
committerMiroslav Lichvar <mlichvar@redhat.com>
Thu, 13 Mar 2025 15:25:54 +0000 (16:25 +0100)
Include the number of unreachable sources in the "Can't synchronise: no
selectable sources" log message to provide a hint whether it might be a
networking issue.

sources.c
test/simulation/014-intermittent

index edd145a0ab0cbbe5f1ef68474c637e0609dbf392..65326398230e3a62495fdd8edf4c142be2a4acdf 100644 (file)
--- a/sources.c
+++ b/sources.c
@@ -935,7 +935,7 @@ SRC_SelectSource(SRC_Instance updated_inst)
   struct timespec now, ref_time;
   int i, j, j1, j2, index, sel_prefer, n_endpoints, n_sel_sources, sel_req_source;
   int max_badstat_reach, max_badstat_reach_size, n_badstats_sources;
-  int max_sel_reach, max_sel_reach_size;
+  int max_sel_reach, max_sel_reach_size, n_unreach_sources;
   int depth, best_depth, trust_depth, best_trust_depth, n_sel_trust_sources;
   int combined, stratum, min_stratum, max_score_index;
   int orphan_stratum, orphan_source;
@@ -964,6 +964,7 @@ SRC_SelectSource(SRC_Instance updated_inst)
   n_endpoints = 0;
   n_sel_sources = n_sel_trust_sources = 0;
   n_badstats_sources = 0;
+  n_unreach_sources = 0;
   sel_req_source = 0;
   max_sel_reach = max_badstat_reach = 0;
   max_sel_reach_size = max_badstat_reach_size = 0;
@@ -986,6 +987,10 @@ SRC_SelectSource(SRC_Instance updated_inst)
       continue;
     }
 
+    /* Count unreachable sources for a warning message */
+    if (sources[i]->reachability == 0)
+      n_unreach_sources++;
+
     si = &sources[i]->sel_info;
     SST_GetSelectionData(sources[i]->stats, &now,
                          &si->lo_limit, &si->hi_limit, &si->root_distance,
@@ -1153,7 +1158,8 @@ SRC_SelectSource(SRC_Instance updated_inst)
 
   if (n_endpoints == 0) {
     /* No sources provided valid endpoints */
-    unselect_selected_source(LOGS_INFO, "Can't synchronise: no selectable sources");
+    unselect_selected_source(LOGS_INFO, "Can't synchronise: no selectable sources"
+                                        " (%d unreachable sources)", n_unreach_sources);
     return;
   }
 
index 2f018ed02950901b6042d93ea72a2a3de6f539d7..4af574b7910824cb64b0576e51a7e1ae9327e0f7 100755 (executable)
@@ -22,7 +22,7 @@ run_test || test_fail
 check_chronyd_exit || test_fail
 check_sync || test_fail
 
-check_log_messages "Can't.*no selectable sources" 9 10 || test_fail
+check_log_messages "Can't.*no selectable sources (1 unreachable" 9 10 || test_fail
 check_log_messages "Selected source 192.168.123.1" 9 10 || test_fail
 
 # Pass every 20th request
@@ -43,7 +43,7 @@ run_test || test_fail
 check_chronyd_exit || test_fail
 check_sync || test_fail
 
-check_log_messages "Can't.*no selectable sources" 5 15 || test_fail
+check_log_messages "Can't.*no selectable sources (1 unreachable" 5 15 || test_fail
 check_log_messages "Selected source 192.168.123.1" 5 15 || test_fail
 
 test_pass