summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMichal Zidek <mzidek@redhat.com>2012-11-20 13:52:12 +0100
committerJakub Hrozek <jhrozek@redhat.com>2012-11-28 10:37:45 +0100
commita290ace39af184d878568e17588b6b2210aea63f (patch)
tree2c817b03ee4d37903372daf17c19d59a46938267 /src
parent62b36cdae054b915da4d29fd3812f3799c27de69 (diff)
downloadsssd-a290ace39af184d878568e17588b6b2210aea63f.tar.gz
sssd-a290ace39af184d878568e17588b6b2210aea63f.tar.bz2
sssd-a290ace39af184d878568e17588b6b2210aea63f.zip
sss_cache: Small refactor.
The logic that checks if sssd_nss is running and then sends SIGHUP to monitor or removes the caches was moved to a function sss_memcache_clear_all() and made public in tools_util.h.
Diffstat (limited to 'src')
-rw-r--r--src/tools/sss_cache.c61
-rw-r--r--src/tools/tools_util.c67
-rw-r--r--src/tools/tools_util.h2
3 files changed, 72 insertions, 58 deletions
diff --git a/src/tools/sss_cache.c b/src/tools/sss_cache.c
index 368b1df9..9305db51 100644
--- a/src/tools/sss_cache.c
+++ b/src/tools/sss_cache.c
@@ -92,7 +92,6 @@ errno_t invalidate_entry(TALLOC_CTX *ctx, struct sysdb_ctx *sysdb,
bool invalidate_entries(TALLOC_CTX *ctx, struct sysdb_ctx *sysdb,
enum sss_cache_entry entry_type, const char *filter,
const char *name);
-static int clear_fastcache(bool *sssd_nss_is_off);
int main(int argc, const char *argv[])
{
@@ -100,9 +99,7 @@ int main(int argc, const char *argv[])
struct cache_tool_ctx *tctx = NULL;
struct sysdb_ctx *sysdb;
int i;
- bool sssd_nss_is_off;
bool skipped = true;
- FILE *clear_mc_flag;
ret = init_context(argc, argv, &tctx);
if (ret != EOK) {
@@ -145,71 +142,19 @@ int main(int argc, const char *argv[])
ret = ENOENT;
goto done;
} else {
- ret = clear_fastcache(&sssd_nss_is_off);
+ ret = sss_memcache_clear_all();
if (ret != EOK) {
- DEBUG(SSSDBG_CRIT_FAILURE, ("Failed to clear caches.\n"));
+ DEBUG(SSSDBG_CRIT_FAILURE, ("Failed to clear memory cache.\n"));
goto done;
}
- if (!sssd_nss_is_off) {
- /* sssd_nss is running -> signal monitor to invalidate fastcache */
- clear_mc_flag = fopen(SSS_NSS_MCACHE_DIR"/"CLEAR_MC_FLAG, "w");
- if (clear_mc_flag == NULL) {
- DEBUG(SSSDBG_CRIT_FAILURE,
- ("Failed to create clear_mc_flag file. "
- "Memory cache will not be cleared.\n"));
- goto done;
- }
- ret = fclose(clear_mc_flag);
- if (ret != 0) {
- ret = errno;
- DEBUG(SSSDBG_CRIT_FAILURE,
- ("Unable to close file descriptor: %s\n",
- strerror(ret)));
- goto done;
- }
-
- DEBUG(SSSDBG_TRACE_FUNC, ("Sending SIGHUP to monitor.\n"));
- ret = signal_sssd(SIGHUP);
- if (ret != EOK) {
- DEBUG(SSSDBG_CRIT_FAILURE,
- ("Failed to send SIGHUP to monitor.\n"));
- goto done;
- }
- }
}
+ ret = EOK;
done:
if (tctx) talloc_free(tctx);
return ret;
}
-static int clear_fastcache(bool *sssd_nss_is_off)
-{
- int ret;
- ret = sss_memcache_invalidate(SSS_NSS_MCACHE_DIR"/passwd");
- if (ret != EOK) {
- if (ret == EACCES) {
- *sssd_nss_is_off = false;
- return EOK;
- } else {
- return ret;
- }
- }
-
- ret = sss_memcache_invalidate(SSS_NSS_MCACHE_DIR"/group");
- if (ret != EOK) {
- if (ret == EACCES) {
- *sssd_nss_is_off = false;
- return EOK;
- } else {
- return ret;
- }
- }
-
- *sssd_nss_is_off = true;
- return EOK;
-}
-
bool invalidate_entries(TALLOC_CTX *ctx, struct sysdb_ctx *sysdb,
enum sss_cache_entry entry_type, const char *filter,
const char *name)
diff --git a/src/tools/tools_util.c b/src/tools/tools_util.c
index 73e94136..406077c8 100644
--- a/src/tools/tools_util.c
+++ b/src/tools/tools_util.c
@@ -766,3 +766,70 @@ done:
}
return ret;
}
+
+static int clear_fastcache(bool *sssd_nss_is_off)
+{
+ int ret;
+ ret = sss_memcache_invalidate(SSS_NSS_MCACHE_DIR"/passwd");
+ if (ret != EOK) {
+ if (ret == EACCES) {
+ *sssd_nss_is_off = false;
+ return EOK;
+ } else {
+ return ret;
+ }
+ }
+
+ ret = sss_memcache_invalidate(SSS_NSS_MCACHE_DIR"/group");
+ if (ret != EOK) {
+ if (ret == EACCES) {
+ *sssd_nss_is_off = false;
+ return EOK;
+ } else {
+ return ret;
+ }
+ }
+
+ *sssd_nss_is_off = true;
+ return EOK;
+}
+
+errno_t sss_memcache_clear_all(void)
+{
+ errno_t ret;
+ bool sssd_nss_is_off = false;
+ FILE *clear_mc_flag;
+
+ ret = clear_fastcache(&sssd_nss_is_off);
+ if (ret != EOK) {
+ DEBUG(SSSDBG_CRIT_FAILURE, ("Failed to clear caches.\n"));
+ return EIO;
+ }
+ if (!sssd_nss_is_off) {
+ /* sssd_nss is running -> signal monitor to invalidate fastcache */
+ clear_mc_flag = fopen(SSS_NSS_MCACHE_DIR"/"CLEAR_MC_FLAG, "w");
+ if (clear_mc_flag == NULL) {
+ DEBUG(SSSDBG_CRIT_FAILURE,
+ ("Failed to create clear_mc_flag file. "
+ "Memory cache will not be cleared.\n"));
+ return EIO;
+ }
+ ret = fclose(clear_mc_flag);
+ if (ret != 0) {
+ ret = errno;
+ DEBUG(SSSDBG_CRIT_FAILURE,
+ ("Unable to close file descriptor: %s\n",
+ strerror(ret)));
+ return EIO;
+ }
+ DEBUG(SSSDBG_TRACE_FUNC, ("Sending SIGHUP to monitor.\n"));
+ ret = signal_sssd(SIGHUP);
+ if (ret != EOK) {
+ DEBUG(SSSDBG_CRIT_FAILURE,
+ ("Failed to send SIGHUP to monitor.\n"));
+ return EIO;
+ }
+ }
+
+ return EOK;
+}
diff --git a/src/tools/tools_util.h b/src/tools/tools_util.h
index a83c8eea..20a2a4af 100644
--- a/src/tools/tools_util.h
+++ b/src/tools/tools_util.h
@@ -106,6 +106,8 @@ errno_t signal_sssd(int signum);
errno_t sss_memcache_invalidate(const char *mc_filename);
+errno_t sss_memcache_clear_all(void);
+
/* from files.c */
int remove_tree(const char *root);