diff options
author | Lukas Slebodnik <lslebodn@redhat.com> | 2015-06-30 20:19:42 +0200 |
---|---|---|
committer | Jakub Hrozek <jhrozek@redhat.com> | 2015-07-03 15:17:08 +0200 |
commit | 0ed6114c6b2cc9d7e0c09842d19f0987e9ebbb4a (patch) | |
tree | 6efd08c1bab1b53c9f062e2481396e735b0c36e7 | |
parent | b08bcc387ad99b9c408183960c127dc77975b6ff (diff) | |
download | sssd-0ed6114c6b2cc9d7e0c09842d19f0987e9ebbb4a.tar.gz sssd-0ed6114c6b2cc9d7e0c09842d19f0987e9ebbb4a.tar.xz sssd-0ed6114c6b2cc9d7e0c09842d19f0987e9ebbb4a.zip |
sss_client: Use unique lock for memory cache
Previously the sma lock was used as for communication with
responder. However it would cause a deadlock in case of
re-checking memcache after acquiring the lock and before communication with
responder..
Required by:
https://fedorahosted.org/sssd/ticket/2581
Reviewed-by: Michal Židek <mzidek@redhat.com>
-rw-r--r-- | src/sss_client/common.c | 20 | ||||
-rw-r--r-- | src/sss_client/nss_mc_common.c | 8 | ||||
-rw-r--r-- | src/sss_client/sss_cli.h | 2 |
3 files changed, 26 insertions, 4 deletions
diff --git a/src/sss_client/common.c b/src/sss_client/common.c index 383572bad..970cfe6f3 100644 --- a/src/sss_client/common.c +++ b/src/sss_client/common.c @@ -1032,6 +1032,7 @@ struct sss_mutex { static void sss_nss_mt_init(void); static void sss_pam_mt_init(void); +static void sss_nss_mc_mt_init(void); static struct sss_mutex sss_nss_mtx = { .mtx = PTHREAD_MUTEX_INITIALIZER, .once = PTHREAD_ONCE_INIT, @@ -1041,6 +1042,9 @@ static struct sss_mutex sss_pam_mtx = { .mtx = PTHREAD_MUTEX_INITIALIZER, .once = PTHREAD_ONCE_INIT, .init = sss_pam_mt_init }; +static struct sss_mutex sss_nss_mc_mtx = { .mtx = PTHREAD_MUTEX_INITIALIZER, + .once = PTHREAD_ONCE_INIT, + .init = sss_nss_mc_mt_init }; /* Wrappers for robust mutex support */ static int sss_mutexattr_setrobust (pthread_mutexattr_t *attr) @@ -1125,6 +1129,20 @@ void sss_pam_unlock(void) sss_mt_unlock(&sss_pam_mtx); } +/* NSS mutex wrappers */ +static void sss_nss_mc_mt_init(void) +{ + sss_mt_init(&sss_nss_mc_mtx); +} +void sss_nss_mc_lock(void) +{ + sss_mt_lock(&sss_nss_mc_mtx); +} +void sss_nss_mc_unlock(void) +{ + sss_mt_unlock(&sss_nss_mc_mtx); +} + #else /* sorry no mutexes available */ @@ -1132,6 +1150,8 @@ void sss_nss_lock(void) { return; } void sss_nss_unlock(void) { return; } void sss_pam_lock(void) { return; } void sss_pam_unlock(void) { return; } +void sss_nss_mc_lock(void) { return; } +void sss_nss_mc_unlock(void) { return; } #endif diff --git a/src/sss_client/nss_mc_common.c b/src/sss_client/nss_mc_common.c index 89ff6b46e..707d1249f 100644 --- a/src/sss_client/nss_mc_common.c +++ b/src/sss_client/nss_mc_common.c @@ -121,7 +121,7 @@ static errno_t sss_nss_mc_init_ctx(const char *name, char *file = NULL; int ret; - sss_nss_lock(); + sss_nss_mc_lock(); /* check if ctx is initialised by previous thread. */ if (ctx->initialized != UNINITIALIZED) { ret = sss_nss_check_header(ctx); @@ -172,7 +172,7 @@ done: sss_nss_mc_destroy_ctx(ctx); } free(file); - sss_nss_unlock(); + sss_nss_mc_unlock(); return ret; } @@ -217,11 +217,11 @@ errno_t sss_nss_mc_get_ctx(const char *name, struct sss_cli_mc_ctx *ctx) } if (ctx->initialized == RECYCLED && ctx->active_threads == 0) { /* just one thread should call munmap */ - sss_nss_lock(); + sss_nss_mc_lock(); if (ctx->initialized == RECYCLED) { sss_nss_mc_destroy_ctx(ctx); } - sss_nss_unlock(); + sss_nss_mc_unlock(); } if (need_decrement) { /* In case of error, we will not touch mmapped area => decrement */ diff --git a/src/sss_client/sss_cli.h b/src/sss_client/sss_cli.h index 6902d711e..0dfb525ba 100644 --- a/src/sss_client/sss_cli.h +++ b/src/sss_client/sss_cli.h @@ -594,6 +594,8 @@ void sss_nss_lock(void); void sss_nss_unlock(void); void sss_pam_lock(void); void sss_pam_unlock(void); +void sss_nss_mc_lock(void); +void sss_nss_mc_unlock(void); errno_t sss_readrep_copy_string(const char *in, size_t *offset, |