]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
sources: reselect earlier when removing selected source
authorMiroslav Lichvar <mlichvar@redhat.com>
Tue, 21 Nov 2023 10:10:23 +0000 (11:10 +0100)
committerMiroslav Lichvar <mlichvar@redhat.com>
Tue, 21 Nov 2023 11:38:41 +0000 (12:38 +0100)
When a selected source is being removed, reset the instance and rerun
the selection while the source is still marked as selected. This forces
a "Can't synchronise" message to be logged when all sources are removed.

Reported-by: Thomas Lange <thomas@corelatus.se>
sources.c

index ec09ff3112e0651e00fbb9e81692939ad9d97117..4bfc1a1c19123c53d63e3bd1af8acb152da3f516 100644 (file)
--- a/sources.c
+++ b/sources.c
@@ -314,8 +314,12 @@ void SRC_DestroyInstance(SRC_Instance instance)
   if (last_updated_inst == instance)
     last_updated_inst = NULL;
 
+  /* Force reselection if currently selected */
+  SRC_ResetInstance(instance);
+
   assert(initialised);
   if (instance->index < 0 || instance->index >= n_sources ||
+      instance->index == selected_source_index ||
       instance != sources[instance->index])
     assert(0);
 
@@ -330,10 +334,7 @@ void SRC_DestroyInstance(SRC_Instance instance)
 
   update_sel_options();
 
-  /* If this was the previous reference source, we have to reselect! */
-  if (selected_source_index == dead_index)
-    SRC_ReselectSource();
-  else if (selected_source_index > dead_index)
+  if (selected_source_index > dead_index)
     --selected_source_index;
 }