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;) {
|
for (;fcntl (rfd, F_GETFL) != -1;) {
|
||||||
r = read (rfd, buf, BUFSIZ - 1);
|
r = read (rfd, buf, BUFSIZ - 1);
|
||||||
if (r < 0 && (errno == EINTR || errno == EAGAIN)) {
|
if (r < 0 && (errno == EINTR || errno == EAGAIN)) {
|
||||||
|
|
||||||
|
#ifdef __APPLE__
|
||||||
again:
|
again:
|
||||||
|
#endif
|
||||||
|
|
||||||
/* wait till ready to read */
|
/* wait till ready to read */
|
||||||
|
|
||||||
struct pollfd pfd;
|
struct pollfd pfd;
|
||||||
|
|
||||||
pfd.fd = rfd;
|
pfd.fd = rfd;
|
||||||
pfd.events = POLLIN|POLLERR|POLLHUP|POLLNVAL;
|
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);
|
int rv = poll (&pfd, 1, 1000);
|
||||||
|
#else
|
||||||
|
int rv = poll (&pfd, 1, -1);
|
||||||
|
#endif
|
||||||
|
|
||||||
if (rv == -1) {
|
if (rv == -1) {
|
||||||
break;
|
break;
|
||||||
|
@ -859,10 +870,12 @@ again:
|
||||||
/* back to read(2) call */
|
/* back to read(2) call */
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
#ifdef __APPLE__
|
||||||
if (rv == 0) {
|
if (rv == 0) {
|
||||||
/* Timeout, poll again */
|
/* Timeout, poll again */
|
||||||
goto again;
|
goto again;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
if (r <= 0) {
|
if (r <= 0) {
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Reference in New Issue