Use poll timeout workaround on macOS only
Other systems implement proper poll according to POSIX and return when the pipe is closed.
This commit is contained in:
parent
cc69274234
commit
1e5ccd4acc
|
@ -836,16 +836,27 @@ SystemExec::output_interposer ()
|
|||
for (;fcntl (rfd, F_GETFL) != -1;) {
|
||||
r = read (rfd, buf, BUFSIZ - 1);
|
||||
if (r < 0 && (errno == EINTR || errno == EAGAIN)) {
|
||||
|
||||
#ifdef __APPLE__
|
||||
again:
|
||||
#endif
|
||||
|
||||
/* wait till ready to read */
|
||||
|
||||
struct pollfd pfd;
|
||||
|
||||
pfd.fd = rfd;
|
||||
pfd.events = POLLIN|POLLERR|POLLHUP|POLLNVAL;
|
||||
|
||||
#ifdef __APPLE__
|
||||
/* on macOS poll() will not return when the pipe
|
||||
* is closed in an EOF state.
|
||||
* Work around with a timeout and fail next time
|
||||
* when with POLLNVAL.
|
||||
*/
|
||||
int rv = poll (&pfd, 1, 1000);
|
||||
#else
|
||||
int rv = poll (&pfd, 1, -1);
|
||||
#endif
|
||||
|
||||
if (rv == -1) {
|
||||
break;
|
||||
|
@ -859,10 +870,12 @@ again:
|
|||
/* back to read(2) call */
|
||||
continue;
|
||||
}
|
||||
#ifdef __APPLE__
|
||||
if (rv == 0) {
|
||||
/* Timeout, poll again */
|
||||
goto again;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
if (r <= 0) {
|
||||
break;
|
||||
|
|
Loading…
Reference in New Issue