summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWilliam Lallemand <wlallemand@haproxy.org>2023-05-14 18:36:00 +0200
committerWilliam Lallemand <wlallemand@haproxy.org>2023-05-14 18:42:31 +0200
commit1601eebcd1dfe47e3222531c91db196e836f562e (patch)
tree905233a166284f04273ea6849e03e80ad05326ab
parent5414d82ce52884d8d3d55c58e2fe137beda24f3b (diff)
downloadhaproxy-1601eebcd1dfe47e3222531c91db196e836f562e.tar.gz
MEDIUM: mworker/cli: does not disconnect the master CLI upon error
In the proxy CLI analyzer, when pcli_parse_request returns -1, the client was shut to prevent any problem with the master CLI. This behavior is a little bit excessive and not handy at all in prompt mode. For example one could have activated multiples mode, then have an error which disconnect the CLI, and they would have to reconnect and enter all the modes again. This patch introduces the pcli_error() function, which only output an error and flush the input buffer, instead of closing everything. When encountering a parsing error, this function is used, and the prompt is written again, without any disconnection.
-rw-r--r--src/cli.c32
1 files changed, 24 insertions, 8 deletions
diff --git a/src/cli.c b/src/cli.c
index 86cc92503..7d6f6675e 100644
--- a/src/cli.c
+++ b/src/cli.c
@@ -2305,9 +2305,26 @@ void pcli_write_prompt(struct stream *s)
co_inject(oc, msg->area, msg->data);
}
-
/* The pcli_* functions are used for the CLI proxy in the master */
+
+/* flush the input buffer and output an error */
+void pcli_error(struct stream *s, const char *msg)
+{
+ struct buffer *buf = get_trash_chunk();
+ struct channel *oc = &s->res;
+ struct channel *ic = &s->req;
+
+ chunk_initstr(buf, msg);
+
+ if (likely(buf && buf->data))
+ co_inject(oc, buf->area, buf->data);
+
+ channel_erase(ic);
+
+}
+
+/* flush the input buffer, output the error and close */
void pcli_reply_and_close(struct stream *s, const char *msg)
{
struct buffer *buf = get_trash_chunk();
@@ -2740,13 +2757,12 @@ read_again:
pcli_write_prompt(s);
goto read_again;
} else if (to_forward == -1) {
- if (errmsg) {
- /* there was an error during the parsing */
- pcli_reply_and_close(s, errmsg);
- s->req.analysers &= ~AN_REQ_WAIT_CLI;
- return 0;
- }
- goto missing_data;
+ if (!errmsg) /* no error means missing data */
+ goto missing_data;
+
+ /* there was an error during the parsing */
+ pcli_error(s, errmsg);
+ pcli_write_prompt(s);
}
return 0;