]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: cli: keep the info of the current keyword being processed in the appctx
authorWilly Tarreau <w@1wt.eu>
Thu, 12 Mar 2026 08:32:26 +0000 (09:32 +0100)
committerWilly Tarreau <w@1wt.eu>
Thu, 12 Mar 2026 17:06:38 +0000 (18:06 +0100)
Till now the CLI didn't know what keyword was being processed after it
was parsed. In order to report the execution context, we'll need to
store it. And this may even help for post-mortem analysis to know the
exact keyword being processed, so let's store the pointer in the cli_ctx
part of the appctx.

include/haproxy/applet-t.h
src/cli.c

index e10c8240ff0379a6a090b81f92cc8bafb2ab64d5..be76d5c4b6cbb9e92f6be0b7ff16d4308f9d4e18 100644 (file)
@@ -130,6 +130,7 @@ struct appctx {
                int (*io_handler)(struct appctx *appctx);  /* used within the cli_io_handler when st0 = CLI_ST_CALLBACK */
                void (*io_release)(struct appctx *appctx); /* used within the cli_io_handler when st0 = CLI_ST_CALLBACK,
                                                              if the command is terminated or the session released */
+               struct cli_kw *kw;      /* the keyword being processed */
        } cli_ctx; /* context dedicated to the CLI applet */
 
        struct buffer_wait buffer_wait; /* position in the list of objects waiting for a buffer */
index 104b7175d13bfb959bf3d9ae1cf84c37805b76e1..f49cca2100302b669318d684dfdb30bfd70b6895 100644 (file)
--- a/src/cli.c
+++ b/src/cli.c
@@ -849,6 +849,7 @@ static int cli_process_cmdline(struct appctx *appctx)
        else if (kw->level == ACCESS_EXPERIMENTAL)
                mark_tainted(TAINTED_CLI_EXPERIMENTAL_MODE);
 
+       appctx->cli_ctx.kw = kw;
        appctx->cli_ctx.io_handler = kw->io_handler;
        appctx->cli_ctx.io_release = kw->io_release;
 
@@ -868,6 +869,7 @@ static int cli_process_cmdline(struct appctx *appctx)
        goto end;
 
   fail:
+       appctx->cli_ctx.kw = NULL;
        appctx->cli_ctx.io_handler = NULL;
        appctx->cli_ctx.io_release = NULL;
 
@@ -1215,11 +1217,13 @@ void cli_io_handler(struct appctx *appctx)
                                                if (appctx->cli_ctx.io_release) {
                                                        appctx->cli_ctx.io_release(appctx);
                                                        appctx->cli_ctx.io_release = NULL;
+                                                       appctx->cli_ctx.kw = NULL;
                                                        /* some release handlers might have
                                                         * pending output to print.
                                                         */
                                                        continue;
                                                }
+                                               appctx->cli_ctx.kw = NULL;
                                        }
                                break;
                        default: /* abnormal state */
@@ -1327,6 +1331,7 @@ static void cli_release_handler(struct appctx *appctx)
        if (appctx->cli_ctx.io_release) {
                appctx->cli_ctx.io_release(appctx);
                appctx->cli_ctx.io_release = NULL;
+               appctx->cli_ctx.kw = NULL;
        }
        else if (appctx->st0 == CLI_ST_PRINT_DYN || appctx->st0 == CLI_ST_PRINT_DYNERR) {
                struct cli_print_ctx *ctx = applet_reserve_svcctx(appctx, sizeof(*ctx));