static pthread_mutex_t nwrap_pw_global_mutex = PTHREAD_MUTEX_INITIALIZER;
static pthread_mutex_t nwrap_sp_global_mutex = PTHREAD_MUTEX_INITIALIZER;
+#define nss_wrapper_init_mutex(m) \
+ _nss_wrapper_init_mutex(m, #m)
+
/* Add new global locks here please */
/* Also don't forget to add locks to
* nwrap_init() function.
*/
+# define NWRAP_REINIT_ALL do { \
+ int ret; \
+ ret = nss_wrapper_init_mutex(&nwrap_initialized_mutex); \
+ if (ret != 0) exit(-1); \
+ ret = nss_wrapper_init_mutex(&nwrap_global_mutex); \
+ if (ret != 0) exit(-1); \
+ ret = nss_wrapper_init_mutex(&nwrap_gr_global_mutex); \
+ if (ret != 0) exit(-1); \
+ ret = nss_wrapper_init_mutex(&nwrap_he_global_mutex); \
+ if (ret != 0) exit(-1); \
+ ret = nss_wrapper_init_mutex(&nwrap_pw_global_mutex); \
+ if (ret != 0) exit(-1); \
+ ret = nss_wrapper_init_mutex(&nwrap_sp_global_mutex); \
+ if (ret != 0) exit(-1); \
+} while(0)
+
# define NWRAP_LOCK_ALL do { \
nwrap_mutex_lock(&nwrap_initialized_mutex); \
nwrap_mutex_lock(&nwrap_global_mutex); \
}
}
+static int _nss_wrapper_init_mutex(pthread_mutex_t *m, const char *name)
+{
+ pthread_mutexattr_t ma;
+ bool need_destroy = false;
+ int ret = 0;
+
+#define __CHECK(cmd) do { \
+ ret = cmd; \
+ if (ret != 0) { \
+ NWRAP_LOG(NWRAP_LOG_ERROR, \
+ "%s: %s - failed %d", \
+ name, #cmd, ret); \
+ goto done; \
+ } \
+} while(0)
+
+ *m = (pthread_mutex_t)PTHREAD_MUTEX_INITIALIZER;
+ __CHECK(pthread_mutexattr_init(&ma));
+ need_destroy = true;
+ __CHECK(pthread_mutexattr_settype(&ma, PTHREAD_MUTEX_ERRORCHECK));
+ __CHECK(pthread_mutex_init(m, &ma));
+done:
+ if (need_destroy) {
+ pthread_mutexattr_destroy(&ma);
+ }
+ return ret;
+}
+
static void nwrap_init(void)
{
const char *env;
static void nwrap_thread_child(void)
{
- NWRAP_UNLOCK_ALL;
+ NWRAP_REINIT_ALL;
}
/****************************
***************************/
void nwrap_constructor(void)
{
+ NWRAP_REINIT_ALL;
+
/*
* If we hold a lock and the application forks, then the child
* is not able to unlock the mutex and we are in a deadlock.