ref: b7cc14789adbd31e4e7334f502782feea34a8524
parent: 4d1d8c342fc391cc8cf4b966a3c4f1d0c756d128
author: Michael Forney <mforney@mforney.org>
date: Fri Nov 4 22:57:49 EDT 2022
ircrc: fix race with pipe causing hangup 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.
--- 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