]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
Rehash NTP source table after removing source
authorMiroslav Lichvar <mlichvar@redhat.com>
Thu, 13 May 2010 16:29:00 +0000 (18:29 +0200)
committerMiroslav Lichvar <mlichvar@redhat.com>
Thu, 13 May 2010 16:29:00 +0000 (18:29 +0200)
This is needed to avoid breaking a probe sequence and losing another
source. It is costly, but it's not expected to happen frequently.

ntp_sources.c

index 00f8e3e47fe3011f31a512e6e9bdb39d379989cd..3750ef2973887a39ab787f0874bf8b4e23988835 100644 (file)
@@ -295,19 +295,41 @@ NSR_AddUnresolvedSource(char *name, int port, NTP_Source_Type type, SourceParame
 NSR_Status
 NSR_RemoveSource(NTP_Remote_Address *remote_addr)
 {
-  int slot, found;
+  int i, slot, found;
+  SourceRecord temp_records[N_RECORDS];
 
   assert(initialised);
 
   find_slot(remote_addr, &slot, &found);
   if (!found) {
     return NSR_NoSuchSource;
-  } else {
-    n_sources--;
-    records[slot].remote_addr = NULL;
-    NCR_DestroyInstance(records[slot].data);
-    return NSR_Success;
   }
+
+  n_sources--;
+  records[slot].remote_addr = NULL;
+  NCR_DestroyInstance(records[slot].data);
+
+  /* Rehash the table to make sure there are no broken probe sequences.
+     This is costly, but it's not expected to happen frequently. */
+
+  memcpy(temp_records, records, sizeof (records));
+
+  for (i = 0; i < N_RECORDS; i++) {
+    records[i].remote_addr = NULL;
+  }
+  
+  for (i = 0; i < N_RECORDS; i++) {
+    if (!temp_records[i].remote_addr)
+      continue;
+
+    find_slot(temp_records[i].remote_addr, &slot, &found);
+    assert(!found);
+
+    records[slot].remote_addr = temp_records[i].remote_addr;
+    records[slot].data = temp_records[i].data;
+  }
+
+  return NSR_Success;
 }
 
 /* ================================================== */