diff options
Diffstat (limited to 'src/or/main.c')
-rw-r--r-- | src/or/main.c | 27 |
1 files changed, 19 insertions, 8 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. */ |