diff options
Diffstat (limited to 'src/or')
-rw-r--r-- | src/or/main.c | 27 | ||||
-rw-r--r-- | src/or/main.h | 2 | ||||
-rw-r--r-- | src/or/periodic.c | 18 | ||||
-rw-r--r-- | src/or/periodic.h | 1 |
4 files changed, 36 insertions, 12 deletions
diff --git a/src/or/main.c b/src/or/main.c index b5c1b8ba69..c9007b9798 100644 --- a/src/or/main.c +++ b/src/or/main.c @@ -1233,6 +1233,7 @@ get_signewnym_epoch(void) static int periodic_events_initialized = 0; /* Declare all the timer callback functions... */ +#undef CALLBACK #define CALLBACK(name) \ static int name ## _callback(time_t, const or_options_t *) CALLBACK(rotate_onion_key); @@ -1352,12 +1353,17 @@ initialize_periodic_events_cb(evutil_socket_t fd, short events, void *data) /** Set up all the members of periodic_events[], and configure them all to be * launched from a callback. */ -static void +STATIC void initialize_periodic_events(void) { tor_assert(periodic_events_initialized == 0); periodic_events_initialized = 1; + int i; + for (i = 0; periodic_events[i].name; ++i) { + periodic_event_setup(&periodic_events[i]); + } + #define NAMED_CALLBACK(name) \ STMT_BEGIN name ## _event = find_periodic_event( #name ); STMT_END @@ -1372,7 +1378,7 @@ initialize_periodic_events(void) &one_second); } -static void +STATIC void teardown_periodic_events(void) { int i; @@ -2196,8 +2202,10 @@ dns_servers_relaunch_checks(void) { if (server_mode(get_options())) { dns_reset_correctness_checks(); - tor_assert(check_dns_honesty_event); - periodic_event_reschedule(check_dns_honesty_event); + if (periodic_events_initialized) { + tor_assert(check_dns_honesty_event); + periodic_event_reschedule(check_dns_honesty_event); + } } } @@ -2291,6 +2299,13 @@ do_main_loop(void) { time_t now; + /* initialize the periodic events first, so that code that depends on the + * events being present does not assert. + */ + if (! periodic_events_initialized) { + initialize_periodic_events(); + } + /* initialize dns resolve map, spawn workers if needed */ if (dns_init() < 0) { if (get_options()->ServerDNSAllowBrokenConfig) @@ -2393,10 +2408,6 @@ do_main_loop(void) tor_assert(second_timer); } - if (! periodic_events_initialized) { - initialize_periodic_events(); - } - #ifdef HAVE_SYSTEMD_209 uint64_t watchdog_delay; /* set up systemd watchdog notification. */ diff --git a/src/or/main.h b/src/or/main.h index 447d3f4eca..37e93d79d3 100644 --- a/src/or/main.h +++ b/src/or/main.h @@ -78,6 +78,8 @@ int tor_init(int argc, char **argv); #ifdef MAIN_PRIVATE STATIC void init_connection_lists(void); STATIC void close_closeable_connections(void); +STATIC void initialize_periodic_events(void); +STATIC void teardown_periodic_events(void); #endif #endif diff --git a/src/or/periodic.c b/src/or/periodic.c index e21b1af37c..109717f738 100644 --- a/src/or/periodic.c +++ b/src/or/periodic.c @@ -78,12 +78,11 @@ periodic_event_reschedule(periodic_event_item_t *event) periodic_event_set_interval(event, 1); } -/** Handles initial dispatch for periodic events. It should happen 1 second - * after the events are created to mimic behaviour before #3199's refactor */ +/** Initializes the libevent backend for a periodic event. */ void -periodic_event_launch(periodic_event_item_t *event) +periodic_event_setup(periodic_event_item_t *event) { - if (event->ev) { /** Already setup? This is a bug */ + if (event->ev) { /* Already setup? This is a bug */ log_err(LD_BUG, "Initial dispatch should only be done once."); tor_assert(0); } @@ -93,6 +92,17 @@ periodic_event_launch(periodic_event_item_t *event) periodic_event_dispatch, event); tor_assert(event->ev); +} + +/** Handles initial dispatch for periodic events. It should happen 1 second + * after the events are created to mimic behaviour before #3199's refactor */ +void +periodic_event_launch(periodic_event_item_t *event) +{ + if (! event->ev) { /* Not setup? This is a bug */ + log_err(LD_BUG, "periodic_event_launch without periodic_event_setup"); + tor_assert(0); + } // Initial dispatch periodic_event_dispatch(-1, EV_TIMEOUT, event); diff --git a/src/or/periodic.h b/src/or/periodic.h index a77f411690..bab0c91916 100644 --- a/src/or/periodic.h +++ b/src/or/periodic.h @@ -29,6 +29,7 @@ typedef struct periodic_event_item_t { #define END_OF_PERIODIC_EVENTS { NULL, 0, NULL, NULL } void periodic_event_launch(periodic_event_item_t *event); +void periodic_event_setup(periodic_event_item_t *event); void periodic_event_destroy(periodic_event_item_t *event); void periodic_event_reschedule(periodic_event_item_t *event); |