tor

The Tor anonymity network
git clone https://git.dasho.dev/tor.git
Log | Files | Refs | README | LICENSE

commit 5e86a2868319f8aa55d2858fdb4d83e6f9f69120
parent abf88af4887782f6952d90755d64f946d4958e6d
Author: Nick Mathewson <nickm@torproject.org>
Date:   Tue,  7 Aug 2018 08:05:56 -0400

Merge branch 'maint-0.3.4'

Diffstat:
Achanges/bug27003 | 6++++++
Msrc/core/mainloop/periodic.c | 8+++++---
Msrc/test/test_periodic_event.c | 8++------
3 files changed, 13 insertions(+), 9 deletions(-)

diff --git a/changes/bug27003 b/changes/bug27003 @@ -0,0 +1,6 @@ + o Major bugfixes (event scheduler): + - When we enable a periodic event, schedule it in the event loop + rather than running it immediately. Previously, we would re-run + periodic events immediately in the middle of (for example) + changing our options, with unpredictable effects. Fixes bug + 27003; bugfix on 0.3.4.1-alpha. diff --git a/src/core/mainloop/periodic.c b/src/core/mainloop/periodic.c @@ -141,8 +141,8 @@ periodic_event_destroy(periodic_event_item_t *event) event->last_action_time = 0; } -/** Enable the given event which means the event is launched and then the - * event's enabled flag is set. This can be called for an event that is +/** Enable the given event by setting its "enabled" flag and scheduling it to + * run immediately in the event loop. This can be called for an event that is * already enabled. */ void periodic_event_enable(periodic_event_item_t *event) @@ -153,7 +153,9 @@ periodic_event_enable(periodic_event_item_t *event) return; } - periodic_event_launch(event); + tor_assert(event->ev); + event->enabled = 1; + mainloop_event_activate(event->ev); } /** Disable the given event which means the event is destroyed and then the diff --git a/src/test/test_periodic_event.c b/src/test/test_periodic_event.c @@ -106,11 +106,11 @@ test_pe_launch(void *arg) periodic_event_item_t *item = &periodic_events[i]; if (item->roles & PERIODIC_EVENT_ROLE_CLIENT) { tt_int_op(periodic_event_is_enabled(item), OP_EQ, 1); - tt_u64_op(item->last_action_time, OP_NE, 0); } else { tt_int_op(periodic_event_is_enabled(item), OP_EQ, 0); - tt_u64_op(item->last_action_time, OP_EQ, 0); } + // enabled or not, the event has not yet been run. + tt_u64_op(item->last_action_time, OP_EQ, 0); } /* Remove Client but become a Relay. */ @@ -127,12 +127,9 @@ test_pe_launch(void *arg) /* Only Client role should be disabled. */ if (item->roles == PERIODIC_EVENT_ROLE_CLIENT) { tt_int_op(periodic_event_is_enabled(item), OP_EQ, 0); - /* Was previously enabled so they should never be to 0. */ - tt_u64_op(item->last_action_time, OP_NE, 0); } if (item->roles & PERIODIC_EVENT_ROLE_RELAY) { tt_int_op(periodic_event_is_enabled(item), OP_EQ, 1); - tt_u64_op(item->last_action_time, OP_NE, 0); } /* Non Relay role should be disabled, except for Dirserver. */ if (!(item->roles & roles)) { @@ -330,4 +327,3 @@ struct testcase_t periodic_event_tests[] = { END_OF_TESTCASES }; -