CLEANUP: ring: pass the ring watch flags to ring_attach_cli(), not in ctx.cli

The ring watch flags (wait, seek end) were dangerously passed via ctx.cli.i0
from "show buf" in sink.c:cli_parse_show_events(), or implicitly reset in
"show errors". That's very unconvenient, difficult to follow, and prone to
short-term breakage.

Let's pass an extra argument to ring_attach_cli() to take these flags, now
defined in ring-t.h as RING_WF_*, and let the function set them itself
where appropriate (still ctx.cli.i0 for now).
diff --git a/include/haproxy/ring-t.h b/include/haproxy/ring-t.h
index a379265..7e4d518 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 c400f91..a3a55d8 100644
--- a/include/haproxy/ring.h
+++ b/include/haproxy/ring.h
@@ -33,7 +33,7 @@
 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 109ec0a..bd3c271 100644
--- a/src/errors.c
+++ b/src/errors.c
@@ -356,7 +356,7 @@
 	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 bfbeed9..0314233 100644
--- a/src/ring.c
+++ b/src/ring.c
@@ -248,9 +248,9 @@
  * 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,
@@ -263,6 +263,7 @@
                 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 @@
 		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 @@
 	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 65a218d..9f0bfb8 100644
--- a/src/sink.c
+++ b/src/sink.c
@@ -234,6 +234,7 @@
 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 @@
 	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 */