>From 9d3f18878aa0ffbc4bb455afac405f0fe037e20f Mon Sep 17 00:00:00 2001 From: Jakub Hrozek Date: Tue, 26 Mar 2013 12:57:33 +0100 Subject: [PATCH 2/2] Centralize resolv_init, remove resolv context list --- src/providers/data_provider_be.c | 2 +- src/providers/ipa/ipa_dyndns.c | 9 +-------- src/providers/ldap/sdap_async_sudo_hostinfo.c | 18 ++---------------- src/resolv/async_resolv.c | 19 ++----------------- src/resolv/async_resolv.h | 2 +- 5 files changed, 7 insertions(+), 43 deletions(-) diff --git a/src/providers/data_provider_be.c b/src/providers/data_provider_be.c index 712d7e7159029d956a4dbc93c905e238b4879a70..05173320ebab8014145f38b1797b7cf999480266 100644 --- a/src/providers/data_provider_be.c +++ b/src/providers/data_provider_be.c @@ -2782,7 +2782,7 @@ static int data_provider_res_init(DBusMessage *message, struct be_ctx *be_ctx; be_ctx = talloc_get_type(sbus_conn_get_private_data(conn), struct be_ctx); - resolv_reread_configuration(); + resolv_reread_configuration(be_ctx->be_res->resolv); check_if_online(be_ctx); return monitor_common_res_init(message, conn); diff --git a/src/providers/ipa/ipa_dyndns.c b/src/providers/ipa/ipa_dyndns.c index 632ed26afef8eb2240cf73709af490bab9dc97d8..a31067cdc09cfac24ff7ab9fabb3cf4f6b742b74 100644 --- a/src/providers/ipa/ipa_dyndns.c +++ b/src/providers/ipa/ipa_dyndns.c @@ -143,14 +143,7 @@ errno_t ipa_dyndns_init(struct be_ctx *be_ctx, { errno_t ret; - ret = resolv_init(be_ctx, be_ctx->ev, - dp_opt_get_int(be_ctx->be_res->opts, - DP_RES_OPT_RESOLVER_OP_TIMEOUT), - &ctx->resolv); - if (ret != EOK) { - DEBUG(1, ("Could not set up resolver context\n")); - return ret; - } + ctx->resolv = be_ctx->be_res->resolv; ret = be_add_online_cb(be_ctx, be_ctx, ipa_dyndns_update, diff --git a/src/providers/ldap/sdap_async_sudo_hostinfo.c b/src/providers/ldap/sdap_async_sudo_hostinfo.c index ff6142237fc98de7e65fbf815b1d4180de204ee3..4e33babd505dd218ddfd37af21e62fb0bcbe451c 100644 --- a/src/providers/ldap/sdap_async_sudo_hostinfo.c +++ b/src/providers/ldap/sdap_async_sudo_hostinfo.c @@ -431,22 +431,8 @@ static struct tevent_req *sdap_sudo_get_hostnames_send(TALLOC_CTX *mem_ctx, DEBUG(SSSDBG_TRACE_INTERNAL, ("Found hostname: %s\n", hostname)); } - /* initialize resolv ctx */ - ret = resolv_init(be_ctx, be_ctx->ev, - dp_opt_get_int(be_ctx->be_res->opts, - DP_RES_OPT_RESOLVER_OP_TIMEOUT), - &state->resolv_ctx); - if (ret != EOK) { - DEBUG(SSSDBG_CRIT_FAILURE, ("Could not set up resolver context\n")); - goto done; - } - - /* get database order */ - - state->host_db = talloc_zero_array(state, enum host_database, 3); - state->host_db[0] = DB_FILES; - state->host_db[1] = DB_DNS; - state->host_db[2] = DB_SENTINEL; + state->resolv_ctx = be_ctx->be_res->resolv; + state->host_db = default_host_dbs; /* get fqdn */ subreq = resolv_gethostbyname_send(state, state->ev, state->resolv_ctx, diff --git a/src/resolv/async_resolv.c b/src/resolv/async_resolv.c index 0a88094e613f004dbc29a5a75a4a9ac1990d5370..3181825b5fc90f5006551219e6bcaecf2832f380 100644 --- a/src/resolv/async_resolv.c +++ b/src/resolv/async_resolv.c @@ -78,11 +78,6 @@ struct fd_watch { }; struct resolv_ctx { - /* Contexts are linked so we can keep track of them and re-create - * the ares channels in all of them at once if we need to. */ - struct resolv_ctx *prev; - struct resolv_ctx *next; - struct tevent_context *ev_ctx; ares_channel channel; @@ -109,8 +104,6 @@ struct resolv_request { struct tevent_timer *request_timeout; }; -struct resolv_ctx *context_list; - static int return_code(int ares_code) { @@ -406,8 +399,6 @@ resolv_ctx_destructor(struct resolv_ctx *ctx) { ares_channel channel; - DLIST_REMOVE(context_list, ctx); - if (ctx->channel == NULL) { DEBUG(1, ("Ares channel already destroyed?\n")); return -1; @@ -487,7 +478,6 @@ resolv_init(TALLOC_CTX *mem_ctx, struct tevent_context *ev_ctx, goto done; } - DLIST_ADD(context_list, ctx); talloc_set_destructor(ctx, resolv_ctx_destructor); *ctxp = ctx; @@ -499,14 +489,9 @@ done: } void -resolv_reread_configuration(void) +resolv_reread_configuration(struct resolv_ctx *ctx) { - struct resolv_ctx *ctx; - - DEBUG(4, ("Recreating all c-ares channels\n")); - DLIST_FOR_EACH(ctx, context_list) { - recreate_ares_channel(ctx); - } + recreate_ares_channel(ctx); } static errno_t diff --git a/src/resolv/async_resolv.h b/src/resolv/async_resolv.h index f6c72b4fafedc016b64e7f5606fc838a585bcab5..b66bf9da2104805b1abea82d7b2e31e40e6d3035 100644 --- a/src/resolv/async_resolv.h +++ b/src/resolv/async_resolv.h @@ -58,7 +58,7 @@ struct resolv_ctx; int resolv_init(TALLOC_CTX *mem_ctx, struct tevent_context *ev_ctx, int timeout, struct resolv_ctx **ctxp); -void resolv_reread_configuration(void); +void resolv_reread_configuration(struct resolv_ctx *ctx); const char *resolv_strerror(int ares_code); -- 1.8.1.4