aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLeah Neukirchen <leah@vuxu.org>2017-03-26 19:21:33 +0200
committerLeah Neukirchen <leah@vuxu.org>2017-03-26 19:21:33 +0200
commita27ba3370ca156a9fc44e27c2dab053ec3e274e3 (patch)
treeb41d64ad507801f0442e301431384629374ba9af
parent6b9f742d7d1c8c7e691bcd42f801c286d6df4bee (diff)
downloadmblaze-a27ba3370ca156a9fc44e27c2dab053ec3e274e3.tar.gz
filter: make more robust
MacOS will send POLLIN for empty reads on EOF, so detect ret == 0 too. Also poll for POLLHUP, which other systems use to message EOF. Fixes #18.
-rw-r--r--filter.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/filter.c b/filter.c
index 7c64bcb..d15e54e 100644
--- a/filter.c
+++ b/filter.c
@@ -48,7 +48,7 @@ filter(char *input, size_t inlen, char *cmd, char **outputo, size_t *outleno)
struct pollfd fds[2];
fds[0].fd = pipe1[0];
- fds[0].events = POLLIN;
+ fds[0].events = POLLIN | POLLHUP;
fds[1].fd = pipe0[1];
fds[1].events = POLLOUT;
@@ -66,7 +66,7 @@ filter(char *input, size_t inlen, char *cmd, char **outputo, size_t *outleno)
ssize_t ret = read(fds[0].fd, output + outlen, 512);
if (ret > 0)
outlen += ret;
- else if (ret < 0)
+ else
close(fds[0].fd);
} else if (fds[0].revents & (POLLERR | POLLHUP | POLLNVAL)) {
fds[0].fd = -1;