From: Eric Wong <e@80x24.org>
To: spew@80x24.org
Subject: [PATCH] redir: detect larger pipe sizes under Linux
Date: Thu, 4 Aug 2016 00:00:25 +0000 [thread overview]
Message-ID: <20160804000025.21515-1-e@80x24.org> (raw)
Not sure if it's worth it, 4K is a lot for heredoc
SCRIPT=${SCRIPT-heredoc.sh}
(
echo 'cat >/dev/null <<EOF'
awk </dev/null 'END{for(i=0;i<6000;i++) print 012345789}'
echo 'EOF'
) >"$SCRIPT"
---
src/redir.c | 25 ++++++++++++++++++++++++-
1 file changed, 24 insertions(+), 1 deletion(-)
diff --git a/src/redir.c b/src/redir.c
index f96a76b..8a65951 100644
--- a/src/redir.c
+++ b/src/redir.c
@@ -285,6 +285,29 @@ err:
sh_error("%d: %s", f, strerror(err));
}
+static size_t
+pipesize(int fd, int want)
+{
+#if defined(F_GETPIPE_SZ) && defined(F_SETPIPE_SZ)
+ static int default_size;
+
+ if (!default_size) {
+ int sz = fcntl(fd, F_GETPIPE_SZ, &sz);
+
+ default_size = sz > 0 ? sz : PIPESIZE;
+ }
+ if (want > default_size) {
+ if (fcntl(fd, F_SETPIPE_SZ, &want) < 0)
+ return default_size;
+
+ return want;
+ }
+
+ return default_size;
+#else
+ return PIPESIZE;
+#endif
+}
/*
* Handle here documents. Normally we fork off a process to write the
@@ -309,7 +332,7 @@ openhere(union node *redir)
}
len = strlen(p);
- if (len <= PIPESIZE) {
+ if (len <= pipesize(pip[0], len)) {
xwrite(pip[1], p, len);
goto out;
}
--
EW
reply other threads:[~2016-08-04 0:00 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20160804000025.21515-1-e@80x24.org \
--to=e@80x24.org \
--cc=spew@80x24.org \
/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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).