summaryrefslogtreecommitdiff
path: root/librabbitmq
diff options
context:
space:
mode:
authorAlan Antonuk <alan.antonuk@gmail.com>2017-10-07 21:37:05 -0700
committerAlan Antonuk <alan.antonuk@gmail.com>2017-12-10 22:38:25 -0800
commitcdfce5a328a59bc9bb51428be0585715546c4634 (patch)
tree390f7c7e36fbdfae53f4349bb647c64aa783aae8 /librabbitmq
parent9cb126c64759fd1294df5cfd4e16dcf938d40743 (diff)
downloadrabbitmq-c-cdfce5a328a59bc9bb51428be0585715546c4634.tar.gz
ssl: Make thread-safety unconditional in rabbitmq-c
Remove the option to disable thread-safety in the parts of rabbitmq-c that use OpenSSL, making it a requirement for thread-safety to use SSL with rabbitmq-c. The existing #ifdef's are a source of additional complexity and the non-thread-safe version is not well tested.
Diffstat (limited to 'librabbitmq')
-rw-r--r--librabbitmq/CMakeLists.txt21
-rw-r--r--librabbitmq/amqp_openssl.c14
-rw-r--r--librabbitmq/amqp_openssl_bio.c6
3 files changed, 12 insertions, 29 deletions
diff --git a/librabbitmq/CMakeLists.txt b/librabbitmq/CMakeLists.txt
index c5dc663..bd5369a 100644
--- a/librabbitmq/CMakeLists.txt
+++ b/librabbitmq/CMakeLists.txt
@@ -96,13 +96,10 @@ if (ENABLE_SSL_SUPPORT)
PROPERTIES COMPILE_FLAGS -Wno-deprecated-declarations)
endif()
- if (ENABLE_THREAD_SAFETY)
- add_definitions(-DENABLE_THREAD_SAFETY)
- if (WIN32)
- set(AMQP_SSL_SRCS ${AMQP_SSL_SRCS} win32/threads.h win32/threads.c)
- else()
- set(AMQP_SSL_SRCS ${AMQP_SSL_SRCS} unix/threads.h)
- endif()
+ if (WIN32)
+ set(AMQP_SSL_SRCS ${AMQP_SSL_SRCS} win32/threads.h win32/threads.c)
+ else()
+ set(AMQP_SSL_SRCS ${AMQP_SSL_SRCS} unix/threads.h)
endif()
endif()
@@ -122,6 +119,9 @@ set(RMQ_LIBRARIES ${AMQP_SSL_LIBS} ${SOCKET_LIBRARIES} ${LIBRT} ${CMAKE_THREAD_L
if (BUILD_SHARED_LIBS)
add_library(rabbitmq SHARED ${RABBITMQ_SOURCES})
+ if (THREADS_HAVE_PTHREAD_ARG)
+ target_compile_options(rabbitmq PUBLIC "-pthread")
+ endif()
target_link_libraries(rabbitmq ${RMQ_LIBRARIES})
@@ -142,6 +142,9 @@ endif (BUILD_SHARED_LIBS)
if (BUILD_STATIC_LIBS)
add_library(rabbitmq-static STATIC ${RABBITMQ_SOURCES})
+ if (THREADS_HAVE_PTHREAD_ARG)
+ target_compile_options(rabbitmq-static PUBLIC "-pthread")
+ endif()
target_link_libraries(rabbitmq-static ${RMQ_LIBRARIES})
@@ -150,14 +153,14 @@ if (BUILD_STATIC_LIBS)
set_target_properties(rabbitmq-static PROPERTIES
VERSION ${RMQ_VERSION}
OUTPUT_NAME librabbitmq.${RMQ_SOVERSION})
-
+
if(MSVC)
set_target_properties(rabbitmq-static PROPERTIES
# Embed debugging info in the library itself instead of generating
# a .pdb file.
COMPILE_OPTIONS "/Z7")
endif(MSVC)
-
+
else (WIN32)
set_target_properties(rabbitmq-static PROPERTIES VERSION ${RMQ_VERSION} SOVERSION ${RMQ_SOVERSION} OUTPUT_NAME rabbitmq)
endif (WIN32)
diff --git a/librabbitmq/amqp_openssl.c b/librabbitmq/amqp_openssl.c
index 417203a..a73cd06 100644
--- a/librabbitmq/amqp_openssl.c
+++ b/librabbitmq/amqp_openssl.c
@@ -54,7 +54,6 @@ static int open_ssl_connections = 0;
static amqp_boolean_t do_initialize_openssl = 1;
static amqp_boolean_t openssl_initialized = 0;
-#ifdef ENABLE_THREAD_SAFETY
static unsigned long amqp_ssl_threadid_callback(void);
static void amqp_ssl_locking_callback(int mode, int n, const char *file,
int line);
@@ -62,7 +61,6 @@ static void amqp_ssl_locking_callback(int mode, int n, const char *file,
static pthread_mutex_t openssl_init_mutex = PTHREAD_MUTEX_INITIALIZER;
static pthread_mutex_t *amqp_openssl_lockarray = NULL;
-#endif /* ENABLE_THREAD_SAFETY */
struct amqp_ssl_socket_t {
const struct amqp_socket_class_t *klass;
@@ -532,7 +530,6 @@ void amqp_set_initialize_ssl_library(amqp_boolean_t do_initialize) {
}
}
-#ifdef ENABLE_THREAD_SAFETY
unsigned long amqp_ssl_threadid_callback(void) {
return (unsigned long)pthread_self();
}
@@ -549,16 +546,12 @@ void amqp_ssl_locking_callback(int mode, int n, AMQP_UNUSED const char *file,
}
}
}
-#endif /* ENABLE_THREAD_SAFETY */
static int initialize_openssl(void) {
-#ifdef ENABLE_THREAD_SAFETY
if (pthread_mutex_lock(&openssl_init_mutex)) {
return -1;
}
-#endif /* ENABLE_THREAD_SAFETY */
if (do_initialize_openssl) {
-#ifdef ENABLE_THREAD_SAFETY
if (NULL == amqp_openssl_lockarray) {
int i = 0;
amqp_openssl_lockarray =
@@ -581,7 +574,6 @@ static int initialize_openssl(void) {
CRYPTO_set_id_callback(amqp_ssl_threadid_callback);
CRYPTO_set_locking_callback(amqp_ssl_locking_callback);
}
-#endif /* ENABLE_THREAD_SAFETY */
if (!openssl_initialized) {
OPENSSL_config(NULL);
@@ -595,24 +587,19 @@ static int initialize_openssl(void) {
++open_ssl_connections;
-#ifdef ENABLE_THREAD_SAFETY
pthread_mutex_unlock(&openssl_init_mutex);
-#endif /* ENABLE_THREAD_SAFETY */
return 0;
}
static int destroy_openssl(void) {
-#ifdef ENABLE_THREAD_SAFETY
if (pthread_mutex_lock(&openssl_init_mutex)) {
return -1;
}
-#endif /* ENABLE_THREAD_SAFETY */
if (open_ssl_connections > 0) {
--open_ssl_connections;
}
-#ifdef ENABLE_THREAD_SAFETY
if (0 == open_ssl_connections && do_initialize_openssl) {
/* Unsetting these allows the rabbitmq-c library to be unloaded
* safely. We do leak the amqp_openssl_lockarray. Which is only
@@ -634,6 +621,5 @@ static int destroy_openssl(void) {
}
pthread_mutex_unlock(&openssl_init_mutex);
-#endif /* ENABLE_THREAD_SAFETY */
return 0;
}
diff --git a/librabbitmq/amqp_openssl_bio.c b/librabbitmq/amqp_openssl_bio.c
index 5279620..df0ce2d 100644
--- a/librabbitmq/amqp_openssl_bio.c
+++ b/librabbitmq/amqp_openssl_bio.c
@@ -42,9 +42,7 @@
#ifdef AMQP_USE_AMQP_BIO
-#ifdef ENABLE_THREAD_SAFETY
static pthread_once_t bio_init_once = PTHREAD_ONCE_INIT;
-#endif
static int bio_initialized = 0;
static BIO_METHOD amqp_bio_method;
@@ -150,11 +148,7 @@ static void amqp_openssl_bio_init(void) {
BIO_METHOD *amqp_openssl_bio(void) {
#ifdef AMQP_USE_AMQP_BIO
if (!bio_initialized) {
-#ifdef ENABLE_THREAD_SAFETY
pthread_once(&bio_init_once, amqp_openssl_bio_init);
-#else
- amqp_openssl_bio_init();
-#endif /* ifndef ENABLE_THREAD_SAFETY */
}
return &amqp_bio_method;