9front - general discussion about 9front
 help / color / mirror / Atom feed
* [9front] [PATCH] ircrc: fix race with pipe causing hangup
@ 2022-11-05  2:57 Michael Forney
  0 siblings, 0 replies; only message in thread
From: Michael Forney @ 2022-11-05  2:57 UTC (permalink / raw)
  To: 9front


If the work function opens and closes $netdir/data for an echo
redirection *before* the asynchronous cat process opens it,
aux/trampoline (or tlsclient) will receive a hangup, terminating the
connection.

To fix this, redirect work's stdout to $netdir/data so that it remains
open, and adjust the echo commands accordingly.
---
diff ccf20e5a2a7c14b2016de1fe0612e272bad693dd 04b541668a06e85ce350ae81f2b0c8a2dd575f56
--- a/rc/bin/ircrc
+++ b/rc/bin/ircrc
@@ -32,14 +32,14 @@
 
 fn work {
         if(~ $#serverpass 1)
-                echo PASS $serverpass > $netdir/data
-	echo USER $user foo bar :$realname > $netdir/data
-	echo NICK $nick > $netdir/data
+                echo PASS $serverpass
+	echo USER $user foo bar :$realname
+	echo NICK $nick
 	if (~ $#pass 1)
-		echo PRIVMSG 'nickserv :'identify $"pass > $netdir/data
+		echo PRIVMSG 'nickserv :'identify $"pass
 	if(! ~ $target ''){
 		title
-		echo JOIN $target > $netdir/data
+		echo JOIN $target
 	}
 	if(~ $target *,*)
 		target = `{echo $target | awk -F',' '{print $NF}'}
@@ -46,7 +46,7 @@
 	while (cmd=`{read}) {
 		s=$status
 		if(~ $s *eof) {
-			echo  QUIT : Leaving... > $netdir/data
+			echo  QUIT : Leaving...
 			exit
 		}
 		msg=()
@@ -53,7 +53,7 @@
 		out=()
 		switch ($cmd(1)) {
 		case /!
-			eval `{mshift $cmd} | while(rc=`{read})echo 'PRIVMSG '^$target^' :' $rc | tee $netdir/data
+			eval `{mshift $cmd} | while(rc=`{read})echo 'PRIVMSG '^$target^' :' $rc | tee /dev/cons
 		case /M
 			msg = (MODE `{mshift $cmd})
 		case /N
@@ -101,18 +101,18 @@
 		case /w
 			msg = (WHO `{mshift $cmd})
 		case /x
-			echo  QUIT : Leaving... > $netdir/data
+			echo  QUIT : Leaving...
 			exit
 		case /*
-			echo unknown command
+			echo unknown command >/dev/cons
 		case *
 			msg = 'PRIVMSG '^$target^' :'^$"cmd
 			out = '('^$target^')	⇐	'^$"cmd
 		}
 		if (! ~ $#msg 0)
-			echo $msg > $netdir/data
+			echo $msg
 		if (! ~ $#out 0)
-			echo `{etime}^' '^$out
+			echo `{etime}^' '^$out >/dev/cons
 	}
 }
 
@@ -248,6 +248,6 @@
 	tlsclient tcp!$server!$port <>$p/data1 >[1=0] &
 }
 netdir=$p
-cat $netdir/data | tr -d '\x2\x8\xd\x1f' | pretty &
-work
+<$netdir/data tr -d '\x2\x8\xd\x1f' | pretty &
+>$netdir/data work
 

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-11-05  3:01 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-05  2:57 [9front] [PATCH] ircrc: fix race with pipe causing hangup Michael Forney

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).