Skip to content

Commit

Permalink
core: main - functions to set PTHREAD_PROCESS_SHARED for pthread mute…
Browse files Browse the repository at this point in the history
…x 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

(cherry picked from commit a8c811e)
  • Loading branch information
miconda committed Sep 24, 2019
1 parent 827dccc commit cba7b6a
Showing 1 changed file with 75 additions and 0 deletions.
75 changes: 75 additions & 0 deletions src/main.c
Expand Up @@ -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>
Expand Down Expand Up @@ -2724,3 +2730,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

0 comments on commit cba7b6a

Please sign in to comment.