shithub: riscv

Download patch

ref: 839f58e99af49deaa14da76a10635086175145d6
parent: ff2ebe6cfdacd890a74a6d2f9b0acd062d2633b7
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Sun Nov 27 11:13:33 EST 2022

trampoline: Add -o option to send protocol-specific ctl string

--- a/sys/man/8/trampoline
+++ b/sys/man/8/trampoline
@@ -14,6 +14,9 @@
 .B -m
 .I netdir
 ] [
+.B -o
+.I opt
+] [
 .B -t
 .I timeout
 ]
@@ -58,6 +61,12 @@
 and the attribute
 .BR trampok .
 If no such entry is found, the call is rejected.
+.TP
+.BI -t " opt
+Write a protocol-specific control string
+.I opt
+to the connections control file.
+This can be specified multiple times.
 .TP
 .BI -t " timeout
 Terminates the connection after
--- a/sys/src/cmd/aux/trampoline.c
+++ b/sys/src/cmd/aux/trampoline.c
@@ -28,10 +28,13 @@
 int		timeout;
 int		activity;
 
+int		nopts;
+char		*opts[16];
+
 void
 usage(void)
 {
-	fprint(2, "usage: trampoline [-9] [-a addr] [-m netdir] [-t timeout] addr\n");
+	fprint(2, "usage: trampoline [-9] [-a addr] [-m netdir] [-o opt] [-t timeout] addr\n");
 	exits("usage");
 }
 
@@ -39,7 +42,7 @@
 main(int argc, char **argv)
 {
 	char *altaddr, *checkmac, *mac;
-	int fd, fd0, fd1;
+	int fd, fd0, fd1, ctl, i;
 	void (*x)(int, int);
 	Endpoints *ep;
 
@@ -59,6 +62,11 @@
 	case 't':
 		timeout = atoi(EARGF(usage()));
 		break;
+	case 'o':
+		if(nopts >= nelem(opts))
+			sysfatal("too many -o options");
+		opts[nopts++] = EARGF(usage());
+		break;
 	default:
 		usage();
 	}ARGEND;
@@ -87,9 +95,15 @@
 			sysfatal("dial %s: %r", altaddr);
 		fd1 = fd0;
 	}
-	fd = dial(argv[0], 0, 0, 0);
+	fd = dial(argv[0], 0, 0, &ctl);
 	if(fd < 0)
 		sysfatal("dial %s: %r", argv[0]);
+
+	for(i = 0; i < nopts; i++){
+		if(write(ctl, opts[i], strlen(opts[i])) < 0)
+			fprint(2, "%s: can't write %s: %r\n", argv0, opts[i]);
+	}
+	close(ctl);
 
 	rfork(RFNOTEG);
 	if(timeout > 0){