From 6c22c8893bfe9a01679f9dbb10d0ef2486df3364 Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Mon, 28 Jan 2019 23:17:42 -0800 Subject: [PATCH] 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. --- share/functions/psub.fish | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/share/functions/psub.fish b/share/functions/psub.fish index b764d6f35..8c8a7eac8 100644 --- a/share/functions/psub.fish +++ b/share/functions/psub.fish @@ -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