|
|
de2e0a |
From 03142f8de42faf4f75465d24d3be9a49c2dd86f7 Mon Sep 17 00:00:00 2001
|
|
|
de2e0a |
From: Alexey Tikhonov <atikhono@redhat.com>
|
|
|
de2e0a |
Date: Fri, 29 Jul 2022 14:57:20 +0200
|
|
|
de2e0a |
Subject: [PATCH] CLIENT:MC: store context mutex outside of context as it
|
|
|
de2e0a |
should survive context destruction / re-initialization
|
|
|
de2e0a |
MIME-Version: 1.0
|
|
|
de2e0a |
Content-Type: text/plain; charset=UTF-8
|
|
|
de2e0a |
Content-Transfer-Encoding: 8bit
|
|
|
de2e0a |
|
|
|
de2e0a |
Reviewed-by: Iker Pedrosa <ipedrosa@redhat.com>
|
|
|
de2e0a |
Reviewed-by: Pavel Březina <pbrezina@redhat.com>
|
|
|
de2e0a |
(cherry picked from commit 0f3a761ed9d654a61f8caed8eae3863c518b9911)
|
|
|
de2e0a |
---
|
|
|
de2e0a |
src/sss_client/nss_mc.h | 4 ++--
|
|
|
de2e0a |
src/sss_client/nss_mc_common.c | 10 ++++++++--
|
|
|
de2e0a |
src/sss_client/nss_mc_group.c | 5 +++++
|
|
|
de2e0a |
src/sss_client/nss_mc_initgr.c | 5 +++++
|
|
|
de2e0a |
src/sss_client/nss_mc_passwd.c | 5 +++++
|
|
|
de2e0a |
src/sss_client/nss_mc_sid.c | 5 +++++
|
|
|
de2e0a |
6 files changed, 30 insertions(+), 4 deletions(-)
|
|
|
de2e0a |
|
|
|
de2e0a |
diff --git a/src/sss_client/nss_mc.h b/src/sss_client/nss_mc.h
|
|
|
de2e0a |
index b66e8f09f..de1496ccc 100644
|
|
|
de2e0a |
--- a/src/sss_client/nss_mc.h
|
|
|
de2e0a |
+++ b/src/sss_client/nss_mc.h
|
|
|
de2e0a |
@@ -48,7 +48,7 @@ enum sss_mc_state {
|
|
|
de2e0a |
struct sss_cli_mc_ctx {
|
|
|
de2e0a |
enum sss_mc_state initialized;
|
|
|
de2e0a |
#if HAVE_PTHREAD
|
|
|
de2e0a |
- pthread_mutex_t mutex;
|
|
|
de2e0a |
+ pthread_mutex_t *mutex;
|
|
|
de2e0a |
#endif
|
|
|
de2e0a |
int fd;
|
|
|
de2e0a |
|
|
|
de2e0a |
@@ -67,7 +67,7 @@ struct sss_cli_mc_ctx {
|
|
|
de2e0a |
};
|
|
|
de2e0a |
|
|
|
de2e0a |
#if HAVE_PTHREAD
|
|
|
de2e0a |
-#define SSS_CLI_MC_CTX_INITIALIZER {UNINITIALIZED, PTHREAD_MUTEX_INITIALIZER, 1, 0, NULL, 0, NULL, 0, NULL, 0, 0}
|
|
|
de2e0a |
+#define SSS_CLI_MC_CTX_INITIALIZER(mtx) {UNINITIALIZED, (mtx), 1, 0, NULL, 0, NULL, 0, NULL, 0, 0}
|
|
|
de2e0a |
#else
|
|
|
de2e0a |
#define SSS_CLI_MC_CTX_INITIALIZER {UNINITIALIZED, 1, 0, NULL, 0, NULL, 0, NULL, 0, 0}
|
|
|
de2e0a |
#endif
|
|
|
de2e0a |
diff --git a/src/sss_client/nss_mc_common.c b/src/sss_client/nss_mc_common.c
|
|
|
de2e0a |
index c73a93a9a..f38a4a85a 100644
|
|
|
de2e0a |
--- a/src/sss_client/nss_mc_common.c
|
|
|
de2e0a |
+++ b/src/sss_client/nss_mc_common.c
|
|
|
de2e0a |
@@ -58,14 +58,14 @@ do { \
|
|
|
de2e0a |
static void sss_mt_lock(struct sss_cli_mc_ctx *ctx)
|
|
|
de2e0a |
{
|
|
|
de2e0a |
#if HAVE_PTHREAD
|
|
|
de2e0a |
- pthread_mutex_lock(&ctx->mutex);
|
|
|
de2e0a |
+ pthread_mutex_lock(ctx->mutex);
|
|
|
de2e0a |
#endif
|
|
|
de2e0a |
}
|
|
|
de2e0a |
|
|
|
de2e0a |
static void sss_mt_unlock(struct sss_cli_mc_ctx *ctx)
|
|
|
de2e0a |
{
|
|
|
de2e0a |
#if HAVE_PTHREAD
|
|
|
de2e0a |
- pthread_mutex_unlock(&ctx->mutex);
|
|
|
de2e0a |
+ pthread_mutex_unlock(ctx->mutex);
|
|
|
de2e0a |
#endif
|
|
|
de2e0a |
}
|
|
|
de2e0a |
|
|
|
de2e0a |
@@ -131,6 +131,9 @@ errno_t sss_nss_check_header(struct sss_cli_mc_ctx *ctx)
|
|
|
de2e0a |
static void sss_nss_mc_destroy_ctx(struct sss_cli_mc_ctx *ctx)
|
|
|
de2e0a |
{
|
|
|
de2e0a |
uint32_t active_threads = ctx->active_threads;
|
|
|
de2e0a |
+#if HAVE_PTHREAD
|
|
|
de2e0a |
+ pthread_mutex_t *mutex = ctx->mutex;
|
|
|
de2e0a |
+#endif
|
|
|
de2e0a |
|
|
|
de2e0a |
if ((ctx->mmap_base != NULL) && (ctx->mmap_size != 0)) {
|
|
|
de2e0a |
munmap(ctx->mmap_base, ctx->mmap_size);
|
|
|
de2e0a |
@@ -143,6 +146,9 @@ static void sss_nss_mc_destroy_ctx(struct sss_cli_mc_ctx *ctx)
|
|
|
de2e0a |
|
|
|
de2e0a |
/* restore count of active threads */
|
|
|
de2e0a |
ctx->active_threads = active_threads;
|
|
|
de2e0a |
+#if HAVE_PTHREAD
|
|
|
de2e0a |
+ ctx->mutex = mutex;
|
|
|
de2e0a |
+#endif
|
|
|
de2e0a |
}
|
|
|
de2e0a |
|
|
|
de2e0a |
static errno_t sss_nss_mc_init_ctx(const char *name,
|
|
|
de2e0a |
diff --git a/src/sss_client/nss_mc_group.c b/src/sss_client/nss_mc_group.c
|
|
|
de2e0a |
index 2ea40c435..d4f2a82ab 100644
|
|
|
de2e0a |
--- a/src/sss_client/nss_mc_group.c
|
|
|
de2e0a |
+++ b/src/sss_client/nss_mc_group.c
|
|
|
de2e0a |
@@ -29,7 +29,12 @@
|
|
|
de2e0a |
#include "nss_mc.h"
|
|
|
de2e0a |
#include "shared/safealign.h"
|
|
|
de2e0a |
|
|
|
de2e0a |
+#if HAVE_PTHREAD
|
|
|
de2e0a |
+static pthread_mutex_t gr_mc_ctx_mutex = PTHREAD_MUTEX_INITIALIZER;
|
|
|
de2e0a |
+static struct sss_cli_mc_ctx gr_mc_ctx = SSS_CLI_MC_CTX_INITIALIZER(&gr_mc_ctx_mutex);
|
|
|
de2e0a |
+#else
|
|
|
de2e0a |
static struct sss_cli_mc_ctx gr_mc_ctx = SSS_CLI_MC_CTX_INITIALIZER;
|
|
|
de2e0a |
+#endif
|
|
|
de2e0a |
|
|
|
de2e0a |
static errno_t sss_nss_mc_parse_result(struct sss_mc_rec *rec,
|
|
|
de2e0a |
struct group *result,
|
|
|
de2e0a |
diff --git a/src/sss_client/nss_mc_initgr.c b/src/sss_client/nss_mc_initgr.c
|
|
|
de2e0a |
index b05946263..bd7282935 100644
|
|
|
de2e0a |
--- a/src/sss_client/nss_mc_initgr.c
|
|
|
de2e0a |
+++ b/src/sss_client/nss_mc_initgr.c
|
|
|
de2e0a |
@@ -32,7 +32,12 @@
|
|
|
de2e0a |
#include "nss_mc.h"
|
|
|
de2e0a |
#include "shared/safealign.h"
|
|
|
de2e0a |
|
|
|
de2e0a |
+#if HAVE_PTHREAD
|
|
|
de2e0a |
+static pthread_mutex_t initgr_mc_ctx_mutex = PTHREAD_MUTEX_INITIALIZER;
|
|
|
de2e0a |
+static struct sss_cli_mc_ctx initgr_mc_ctx = SSS_CLI_MC_CTX_INITIALIZER(&initgr_mc_ctx_mutex);
|
|
|
de2e0a |
+#else
|
|
|
de2e0a |
static struct sss_cli_mc_ctx initgr_mc_ctx = SSS_CLI_MC_CTX_INITIALIZER;
|
|
|
de2e0a |
+#endif
|
|
|
de2e0a |
|
|
|
de2e0a |
static errno_t sss_nss_mc_parse_result(struct sss_mc_rec *rec,
|
|
|
de2e0a |
long int *start, long int *size,
|
|
|
de2e0a |
diff --git a/src/sss_client/nss_mc_passwd.c b/src/sss_client/nss_mc_passwd.c
|
|
|
de2e0a |
index 01c6801da..256d48444 100644
|
|
|
de2e0a |
--- a/src/sss_client/nss_mc_passwd.c
|
|
|
de2e0a |
+++ b/src/sss_client/nss_mc_passwd.c
|
|
|
de2e0a |
@@ -28,7 +28,12 @@
|
|
|
de2e0a |
#include <time.h>
|
|
|
de2e0a |
#include "nss_mc.h"
|
|
|
de2e0a |
|
|
|
de2e0a |
+#if HAVE_PTHREAD
|
|
|
de2e0a |
+static pthread_mutex_t pw_mc_ctx_mutex = PTHREAD_MUTEX_INITIALIZER;
|
|
|
de2e0a |
+static struct sss_cli_mc_ctx pw_mc_ctx = SSS_CLI_MC_CTX_INITIALIZER(&pw_mc_ctx_mutex);
|
|
|
de2e0a |
+#else
|
|
|
de2e0a |
static struct sss_cli_mc_ctx pw_mc_ctx = SSS_CLI_MC_CTX_INITIALIZER;
|
|
|
de2e0a |
+#endif
|
|
|
de2e0a |
|
|
|
de2e0a |
static errno_t sss_nss_mc_parse_result(struct sss_mc_rec *rec,
|
|
|
de2e0a |
struct passwd *result,
|
|
|
de2e0a |
diff --git a/src/sss_client/nss_mc_sid.c b/src/sss_client/nss_mc_sid.c
|
|
|
de2e0a |
index af7d7bbd5..52e684da5 100644
|
|
|
de2e0a |
--- a/src/sss_client/nss_mc_sid.c
|
|
|
de2e0a |
+++ b/src/sss_client/nss_mc_sid.c
|
|
|
de2e0a |
@@ -30,7 +30,12 @@
|
|
|
de2e0a |
#include "util/mmap_cache.h"
|
|
|
de2e0a |
#include "idmap/sss_nss_idmap.h"
|
|
|
de2e0a |
|
|
|
de2e0a |
+#if HAVE_PTHREAD
|
|
|
de2e0a |
+static pthread_mutex_t sid_mc_ctx_mutex = PTHREAD_MUTEX_INITIALIZER;
|
|
|
de2e0a |
+static struct sss_cli_mc_ctx sid_mc_ctx = SSS_CLI_MC_CTX_INITIALIZER(&sid_mc_ctx_mutex);
|
|
|
de2e0a |
+#else
|
|
|
de2e0a |
static struct sss_cli_mc_ctx sid_mc_ctx = SSS_CLI_MC_CTX_INITIALIZER;
|
|
|
de2e0a |
+#endif
|
|
|
de2e0a |
|
|
|
de2e0a |
static errno_t mc_get_sid_by_typed_id(uint32_t id, enum sss_id_type object_type,
|
|
|
de2e0a |
char **sid, uint32_t *type,
|
|
|
de2e0a |
--
|
|
|
de2e0a |
2.37.1
|
|
|
de2e0a |
|