diff options
| author | Andreas Schneider <asn@samba.org> | 2016-10-20 10:22:40 +0200 |
|---|---|---|
| committer | Michael Adam <obnox@samba.org> | 2016-10-20 11:21:59 +0200 |
| commit | f5cddcd300b779131662519d56ae90fcebe459e1 (patch) | |
| tree | 22ee5db90b3464f87a343ac633580a8bb48ff3a6 /src | |
| parent | 201811dc614a4787482c3bb2fa14f47112a05a34 (diff) | |
| download | socket_wrapper-f5cddcd300b779131662519d56ae90fcebe459e1.tar.gz socket_wrapper-f5cddcd300b779131662519d56ae90fcebe459e1.tar.xz socket_wrapper-f5cddcd300b779131662519d56ae90fcebe459e1.zip | |
swrap: Make symbol loading thread-safe
Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Michael Adam <obnox@samba.org>
Diffstat (limited to 'src')
| -rw-r--r-- | src/socket_wrapper.c | 25 |
1 files changed, 22 insertions, 3 deletions
diff --git a/src/socket_wrapper.c b/src/socket_wrapper.c index f7a0d55..e205a36 100644 --- a/src/socket_wrapper.c +++ b/src/socket_wrapper.c @@ -79,6 +79,7 @@ #ifdef HAVE_RPC_RPC_H #include <rpc/rpc.h> #endif +#include <pthread.h> enum swrap_dbglvl_e { SWRAP_LOG_ERROR = 0, @@ -152,6 +153,15 @@ enum swrap_dbglvl_e { # endif #endif +/* Macros for accessing mutexes */ +# define SWRAP_LOCK(m) do { \ + pthread_mutex_lock(&(m ## _mutex)); \ +} while(0) + +# define SWRAP_UNLOCK(m) do { \ + pthread_mutex_unlock(&(m ## _mutex)); \ +} while(0) + #define SWRAP_DLIST_ADD(list,item) do { \ if (!(list)) { \ @@ -305,6 +315,9 @@ static size_t max_sockets = 0; */ static struct socket_info_fd *socket_fds; +/* The mutex for accessing the global libc.symbols */ +static pthread_mutex_t libc_symbol_binding_mutex = PTHREAD_MUTEX_INITIALIZER; + /* Function prototypes */ bool socket_wrapper_enabled(void); @@ -623,22 +636,28 @@ static void *_swrap_bind_symbol(enum swrap_lib lib, const char *fn_name) } #define swrap_bind_symbol_libc(sym_name) \ + SWRAP_LOCK(libc_symbol_binding); \ if (swrap.libc.symbols._libc_##sym_name.obj == NULL) { \ swrap.libc.symbols._libc_##sym_name.obj = \ _swrap_bind_symbol(SWRAP_LIBC, #sym_name); \ - } + } \ + SWRAP_UNLOCK(libc_symbol_binding) #define swrap_bind_symbol_libsocket(sym_name) \ + SWRAP_LOCK(libc_symbol_binding); \ if (swrap.libc.symbols._libc_##sym_name.obj == NULL) { \ swrap.libc.symbols._libc_##sym_name.obj = \ _swrap_bind_symbol(SWRAP_LIBSOCKET, #sym_name); \ - } + } \ + SWRAP_UNLOCK(libc_symbol_binding) #define swrap_bind_symbol_libnsl(sym_name) \ + SWRAP_LOCK(libc_symbol_binding); \ if (swrap.libc.symbols._libc_##sym_name.obj == NULL) { \ swrap.libc.symbols._libc_##sym_name.obj = \ _swrap_bind_symbol(SWRAP_LIBNSL, #sym_name); \ - } + } \ + SWRAP_UNLOCK(libc_symbol_binding) /* * IMPORTANT |
