]> git.kaiwu.me - haproxy.git/commitdiff
MINOR: ring: permit to combine options on "show events"
authorWilly Tarreau <w@1wt.eu>
Mon, 7 Sep 2026 13:56:35 +0000 (15:56 +0200)
committerWilly Tarreau <w@1wt.eu>
Mon, 7 Sep 2026 14:29:16 +0000 (16:29 +0200)
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.

doc/management.txt
src/sink.c

index 9f8f7df145e0b78ea1415bca754e8be8032955ef..7f41b3accf91653f9b17132f4c9c3a47ec66cafd 100644 (file)
@@ -3193,8 +3193,7 @@ show events [<sink>] [-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 [<sink>] [-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]* [[<tgid>]/[<fd>] | <fd>]
   Dump the list of either all open file descriptors or just the one number <fd>
index ea6fe987d504391a19f210f548830f6bf44892be..25f76ba3f56c2a218a4dbf5c2b308feb5c75b5b6 100644 (file)
@@ -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 [<sink>] [-w] [-n] [-0]     : show event sink state", cli_parse_show_events, NULL, NULL },
+       { { "show", "events", NULL }, "show events [<sink>] [-0nrsw]*          : show event sink state", cli_parse_show_events, NULL, NULL },
        {{},}
 }};