]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MINOR: mworker/cli: fix set severity-output support
authorWilliam Lallemand <wlallemand@haproxy.com>
Wed, 6 Dec 2023 10:15:01 +0000 (11:15 +0100)
committerWilliam Lallemand <wlallemand@haproxy.com>
Thu, 7 Dec 2023 16:37:23 +0000 (17:37 +0100)
"set severity-output" is one of these command that changes the appctx
state so the next commands are affected.

Unfortunately the master CLI works with pipelining and server close
mode, which means the connection between the master and the worker is
closed after each response, so for the next command this is a new appctx
state.

To fix the problem, 2 new flags are added ACCESS_MCLI_SEVERITY_STR and
ACCESS_MCLI_SEVERITY_NB which are used to prefix each command sent to
the worker with the right "set severity-output" command.

This patch fixes issue #2350.

It could be backported as far as 2.6.

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

index 0570b69db622b57ebfb9920ff628e9855fea814d..c155df33873b582f254544a7a5332a8e8b390953 100644 (file)
@@ -37,6 +37,8 @@
 #define ACCESS_EXPERT       0x0020  /* access to dangerous commands reserved to experts */
 #define ACCESS_EXPERIMENTAL 0x0040
 #define ACCESS_MCLI_DEBUG   0x0080 /* allow the master CLI to use any command without the flag ACCESS_MASTER */
+#define ACCESS_MCLI_SEVERITY_NB  0x0100 /* 'set severity-output number' on master CLI */
+#define ACCESS_MCLI_SEVERITY_STR 0x0200 /* 'set severity-output string' on master CLI */
 
 /* flags for appctx->st1 */
 #define APPCTX_CLI_ST1_PROMPT  (1 << 0)
index 069a2659327b6f728b4c6724cf4e4bd2f610db5b..24c395033357dc9e53dfeffbf6e4905407e1a764 100644 (file)
--- a/src/cli.c
+++ b/src/cli.c
@@ -1759,6 +1759,10 @@ static int set_severity_output(int *target, char *argument)
 /* parse a "set severity-output" command. */
 static int cli_parse_set_severity_output(char **args, char *payload, struct appctx *appctx, void *private)
 {
+       /* this will ask the applet to not output a \n after the command */
+       if (strcmp(args[3], "-") == 0)
+               appctx->st1 |= APPCTX_CLI_ST1_NOLF;
+
        if (*args[2] && set_severity_output(&appctx->cli_severity_output, args[2]))
                return 0;
 
@@ -2453,7 +2457,6 @@ static int pcli_prefix_to_pid(const char *prefix)
  *  >= 0 : number of words to escape
  *  = -1 : error
  */
-
 int pcli_find_and_exec_kw(struct stream *s, char **args, int argl, char **errmsg, int *next_pid)
 {
        if (argl < 1)
@@ -2533,6 +2536,21 @@ int pcli_find_and_exec_kw(struct stream *s, char **args, int argl, char **errmsg
                if ((argl > 1) && (strcmp(args[1], "on") == 0))
                        s->pcli_flags |= ACCESS_MCLI_DEBUG;
                return argl;
+       } else if (strcmp(args[0], "set") == 0) {
+               if ((argl > 1) && (strcmp(args[1], "severity-output") == 0)) {
+                       if ((argl > 2) &&strcmp(args[2], "none") == 0) {
+                               s->pcli_flags &= ~(ACCESS_MCLI_SEVERITY_NB|ACCESS_MCLI_SEVERITY_STR);
+                       } else if ((argl > 2) && strcmp(args[2], "string") == 0) {
+                               s->pcli_flags |= ACCESS_MCLI_SEVERITY_STR;
+                       } else if ((argl > 2) && strcmp(args[2], "number") == 0) {
+                               s->pcli_flags |= ACCESS_MCLI_SEVERITY_NB;
+                       } else {
+                               memprintf(errmsg, "one of 'none', 'number', 'string' is a required argument\n");
+                               return -1;
+                       }
+                       /* only skip argl if we have "set severity-output" not only "set" */
+                       return argl;
+               }
        }
 
        return 0;
@@ -2711,6 +2729,16 @@ int pcli_parse_request(struct stream *s, struct channel *req, char **errmsg, int
                        ci_insert_line2(req, 0, "expert-mode on -", strlen("expert-mode on -"));
                        ret += strlen("expert-mode on -") + 2;
                }
+               if (s->pcli_flags & ACCESS_MCLI_SEVERITY_STR) {
+                       const char *cmd = "set severity-output string -";
+                       ci_insert_line2(req, 0, cmd, strlen(cmd));
+                       ret += strlen(cmd) + 2;
+               }
+               if (s->pcli_flags & ACCESS_MCLI_SEVERITY_NB) {
+                       const char *cmd = "set severity-output number -";
+                       ci_insert_line2(req, 0, cmd, strlen(cmd));
+                       ret += strlen(cmd) + 2;
+               }
 
                if (pcli_has_level(s, ACCESS_LVL_ADMIN)) {
                        goto end;