]> git.ipfire.org Git - thirdparty/coreutils.git/commit
tee: enhance -p mode using iopoll() to detect broken pipe outputs
authorCarl Edquist <edquist@cs.wisc.edu>
Thu, 15 Dec 2022 18:32:49 +0000 (12:32 -0600)
committerPádraig Brady <P@draigBrady.com>
Tue, 28 Feb 2023 14:02:42 +0000 (14:02 +0000)
commit6b12e62d9585726424b3105b84827d39380d7ab2
treeb04ed6983707cb49012d53cd3260b09773aec494
parentb5c421a78431e707a3713df2de9e08e00f63feff
tee: enhance -p mode using iopoll() to detect broken pipe outputs

If input is intermittent (a tty, pipe, or socket), and all remaining
outputs are pipes (eg, >(cmd) process substitutions), exit early when
they have all become broken pipes (and thus future writes will fail),
without waiting for more input to become available, as future write
attempts to these outputs will fail (SIGPIPE/EPIPE).

Only provide this enhancement when pipe errors are ignored (-p mode).

Note that only one output needs to be monitored at a time with iopoll(),
as we only want to exit early if _all_ outputs have been removed.

* src/tee.c (pipe_check): New global for iopoll mode.
(main): enable pipe_check for -p, as long as output_error ignores EPIPE,
and input is suitable for iopoll().
(get_next_out): Helper function for finding next valid output.
(fail_output, tee_files): Break out write failure/output removal logic
to helper function.
(tee_files): Add out_pollable array to track which outputs are suitable
for iopoll() (ie, that are pipes); track first output index that is
still valid; add iopoll() broken pipe detection before calling read(),
removing an output that becomes a broken pipe.
* src/local.mk (src_tee_SOURCES): include src/iopoll.c.
* NEWS: Mention tee -p enhancement in Improvements.
* doc/coreutils.texi: Mention the new early exit behavior in the nopipe
modes for the tee -p option.

Suggested-by: Arsen Arsenović <arsen@aarsen.me>
NEWS
doc/coreutils.texi
src/iopoll.h
src/local.mk
src/tee.c