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.
This commit is contained in:
Willy Tarreau 2026-03-12 09:32:26 +01:00
parent 9cb11d0859
commit 8139795c64
2 changed files with 6 additions and 0 deletions

View 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 */

View File

@ -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));