bug-coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#6900: pitfalls of recoding named fifo as pipe


From: Paul Eggert
Subject: bug#6900: pitfalls of recoding named fifo as pipe
Date: Wed, 25 Aug 2010 13:40:35 -0700
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.11) Gecko/20100713 Thunderbird/3.0.6

On 08/25/2010 07:14 AM, John Reiser wrote:
> That is not equivalent!  stdout from listener1 gets piped into
> cmd2, instead of going to the common stdout of all processes
> other than cmd1.

Yes, you're right.  I had assumed that the listeners did not generate
standard output.  If they do, it should have been this:

  ((cmd1 2>&1 >&3 | listener1 >&4) 3>&1 |
   (cmd2 2>&1 >&4 | listener2    )
  ) 4>&1

> Also, file descriptor 3 is left open in all processes, which
> hogs system resources and is less safe.

Those resource and safety issues are typically negligible.
If one wanted to be extremely cautious, one could write this:

  ((cmd1 2>&1 >&3 3>&- 4>&- | listener1 >&4 3>&- 4>&-) 3>&1 |
   (cmd2 2>&1 >&4      4>&- | listener2          4>&-)
  ) 4>&1

(This is a shorter and POSIX-conforming way of writing the variant
that you sent, plus it fixes a couple of bugs in the way that variant
redirected file descriptor 2.)  But almost nobody would or should
bother with this level of complication.

> Using the named fifos is much more readable and understandable.

Yes, as I said, once things get sufficiently complicated, it's quite
possible for named fifos to be easier to use.  It's still not clear to
me that this is the case here, as even the overly-complicated piped
version is a tad simpler than the named-fifo version.  But the point
remains that, once a script is complicated enough to need a lot of
named fifos, it should be using mktemp -d anyway.






reply via email to

[Prev in Thread] Current Thread [Next in Thread]