From a09b3853da819cc773c0098100f9dd96af08f933 Mon Sep 17 00:00:00 2001 From: Lukas Slebodnik Date: Mon, 10 Aug 2015 10:16:58 +0200 Subject: [PATCH 51/57] sss_cache: Wait a while for invalidation of mc by nss responder MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The sss_cache cannot invalidate memory cache directly because the nss responder owns file locks to memory caches. Therefore sss_cache just "tell" nss responder to invalidate memory cache. However there might be short interval between calling the utility sss_cache and stopping sssd. So nss responder needn't be so fast and therefore memory cache needn't be invalidated. Resolves: https://fedorahosted.org/sssd/ticket/2748 Reviewed-by: Michal Židek --- src/tools/tools_mc_util.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/src/tools/tools_mc_util.c b/src/tools/tools_mc_util.c index c1b5c616d0e6d50147ecd81308aaa1e69304af92..65c461093e859d4da73761782a3a694bf5bda8fb 100644 --- a/src/tools/tools_mc_util.c +++ b/src/tools/tools_mc_util.c @@ -21,6 +21,7 @@ #include #include +#include #include "db/sysdb.h" #include "util/util.h" @@ -161,6 +162,33 @@ static int clear_fastcache(bool *sssd_nss_is_off) return EOK; } +static errno_t wait_till_nss_responder_invalidate_cache(void) +{ + struct stat stat_buf = { 0 }; + const time_t max_wait = 1000000; /* 1 second */ + const time_t step_time = 5000; /* 5 miliseconds */ + const size_t steps_count = max_wait / step_time; + int ret; + + for (size_t i = 0; i < steps_count; ++i) { + ret = stat(SSS_NSS_MCACHE_DIR "/" CLEAR_MC_FLAG, &stat_buf); + if (ret == -1) { + ret = errno; + if (ret == ENOENT) { + /* nss responder has already invalidated memory caches */ + return EOK; + } + + DEBUG(SSSDBG_CRIT_FAILURE, + "stat failed: %s (%d)\n", sss_strerror(ret), ret); + } + + usleep(step_time); + } + + return EAGAIN; +} + errno_t sss_memcache_clear_all(void) { errno_t ret; @@ -196,6 +224,12 @@ errno_t sss_memcache_clear_all(void) "Failed to send SIGHUP to monitor.\n"); return EIO; } + + ret = wait_till_nss_responder_invalidate_cache(); + if (ret != EOK) { + ERROR("The fast memory caches was not invalidated by NSS " + "responder.\n"); + } } return EOK; -- 2.4.3