]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
sched: add function to remove all timers and descriptors
authorMiroslav Lichvar <mlichvar@redhat.com>
Wed, 20 Nov 2019 11:39:32 +0000 (12:39 +0100)
committerMiroslav Lichvar <mlichvar@redhat.com>
Thu, 5 Mar 2020 15:02:15 +0000 (16:02 +0100)
This allows a helper process to be started in an *_Initialise() call
and use the scheduler (unlike the privops helper, which has its own
loop).

sched.c
sched.h

diff --git a/sched.c b/sched.c
index fce9f0684e86d1b73be34d23e1f3bfa513e0425c..2301258627691b6cc6de7404aec16c864461c5f9 100644 (file)
--- a/sched.c
+++ b/sched.c
@@ -472,6 +472,20 @@ SCH_RemoveTimeout(SCH_TimeoutID id)
   assert(0);
 }
 
+/* ================================================== */
+
+void
+SCH_Reset(void)
+{
+  while (n_timer_queue_entries > 0)
+    SCH_RemoveTimeout(timer_queue.next->id);
+
+  while (one_highest_fd > 0) {
+    close(one_highest_fd - 1);
+    SCH_RemoveFileHandler(one_highest_fd - 1);
+  }
+}
+
 /* ================================================== */
 /* Try to dispatch any timeouts that have already gone by, and
    keep going until all are done.  (The earlier ones may take so
diff --git a/sched.h b/sched.h
index 5ff53c7d544c1a9369a51e4943688c8d78fdf5ef..b7d4279fcbc2f29f6f71d67e22a40d22ebc6a474 100644 (file)
--- a/sched.h
+++ b/sched.h
@@ -82,6 +82,9 @@ extern SCH_TimeoutID SCH_AddTimeoutInClass(double min_delay, double separation,
 /* The next one probably ought to return a status code */
 extern void SCH_RemoveTimeout(SCH_TimeoutID);
 
+/* Remove all timeouts and close all file descriptors */
+extern void SCH_Reset(void);
+
 extern void SCH_MainLoop(void);
 
 extern void SCH_QuitProgram(void);