]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
CLEANUP: cli: make "show cli sockets" use its own context
authorWilly Tarreau <w@1wt.eu>
Thu, 5 May 2022 17:11:05 +0000 (19:11 +0200)
committerWilly Tarreau <w@1wt.eu>
Fri, 6 May 2022 16:13:36 +0000 (18:13 +0200)
Let's create a show_sock_ctx to store the bind_conf and the listener.
The entry is reserved when entering the I/O handler since there's no
parser here. That's fine because the function doesn't touch the area.

src/cli.c

index 46052d951f4b4e3cdb4f79e01ff52591901bc0bf..f13cfd00d422ef3342ea1a12d38195a658fecf10 100644 (file)
--- a/src/cli.c
+++ b/src/cli.c
@@ -98,6 +98,12 @@ struct show_fd_ctx {
        int show_one;    /* stop after showing one FD */
 };
 
+/* CLI context for the "show cli sockets" command */
+struct show_sock_ctx {
+       struct bind_conf *bind_conf;
+       struct listener *listener;
+};
+
 static int cmp_kw_entries(const void *a, const void *b)
 {
        const struct cli_kw *l = *(const struct cli_kw **)a;
@@ -1552,11 +1558,13 @@ static int cli_io_handler_show_activity(struct appctx *appctx)
 
 /*
  * CLI IO handler for `show cli sockets`.
- * Uses ctx.cli.p0 to store the bind_conf pointer, and cli.p1 for the listener.
+ * Uses the svcctx as a show_sock_ctx to store/retrieve the bind_conf and the
+ * listener pointers.
  */
 static int cli_io_handler_show_cli_sock(struct appctx *appctx)
 {
-       struct bind_conf *bind_conf = appctx->ctx.cli.p0;
+       struct show_sock_ctx *ctx = applet_reserve_svcctx(appctx, sizeof(*ctx));
+       struct bind_conf *bind_conf = ctx->bind_conf;
        struct conn_stream *cs = appctx->owner;
 
        if (!global.cli_fe)
@@ -1572,7 +1580,7 @@ static int cli_io_handler_show_cli_sock(struct appctx *appctx)
        }
 
        list_for_each_entry_from(bind_conf, &global.cli_fe->conf.bind, by_fe) {
-               struct listener *l = appctx->ctx.cli.p1;
+               struct listener *l = ctx->listener;
 
                if (!l)
                        l = LIST_ELEM(bind_conf->listeners.n, typeof(l), by_bind);
@@ -1615,8 +1623,8 @@ static int cli_io_handler_show_cli_sock(struct appctx *appctx)
                        chunk_appendf(&trash, "all\n");
 
                        if (ci_putchk(cs_ic(cs), &trash) == -1) {
-                               appctx->ctx.cli.p0 = bind_conf;
-                               appctx->ctx.cli.p1 = l;
+                               ctx->bind_conf = bind_conf;
+                               ctx->listener  = l;
                                goto full;
                        }
                }