shithub: tlsclient

Download patch

ref: 3163e5253240db5a98d05b8392704dd8c99fc196
parent: 396f8f369db25a0d6b0120ea08ecc84d089b8202
author: Jacob Moody <moody@posixcafe.org>
date: Tue Feb 16 08:23:44 EST 2021

/dev/tty works so we dont need the console fd hack

--- a/9cpu
+++ b/9cpu
@@ -32,12 +32,10 @@
 
 len=`echo $cmd | wc -c`
 
-USER=$user AUTH=$auth CPU=$cpu tlsclient -f -p 17019 sh <(cat <<EOF
-consin=\`head -c 1\`
-consout=\`head -c 1\`
+USER=$user AUTH=$auth CPU=$cpu tlsclient -p 17019 sh <(cat <<EOF
 printf '%7ld\n' $len
 echo $cmd
-cat <&\$consin 2>/dev/null &
-cat >&\$consout 2>/dev/null 
+cat </dev/tty 2>/dev/null &
+cat >/dev/tty 2>/dev/null
 EOF
 )
--- a/README
+++ b/README
@@ -3,15 +3,10 @@
 tlsclient comes with two programs, tlsclient itself and 9cpu which uses tlsclient
 to connect to a 9front cpu server and acts as rcpu(1).
 
-Due to the lack of /dev/cons on unix, an additional flag '-f' is added which
-causes tlsclient to dup additional copies of it's own stdin and stdout and place
-them on additional file descriptors for the child process. The additional file
-descriptor numbers are sent as the first two bytes to the child process.
-
 Most of this code is pillaged from jsdrawterm: https://github.com/aiju/jsdrawterm
 
 Usage:
-	tlsclient [-f] [ -u user] [ -h host ] [ -a auth ] -p port cmd...
+	tlsclient [ -u user] [ -h host ] [ -a auth ] -p port cmd...
 	9cpu [ -u user ] [ -h host ] [ -a auth ] cmd...
 
 Bugs:
--- a/cpu.c
+++ b/cpu.c
@@ -98,7 +98,7 @@
 void
 usage(void)
 {
-	fprint(2, "Usage: %s [-f] [ -u user ] [ -h host ] [ -a authserver ] -p port cmd...\n", argv0);
+	fprint(2, "Usage: %s [ -u user ] [ -h host ] [ -a authserver ] -p port cmd...\n", argv0);
 	exits("usage");
 }
 
@@ -114,10 +114,8 @@
 	int pout[2];
 	int infd, outfd;
 	pid_t execc, xferc;
-	int consin, consout, consflag;
 
 	execc = xferc = 0;
-	consflag = 0;
 	infd = 0;
 	outfd = 1;
 	user = getenv("USER");	
@@ -131,7 +129,6 @@
 		case 'h': host = EARGF(usage()); break;
 		case 'a': authserver = EARGF(usage()); break;
 		case 'p': port = EARGF(usage()); break;
-		case 'f': consflag++; break;
 	} ARGEND
 
 	if(user == nil || host == nil || authserver == nil || port == nil)
@@ -149,16 +146,6 @@
 	if(*argv){
 		pipe(pin);
 		pipe(pout);
-		if(consflag){
-			/*
-			 * Unix has no /dev/cons, so there is no way to read
-			 * and write from the terminal if stdin and stdout
-			 * are dup'd over with the socket. This gives a bit
-			 * of a back door in to the orginal stdin and stdout.
-			 */
-			consin = dup(0);
-			consout = dup(1);
-		}
 		switch((execc = fork())){
 		case -1:
 			sysfatal("fork");
@@ -174,16 +161,6 @@
 		close(pin[0]);
 		infd = pout[0];
 		outfd = pin[1];
-		if(consflag){
-			/*
-			 * For the sake of portability,
-			 * send the "cons" fds as the first
-			 * to lines to the child process to avoid
-			 * having to assume the next two fds
-			 */
-			n = sprint(buf, "%d%d", consin, consout);
-			write(pin[1], buf, n);
-		}
 	}
 
 	fd = unix_dial(host, port);