From d741e9c4b1cb4e58fa8e965747de99b96cce7271 Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Thu, 5 May 2022 19:26:18 +0200 Subject: [PATCH] CLEANUP: proxy/cli: get rid of appctx->st2 in "show servers" Now that we have the show_srv_ctx, let's store a state in it. We only need two states here, header and list. --- src/proxy.c | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/src/proxy.c b/src/proxy.c index 2885259..92e4f4b 100644 --- a/src/proxy.c +++ b/src/proxy.c @@ -65,6 +65,10 @@ struct show_srv_ctx { struct server *sv; /* current server to dump or NULL */ uint only_pxid; /* dump only this proxy ID when explicit */ int show_conn; /* non-zero = "conn" otherwise "state" */ + enum { + SHOW_SRV_HEAD = 0, + SHOW_SRV_LIST, + } state; }; /* proxy->options */ @@ -2786,15 +2790,7 @@ static int cli_io_handler_servers_state(struct appctx *appctx) struct conn_stream *cs = appctx->owner; struct proxy *curproxy; - chunk_reset(&trash); - - if (appctx->st2 == STAT_ST_INIT) { - if (!ctx->px) - ctx->px = proxies_list; - appctx->st2 = STAT_ST_HEAD; - } - - if (appctx->st2 == STAT_ST_HEAD) { + if (ctx->state == SHOW_SRV_HEAD) { if (ctx->show_conn == 0) chunk_printf(&trash, "%d\n# %s\n", SRV_STATE_FILE_VERSION, SRV_STATE_FILE_FIELD_NAMES); else @@ -2806,10 +2802,12 @@ static int cli_io_handler_servers_state(struct appctx *appctx) cs_rx_room_blk(cs); return 0; } - appctx->st2 = STAT_ST_INFO; + ctx->state = SHOW_SRV_LIST; + + if (!ctx->px) + ctx->px = proxies_list; } - /* STAT_ST_INFO */ for (; ctx->px != NULL; ctx->px = curproxy->next) { curproxy = ctx->px; /* servers are only in backends */ -- 1.7.10.4