coreutils
[Top][All Lists]
Advanced

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

Re: [PATCH] tee: Add --pipe-check to allow instantly detecting closed ou


From: Pádraig Brady
Subject: Re: [PATCH] tee: Add --pipe-check to allow instantly detecting closed outputs
Date: Tue, 29 Nov 2022 18:08:46 +0000
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.0

On 29/11/2022 17:32, Carl Edquist wrote:
Oh and, ...

On Mon, 28 Nov 2022, Pádraig Brady wrote:

I'm presuming the input generator is depending on the compiler runs
(written to by tee) to exit cleanly, before exiting / generating more?
Hence the hangs?

If that was the case then there still might be the potential for hangs
even if tee detected closed pipes. I.e. if the compiler runs hung rather
than exited, this not be distinguishable from tee as the pipe outputs
would remain.

This is a good point too.

So perhaps the generally useful cases are (1) if the intermittent input is
from a tty, but also (2) if the input program (that writes to a pipe) has
similar logic to what we are proposing to add to tee here; ie, that it
detects when its output becomes a broken pipe.

More generally for (2), if the whole command pipeline is written that way,
this will propagate all the way back.  In that sense there might even be
some merit in adding this type of logic to all coreutils programs that
filter stdin to stdout.

For instance, take this oversimplified example with cat:

        cat | cat | cat | cat | true

If this is run on a terminal, you have to hit Enter *4 times* before
control returns to the shell, as it takes that many separate writes to
cause all the pipes to break in sequence (right-to-left) and finally get
the write failure in the left-most cat.

If this kind of detect-broken-output-pipe logic were added to filter utils
generally, the above example (with 4 cats) would return to the shell
immediately.

Right. Thanks for discussing the more general pattern.
I.e. that SIGPIPE doesn't cascade back up the pipeline,
only upon attempted write to the pipe.
So it's not really a tee issue, more of a general pattern.

So it wouldn't be wrong to add this to tee (by default),
but I'm not sure how useful it is given this is a general issue for all filters.
Also I'm a bit wary of inducing SIGPIPE as traditionally it hasn't been handled 
well:
https://www.pixelbeat.org/programming/sigpipe_handling.html

cheers,
Pádraig



reply via email to

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