[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [tor/maint-0.2.6] Use PTHREAD_CREATE_DETACHED macro instead of 1: fix Solaris crash



commit 192ed944101174d775d27ac54002ee9bc2708080
Author: Nick Mathewson <nickm@xxxxxxxxxxxxxx>
Date:   Thu Mar 12 09:49:45 2015 -0400

    Use PTHREAD_CREATE_DETACHED macro instead of 1: fix Solaris crash
    
    When calling pthread_attr_setdetachstate, we were using 1 as the
    argument. But the pthreads documentation says that you have to say
    PTHREAD_CREATE_DETACH, which on Solaris is apparently 0x40.  Calling
    pthread_attr_setdetachstate with 1 crashes on Solaris with FLTBOUNDS.
    
    (Because we're so late in the release cycle, I made the code define
    PTHREAD_CREATE_DETACHED if it doesn't exist, so we aren't likely to
    break any other platforms.)
    
    This bug was introduced when we made threading mandatory in
    0.2.6.1-alpha; previously, we had force-disabled threading on
    Solaris.  See #9495 discussion.
---
 changes/bug9495_redux        |    4 ++++
 src/common/compat_pthreads.c |    6 +++++-
 2 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/changes/bug9495_redux b/changes/bug9495_redux
new file mode 100644
index 0000000..74b0cdf
--- /dev/null
+++ b/changes/bug9495_redux
@@ -0,0 +1,4 @@
+  o Major bugfixes (portability):
+    - Do not crash on startup when running on Solaris. Fixes a bug
+      related to our fix for 9495; bugfix on 0.2.6.1-alpha. Reported
+      by "ruebezahl".
diff --git a/src/common/compat_pthreads.c b/src/common/compat_pthreads.c
index f4a6cad..246076b 100644
--- a/src/common/compat_pthreads.c
+++ b/src/common/compat_pthreads.c
@@ -279,7 +279,11 @@ tor_threads_init(void)
     pthread_mutexattr_init(&attr_recursive);
     pthread_mutexattr_settype(&attr_recursive, PTHREAD_MUTEX_RECURSIVE);
     tor_assert(0==pthread_attr_init(&attr_detached));
-    tor_assert(0==pthread_attr_setdetachstate(&attr_detached, 1));
+#ifndef PTHREAD_CREATE_DETACHED
+#define PTHREAD_CREATE_DETACHED 1
+#endif
+    tor_assert(0==pthread_attr_setdetachstate(&attr_detached,
+                                              PTHREAD_CREATE_DETACHED));
     threads_initialized = 1;
     set_main_thread();
   }



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits