summary refs log tree commit diff
path: root/bin
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2022-06-03 10:34:51 -0400
committerJune McEnroe <june@causal.agency>2022-06-03 10:34:51 -0400
commit12c2b0651eb572010be117ce342692e45fdebdb3 (patch)
tree06962a8917498d71570c6ffdbff6dcf18818bb45 /bin
parentSet TABSIZE=4 (diff)
downloadsrc-12c2b0651eb572010be117ce342692e45fdebdb3.tar.gz
src-12c2b0651eb572010be117ce342692e45fdebdb3.zip
Stop polling stdin after EOF
Diffstat (limited to 'bin')
-rw-r--r--bin/qf.c15
1 files changed, 8 insertions, 7 deletions
diff --git a/bin/qf.c b/bin/qf.c
index 0975cea8..aac44fa5 100644
--- a/bin/qf.c
+++ b/bin/qf.c
@@ -249,18 +249,22 @@ int main(int argc, char *argv[]) {
 	}
 	curse();
 	struct pollfd fds[2] = {
-		{ .fd = STDIN_FILENO, .events = POLLIN },
 		{ .fd = STDERR_FILENO, .events = POLLIN },
+		{ .fd = STDIN_FILENO, .events = POLLIN },
 	};
+	int nfds = 2;
 	size_t len = 0;
 	size_t cap = 4096;
 	char *buf = malloc(cap);
 	if (!buf) err(EX_OSERR, "malloc");
-	while (poll(fds, 2, -1)) {
+	while (poll(fds, nfds, -1)) {
 		if (fds[0].revents) {
-			ssize_t n = read(fds[0].fd, &buf[len], cap - len);
+			input();
+		}
+		if (nfds > 1 && fds[1].revents) {
+			ssize_t n = read(fds[1].fd, &buf[len], cap - len);
 			if (n < 0) err(EX_IOERR, "read");
-			if (!n) fds[0].events = 0;
+			if (!n) nfds--;
 			len += n;
 			char *ptr = buf;
 			for (
@@ -280,9 +284,6 @@ int main(int argc, char *argv[]) {
 				if (!buf) err(EX_OSERR, "realloc");
 			}
 		}
-		if (fds[1].revents) {
-			input();
-		}
 		draw();
 	}
 	err(EX_IOERR, "poll");