From 7d5f5c5f543df0c06e57b3f85da50cc577a99421 Mon Sep 17 00:00:00 2001 From: Michael Brantley Date: Wed, 18 Dec 2024 16:07:18 +0000 Subject: [PATCH] fix: process the final pipe input event before closing (#8) In the event that poll returned both POLLIN and POLLHUP in a single pass we were mistakenly closing the file descriptor without processing that final input. This was addressed by changing the condition for ending the loop. Also expanded the midline-flush test to run 10 times because that's what was most effective in demonstrating the problem. --- t3.c | 4 ++-- tests/midline-flush.args | 2 +- tests/midline-flush.err | 9 +++++++++ tests/midline-flush.log | 18 ++++++++++++++++++ tests/midline-flush.out | 9 +++++++++ 5 files changed, 39 insertions(+), 3 deletions(-) diff --git a/t3.c b/t3.c index efd8e57..3733a8d 100644 --- a/t3.c +++ b/t3.c @@ -640,7 +640,7 @@ int main(int argc, char *argv[]) { pfds[0].revents & POLLIN, pfds[0].revents & POLLPRI, pfds[0].revents & POLLOUT, pfds[0].revents & POLLERR, pfds[0].revents & POLLHUP, pfds[0].revents & POLLNVAL); - if ((pfds[0].revents & POLLIN) && !(pfds[0].revents & POLLHUP)) { + if (pfds[0].revents & POLLIN) { _debug(2, "detected input on stdout_msg_pipe[0]"); struct payload *msg_payload = malloc(sizeof(struct payload)); if (read(stdout_msg_pipe[0], msg_payload, sizeof(struct payload)) > @@ -659,7 +659,7 @@ int main(int argc, char *argv[]) { num_open_fds--; waitpid(stdout_worker, NULL, WNOHANG); } - if ((pfds[1].revents & POLLIN) && !(pfds[1].revents & POLLHUP)) { + if (pfds[1].revents & POLLIN) { _debug(2, "detected input on stderr_msg_pipe[0]"); struct payload *msg_payload = malloc(sizeof(struct payload)); if (read(stderr_msg_pipe[0], msg_payload, sizeof(struct payload)) > diff --git a/tests/midline-flush.args b/tests/midline-flush.args index 75b62c1..f9cb27a 100644 --- a/tests/midline-flush.args +++ b/tests/midline-flush.args @@ -1 +1 @@ --- tests/midline-flush +-- sh -c 'for i in `seq 1 10`; do tests/midline-flush; done' diff --git a/tests/midline-flush.err b/tests/midline-flush.err index 24ef8b5..a677517 100644 --- a/tests/midline-flush.err +++ b/tests/midline-flush.err @@ -1 +1,10 @@ Hello, stderr! Goodbye, stderr! +Hello, stderr! Goodbye, stderr! +Hello, stderr! Goodbye, stderr! +Hello, stderr! Goodbye, stderr! +Hello, stderr! Goodbye, stderr! +Hello, stderr! Goodbye, stderr! +Hello, stderr! Goodbye, stderr! +Hello, stderr! Goodbye, stderr! +Hello, stderr! Goodbye, stderr! +Hello, stderr! Goodbye, stderr! diff --git a/tests/midline-flush.log b/tests/midline-flush.log index 0f12ff8..5da343b 100644 --- a/tests/midline-flush.log +++ b/tests/midline-flush.log @@ -1,2 +1,20 @@ Hello, stderr! Goodbye, stderr! Hello, stdout! Goodbye, stdout! +Hello, stderr! Goodbye, stderr! +Hello, stdout! Goodbye, stdout! +Hello, stderr! Goodbye, stderr! +Hello, stdout! Goodbye, stdout! +Hello, stderr! Goodbye, stderr! +Hello, stdout! Goodbye, stdout! +Hello, stderr! Goodbye, stderr! +Hello, stdout! Goodbye, stdout! +Hello, stderr! Goodbye, stderr! +Hello, stdout! Goodbye, stdout! +Hello, stderr! Goodbye, stderr! +Hello, stdout! Goodbye, stdout! +Hello, stderr! Goodbye, stderr! +Hello, stdout! Goodbye, stdout! +Hello, stderr! Goodbye, stderr! +Hello, stdout! Goodbye, stdout! +Hello, stderr! Goodbye, stderr! +Hello, stdout! Goodbye, stdout! diff --git a/tests/midline-flush.out b/tests/midline-flush.out index 4bafc1c..1d8bdd2 100644 --- a/tests/midline-flush.out +++ b/tests/midline-flush.out @@ -1 +1,10 @@ Hello, stdout! Goodbye, stdout! +Hello, stdout! Goodbye, stdout! +Hello, stdout! Goodbye, stdout! +Hello, stdout! Goodbye, stdout! +Hello, stdout! Goodbye, stdout! +Hello, stdout! Goodbye, stdout! +Hello, stdout! Goodbye, stdout! +Hello, stdout! Goodbye, stdout! +Hello, stdout! Goodbye, stdout! +Hello, stdout! Goodbye, stdout!