]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
Move responsibility for checking if events are setup into periodic.c
authorNick Mathewson <nickm@torproject.org>
Thu, 25 Apr 2019 17:23:18 +0000 (13:23 -0400)
committerNick Mathewson <nickm@torproject.org>
Thu, 25 Apr 2019 17:23:18 +0000 (13:23 -0400)
We have checks in various places in mainlook.c to make sure that
events are initialized before we invoke any periodic_foo() functions
on them.  But now that each subsystem will own its own periodic
events, it will be cleaner if we don't assume that they are all
setup or not.

src/core/mainloop/mainloop.c
src/core/mainloop/periodic.c

index b32532c7626cd8d737cf832a6a60d6b5bb9989df..ddcc3bcd7689c0f03801b2e2fc9b556704c3a97d 100644 (file)
@@ -1587,6 +1587,13 @@ STATIC void
 teardown_periodic_events(void)
 {
   periodic_events_destroy_all();
+  check_descriptor_event = NULL;
+  dirvote_event = NULL;
+  fetch_networkstatus_event = NULL;
+  launch_descriptor_fetches_event = NULL;
+  check_dns_honesty_event = NULL;
+  save_state_event = NULL;
+  prune_old_routers_event = NULL;
   periodic_events_initialized = 0;
 }
 
@@ -1621,13 +1628,6 @@ rescan_periodic_events(const or_options_t *options)
 {
   tor_assert(options);
 
-  /* Avoid scanning the event list if we haven't initialized it yet. This is
-   * particularly useful for unit tests in order to avoid initializing main
-   * loop events everytime. */
-  if (!periodic_events_initialized) {
-    return;
-  }
-
   periodic_events_rescan_by_roles(get_my_roles(options), net_is_disabled());
 }
 
@@ -1636,13 +1636,7 @@ rescan_periodic_events(const or_options_t *options)
 void
 periodic_events_on_new_options(const or_options_t *options)
 {
-  /* Only if we've already initialized the events, rescan the list which will
-   * enable or disable events depending on our roles. This will be called at
-   * bootup and we don't want this function to initialize the events because
-   * they aren't set up at this stage. */
-  if (periodic_events_initialized) {
-    rescan_periodic_events(options);
-  }
+  rescan_periodic_events(options);
 }
 
 /**
@@ -2107,7 +2101,7 @@ dirvote_callback(time_t now, const or_options_t *options)
 void
 reschedule_dirvote(const or_options_t *options)
 {
-  if (periodic_events_initialized && authdir_mode_v3(options)) {
+  if (authdir_mode_v3(options) && dirvote_event) {
     periodic_event_reschedule(dirvote_event);
   }
 }
@@ -2753,8 +2747,7 @@ dns_servers_relaunch_checks(void)
 {
   if (server_mode(get_options())) {
     dns_reset_correctness_checks();
-    if (periodic_events_initialized) {
-      tor_assert(check_dns_honesty_event);
+    if (check_dns_honesty_event) {
       periodic_event_reschedule(check_dns_honesty_event);
     }
   }
index 706dbc1b5e3b4bab0e9a84c9e03b7ef0a984ca7b..a4a03ed29799f98b28b34babc2abc8e189a428b2 100644 (file)
@@ -100,8 +100,8 @@ periodic_event_dispatch(mainloop_event_t *ev, void *data)
 void
 periodic_event_reschedule(periodic_event_item_t *event)
 {
-  /* Don't reschedule a disabled event. */
-  if (periodic_event_is_enabled(event)) {
+  /* Don't reschedule a disabled or uninitialized event. */
+  if (event->ev && periodic_event_is_enabled(event)) {
     periodic_event_set_interval(event, 1);
   }
 }
@@ -243,6 +243,9 @@ periodic_events_reset_all(void)
     return;
 
   SMARTLIST_FOREACH_BEGIN(the_periodic_events, periodic_event_item_t *, item) {
+    if (!item->ev)
+      continue;
+
     periodic_event_reschedule(item);
   } SMARTLIST_FOREACH_END(item);
 }
@@ -277,6 +280,9 @@ periodic_events_rescan_by_roles(int roles, bool net_disabled)
     return;
 
   SMARTLIST_FOREACH_BEGIN(the_periodic_events, periodic_event_item_t *, item) {
+    if (!item->ev)
+      continue;
+
     int enable = !!(item->roles & roles);
 
     /* Handle the event flags. */