From 7363eae13cb8febd85923957de19e2de7c186cea Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Mon, 14 Nov 2011 17:46:43 -0500 Subject: Use the EVENT_BASE_FLAG_NOLOCK flag to prevent socketpair() invocation In Tor 0.2.2, we never need the event base to be notifiable, since we don't call it from other threads. This is a workaround for bug 4457, which is not actually a Tor bug IMO. --- changes/bug4457 | 8 ++++++++ src/common/compat_libevent.c | 13 ++++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 changes/bug4457 diff --git a/changes/bug4457 b/changes/bug4457 new file mode 100644 index 000000000..d3d9eb3b4 --- /dev/null +++ b/changes/bug4457 @@ -0,0 +1,8 @@ + o Minor bugfixes: + - Initialize Libevent with the EVENT_BASE_FLAG_NOLOCK flag enabled, so + that it doesn't attempt to allocate a socketpair. This could cause + some problems on windows systems with overzealous firewalls. Fix for + bug 4457; workaround for Libevent versions 2.0.1-alpha through + 2.0.15-stable. + + diff --git a/src/common/compat_libevent.c b/src/common/compat_libevent.c index 6d89be804..3e35e093e 100644 --- a/src/common/compat_libevent.c +++ b/src/common/compat_libevent.c @@ -177,7 +177,18 @@ tor_libevent_initialize(void) #endif #ifdef HAVE_EVENT2_EVENT_H - the_event_base = event_base_new(); + { + struct event_config *cfg = event_config_new(); + + /* In 0.2.2, we don't use locking at all. Telling Libevent not to try to + * turn it on can avoid a needless socketpair() attempt. + */ + event_config_set_flag(cfg, EVENT_BASE_FLAG_NOLOCK); + + the_event_base = event_base_new_with_config(cfg); + + event_config_free(cfg); + } #else the_event_base = event_init(); #endif -- cgit v1.2.3 From 0f6c02161793fa1022fe721ed9c1aac3538294b3 Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Mon, 14 Nov 2011 17:53:45 -0500 Subject: Detect failure from event_init() or event_base_new_with_config() --- changes/bug4457 | 1 + src/common/compat_libevent.c | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/changes/bug4457 b/changes/bug4457 index d3d9eb3b4..fe7c95ff8 100644 --- a/changes/bug4457 +++ b/changes/bug4457 @@ -5,4 +5,5 @@ bug 4457; workaround for Libevent versions 2.0.1-alpha through 2.0.15-stable. + - Detect failure to initialize Libevent. Better detection for bug 4457. diff --git a/src/common/compat_libevent.c b/src/common/compat_libevent.c index 3e35e093e..ddb2da68a 100644 --- a/src/common/compat_libevent.c +++ b/src/common/compat_libevent.c @@ -179,6 +179,7 @@ tor_libevent_initialize(void) #ifdef HAVE_EVENT2_EVENT_H { struct event_config *cfg = event_config_new(); + tor_assert(cfg); /* In 0.2.2, we don't use locking at all. Telling Libevent not to try to * turn it on can avoid a needless socketpair() attempt. @@ -193,6 +194,11 @@ tor_libevent_initialize(void) the_event_base = event_init(); #endif + if (!the_event_base) { + log_err(LD_GENERAL, "Unable to initialize Libevent: cannot continue."); + exit(1); + } + #if defined(HAVE_EVENT_GET_VERSION) && defined(HAVE_EVENT_GET_METHOD) /* Making this a NOTICE for now so we can link bugs to a libevent versions * or methods better. */ -- cgit v1.2.3