From: Miroslav Lichvar Date: Tue, 21 Jan 2014 16:18:48 +0000 (+0100) Subject: Fix selecting of sources with prefer option X-Git-Tag: 1.30-pre1~144 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=f456cd57b93695b1a9bd792ed084c62f9ffa7c9f;p=thirdparty%2Fchrony.git Fix selecting of sources with prefer option List of selectable sources that is used in combining was trimmed to sources with prefer option, but scoring algorithm considered all selectable sources. When a source without prefer was selected and no source was combined, it caused assertion failure. --- diff --git a/sources.c b/sources.c index 6c6a5bb5..de07bd3a 100644 --- a/sources.c +++ b/sources.c @@ -503,7 +503,7 @@ combine_sources(int n_sel_sources, struct timeval *ref_time, double *offset, void SRC_SelectSource(uint32_t match_refid) { - int i, j, index, old_selected_index; + int i, j, index, old_selected_index, sel_prefer; struct timeval now, ref_time; double src_offset, src_offset_sd, src_frequency, src_skew; double src_root_delay, src_root_dispersion; @@ -811,6 +811,9 @@ SRC_SelectSource(uint32_t match_refid) } if (j > 0) { n_sel_sources = j; + sel_prefer = 1; + } else { + sel_prefer = 0; } /* Now find minimum stratum. If none are left now, @@ -843,7 +846,8 @@ SRC_SelectSource(uint32_t match_refid) for (i = 0; i < n_sources; i++) { /* Reset score for non-selectable sources */ - if (sources[i]->status != SRC_SELECTABLE) { + if (sources[i]->status != SRC_SELECTABLE || + (sel_prefer && sources[i]->sel_option != SRC_SelectPrefer)) { sources[i]->sel_score = 1.0; sources[i]->outlier = OUTLIER_PENALTY; continue;