diff --git a/include/haproxy/ring-t.h b/include/haproxy/ring-t.h index a379265cf..7e4d5188a 100644 --- a/include/haproxy/ring-t.h +++ b/include/haproxy/ring-t.h @@ -92,6 +92,10 @@ * removed */ +/* ring watch flags to be used when watching the ring */ +#define RING_WF_WAIT_MODE 0x00000001 /* wait for new contents */ +#define RING_WF_SEEK_NEW 0x00000002 /* seek to new contents */ + struct ring { struct buffer buf; // storage area size_t ofs; // absolute offset in history of the buffer's head diff --git a/include/haproxy/ring.h b/include/haproxy/ring.h index c400f915d..a3a55d8fb 100644 --- a/include/haproxy/ring.h +++ b/include/haproxy/ring.h @@ -33,7 +33,7 @@ void ring_free(struct ring *ring); ssize_t ring_write(struct ring *ring, size_t maxlen, const struct ist pfx[], size_t npfx, const struct ist msg[], size_t nmsg); int ring_attach(struct ring *ring); void ring_detach_appctx(struct ring *ring, struct appctx *appctx, size_t ofs); -int ring_attach_cli(struct ring *ring, struct appctx *appctx); +int ring_attach_cli(struct ring *ring, struct appctx *appctx, uint flags); int cli_io_handler_show_ring(struct appctx *appctx); void cli_io_release_show_ring(struct appctx *appctx); diff --git a/src/errors.c b/src/errors.c index 109ec0aaa..bd3c271f4 100644 --- a/src/errors.c +++ b/src/errors.c @@ -356,7 +356,7 @@ static int cli_parse_show_startup_logs(char **args, char *payload, struct appctx if (!startup_logs) return cli_msg(appctx, LOG_INFO, "\n"); // nothing to print - return ring_attach_cli(startup_logs, appctx); + return ring_attach_cli(startup_logs, appctx, 0); } /* register cli keywords */ diff --git a/src/ring.c b/src/ring.c index bfbeed998..031423304 100644 --- a/src/ring.c +++ b/src/ring.c @@ -248,9 +248,9 @@ void ring_detach_appctx(struct ring *ring, struct appctx *appctx, size_t ofs) * 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. It automatically sets the io_handler and io_release callbacks if - * they were not set. + * they were not set. The take a combination of RING_WF_*. */ -int ring_attach_cli(struct ring *ring, struct appctx *appctx) +int ring_attach_cli(struct ring *ring, struct appctx *appctx, uint flags) { if (!ring_attach(ring)) return cli_err(appctx, @@ -263,6 +263,7 @@ int ring_attach_cli(struct ring *ring, struct appctx *appctx) appctx->io_release = cli_io_release_show_ring; appctx->ctx.cli.p0 = ring; appctx->ctx.cli.o0 = ~0; // start from the oldest event + appctx->ctx.cli.i0 = flags; return 0; } @@ -306,7 +307,7 @@ int cli_io_handler_show_ring(struct appctx *appctx) ofs = 0; /* going to the end means looking at tail-1 */ - if (appctx->ctx.cli.i0 & 2) + if (appctx->ctx.cli.i0 & RING_WF_SEEK_NEW) ofs += b_data(buf) - 1; HA_ATOMIC_INC(b_peek(buf, ofs)); @@ -357,7 +358,7 @@ int cli_io_handler_show_ring(struct appctx *appctx) appctx->ctx.cli.o0 = ofs; HA_RWLOCK_RDUNLOCK(LOGSRV_LOCK, &ring->lock); - if (ret && (appctx->ctx.cli.i0 & 1)) { + if (ret && (appctx->ctx.cli.i0 & RING_WF_WAIT_MODE)) { /* we've drained everything and are configured to wait for more * data or an event (keypress, close) */ diff --git a/src/sink.c b/src/sink.c index 65a218d63..9f0bfb8bf 100644 --- a/src/sink.c +++ b/src/sink.c @@ -234,6 +234,7 @@ int sink_announce_dropped(struct sink *sink, int facility) static int cli_parse_show_events(char **args, char *payload, struct appctx *appctx, void *private) { struct sink *sink; + uint ring_flags; int arg; args++; // make args[1] the 1st arg @@ -264,17 +265,18 @@ static int cli_parse_show_events(char **args, char *payload, struct appctx *appc if (sink->type != SINK_TYPE_BUFFER) return cli_msg(appctx, LOG_NOTICE, "Nothing to report for this sink"); + ring_flags = 0; for (arg = 2; *args[arg]; arg++) { if (strcmp(args[arg], "-w") == 0) - appctx->ctx.cli.i0 |= 1; // wait mode + ring_flags |= RING_WF_WAIT_MODE; else if (strcmp(args[arg], "-n") == 0) - appctx->ctx.cli.i0 |= 2; // seek to new + ring_flags |= RING_WF_SEEK_NEW; else if (strcmp(args[arg], "-nw") == 0 || strcmp(args[arg], "-wn") == 0) - appctx->ctx.cli.i0 |= 3; // seek to new + wait + ring_flags |= RING_WF_WAIT_MODE | RING_WF_SEEK_NEW; else return cli_err(appctx, "unknown option"); } - return ring_attach_cli(sink->ctx.ring, appctx); + return ring_attach_cli(sink->ctx.ring, appctx, ring_flags); } /* Pre-configures a ring proxy to emit connections */