* 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
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);
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 */
* 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 <flags> 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,
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;
}
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));
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)
*/
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
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 */