From: Herbert Xu <herbert@gondor.apana.org.au>
To: DASH Mailing List <dash@vger.kernel.org>
Cc: ignacy.gawedzki@green-communications.fr
Subject: [v4 PATCH] input: Fix EINTR handling when reading from a pipe
Date: Tue, 14 Apr 2026 07:45:08 +0800 [thread overview]
Message-ID: <ad2ABNCVXruuMNvQ@gondor.apana.org.au> (raw)
In-Reply-To: <adt1kl_3p0r4E7PG@gondor.apana.org.au>
Restore the fallback tee definition so that it actually compiles.
---8<---
Errors from tee(2) should not lead to the fallback path in every
case. In fact, only EINVAL should trigger an attempt to call
read(2).
Every other error (and zero == EOF) returned by tee(2) should be
treated as if it came from read(2).
Reported-by: Ignacy Gawędzki <ignacy.gawedzki@green-communications.fr>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
diff --git a/configure.ac b/configure.ac
index c37eefe..d749440 100644
--- a/configure.ac
+++ b/configure.ac
@@ -135,6 +135,10 @@ if test "$use_fnmatch" = yes && test "$enable_glob" = yes; then
fi
if test "$enable_tee" != no; then
+ AC_CHECK_FUNCS(tee, use_tee=yes)
+fi
+
+if test "$use_tee" = yes; then
AC_DEFINE([USE_TEE], [1], [Non-zero if tee(2) should be used])
else
AC_DEFINE([USE_TEE], [0], [Non-zero if tee(2) should be used])
diff --git a/src/input.c b/src/input.c
index 71282fb..4e30010 100644
--- a/src/input.c
+++ b/src/input.c
@@ -183,7 +183,12 @@ static int stdin_tee(void *buf, int nr)
flush_tee(buf, nr, stdin_state.pending);
- err = USE_TEE ? tee(0, stdin_state.pip[1], nr, 0) : -1;
+ if (USE_TEE)
+ err = tee(0, stdin_state.pip[1], nr, 0);
+ else {
+ errno = EINVAL;
+ err = -1;
+ }
stdin_state.pending = err;
return err;
}
@@ -324,13 +329,13 @@ retry:
if (!fd && !stdin_bufferable()) {
nr = stdin_tee(buf, nr);
fd = stdin_state.pip[0];
- if (nr <= 0) {
+ if (nr < 0 && errno == EINVAL) {
fd = 0;
nr = 1;
}
}
- if (nr >= 0)
+ if (nr > 0)
nr = read(fd, buf, nr);
if (nr < 0) {
--
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
prev parent reply other threads:[~2026-04-13 23:45 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-02 13:59 [PATCH v2] Fix EINTR handling when reading from a pipe Ignacy Gawędzki
2026-04-12 10:36 ` [v3 PATCH] input: " Herbert Xu
2026-04-13 23:45 ` Herbert Xu [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ad2ABNCVXruuMNvQ@gondor.apana.org.au \
--to=herbert@gondor.apana.org.au \
--cc=dash@vger.kernel.org \
--cc=ignacy.gawedzki@green-communications.fr \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox