From f4166fb61d2b33a82ea797b18aabae379fa922ef Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Mon, 21 Jun 2021 01:58:40 +0200 Subject: [PATCH] Fix endless poll on macOS #8753 Harvid daemonizes and does not write anything to stdout/err. as opposed to select(), poll() on macOS does not return when the child process terminates or is killed. However poll() on an invalid FD does throw an error and POLLNVAL is set. --- libs/pbd/system_exec.cc | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/libs/pbd/system_exec.cc b/libs/pbd/system_exec.cc index f2b3b6ea90..61670917d5 100644 --- a/libs/pbd/system_exec.cc +++ b/libs/pbd/system_exec.cc @@ -836,21 +836,22 @@ SystemExec::output_interposer () for (;fcntl (rfd, F_GETFL) != -1;) { r = read (rfd, buf, BUFSIZ - 1); if (r < 0 && (errno == EINTR || errno == EAGAIN)) { +again: /* wait till ready to read */ struct pollfd pfd; pfd.fd = rfd; - pfd.events = POLLIN|POLLERR|POLLHUP; + pfd.events = POLLIN|POLLERR|POLLHUP|POLLNVAL; - int rv = poll (&pfd, 1, -1); + int rv = poll (&pfd, 1, 1000); if (rv == -1) { break; } - if (pfd.revents & (POLLERR|POLLHUP)) { + if (pfd.revents & (POLLERR|POLLHUP|POLLNVAL)) { break; } @@ -858,6 +859,10 @@ SystemExec::output_interposer () /* back to read(2) call */ continue; } + if (rv == 0) { + /* Timeout, poll again */ + goto again; + } } if (r <= 0) { break;