diff options
author | Leah Neukirchen <leah@vuxu.org> | 2017-08-06 18:53:51 +0200 |
---|---|---|
committer | Leah Neukirchen <leah@vuxu.org> | 2017-08-06 18:53:51 +0200 |
commit | 6b5b42f5836388d467ab0c2adcca58bb2a6fb0f3 (patch) | |
tree | 2a16a7c98850d60502358fddc78e78304164a978 | |
parent | 8a9825596b0cff53d3cf1475ad540f23273442bb (diff) | |
download | mblaze-6b5b42f5836388d467ab0c2adcca58bb2a6fb0f3.tar.gz mblaze-6b5b42f5836388d467ab0c2adcca58bb2a6fb0f3.tar.xz mblaze-6b5b42f5836388d467ab0c2adcca58bb2a6fb0f3.zip |
filter: don't write more than PIPE_BUF at once
This could result in stalling during big writes when we can't read the output of the child in the mean time.
-rw-r--r-- | filter.c | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/filter.c b/filter.c index 111b606..c0b1541 100644 --- a/filter.c +++ b/filter.c @@ -1,9 +1,11 @@ +#include <sys/wait.h> + +#include <limits.h> #include <poll.h> #include <signal.h> #include <stdio.h> #include <stdlib.h> #include <string.h> -#include <sys/wait.h> #include <time.h> #include <unistd.h> @@ -83,7 +85,8 @@ filter(char *input, size_t inlen, char *cmd, char **outputo, size_t *outleno) } if (fds[1].revents & POLLOUT) { - ssize_t ret = write(fds[1].fd, input, inlen); + ssize_t ret = write(fds[1].fd, input, + inlen > PIPE_BUF ? PIPE_BUF : inlen); if (ret > 0) { input += ret; inlen -= ret; |