* [PATCH] redir: detect larger pipe sizes under Linux
@ 2016-08-04 0:00 Eric Wong
0 siblings, 0 replies; only message in thread
From: Eric Wong @ 2016-08-04 0:00 UTC (permalink / raw)
To: spew
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
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2016-08-04 0:00 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-08-04 0:00 [PATCH] redir: detect larger pipe sizes under Linux Eric Wong
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).