Module: kamailio
Branch: master
Commit: a8c811e69e964821b73d0861a9547a301253d172
URL:
https://github.com/kamailio/kamailio/commit/a8c811e69e964821b73d0861a9547a3…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: 2019-09-13T13:00:17+02:00
core: main - functions to set PTHREAD_PROCESS_SHARED for pthread mutex and rwlock
- code relocated from src/modules/tls/utils/openssl_mutex_shared/openssl_mutex_shared.c
- simpler option to initialize kamailio with the workaround for libssl
v1.1+ without using the preloaded library approach
---
Modified: src/main.c
---
Diff:
https://github.com/kamailio/kamailio/commit/a8c811e69e964821b73d0861a9547a3…
Patch:
https://github.com/kamailio/kamailio/commit/a8c811e69e964821b73d0861a9547a3…
---
diff --git a/src/main.c b/src/main.c
index 5af5284c55..03d39b46d4 100644
--- a/src/main.c
+++ b/src/main.c
@@ -30,6 +30,12 @@
* sip router core part.
*/
+#ifdef KSR_PTHREAD_MUTEX_SHARED
+#define _GNU_SOURCE
+#include <pthread.h>
+#include <dlfcn.h>
+#endif
+
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
@@ -2814,3 +2820,72 @@ int main(int argc, char** argv)
}
return -1;
}
+
+
+#ifdef KSR_PTHREAD_MUTEX_SHARED
+
+/**
+ * code to set PTHREAD_PROCESS_SHARED attribute for phtread mutex to cope
+ * with libssl 1.1+ thread-only mutex initialization
+ */
+
+#define SYMBOL_EXPORT __attribute__((visibility("default")))
+
+int SYMBOL_EXPORT pthread_mutex_init (pthread_mutex_t *__mutex,
+ const pthread_mutexattr_t *__mutexattr)
+{
+ static int (*real_pthread_mutex_init)(pthread_mutex_t *__mutex,
+ const pthread_mutexattr_t *__mutexattr) = 0;
+ pthread_mutexattr_t attr;
+ int ret;
+
+ if (!real_pthread_mutex_init) {
+ real_pthread_mutex_init = dlsym(RTLD_NEXT, "pthread_mutex_init");
+ if (!real_pthread_mutex_init) {
+ return -1;
+ }
+ }
+
+ if (__mutexattr) {
+ pthread_mutexattr_t attr = *__mutexattr;
+ pthread_mutexattr_setpshared(&attr, PTHREAD_PROCESS_SHARED);
+ return real_pthread_mutex_init(__mutex, &attr);
+ }
+
+ pthread_mutexattr_init(&attr);
+ pthread_mutexattr_setpshared(&attr, PTHREAD_PROCESS_SHARED);
+ ret = real_pthread_mutex_init(__mutex, &attr);
+ pthread_mutexattr_destroy(&attr);
+
+ return ret;
+}
+
+int SYMBOL_EXPORT pthread_rwlock_init (pthread_rwlock_t *__restrict __rwlock,
+ const pthread_rwlockattr_t *__restrict __attr)
+{
+ static int (*real_pthread_rwlock_init)(pthread_rwlock_t *__restrict __rwlock,
+ const pthread_rwlockattr_t *__restrict __attr) = 0;
+ pthread_rwlockattr_t attr;
+ int ret;
+
+ if (!real_pthread_rwlock_init) {
+ real_pthread_rwlock_init = dlsym(RTLD_NEXT, "pthread_rwlock_init");
+ if (!real_pthread_rwlock_init) {
+ return -1;
+ }
+ }
+
+ if (__attr) {
+ pthread_rwlockattr_t attr = *__attr;
+ pthread_rwlockattr_setpshared(&attr, PTHREAD_PROCESS_SHARED);
+ return real_pthread_rwlock_init(__rwlock, &attr);
+ }
+
+ pthread_rwlockattr_init(&attr);
+ pthread_rwlockattr_setpshared(&attr, PTHREAD_PROCESS_SHARED);
+ ret = real_pthread_rwlock_init(__rwlock, &attr);
+ pthread_rwlockattr_destroy(&attr);
+
+ return ret;
+}
+#endif