diff options
author | sjg <sjg@FreeBSD.org> | 2013-04-12 20:48:55 +0000 |
---|---|---|
committer | sjg <sjg@FreeBSD.org> | 2013-04-12 20:48:55 +0000 |
commit | 97d8b9495668afa398ab17c8c5f7e223b5fd2e89 (patch) | |
tree | 54038c9ac32a45f8741dcc23fb9a8ffc0e15ff89 /bin/sh/redir.c | |
parent | 5ee3bfdb338e7c80af29a67f4425c4be24c7b866 (diff) | |
parent | 086d73aef6d0ab7d21daa2076fdc8d25961f9b05 (diff) | |
download | FreeBSD-src-97d8b9495668afa398ab17c8c5f7e223b5fd2e89.zip FreeBSD-src-97d8b9495668afa398ab17c8c5f7e223b5fd2e89.tar.gz |
sync from head
Diffstat (limited to 'bin/sh/redir.c')
-rw-r--r-- | bin/sh/redir.c | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/bin/sh/redir.c b/bin/sh/redir.c index c11cb71..fda094d2 100644 --- a/bin/sh/redir.c +++ b/bin/sh/redir.c @@ -64,7 +64,6 @@ __FBSDID("$FreeBSD$"); #define EMPTY -2 /* marks an unused slot in redirtab */ #define CLOSED -1 /* fd was not open before redir */ -#define PIPESIZE 4096 /* amount of buffering in a pipe */ MKINIT @@ -253,7 +252,9 @@ openhere(union node *redir) { char *p; int pip[2]; - int len = 0; + size_t len = 0; + int flags; + ssize_t written = 0; if (pipe(pip) < 0) error("Pipe call failed: %s", strerror(errno)); @@ -263,9 +264,16 @@ openhere(union node *redir) else p = redir->nhere.doc->narg.text; len = strlen(p); - if (len <= PIPESIZE) { - xwrite(pip[1], p, len); + if (len == 0) goto out; + flags = fcntl(pip[1], F_GETFL, 0); + if (flags != -1 && fcntl(pip[1], F_SETFL, flags | O_NONBLOCK) != -1) { + written = write(pip[1], p, len); + if (written < 0) + written = 0; + if ((size_t)written == len) + goto out; + fcntl(pip[1], F_SETFL, flags); } if (forkshell((struct job *)NULL, (union node *)NULL, FORK_NOJOB) == 0) { @@ -275,7 +283,7 @@ openhere(union node *redir) signal(SIGHUP, SIG_IGN); signal(SIGTSTP, SIG_IGN); signal(SIGPIPE, SIG_DFL); - xwrite(pip[1], p, len); + xwrite(pip[1], p + written, len - written); _exit(0); } out: |