summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDominique Martinet <asmadeus@codewreck.org>2017-02-12 10:34:26 +0100
committerDominique Martinet <asmadeus@codewreck.org>2017-02-12 10:34:26 +0100
commitc3d763eccbfd13178a3bcb4c028aa6b4c076d783 (patch)
tree5904a30a6ca38c10748f60a09c615cb1285a95c3
parentbb0e76c4b1146a5bc2e9c10d01f3d4cbf97de966 (diff)
better eof handling
remove pollhup, but clear errno properly so we can return empty read
-rw-r--r--tailburst.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/tailburst.c b/tailburst.c
index f3b63c9..1c621f2 100644
--- a/tailburst.c
+++ b/tailburst.c
@@ -55,6 +55,9 @@ ssize_t fdgetline(int fd, struct getline_states *line) {
line->cur = line->base;
}
+ /* clear errno before read */
+ errno = 0;
+
while ((nread = read(fd, line->base + line->read, line->size - line->read)) > 0 ) {
pr_debug("read %zd\n", nread);
line->read += nread;
@@ -100,7 +103,7 @@ int main(int argc, char **argv)
fcntl(fd, F_SETFL, flags);
pollfd.fd = fd;
- pollfd.events = POLLIN | POLLHUP;
+ pollfd.events = POLLIN;
while (poll(&pollfd, 1, -1) > 0) {
cur = NULL;
while ((nread = fdgetline(fd, &line)) > 0)
@@ -109,7 +112,8 @@ int main(int argc, char **argv)
if (cur)
printf("%s\n", cur);
- if (pollfd.revents & POLLHUP)
+ /* eof */
+ if (nread == 0)
break;
}