]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: ring: make the parse function automatically set the handler/release
authorWilly Tarreau <w@1wt.eu>
Fri, 15 Nov 2019 14:07:21 +0000 (15:07 +0100)
committerWilly Tarreau <w@1wt.eu>
Fri, 15 Nov 2019 14:48:12 +0000 (15:48 +0100)
ring_attach_cli() is called by the keyword parsing function to dump a
ring to the CLI. It can only work with a specific handler and release
function. Let's make it set them appropriately instead of having the
caller know these functions. This way adding a command to dump a ring
is as simple as declaring a parsing function calling ring_attach_cli().

src/ring.c
src/sink.c

index 755e69cc130c25fdb0e5f924b225f9cced46715e..b94b5699bf54261112ee262cc9eba96ad2646f9f 100644 (file)
@@ -202,7 +202,8 @@ ssize_t ring_write(struct ring *ring, size_t maxlen, const struct ist pfx[], siz
 /* Tries to attach CLI handler <appctx> as a new reader on ring <ring>. This is
  * meant to be used when registering a CLI function to dump a buffer, so it
  * returns zero on success, or non-zero on failure with a message in the appctx
- * CLI context.
+ * CLI context. It automatically sets the io_handler and io_release callbacks if
+ * they were not set.
  */
 int ring_attach_cli(struct ring *ring, struct appctx *appctx)
 {
@@ -216,6 +217,10 @@ int ring_attach_cli(struct ring *ring, struct appctx *appctx)
 
        } while (!_HA_ATOMIC_CAS(&ring->readers_count, &users, users + 1));
 
+       if (!appctx->io_handler)
+               appctx->io_handler = cli_io_handler_show_ring;
+       if (!appctx->io_release)
+                appctx->io_release = cli_io_release_show_ring;
        appctx->ctx.cli.p0 = ring;
        appctx->ctx.cli.o0 = ~0; // start from the oldest event
        return 0;
index 72e17433ea15f3d1558ed22b3f829cdde7ec7a2e..b601fae1b5a84918a06c90448b417cec37c92e4f 100644 (file)
@@ -269,7 +269,7 @@ INITCALL0(STG_REGISTER, sink_init);
 REGISTER_POST_DEINIT(sink_deinit);
 
 static struct cli_kw_list cli_kws = {{ },{
-       { { "show", "events", NULL }, "show events [<sink>] : show event sink state", cli_parse_show_events, cli_io_handler_show_ring, cli_io_release_show_ring },
+       { { "show", "events", NULL }, "show events [<sink>] : show event sink state", cli_parse_show_events, NULL, NULL },
        {{},}
 }};