From a27ba3370ca156a9fc44e27c2dab053ec3e274e3 Mon Sep 17 00:00:00 2001 From: Leah Neukirchen Date: Sun, 26 Mar 2017 19:21:33 +0200 Subject: 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. --- filter.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'filter.c') 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; -- cgit 1.4.1