]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MEDIUM: mworker/cli: fix pipelined modes on master CLI
authorWilliam Lallemand <wlallemand@haproxy.com>
Thu, 8 Aug 2024 15:09:15 +0000 (17:09 +0200)
committerWilliam Lallemand <wlallemand@haproxy.com>
Thu, 8 Aug 2024 15:29:37 +0000 (17:29 +0200)
Since commit 3d93ecc ("BUG/MAJOR: cli: Restore non-interactive mode
behavior with pipelined commands") and commit 598c7f16 ("BUG/MEDIUM:
cli: Warn if pipelined commands are delimited by a \n"), the pipelined
command on the master CLI are either broken or emit warnings depending
on which version.

The reason is that mode applied on the master CLI are saved on the in
the current CLI session, and then reinserted for each pipelined command,
however, these commande were inserted as new lines.

For example:

 "@1; expert-mode on; debug dev log foo; debug dev log bar"

 Would be sent as:

  "expert mode on\ndebug dev log foo"
  "expert mode on\ndebug dev log bar"

This patch fixes the issue by using the new ci_insert() function which
inserts a string instead of a newline, and the command are now suffixed
by ';' upon insertion allowing a correct pipelined command chain.

This must be backported with the previous commit introducing ci_insert()
in every stable version.

This is broken since the 3.0 version, but it emits a warning in every
version below, because 598c7f164 was backported.

src/cli.c

index 3b88c7872a4099e2f4a18163577042e1579699ad..55965b7103942d7fe2db4f018a89dc11701bde6d 100644 (file)
--- a/src/cli.c
+++ b/src/cli.c
@@ -2918,36 +2918,36 @@ int pcli_parse_request(struct stream *s, struct channel *req, char **errmsg, int
 
                /* the mcli-debug-mode is only sent to the applet of the master */
                if ((s->pcli_flags & ACCESS_MCLI_DEBUG) && *next_pid <= 0) {
-                       ci_insert_line2(req, 0, "mcli-debug-mode on -", strlen("mcli-debug-mode on -"));
-                       ret += strlen("mcli-debug-mode on -") + 2;
+                       ci_insert(req, 0, "mcli-debug-mode on -;", strlen("mcli-debug-mode on -;"));
+                       ret += strlen("mcli-debug-mode on -;");
                }
                if (s->pcli_flags & ACCESS_EXPERIMENTAL) {
-                       ci_insert_line2(req, 0, "experimental-mode on -", strlen("experimental-mode on -"));
-                       ret += strlen("experimental-mode on -") + 2;
+                       ci_insert(req, 0, "experimental-mode on -;", strlen("experimental-mode on -;"));
+                       ret += strlen("experimental-mode on -;");
                }
                if (s->pcli_flags & ACCESS_EXPERT) {
-                       ci_insert_line2(req, 0, "expert-mode on -", strlen("expert-mode on -"));
-                       ret += strlen("expert-mode on -") + 2;
+                       ci_insert(req, 0, "expert-mode on -;", strlen("expert-mode on -;"));
+                       ret += strlen("expert-mode on -;");
                }
                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;
+                       const char *cmd = "set severity-output string -;";
+                       ci_insert(req, 0, cmd, strlen(cmd));
+                       ret += strlen(cmd);
                }
                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;
+                       const char *cmd = "set severity-output number -;";
+                       ci_insert(req, 0, cmd, strlen(cmd));
+                       ret += strlen(cmd);
                }
 
                if (pcli_has_level(s, ACCESS_LVL_ADMIN)) {
                        goto end;
                } else if (pcli_has_level(s, ACCESS_LVL_OPER)) {
-                       ci_insert_line2(req, 0, "operator -", strlen("operator -"));
-                       ret += strlen("operator -") + 2;
+                       ci_insert(req, 0, "operator -;", strlen("operator -;"));
+                       ret += strlen("operator -;");
                } else if (pcli_has_level(s, ACCESS_LVL_USER)) {
-                       ci_insert_line2(req, 0, "user -", strlen("user -"));
-                       ret += strlen("user -") + 2;
+                       ci_insert(req, 0, "user -;", strlen("user -;"));
+                       ret += strlen("user -;");
                }
        }
 end: