diff options
author | Lukas Slebodnik <lslebodn@redhat.com> | 2015-08-10 10:16:58 +0200 |
---|---|---|
committer | Jakub Hrozek <jhrozek@redhat.com> | 2015-08-13 13:21:02 +0200 |
commit | 32c6db689a0206e062b799dfd32c34ba878ff044 (patch) | |
tree | 63a96cb5722becfe62f265e615b47b2c5150d2af | |
parent | 6c676de3f7e8dee3655343c2975995f73ec1ef04 (diff) | |
download | sssd-32c6db689a0206e062b799dfd32c34ba878ff044.tar.gz sssd-32c6db689a0206e062b799dfd32c34ba878ff044.tar.xz sssd-32c6db689a0206e062b799dfd32c34ba878ff044.zip |
sss_cache: Wait a while for invalidation of mc by nss responder
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 <mzidek@redhat.com>
-rw-r--r-- | src/tools/tools_mc_util.c | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/src/tools/tools_mc_util.c b/src/tools/tools_mc_util.c index c1b5c616d..65c461093 100644 --- a/src/tools/tools_mc_util.c +++ b/src/tools/tools_mc_util.c @@ -21,6 +21,7 @@ #include <talloc.h> #include <fcntl.h> +#include <sys/stat.h> #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; |