aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLeah Neukirchen <leah@vuxu.org>2017-08-06 18:53:51 +0200
committerLeah Neukirchen <leah@vuxu.org>2017-08-06 18:53:51 +0200
commit6b5b42f5836388d467ab0c2adcca58bb2a6fb0f3 (patch)
tree2a16a7c98850d60502358fddc78e78304164a978
parent8a9825596b0cff53d3cf1475ad540f23273442bb (diff)
downloadmblaze-6b5b42f5836388d467ab0c2adcca58bb2a6fb0f3.tar.gz
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.c7
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;