Blob Blame History Raw
commit f456cd57b93695b1a9bd792ed084c62f9ffa7c9f
Author: Miroslav Lichvar <mlichvar@redhat.com>
Date:   Tue Jan 21 17:18:48 2014 +0100

    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 6c6a5bb..de07bd3 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;