commit d6903e9e87ffd39846b7cacebcfc8bae71f3ca5f Author: David Goulet dgoulet@torproject.org Date: Thu Apr 26 15:00:19 2018 -0400
hibernation: Rescan the event list on state change
When we change the hibernation state, rescan the main loop event list because the new state might affect the events.
Signed-off-by: David Goulet dgoulet@torproject.org --- src/or/hibernate.c | 10 +++++++++- src/or/main.c | 3 +-- src/or/main.h | 1 + 3 files changed, 11 insertions(+), 3 deletions(-)
diff --git a/src/or/hibernate.c b/src/or/hibernate.c index 9fed33855..c4ae63acc 100644 --- a/src/or/hibernate.c +++ b/src/or/hibernate.c @@ -1111,10 +1111,18 @@ getinfo_helper_accounting(control_connection_t *conn, static void on_hibernate_state_change(hibernate_state_t prev_state) { - (void)prev_state; /* Should we do something with this? */ control_event_server_status(LOG_NOTICE, "HIBERNATION_STATUS STATUS=%s", hibernate_state_to_string(hibernate_state)); + + /* We are changing hibernation state, this can affect the main loop event + * list. Rescan it to update the events state. We do this whatever the new + * hibernation state because they can each possibly affect an event. The + * initial state means we are booting up so we shouldn't scan here because + * at this point the events in the list haven't been initialized. */ + if (prev_state != HIBERNATE_STATE_INITIAL) { + rescan_periodic_events(get_options()); + } }
#ifdef TOR_UNIT_TESTS diff --git a/src/or/main.c b/src/or/main.c index c7bd720cc..b5a701713 100644 --- a/src/or/main.c +++ b/src/or/main.c @@ -150,7 +150,6 @@ static int run_main_loop_until_done(void); static void process_signal(int sig); static void shutdown_did_not_work_callback(evutil_socket_t fd, short event, void *arg) ATTR_NORETURN; -static void rescan_periodic_events(const or_options_t *options);
/********* START VARIABLES **********/
@@ -1549,7 +1548,7 @@ teardown_periodic_events(void)
/** Do a pass at all our periodic events, disable those we don't need anymore * and enable those we need now using the given options. */ -static void +void rescan_periodic_events(const or_options_t *options) { tor_assert(options); diff --git a/src/or/main.h b/src/or/main.h index 33ef40ce4..2447339fb 100644 --- a/src/or/main.h +++ b/src/or/main.h @@ -62,6 +62,7 @@ void reset_all_main_loop_timers(void); void reschedule_descriptor_update_check(void); void reschedule_directory_downloads(void); void mainloop_schedule_postloop_cleanup(void); +void rescan_periodic_events(const or_options_t *options);
MOCK_DECL(long,get_uptime,(void)); MOCK_DECL(void,reset_uptime,(void));
tor-commits@lists.torproject.org