summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2008-04-23 20:32:09 +0000
committerNick Mathewson <nickm@torproject.org>2008-04-23 20:32:09 +0000
commit5dfd0c354f574e05c2a4003592f1c043252040c0 (patch)
tree4ae678bd32f36f70a861b3b59e1275f057f8edc1
parent94a9eaaf149b1b9fd5c066a3ed56cb0a1f69a16f (diff)
downloadtor-5dfd0c354f574e05c2a4003592f1c043252040c0.tar.gz
tor-5dfd0c354f574e05c2a4003592f1c043252040c0.zip
r15303@tombo: nickm | 2008-04-23 16:29:45 -0400
Embarassing. I had apparently broken OSX and Freebsd by not initializing threading before we initialize the logging system. This patch should do so, and fix bug 671. Forward-port candidate. svn:r14429
-rw-r--r--ChangeLog7
-rw-r--r--src/common/compat.c10
-rw-r--r--src/or/main.c3
-rw-r--r--src/or/test.c1
4 files changed, 17 insertions, 4 deletions
diff --git a/ChangeLog b/ChangeLog
index 75d6bdbba7..9d92be9397 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+Changes in version 0.2.0.25-rc - 2008-04-23
+ o Major bugfixes:
+ - Remember to initialize threading before initializing logging.
+ Otherwise, many BSD-family implementations will crash hard on
+ startup. Fixes bug 671. Bugfix on 0.2.0.24-rc.
+
+
Changes in version 0.2.0.24-rc - 2008-04-22
o New directory authorities:
- Take lefkada out of the list of v3 directory authorities, since
diff --git a/src/common/compat.c b/src/common/compat.c
index 90905c0194..c7bd0fb564 100644
--- a/src/common/compat.c
+++ b/src/common/compat.c
@@ -1747,12 +1747,15 @@ struct tor_mutex_t {
pthread_mutex_t mutex;
};
static pthread_mutexattr_t attr_reentrant;
+static int threads_initialized = 0;
/** Allocate and return new lock. */
tor_mutex_t *
tor_mutex_new(void)
{
int err;
tor_mutex_t *mutex = tor_malloc_zero(sizeof(tor_mutex_t));
+ if (PREDICT_UNLIKELY(!threads_initialized))
+ tor_threads_init();
err = pthread_mutex_init(&mutex->mutex, &attr_reentrant);
if (PREDICT_UNLIKELY(err)) {
log_err(LD_GENERAL, "Error %d creating a mutex.", err);
@@ -1869,8 +1872,11 @@ tor_cond_signal_all(tor_cond_t *cond)
void
tor_threads_init(void)
{
- pthread_mutexattr_init(&attr_reentrant);
- pthread_mutexattr_settype(&attr_reentrant, PTHREAD_MUTEX_RECURSIVE);
+ if (!threads_initialized) {
+ pthread_mutexattr_init(&attr_reentrant);
+ pthread_mutexattr_settype(&attr_reentrant, PTHREAD_MUTEX_RECURSIVE);
+ threads_initialized = 1;
+ }
}
#elif defined(USE_WIN32_THREADS)
#if 0
diff --git a/src/or/main.c b/src/or/main.c
index 8357124297..3eee60669b 100644
--- a/src/or/main.c
+++ b/src/or/main.c
@@ -1768,8 +1768,6 @@ tor_init(int argc, char *argv[])
/* Have the log set up with our application name. */
tor_snprintf(buf, sizeof(buf), "Tor %s", get_version());
log_set_application_name(buf);
- /* Initialize threading. */
- tor_threads_init();
/* Initialize the history structures. */
rep_hist_init();
/* Initialize the service cache. */
@@ -1965,6 +1963,7 @@ int
tor_main(int argc, char *argv[])
{
int result = 0;
+ tor_threads_init();
init_logging();
#ifdef USE_DMALLOC
int r = CRYPTO_set_mem_ex_functions(_tor_malloc, _tor_realloc,
diff --git a/src/or/test.c b/src/or/test.c
index 858ff4700f..d4d5275a39 100644
--- a/src/or/test.c
+++ b/src/or/test.c
@@ -3561,6 +3561,7 @@ main(int c, char**v)
int verbose = 0, any_selected = 0;
int loglevel = LOG_ERR;
+ tor_threads_init();
init_logging();
for (i = 1; i < c; ++i) {