From: Willy Tarreau Date: Mon, 28 Apr 2025 15:42:03 +0000 (+0200) Subject: MINOR: cli: split APPCTX_CLI_ST1_PROMPT into two distinct flags X-Git-Tag: v3.2-dev13~57 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f25b4abc9bc561cb963a9eb34e8f089218002bf8;p=thirdparty%2Fhaproxy.git MINOR: cli: split APPCTX_CLI_ST1_PROMPT into two distinct flags The CLI's "prompt" command toggles two distinct things: - displaying or hiding the prompt at the beginning of the line - single-command vs interactive mode These are two independent concepts and the prompt mode doesn't always cope well with tools that would like to upload data without having to read the prompt on return. Also, the master command line works in interactive mode by default with no prompt, which is not consistent (and not convenient for tools). So let's start by splitting the bit in two, and have a new APPCTX_CLI_ST1_INTER flag dedicated to the interactive mode. For now the "prompt" command alone continues to toggle the two at once. --- diff --git a/include/haproxy/cli-t.h b/include/haproxy/cli-t.h index f3b931f9b..45eed35bc 100644 --- a/include/haproxy/cli-t.h +++ b/include/haproxy/cli-t.h @@ -41,11 +41,12 @@ #define ACCESS_MCLI_SEVERITY_STR 0x0200 /* 'set severity-output string' on master CLI */ /* flags for appctx->st1 */ -#define APPCTX_CLI_ST1_PROMPT (1 << 0) -#define APPCTX_CLI_ST1_PAYLOAD (1 << 1) -#define APPCTX_CLI_ST1_NOLF (1 << 2) -#define APPCTX_CLI_ST1_TIMED (1 << 3) -#define APPCTX_CLI_ST1_LASTCMD (1 << 4) +#define APPCTX_CLI_ST1_PAYLOAD (1 << 0) +#define APPCTX_CLI_ST1_NOLF (1 << 1) +#define APPCTX_CLI_ST1_LASTCMD (1 << 2) +#define APPCTX_CLI_ST1_INTER (1 << 3) /* interactive mode (i.e. don't close after 1st cmd) */ +#define APPCTX_CLI_ST1_PROMPT (1 << 4) /* display prompt */ +#define APPCTX_CLI_ST1_TIMED (1 << 5) /* display timer in prompt */ #define CLI_PREFIX_KW_NB 5 #define CLI_MAX_MATCHES 5 diff --git a/src/cli.c b/src/cli.c index 5791a89ce..663bdad69 100644 --- a/src/cli.c +++ b/src/cli.c @@ -1260,7 +1260,7 @@ void cli_io_handler(struct appctx *appctx) appctx->cli_ctx.payload = NULL; appctx->cli_ctx.cmdline = NULL; appctx->st1 &= ~APPCTX_CLI_ST1_LASTCMD; - if (appctx->st1 & APPCTX_CLI_ST1_PROMPT) { + if (appctx->st1 & APPCTX_CLI_ST1_INTER) { appctx->st0 = CLI_ST_PARSE_CMDLINE; applet_will_consume(appctx); applet_expect_data(appctx); @@ -2497,11 +2497,11 @@ static int cli_parse_simple(char **args, char *payload, struct appctx *appctx, v else if (*args[0] == 'p') /* prompt */ if (strcmp(args[1], "timed") == 0) { - appctx->st1 |= APPCTX_CLI_ST1_PROMPT; + appctx->st1 |= APPCTX_CLI_ST1_PROMPT | APPCTX_CLI_ST1_INTER; appctx->st1 ^= APPCTX_CLI_ST1_TIMED; } else - appctx->st1 ^= APPCTX_CLI_ST1_PROMPT; + appctx->st1 ^= APPCTX_CLI_ST1_PROMPT | APPCTX_CLI_ST1_INTER; else if (*args[0] == 'q') { /* quit */ applet_set_eoi(appctx);