shithub: riscv

Download patch

ref: c78384333ec9f0b819ba3a1fa508b89576a6eff6
parent: 98a66671cf6900b6239ac1b48638ffa835e75c27
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Sun Nov 20 10:40:12 EST 2022

aux/listen: add -o and -O options

--- a/sys/man/8/listen
+++ b/sys/man/8/listen
@@ -12,6 +12,10 @@
 .IR namespace ]
 .RB [ -p
 .IR maxprocs ]
+.RB [ -o
+.IR copt ]
+.RB [ -O
+.IR sopt ]
 .RB [ -a
 .IR addr ]
 .RI [ proto ]
@@ -20,10 +24,14 @@
 [
 .B -1tv
 ]
-.RB [ -p
-.IR maxprocs ]
 .RB [ -n
 .IR namespace ]
+.RB [ -p
+.IR maxprocs ]
+.RB [ -o
+.IR copt ]
+.RB [ -O
+.IR sopt ]
 .I addr
 .I cmd
 [
@@ -83,6 +91,21 @@
 of connection processes drops below the limit again. A
 .I maxprocs
 smaller or equal zero means no limit (default).
+The
+.B -o
+and
+.B -O
+options cause protocol-specific control messages
+to be written to the control file of the listening
+server connection
+.B -O
+or the incoming client
+connection
+.BR -o .
+They can be specified multiple
+times. See
+.IR ip (3)
+for details.
 Option
 .B -q
 suppresses affirmative log information.
@@ -251,7 +274,8 @@
 .B /rc/bin/service*
 .SH "SEE ALSO"
 .IR authsrv (6),
-.IR dial (2)
+.IR dial (2),
+.IR ip (3)
 .SH BUGS
 .IR Srvdir ,
 .IR trustsrvdir
--- a/sys/src/cmd/aux/listen.c
+++ b/sys/src/cmd/aux/listen.c
@@ -38,10 +38,15 @@
 
 char *namespace;
 
+int nsopts, ncopts = 1;
+char *sopts[16], *copts[16] = { "keepalive", };
+
 void
 usage(void)
 {
-	error("usage: aux/listen [-iq] [-d srvdir] [-t trustsrvdir] [-n namespace] [-p maxprocs]"
+	error("usage: aux/listen [-iq] [-d srvdir] [-t trustsrvdir]"
+		" [-n namespace] [-p maxprocs]"
+		" [-o copt] [-O sopt]"
 		" [-a addr] [proto]");
 }
 
@@ -79,6 +84,16 @@
 	case 'p':
 		maxprocs = atoi(EARGF(usage()));
 		break;
+	case 'o':
+		if(ncopts >= nelem(copts))
+			sysfatal("too many -o options");
+		copts[ncopts++] = EARGF(usage());
+		break;
+	case 'O':
+		if(nsopts >= nelem(sopts))
+			sysfatal("too many -O options");
+		sopts[nsopts++] = EARGF(usage());
+		break;
 	case 'i':
 		/*
 		 * fixed configuration, no periodic
@@ -134,7 +149,7 @@
 void
 listendir(char *srvdir, int trusted)
 {
-	int ctl, pid, start;
+	int ctl, pid, start, i;
 	char dir[40], err[128], ds[128];
 	char prog[Maxpath], serv[Maxserv], ns[Maxpath];
 	long childs;
@@ -343,8 +358,13 @@
 dolisten(char *dir, int ctl, char *serv, char *prog, long *pchilds)
 {
 	char ndir[40], wbuf[64];
-	int nctl, data, wfd, nowait;
+	int nctl, data, wfd, nowait, i;
 	
+	for(i = 0; i < nsopts; i++){
+		if(write(ctl, sopts[i], strlen(sopts[i])) < 0)
+			syslog(1, listenlog, "%s/ctl: can't write %s: %r", dir, sopts[i]);
+	}
+
 	wfd = -1;
 	nowait = RFNOWAIT;
 	if(pchilds && maxprocs > 0){
@@ -414,7 +434,8 @@
 				syslog(1, listenlog, "can't open %s/data: %r", ndir);
 				exits(0);
 			}
-			fprint(nctl, "keepalive");
+			for(i = 0; i < ncopts; i++)
+				write(nctl, copts[i], strlen(copts[i]));
 			close(ctl);
 			close(nctl);
 			if(wfd >= 0)
--- a/sys/src/cmd/aux/listen1.c
+++ b/sys/src/cmd/aux/listen1.c
@@ -7,11 +7,16 @@
 int trusted;
 int oneshot;
 char *nsfile;
+int nsopts, ncopts = 1;
+char *sopts[16], *copts[16] = { "keepalive", };
 
 void
 usage(void)
 {
-	fprint(2, "usage: listen1 [-1tv] [-p maxprocs] [-n namespace] address cmd args...\n");
+	fprint(2, "usage: listen1 [-1tv]"
+		" [-n namespace] [-p maxprocs]"
+		" [-O msg] [-o msg]"
+		" address cmd args...\n");
 	exits("usage");
 }
 
@@ -51,7 +56,7 @@
 main(int argc, char **argv)
 {
 	char data[60], dir[40], ndir[40], wbuf[64];
-	int ctl, nctl, fd;
+	int ctl, nctl, fd, i;
 	int wfd, nowait, procs;
 	Dir *d;
 
@@ -73,6 +78,16 @@
 	case 'n':
 		nsfile = EARGF(usage());
 		break;
+	case 'o':
+		if(ncopts >= nelem(copts))
+			sysfatal("too many -o options");
+		copts[ncopts++] = EARGF(usage());
+		break;
+	case 'O':
+		if(nsopts >= nelem(sopts))
+			sysfatal("too many -O options");
+		sopts[nsopts++] = EARGF(usage());
+		break;
 	}ARGEND
 
 	if(argc < 2)
@@ -95,6 +110,11 @@
 	if(ctl < 0)
 		sysfatal("announce %s: %r", argv[0]);
 
+	for(i = 0; i < nsopts; i++){
+		if(write(ctl, sopts[i], strlen(sopts[i])) < 0)
+			fprint(2, "%s/ctl: can't write %s: %r\n", dir, sopts[i]);
+	}
+
 	wfd = -1;
 	nowait = RFNOWAIT;
 	if(maxprocs > 0){
@@ -147,7 +167,10 @@
 		}
 
 		print("incoming call for %s from %s in %s\n", argv[0], remoteaddr(ndir), ndir);
-		fprint(nctl, "keepalive");
+
+		for(i = 0; i < ncopts; i++)
+			write(nctl, copts[i], strlen(copts[i]));
+
 		close(ctl);
 		close(nctl);
 		if(wfd >= 0)