From: Willy Tarreau Date: Mon, 7 Sep 2026 13:56:35 +0000 (+0200) Subject: MINOR: ring: permit to combine options on "show events" X-Git-Tag: v3.5-dev7~67 X-Git-Url: https://git.kaiwu.me/?a=commitdiff_plain;h=98ccfde3f0a5a72954dfedad5d5b519a0de99e58;p=haproxy.git MINOR: ring: permit to combine options on "show events" The "show events" command supports a handful of options starting with a "-", but only a few combinations were manually checked for (nw and wn), other ones may not be combined. This patch changes the parser to permit any combination, continuing to process them in declaration order, so that -nsw or -rnw work. The doc was updated. This also updates the help message which would previously not list all options by lack of room. --- diff --git a/doc/management.txt b/doc/management.txt index 9f8f7df14..7f41b3acc 100644 --- a/doc/management.txt +++ b/doc/management.txt @@ -3193,8 +3193,7 @@ show events [] [-w] [-n] [-0] [-r] [-s] them. It is possible to stop the operation by entering any input (which will be discarded) or by closing the session. Finally, option "-n" is used to directly seek to the end of the buffer, which is often convenient when - combined with "-w" to only report new events. For convenience, "-wn" or "-nw" - may be used to enable both options at once. By default, all events are + combined with "-w" to only report new events. By default, all events are delimited by a line feed character ('\n' or 10 or 0x0A). It is possible to change this to the NUL character ('\0' or 0) by passing the "-0" argument. Option "-s" sanitizes the output, so that binary contents resulting from @@ -3208,7 +3207,8 @@ show events [] [-w] [-n] [-0] [-r] [-s] not be interpreted as special (e.g. monitoring scripts whose output is copied verbatim into reports). Finally, "-r" undoes "-s" and may be appended in cases where "-s" was unconditionally appended, or as a future-proof way to - ensure long-term compatibility in case the default changes. + ensure long-term compatibility in case the default changes. All options + starting with "-" may conveniently be combined (e.g. "-nsw"). show fd [-!plcfbs]* [[]/[] | ] Dump the list of either all open file descriptors or just the one number diff --git a/src/sink.c b/src/sink.c index ea6fe987d..25f76ba3f 100644 --- a/src/sink.c +++ b/src/sink.c @@ -363,7 +363,7 @@ static int cli_parse_show_events(char **args, char *payload, struct appctx *appc if (!*args[1]) { /* no arg => report the list of supported sink */ - chunk_printf(&trash, "Supported events sinks are listed below. Add -0(zero), -w(wait), -n(new), -r(raw), -s(anitize). Any key to stop.\n"); + chunk_printf(&trash, "Supported events sinks are listed below. Add combinations of -0(zero), -w(wait), -n(new), -r(raw), -s(anitize). Any key to stop.\n"); list_for_each_entry(sink, &sink_list, sink_list) { chunk_appendf(&trash, " %-10s : type=%s, %u dropped, %s\n", sink->name, @@ -389,20 +389,21 @@ static int cli_parse_show_events(char **args, char *payload, struct appctx *appc ring_flags = 0; for (arg = 2; *args[arg]; arg++) { - if (strcmp(args[arg], "-w") == 0) - ring_flags |= RING_WF_WAIT_MODE; - else if (strcmp(args[arg], "-n") == 0) - ring_flags |= RING_WF_SEEK_NEW; - else if (strcmp(args[arg], "-0") == 0) - ring_flags |= RING_WF_END_ZERO; - else if (strcmp(args[arg], "-nw") == 0 || strcmp(args[arg], "-wn") == 0) - ring_flags |= RING_WF_WAIT_MODE | RING_WF_SEEK_NEW; - else if (strcmp(args[arg], "-s") == 0) - ring_flags |= RING_WF_SANITIZE; - else if (strcmp(args[arg], "-r") == 0) - ring_flags &= ~RING_WF_SANITIZE; - else - return cli_err(appctx, "unknown option"); + const char *p = args[arg]; + + if (*p != '-') + continue; + + while (*++p) { + switch (*p) { + case '0' : ring_flags |= RING_WF_END_ZERO; break; + case 'n' : ring_flags |= RING_WF_SEEK_NEW; break; + case 'w' : ring_flags |= RING_WF_WAIT_MODE; break; + case 's' : ring_flags |= RING_WF_SANITIZE; break; + case 'r' : ring_flags &= ~RING_WF_SANITIZE; break; + default: return cli_err(appctx, "unknown option"); + } + } } return ring_attach_cli(sink->ctx.ring, appctx, ring_flags); } @@ -1497,7 +1498,7 @@ REGISTER_POST_CHECK(sink_postcheck); REGISTER_POST_DEINIT(sink_deinit); static struct cli_kw_list cli_kws = {{ },{ - { { "show", "events", NULL }, "show events [] [-w] [-n] [-0] : show event sink state", cli_parse_show_events, NULL, NULL }, + { { "show", "events", NULL }, "show events [] [-0nrsw]* : show event sink state", cli_parse_show_events, NULL, NULL }, {{},} }};