Re: Putting fifos in subshells into the background

2019-06-13 Thread maillists . rulmer
Philip Guenther  wrote:
> On Wed, Jun 12, 2019 at 12:54 AM Richard Ulmer 
> wrote:
> 
> > while making the Kakoune editor work on OpenBSD, I encountered some
> > strange behaviour [1]. This little script doesn't work with the OpenBSD
> > sh, but works at least with dash, bash and zsh:
> >
> > mkfifo 'testfifo'
> > cat "$(
> > ( printf 'foo\n' > testfifo 2>&1 ) > /dev/null 2>&1 &
> > printf 'testfifo'
> > )"
> >
> > I can make it work for all the mentioned shells like this:
> >
> > mkfifo 'testfifo'
> > cat "$(
> > ( ( printf 'foo\n' > testfifo 2>&1 ) & ) > /dev/null 2>&1
> > printf 'testfifo'
> > )"
> >
> > Can someone explain or justify the behaviour of the OpenBSD sh, or do
> > you think this is a bug?
> >
> 
> This is a bug, almost certainly from an over-zealous optimization in the
> logic handling subshells where the possibility that an inner redirection
> could be blocking wasn't taken into account when it tries to avoid
> unnecessary forks.

Thanks for the clarification! I'll note your assessment on the issue for
Kakoune.

> Sorry, I don't have a fix in my back pocket.  Your workaround is good; I'll
> note the intermediate set of parens can also be braces, which would let you
> avoid the otherwise necessary whitespace between open-parens if that grates
> on your soul like it does mine.  :)

I feel you, but I'm afraid our souls will keep getting grated, because
unfortunately bash and the like won't work if I use `{}` instead of the
intermediate `()`. I guess this is a bug of thes other shells then.

Thanks for your help!
Richard Ulmer



Re: Putting fifos in subshells into the background

2019-06-12 Thread Philip Guenther
On Wed, Jun 12, 2019 at 12:54 AM Richard Ulmer 
wrote:

> while making the Kakoune editor work on OpenBSD, I encountered some
> strange behaviour [1]. This little script doesn't work with the OpenBSD
> sh, but works at least with dash, bash and zsh:
>
> mkfifo 'testfifo'
> cat "$(
> ( printf 'foo\n' > testfifo 2>&1 ) > /dev/null 2>&1 &
> printf 'testfifo'
> )"
>
> I can make it work for all the mentioned shells like this:
>
> mkfifo 'testfifo'
> cat "$(
> ( ( printf 'foo\n' > testfifo 2>&1 ) & ) > /dev/null 2>&1
> printf 'testfifo'
> )"
>
> Can someone explain or justify the behaviour of the OpenBSD sh, or do
> you think this is a bug?
>

This is a bug, almost certainly from an over-zealous optimization in the
logic handling subshells where the possibility that an inner redirection
could be blocking wasn't taken into account when it tries to avoid
unnecessary forks.

Sorry, I don't have a fix in my back pocket.  Your workaround is good; I'll
note the intermediate set of parens can also be braces, which would let you
avoid the otherwise necessary whitespace between open-parens if that grates
on your soul like it does mine.  :)


Philip Guenther


Putting fifos in subshells into the background

2019-06-12 Thread Richard Ulmer
Hi,
while making the Kakoune editor work on OpenBSD, I encountered some
strange behaviour [1]. This little script doesn't work with the OpenBSD
sh, but works at least with dash, bash and zsh:

mkfifo 'testfifo'
cat "$(
( printf 'foo\n' > testfifo 2>&1 ) > /dev/null 2>&1 &
printf 'testfifo'
)"

I can make it work for all the mentioned shells like this:

mkfifo 'testfifo'
cat "$(
( ( printf 'foo\n' > testfifo 2>&1 ) & ) > /dev/null 2>&1
printf 'testfifo'
)"

Can someone explain or justify the behaviour of the OpenBSD sh, or do
you think this is a bug?

Cheers,
Richard Ulmer


[1] See https://github.com/mawww/kakoune/pull/2955 for more info.