mblaze

Unix utilities to deal with Maildir - my mirror
git clone https://pi.duncano.de/git/mblaze.git
Log | Files | Refs | README | COPYING

commit a27ba3370ca156a9fc44e27c2dab053ec3e274e3
parent 6b9f742d7d1c8c7e691bcd42f801c286d6df4bee
Author: Leah Neukirchen <leah@vuxu.org>
Date:   Sun, 26 Mar 2017 19:21:33 +0200

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.

Diffstat:
filter.c | 4++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git 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;