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: Carl Edquist
Subject: Re: [PATCH] tee: Add --pipe-check to allow instantly detecting closed outputs
Date: Thu, 15 Dec 2022 12:24:39 -0600 (CST)

Hi Pádraig,
O2
At your convenience, please see my attached patch set.


... A couple very small implementation details I guess I'll mention here.

1. In iopoll.c, I use isapipe() from gnulib, as is done in tail.c. I am not wild about the gnulib implementation of isapipe() - I would rather do a simple S_ISFIFO check, as the FIFO vs pipe distinction is irrelevant for iopoll(), and I'm not sure whether the "pipes are sockets" for Darwin 7.7 still needs to be supported. But I was happy to see (at least for me on Linux) it looks like the config.h macros end up compiling away the complicated parts of this function, so I guess it's not that bad :)

2. I believe the "if (errno == EINTR) continue;" logic in iopoll() is unnecessary, as an interrupted poll() or select() call will result in repeating the loop anyway. I've left it for clarity, but as far as I can tell it could be removed just the same.


On Tue, 13 Dec 2022, Arsen Arsenović wrote:

It might also be good to give a quick test on FreeBSD, since it has some popularity too.

I don't have easy access to play with this, but yeah I think I've seen the BSD man page for poll(2), and I imagine poll would work there. If so we can tweak the IOPOLL_USES_POLL definition in iopoll.c to include an appropriate preprocessor check for BSD.


If you prefer, I'll have some time in the latter part of this week too.

Let's not forget to include the testcase posted previously (with -p instead of -P, since it was suggested to enable polling for -p):

Hi Arsen,

Would you like to add your test case and comments in a separate commit?

Thanks!
Carl


( sleep 5 | (timeout 3 tee -p 2>/dev/null && echo TEST_PASSED >&8) | : ) 8>&1 | 
grep -qx TEST_PASSED

To annotate it, and let's include this info in a comment:

- sleep emulates misbehaving input.
- The timeout is our failure safety-net.
- We ignore stderr from tee, and should have no stdout anyway.
- If that succeeds, we print TEST_PASSED into FD 8 to grep for later.
 (FD 8 was selected by a D20 roll, or rather, a software emulation)
- The colon is the immediately closed output process.
- We redirect 8 back into stdout to grep it.

If tee fails, for instance because it times out, or it fails to
recognize -P for some reason, the echo simply won't run.  The grep
options are in POSIX (or, at least, in POSIX.1-2017).

Thank you both, have a great night.
--
Arsen Arsenović

Attachment: 0001-iopoll-broken-pipe-detection.patch
Description: Text Data

Attachment: 0002-tee-enhance-p-mode-using-iopoll.patch
Description: Text Data


reply via email to

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