diff options
author | Simo Sorce <simo@redhat.com> | 2013-01-06 03:16:08 -0500 |
---|---|---|
committer | Jakub Hrozek <jhrozek@redhat.com> | 2013-01-15 10:49:20 +0100 |
commit | 72aa8e7b1d234b6b68446d42efa1cff22b70c81b (patch) | |
tree | b712144660ce3eb931a173fc2d98f00031ca6a52 /src/tools | |
parent | f2ce4a4a45bfc0c9ba6d1a13348494dd4c49d4fb (diff) | |
download | sssd-72aa8e7b1d234b6b68446d42efa1cff22b70c81b.tar.gz sssd-72aa8e7b1d234b6b68446d42efa1cff22b70c81b.tar.bz2 sssd-72aa8e7b1d234b6b68446d42efa1cff22b70c81b.zip |
Refactor sysdb initialization
Change the way sysdbs are initialized. Make callers responsible for providing
the list of domains.
Remove the returned array of sysdb contexts, it was used only by sss_cache
and not really necessary there either as that tool can easily iterate the
domains.
Make sysdb ctx children of their respective domains.
Neither sysdb context nor domains are ever freed until a program is done so
there shouldn't be any memory hierarchy issue. As plus we simplify the code by
removing a destructor and a setter function.
Diffstat (limited to 'src/tools')
-rw-r--r-- | src/tools/sss_cache.c | 31 |
1 files changed, 10 insertions, 21 deletions
diff --git a/src/tools/sss_cache.c b/src/tools/sss_cache.c index 684b8b25..5f8450f7 100644 --- a/src/tools/sss_cache.c +++ b/src/tools/sss_cache.c @@ -53,7 +53,6 @@ static errno_t search_autofsmaps(TALLOC_CTX *mem_ctx, struct sysdb_ctx *sysdb, struct cache_tool_ctx { struct confdb_ctx *confdb; struct sss_domain_info *domains; - struct sysdb_ctx_list *sysdb_list; struct sss_names_ctx *nctx; char *user_filter; @@ -90,7 +89,6 @@ int main(int argc, const char *argv[]) errno_t ret; struct cache_tool_ctx *tctx = NULL; struct sysdb_ctx *sysdb; - int i; bool skipped = true; struct sss_domain_info *dinfo; @@ -101,9 +99,8 @@ int main(int argc, const char *argv[]) goto done; } - for (i = 0; i < tctx->sysdb_list->num_dbs; i++) { - sysdb = tctx->sysdb_list->dbs[i]; - dinfo = sysdb_ctx_get_domain(sysdb); + for (dinfo = tctx->domains; dinfo; dinfo = dinfo->next) { + sysdb = dinfo->sysdb; /* Update filters for each domain */ ret = update_all_filters(tctx, dinfo->name); @@ -422,33 +419,25 @@ errno_t init_domains(struct cache_tool_ctx *ctx, const char *domain) if (ret != EOK) { SYSDB_VERSION_ERROR(ret); DEBUG(1, ("Could not initialize connection to the sysdb\n")); - goto fail; + return ret; } - ret = sysdb_list_init(ctx, DB_PATH, db_ctx, &ctx->sysdb_list); + } else { + ret = confdb_get_domains(ctx->confdb, &ctx->domains); if (ret != EOK) { - DEBUG(1, ("Could not initialize the list of connections\n")); - goto fail; + DEBUG(1, ("Could not initialize domains\n")); + return ret; } - } else { - ret = sysdb_init(ctx, ctx->confdb, NULL, false, &ctx->sysdb_list); + + ret = sysdb_init(ctx, ctx->domains, NULL, false); SYSDB_VERSION_ERROR(ret); if (ret != EOK) { DEBUG(1, ("Could not initialize connection to the sysdb\n")); - goto fail; + return ret; } } return EOK; -fail: - if (ctx->confdb) talloc_zfree(ctx->confdb); - if (ctx->domains) talloc_zfree(ctx->domains); - if (ctx->sysdb_list) { - talloc_zfree(ctx->sysdb_list); - } else { - if (db_ctx) talloc_free(db_ctx); - } - return ret; } errno_t init_context(int argc, const char *argv[], struct cache_tool_ctx **tctx) |