This change will make libwbclient thread safe for all API calls not using a
context. Especially there are no more conflicts with threads using nsswitch
and libwbclient in parallel.
Signed-off-by: Ralph Wuerthner <ralph.wuerthner@de.ibm.com>
Reviewed-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
#include "system/select.h"
#include "winbind_client.h"
+#if HAVE_PTHREAD_H
+#include <pthread.h>
+#endif
+
/* Global context */
struct winbindd_context {
pid_t our_pid; /* calling process pid */
};
+#if HAVE_PTHREAD
+static pthread_mutex_t wb_global_ctx_mutex = PTHREAD_MUTEX_INITIALIZER;
+#endif
+
static struct winbindd_context *get_wb_global_ctx(void)
{
static struct winbindd_context wb_global_ctx = {
.our_pid = 0
};
+#if HAVE_PTHREAD
+ pthread_mutex_lock(&wb_global_ctx_mutex);
+#endif
return &wb_global_ctx;
}
static void put_wb_global_ctx(void)
{
- /* noop for now */
+#if HAVE_PTHREAD
+ pthread_mutex_unlock(&wb_global_ctx_mutex);
+#endif
return;
}