diff --git a/src/app/main/main.c b/src/app/main/main.c index 7bf9d3fe2b..e0f6352879 100644 --- a/src/app/main/main.c +++ b/src/app/main/main.c @@ -1428,6 +1428,13 @@ tor_run_main(const tor_main_configuration_t *tor_cfg) } } + if (get_options()->command == CMD_RUN_TOR) { + tor_mainloop_connect_pubsub_events(); + /* XXXX For each pubsub channel, its delivery strategy should be set at + * this XXXX point, using tor_mainloop_set_delivery_strategy(). + */ + } + if (get_options()->Sandbox && get_options()->command == CMD_RUN_TOR) { sandbox_cfg_t* cfg = sandbox_init_filter(); diff --git a/src/core/mainloop/mainloop_pubsub.c b/src/core/mainloop/mainloop_pubsub.c index ab3614ae00..aac607126d 100644 --- a/src/core/mainloop/mainloop_pubsub.c +++ b/src/core/mainloop/mainloop_pubsub.c @@ -44,6 +44,9 @@ flush_channel_event(mainloop_event_t *ev, void *arg) dispatch_flush(the_dispatcher, chan, INT_MAX); } +/** + * Construct our global pubsub object from builder. Return 0 on + * success, -1 on failure. */ int tor_mainloop_connect_pubsub(struct pubsub_builder_t *builder) { @@ -54,6 +57,26 @@ tor_mainloop_connect_pubsub(struct pubsub_builder_t *builder) if (! the_dispatcher) goto err; + rv = 0; + goto done; + err: + tor_mainloop_disconnect_pubsub(); + done: + return rv; +} + +/** + * Install libevent events for all of the pubsub channels. + * + * Invoke this after tor_mainloop_connect_pubsub, and after libevent has been + * initialized. + */ +void +tor_mainloop_connect_pubsub_events(void) +{ + tor_assert(the_dispatcher); + tor_assert(! alert_events); + const size_t num_channels = get_num_channel_ids(); alert_events = smartlist_new(); for (size_t i = 0; i < num_channels; ++i) { @@ -61,11 +84,6 @@ tor_mainloop_connect_pubsub(struct pubsub_builder_t *builder) mainloop_event_postloop_new(flush_channel_event, (void*)(uintptr_t)(i))); } - - rv = 0; - err: - tor_mainloop_disconnect_pubsub(); - return rv; } /** diff --git a/src/core/mainloop/mainloop_pubsub.h b/src/core/mainloop/mainloop_pubsub.h index 6eff778420..a31b2b4ba7 100644 --- a/src/core/mainloop/mainloop_pubsub.h +++ b/src/core/mainloop/mainloop_pubsub.h @@ -16,6 +16,7 @@ typedef enum { } deliv_strategy_t; int tor_mainloop_connect_pubsub(struct pubsub_builder_t *builder); +void tor_mainloop_connect_pubsub_events(void); int tor_mainloop_set_delivery_strategy(const char *msg_channel_name, deliv_strategy_t strategy); void tor_mainloop_disconnect_pubsub(void);