]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MEDIUM: mcli: replicate the current mode when enterin the worker process
authorWilly Tarreau <w@1wt.eu>
Mon, 28 Apr 2025 17:09:02 +0000 (19:09 +0200)
committerWilly Tarreau <w@1wt.eu>
Mon, 28 Apr 2025 18:21:06 +0000 (20:21 +0200)
While humans can find it convenient to enter the worker process in prompt
mode, for external tools it will not be convenient to have to systematically
disable it. A better approach is to replicate the master socket's mode
there, since it has already been configured to suit the user: interactive,
prompt and timed modes are automatically passed to the worker process.
This makes the using the worker commands more natural from the master
process, without having to systematically adapt it for each new connection.

doc/management.txt
src/cli.c

index 52d3c61c4c715b718c1ebd8eee2d991223cb44cd..66fecc635e531512366402e83104a800c3d52c19 100644 (file)
@@ -4427,7 +4427,8 @@ Example:
   interactive session on the worker process by not specifying any command
   (i.e. "@@1" on its own line). This session can be terminated either by
   closing the connection or by quitting the worker process (using the "quit"
-  command).
+  command). In this case, the prompt mode of the master socket (interactive,
+  prompt, timed) is propagated into the worker process.
 
   Examples:
     # gracefully close connections and delete a server once idle (wait max 10s)
index 954087140b73d4cae2e23b56ef2befb9d64624a6..41e8750ff26c7e6bc7dad01445cc04c491ce275a 100644 (file)
--- a/src/cli.c
+++ b/src/cli.c
@@ -3039,11 +3039,27 @@ int pcli_find_bidir_prefix(struct stream *s, struct channel *req, char **str, co
                /* forward what remains */
                ret = end - p;
 
-               /* without any command, simply enter the worker in interactive mode */
+               /* without any command, simply enter the worker in interactive
+                * mode or prompt mode (the same as currently used in the master).
+                * The goal is to make it easy for both scripts and humans to
+                * enter in the same mode in the worker as they were in the master.
+                */
                if (!ret) {
-                       const char *cmd = "prompt\n";
-                       ci_insert(req, 0, cmd, strlen(cmd));
-                       ret += strlen(cmd);
+                       const char *cmd;
+
+                       cmd = "prompt";
+                       ret += ci_insert(req, ret, cmd, strlen(cmd));
+
+                       cmd = (s->pcli_flags & PCLI_F_PROMPT) ? " p" : " i";
+                       ret += ci_insert(req, ret, cmd, strlen(cmd));
+
+                       if (s->pcli_flags & PCLI_F_TIMED) {
+                               cmd = " timed";
+                               ret += ci_insert(req, ret, cmd, strlen(cmd));
+                       }
+
+                       cmd = "\n";
+                       ret += ci_insert(req, ret, cmd, strlen(cmd));
                }
        }