From f74dc660c238684f25a2e64eb5ae4490575e01bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20Jaramago=20Fern=C3=A1ndez?= Date: Thu, 21 May 2020 20:41:04 +0200 Subject: [PATCH] Minimal changes to pipe handling in helper function to isolate eof reading --- test/tap/tap/utils.cpp | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/test/tap/tap/utils.cpp b/test/tap/tap/utils.cpp index 319994193..fbf7442b5 100644 --- a/test/tap/tap/utils.cpp +++ b/test/tap/tap/utils.cpp @@ -277,7 +277,7 @@ int wexecvp(const std::string& file, const std::vector& argv, const bool stdout_eof = false; bool stderr_eof = false; - while (!stdout_eof && !stderr_eof) { + while (!stdout_eof || !stderr_eof) { FD_ZERO(&read_fds); FD_SET(PARENT_READ_FD, &read_fds); FD_SET(PARENT_READ_ERR, &read_fds); @@ -286,12 +286,11 @@ int wexecvp(const std::string& file, const std::vector& argv, const timeval select_to = { 0, to_opts.select_to_us }; select(maxfd + 1, &read_fds, NULL, NULL, &select_to); - if (FD_ISSET(PARENT_READ_FD, &read_fds)) { + if (FD_ISSET(PARENT_READ_FD, &read_fds) && stdout_eof == false) { int read_res = read_pipe(PARENT_READ_FD, stdout_); if (read_res == 0) { stdout_eof = true; - close(PARENT_READ_FD); } // Unexpected error while reading pipe if (read_res < 0) { @@ -307,12 +306,11 @@ int wexecvp(const std::string& file, const std::vector& argv, const } } - if(FD_ISSET(PARENT_READ_ERR, &read_fds)) { + if(FD_ISSET(PARENT_READ_ERR, &read_fds) && stderr_eof == false) { int read_res = read_pipe(PARENT_READ_ERR, stderr_); if (read_res == 0) { stderr_eof = true; - close(PARENT_READ_ERR); } // Unexpected error while reading pipe if (read_res < 0) {