]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
sources: include trust option in leap second voting
authorMiroslav Lichvar <mlichvar@redhat.com>
Wed, 24 Aug 2016 08:21:39 +0000 (10:21 +0200)
committerMiroslav Lichvar <mlichvar@redhat.com>
Tue, 6 Sep 2016 13:48:59 +0000 (15:48 +0200)
When sources specified with the trust option pass the source selection,
ignore other sources in the vote of leap second status.

sources.c

index a09ef48a3f84f2a943e38f72fa3b1f9ad165c531..81091726014ab1f065c814c54c5dff1d54310dd1 100644 (file)
--- a/sources.c
+++ b/sources.c
@@ -609,7 +609,7 @@ SRC_SelectSource(SRC_Instance updated_inst)
   int n_badstats_sources, max_sel_reach, max_badstat_reach, sel_req_source;
   int depth, best_depth, trust_depth, best_trust_depth;
   int combined, stratum, min_stratum, max_score_index;
-  int orphan_stratum, orphan_source;
+  int orphan_stratum, orphan_source, leap_votes, leap_ins, leap_del;
   double src_offset, src_offset_sd, src_frequency, src_skew;
   double src_root_delay, src_root_dispersion;
   double best_lo, best_hi, distance, sel_src_distance, max_score;
@@ -907,18 +907,22 @@ SRC_SelectSource(SRC_Instance updated_inst)
     return;
   }
 
-  /* Accept leap second status if more than half of selectable sources agree */
-  for (i = j1 = j2 = 0; i < n_sel_sources; i++) {
+  /* Accept leap second status if more than half of selectable (and trusted
+     if there are any) sources agree */
+  for (i = leap_ins = leap_del = leap_votes = 0; i < n_sel_sources; i++) {
     index = sel_sources[i];
+    if (best_trust_depth && !(sources[index]->sel_options & SRC_SELECT_TRUST))
+      continue;
+    leap_votes++;
     if (sources[index]->leap_status == LEAP_InsertSecond)
-      j1++;
+      leap_ins++;
     else if (sources[index]->leap_status == LEAP_DeleteSecond)
-      j2++;
+      leap_del++;
   }
 
-  if (j1 > n_sel_sources / 2)
+  if (leap_ins > leap_votes / 2)
     leap_status = LEAP_InsertSecond;
-  else if (j2 > n_sel_sources / 2)
+  else if (leap_del > leap_votes / 2)
     leap_status = LEAP_DeleteSecond;
   else
     leap_status = LEAP_Normal;