From: Willy Tarreau Date: Thu, 5 May 2022 14:38:13 +0000 (+0200) Subject: CLEANUP: resolvers/cli: remove the unneeded appctx->st2 from "show resolvers" X-Git-Tag: v2.6-dev9~25 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=12d5228a447f233e7e8e51079113edb158b946ff;p=thirdparty%2Fhaproxy.git CLEANUP: resolvers/cli: remove the unneeded appctx->st2 from "show resolvers" The command uses this state but _INIT immediately turns to _LIST, which turns to _FIN at the end without doing anything in that state, thus the only existing state is _LIST so we don't need to store a state. Let's just get rid of it. --- diff --git a/src/resolvers.c b/src/resolvers.c index feed4c6874..e58fa59678 100644 --- a/src/resolvers.c +++ b/src/resolvers.c @@ -2766,73 +2766,63 @@ static int cli_io_handler_dump_resolvers_to_buffer(struct appctx *appctx) chunk_reset(&trash); - switch (appctx->st2) { - case STAT_ST_INIT: - appctx->st2 = STAT_ST_LIST; /* let's start producing data */ - /* fall through */ - - case STAT_ST_LIST: - if (LIST_ISEMPTY(&sec_resolvers)) { - if (ci_putstr(cs_ic(cs), "No resolvers found\n") == -1) - goto full; - } - else { - if (!resolvers) - resolvers = LIST_ELEM(sec_resolvers.n, typeof(resolvers), list); - - list_for_each_entry_from(resolvers, &sec_resolvers, list) { - if (ctx->forced_section != NULL && ctx->forced_section != resolvers) - continue; - - ctx->resolvers = resolvers; - ns = ctx->ns; + if (LIST_ISEMPTY(&sec_resolvers)) { + if (ci_putstr(cs_ic(cs), "No resolvers found\n") == -1) + goto full; + } + else { + if (!resolvers) + resolvers = LIST_ELEM(sec_resolvers.n, typeof(resolvers), list); - if (!ns) { - chunk_printf(&trash, "Resolvers section %s\n", resolvers->id); - if (ci_putchk(cs_ic(cs), &trash) == -1) - goto full; + list_for_each_entry_from(resolvers, &sec_resolvers, list) { + if (ctx->forced_section != NULL && ctx->forced_section != resolvers) + continue; - ns = LIST_ELEM(resolvers->nameservers.n, typeof(ns), list); - ctx->ns = ns; - } + ctx->resolvers = resolvers; + ns = ctx->ns; - list_for_each_entry_from(ns, &resolvers->nameservers, list) { - chunk_reset(&trash); - chunk_appendf(&trash, " nameserver %s:\n", ns->id); - chunk_appendf(&trash, " sent: %lld\n", ns->counters->sent); - chunk_appendf(&trash, " snd_error: %lld\n", ns->counters->snd_error); - chunk_appendf(&trash, " valid: %lld\n", ns->counters->app.resolver.valid); - chunk_appendf(&trash, " update: %lld\n", ns->counters->app.resolver.update); - chunk_appendf(&trash, " cname: %lld\n", ns->counters->app.resolver.cname); - chunk_appendf(&trash, " cname_error: %lld\n", ns->counters->app.resolver.cname_error); - chunk_appendf(&trash, " any_err: %lld\n", ns->counters->app.resolver.any_err); - chunk_appendf(&trash, " nx: %lld\n", ns->counters->app.resolver.nx); - chunk_appendf(&trash, " timeout: %lld\n", ns->counters->app.resolver.timeout); - chunk_appendf(&trash, " refused: %lld\n", ns->counters->app.resolver.refused); - chunk_appendf(&trash, " other: %lld\n", ns->counters->app.resolver.other); - chunk_appendf(&trash, " invalid: %lld\n", ns->counters->app.resolver.invalid); - chunk_appendf(&trash, " too_big: %lld\n", ns->counters->app.resolver.too_big); - chunk_appendf(&trash, " truncated: %lld\n", ns->counters->app.resolver.truncated); - chunk_appendf(&trash, " outdated: %lld\n", ns->counters->app.resolver.outdated); - if (ci_putchk(cs_ic(cs), &trash) == -1) - goto full; - ctx->ns = ns; - } + if (!ns) { + chunk_printf(&trash, "Resolvers section %s\n", resolvers->id); + if (ci_putchk(cs_ic(cs), &trash) == -1) + goto full; - ctx->ns = NULL; + ns = LIST_ELEM(resolvers->nameservers.n, typeof(ns), list); + ctx->ns = ns; + } - /* was this the only section to dump ? */ - if (ctx->forced_section) - break; + list_for_each_entry_from(ns, &resolvers->nameservers, list) { + chunk_reset(&trash); + chunk_appendf(&trash, " nameserver %s:\n", ns->id); + chunk_appendf(&trash, " sent: %lld\n", ns->counters->sent); + chunk_appendf(&trash, " snd_error: %lld\n", ns->counters->snd_error); + chunk_appendf(&trash, " valid: %lld\n", ns->counters->app.resolver.valid); + chunk_appendf(&trash, " update: %lld\n", ns->counters->app.resolver.update); + chunk_appendf(&trash, " cname: %lld\n", ns->counters->app.resolver.cname); + chunk_appendf(&trash, " cname_error: %lld\n", ns->counters->app.resolver.cname_error); + chunk_appendf(&trash, " any_err: %lld\n", ns->counters->app.resolver.any_err); + chunk_appendf(&trash, " nx: %lld\n", ns->counters->app.resolver.nx); + chunk_appendf(&trash, " timeout: %lld\n", ns->counters->app.resolver.timeout); + chunk_appendf(&trash, " refused: %lld\n", ns->counters->app.resolver.refused); + chunk_appendf(&trash, " other: %lld\n", ns->counters->app.resolver.other); + chunk_appendf(&trash, " invalid: %lld\n", ns->counters->app.resolver.invalid); + chunk_appendf(&trash, " too_big: %lld\n", ns->counters->app.resolver.too_big); + chunk_appendf(&trash, " truncated: %lld\n", ns->counters->app.resolver.truncated); + chunk_appendf(&trash, " outdated: %lld\n", ns->counters->app.resolver.outdated); + if (ci_putchk(cs_ic(cs), &trash) == -1) + goto full; + ctx->ns = ns; } - } - /* fall through */ + ctx->ns = NULL; - default: - appctx->st2 = STAT_ST_FIN; - return 1; + /* was this the only section to dump ? */ + if (ctx->forced_section) + break; + } } + + /* done! */ + return 1; full: /* the output buffer is full, retry later */ cs_rx_room_blk(cs);