From 8139795c64021dfcba2febb282b323c8cb1b6ad1 Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Thu, 12 Mar 2026 09:32:26 +0100 Subject: [PATCH] MINOR: cli: keep the info of the current keyword being processed in the appctx 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 | 1 + src/cli.c | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/include/haproxy/applet-t.h b/include/haproxy/applet-t.h index e10c8240f..be76d5c4b 100644 --- a/include/haproxy/applet-t.h +++ b/include/haproxy/applet-t.h @@ -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 */ diff --git a/src/cli.c b/src/cli.c index 104b7175d..f49cca210 100644 --- 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));