diff --git a/sources.c b/sources.c index 626aaa5..2614448 100644 --- a/sources.c +++ b/sources.c @@ -177,6 +177,8 @@ static int reported_no_majority; /* Flag to avoid repeated log message static int report_selection_loss; /* Flag to force logging a message if selection is lost in a transient state (SRC_WAITS_STATS, SRC_WAITS_UPDATE) */ +static int forced_first_report; /* Flag to allow one failed selection to be + logged before a successful selection */ /* Score needed to replace the currently selected source */ #define SCORE_LIMIT 10.0 @@ -862,7 +864,8 @@ SRC_SelectSource(SRC_Instance updated_inst) struct SelectInfo *si; struct timespec now, ref_time; int i, j, j1, j2, index, sel_prefer, n_endpoints, n_sel_sources, sel_req_source; - int n_badstats_sources, max_sel_reach, max_sel_reach_size, max_badstat_reach; + int max_badstat_reach, max_badstat_reach_size, n_badstats_sources; + int max_sel_reach, max_sel_reach_size; 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; @@ -893,7 +896,7 @@ SRC_SelectSource(SRC_Instance updated_inst) n_badstats_sources = 0; sel_req_source = 0; max_sel_reach = max_badstat_reach = 0; - max_sel_reach_size = 0; + max_sel_reach_size = max_badstat_reach_size = 0; max_reach_sample_ago = 0.0; for (i = 0; i < n_sources; i++) { @@ -924,6 +927,8 @@ SRC_SelectSource(SRC_Instance updated_inst) mark_source(sources[i], SRC_BAD_STATS); if (max_badstat_reach < sources[i]->reachability) max_badstat_reach = sources[i]->reachability; + if (max_badstat_reach_size < sources[i]->reachability_size) + max_badstat_reach_size = sources[i]->reachability_size; continue; } @@ -1068,6 +1073,14 @@ SRC_SelectSource(SRC_Instance updated_inst) return; } + /* Wait for a source to have full reachability register to allow one + failed selection to be logged before first successful selection */ + if (!forced_first_report && + MAX(max_sel_reach_size, max_badstat_reach_size) == SOURCE_REACH_BITS) { + report_selection_loss = 1; + forced_first_report = 1; + } + if (n_endpoints == 0) { /* No sources provided valid endpoints */ unselect_selected_source(LOGS_INFO, "Can't synchronise: no selectable sources", NULL); @@ -1334,6 +1347,7 @@ SRC_SelectSource(SRC_Instance updated_inst) reported_no_majority = 0; report_selection_loss = 0; + forced_first_report = 1; } mark_source(sources[selected_source_index], SRC_SELECTED); diff --git a/test/simulation/118-maxdelay b/test/simulation/118-maxdelay index 117b170..8ab0a62 100755 --- a/test/simulation/118-maxdelay +++ b/test/simulation/118-maxdelay @@ -14,7 +14,6 @@ client_server_options="maxpoll 6 maxdelay 3e-5 maxdelayratio 2.0 maxdelaydevrati run_test || test_fail check_chronyd_exit || test_fail -check_source_selection || test_fail check_packet_interval || test_fail check_sync || test_fail diff --git a/test/simulation/119-smoothtime b/test/simulation/119-smoothtime index 7f5114c..fc2c6be 100755 --- a/test/simulation/119-smoothtime +++ b/test/simulation/119-smoothtime @@ -14,7 +14,7 @@ max_sync_time=800 run_test || test_fail check_chronyd_exit || test_fail -check_source_selection || test_fail +check_source_selection && test_fail check_sync || test_fail limit=10000 diff --git a/test/simulation/122-xleave b/test/simulation/122-xleave index c19063a..77059d8 100755 --- a/test/simulation/122-xleave +++ b/test/simulation/122-xleave @@ -53,7 +53,6 @@ for rpoll in 4 5 6; do run_test || test_fail check_chronyd_exit || test_fail - check_source_selection || test_fail check_sync || test_fail if [ $rpoll -le 5 ]; then diff --git a/test/simulation/126-burst b/test/simulation/126-burst index 1cb6f9c..baae3d5 100755 --- a/test/simulation/126-burst +++ b/test/simulation/126-burst @@ -22,7 +22,7 @@ client_min_mean_out_interval=150.0 run_test || test_fail check_chronyd_exit || test_fail -check_source_selection || test_fail +check_source_selection && test_fail check_packet_interval || test_fail check_sync || test_fail diff --git a/test/simulation/127-filter b/test/simulation/127-filter index 739dd91..68afec2 100755 --- a/test/simulation/127-filter +++ b/test/simulation/127-filter @@ -12,7 +12,7 @@ client_min_mean_out_interval=15.9 run_test || test_fail check_chronyd_exit || test_fail -check_source_selection || test_fail +check_source_selection && test_fail check_packet_interval || test_fail check_sync || test_fail diff --git a/test/simulation/144-monoroot b/test/simulation/144-monoroot index 20fae12..d97f30d 100755 --- a/test/simulation/144-monoroot +++ b/test/simulation/144-monoroot @@ -20,7 +20,7 @@ for options in "extfield F323" "xleave extfield F323"; do run_test || test_fail check_chronyd_exit || test_fail - check_source_selection || test_fail + check_source_selection && test_fail check_sync || test_fail done @@ -47,7 +47,7 @@ for lpoll in 5 6 7; do run_test || test_fail check_chronyd_exit || test_fail - check_source_selection || test_fail + check_source_selection && test_fail check_sync || test_fail done done