]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
Fix selecting of sources with prefer option
authorMiroslav Lichvar <mlichvar@redhat.com>
Tue, 21 Jan 2014 16:18:48 +0000 (17:18 +0100)
committerMiroslav Lichvar <mlichvar@redhat.com>
Tue, 21 Jan 2014 16:18:48 +0000 (17:18 +0100)
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.

sources.c

index 6c6a5bb5ffd824a0b739efdd4c85980462ab6622..de07bd3a86b71058356b9a60fc65801dae178596 100644 (file)
--- 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;