From: Willy Tarreau Date: Mon, 28 Apr 2025 17:09:02 +0000 (+0200) Subject: MEDIUM: mcli: replicate the current mode when enterin the worker process X-Git-Tag: v3.2-dev13~54 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=dc06495b71142f3df38d691ead9a3fb8fb091145;p=thirdparty%2Fhaproxy.git MEDIUM: mcli: replicate the current mode when enterin the worker process 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. --- diff --git a/doc/management.txt b/doc/management.txt index 52d3c61c4..66fecc635 100644 --- a/doc/management.txt +++ b/doc/management.txt @@ -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) diff --git a/src/cli.c b/src/cli.c index 954087140..41e8750ff 100644 --- 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)); } }