shithub: mq

Download patch

ref: d984bc03cb18599766d752b4622f5d527e900933
parent: 0ee1f70dd0a81d13210dd76568eeb6977606d1d7
author: kvik <kvik@a-b.xyz>
date: Tue Sep 15 11:25:03 EDT 2020

mq: reading 'ctl' file reports current configuration

--- a/src/mq.c
+++ b/src/mq.c
@@ -95,7 +95,7 @@
 		goto err;
 	filesettype(d, Qmq);
 
-	if((ctl = createfile(d, "ctl", nil, 0220, mq)) == nil)
+	if((ctl = createfile(d, "ctl", nil, 0664, mq)) == nil)
 		goto err;
 	filesettype(ctl, Qctl);
 	closefile(ctl);
@@ -314,6 +314,28 @@
 	respond(r, nil);
 }
 
+void
+ctlread(Req *r)
+{
+	File *f = r->fid->file;
+	Mq *mq = f->aux;
+	char buf[256];
+
+	char *mode2str[] = {
+		[Message] "message",
+		[Coalesce] "coalesce",
+	};
+	char *replay2str[] = {
+		[Replayoff] "off",
+		[Replaylast] "last",
+		[Replayall] "all",
+	};
+	snprint(buf, sizeof buf, "data %s\nreplay %s\n",
+		mode2str[mq->mode], replay2str[mq->replay]);
+	readstr(r, buf);
+	respond(r, nil);
+}
+
 enum {
 	Cmddata,
 	Cmdreplay,
@@ -476,6 +498,9 @@
 	case Qstream:
 	case Qorder:
 		streamread(r);
+		break;
+	case Qctl:
+		ctlread(r);
 		break;
 	default:
 		respond(r, "forbidden");