From: Michael Forney <mforney@mforney.org>
To: 9front@9front.org
Subject: [9front] [PATCH] ircrc: fix race with pipe causing hangup
Date: Sat, 05 Nov 2022 02:57:49 +0000 [thread overview]
Message-ID: <F087A0B9A27178DDE113C58C5C079737@mforney.org> (raw)
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
reply other threads:[~2022-11-05 3:01 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=F087A0B9A27178DDE113C58C5C079737@mforney.org \
--to=mforney@mforney.org \
--cc=9front@9front.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).