[or-cvs] r14429: Embarassing. I had apparently broken OSX and Freebsd by not (in tor/branches/tor-0_2_0-patches: . src/common src/or)

nickm at seul.org nickm at seul.org
Wed Apr 23 20:32:09 UTC 2008


Author: nickm
Date: 2008-04-23 16:32:09 -0400 (Wed, 23 Apr 2008)
New Revision: 14429

Modified:
   tor/branches/tor-0_2_0-patches/
   tor/branches/tor-0_2_0-patches/ChangeLog
   tor/branches/tor-0_2_0-patches/src/common/compat.c
   tor/branches/tor-0_2_0-patches/src/or/main.c
   tor/branches/tor-0_2_0-patches/src/or/test.c
Log:
 r15303 at 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.



Property changes on: tor/branches/tor-0_2_0-patches
___________________________________________________________________
 svk:merge ticket from /tor/020 [r15303] on 49666b30-7950-49c5-bedf-9dc8f3168102

Modified: tor/branches/tor-0_2_0-patches/ChangeLog
===================================================================
--- tor/branches/tor-0_2_0-patches/ChangeLog	2008-04-23 18:37:24 UTC (rev 14428)
+++ tor/branches/tor-0_2_0-patches/ChangeLog	2008-04-23 20:32:09 UTC (rev 14429)
@@ -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

Modified: tor/branches/tor-0_2_0-patches/src/common/compat.c
===================================================================
--- tor/branches/tor-0_2_0-patches/src/common/compat.c	2008-04-23 18:37:24 UTC (rev 14428)
+++ tor/branches/tor-0_2_0-patches/src/common/compat.c	2008-04-23 20:32:09 UTC (rev 14429)
@@ -1747,12 +1747,15 @@
   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 @@
 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

Modified: tor/branches/tor-0_2_0-patches/src/or/main.c
===================================================================
--- tor/branches/tor-0_2_0-patches/src/or/main.c	2008-04-23 18:37:24 UTC (rev 14428)
+++ tor/branches/tor-0_2_0-patches/src/or/main.c	2008-04-23 20:32:09 UTC (rev 14429)
@@ -1768,8 +1768,6 @@
   /* 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 @@
 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,

Modified: tor/branches/tor-0_2_0-patches/src/or/test.c
===================================================================
--- tor/branches/tor-0_2_0-patches/src/or/test.c	2008-04-23 18:37:24 UTC (rev 14428)
+++ tor/branches/tor-0_2_0-patches/src/or/test.c	2008-04-23 20:32:09 UTC (rev 14429)
@@ -3561,6 +3561,7 @@
   int verbose = 0, any_selected = 0;
   int loglevel = LOG_ERR;
 
+  tor_threads_init();
   init_logging();
 
   for (i = 1; i < c; ++i) {



More information about the tor-commits mailing list