Switch from tee to cat in psub --fifo

Prior to this fix, we would write to a fifo via cat >$filename & .
However in some cases (and soon in all cases) we open the file before
the fork, not after. This results in a deadlock because the file open
cannot succeed until a write begins.

Switch to using tee to write to the file. Because tee opens the file itself,
fish is no longer responsible and the deadlock is resolved.
This commit is contained in:
ridiculousfish 2019-01-28 23:17:42 -08:00
parent dbe906b79e
commit 6c22c8893b

View file

@ -29,7 +29,10 @@ function psub --description "Read from stdin into a file and output the filename
or return
set filename $dirname/psub.fifo"$_flag_suffix"
mkfifo $filename
cat >$filename &
# Note that if we were to do the obvious `cat >$filename &`, we would deadlock
# because $filename may be opened before the fork. Use tee to ensure it is opened
# after the fork.
tee $filename >/dev/null &
else if test -z "$_flag_suffix"
set filename (mktemp $tmpdir/.psub.XXXXXXXXXX)
cat >$filename