Update src/lcpex/liblcpex.cpp
parent
e16c663b5f
commit
bb466185d0
|
@ -280,6 +280,12 @@ int execute(
|
||||||
// loop until we've read all the data from the child process
|
// loop until we've read all the data from the child process
|
||||||
while ( ! break_out ) {
|
while ( ! break_out ) {
|
||||||
num_files_readable = poll(watched_fds, sizeof(watched_fds) / sizeof(watched_fds[0]), -1);
|
num_files_readable = poll(watched_fds, sizeof(watched_fds) / sizeof(watched_fds[0]), -1);
|
||||||
|
// after the poll() call, add a check to see if both pipes are closed
|
||||||
|
if (!(watched_fds[CHILD_PIPE_NAMES::STDOUT_READ].events & POLLIN) &&
|
||||||
|
!(watched_fds[CHILD_PIPE_NAMES::STDERR_READ].events & POLLIN)) {
|
||||||
|
break_out = true;
|
||||||
|
}
|
||||||
|
|
||||||
if (num_files_readable == -1) {
|
if (num_files_readable == -1) {
|
||||||
// error occurred in poll()
|
// error occurred in poll()
|
||||||
perror("poll");
|
perror("poll");
|
||||||
|
@ -328,12 +334,17 @@ int execute(
|
||||||
close(watched_fds[this_fd].fd);
|
close(watched_fds[this_fd].fd);
|
||||||
break_out = true;
|
break_out = true;
|
||||||
}
|
}
|
||||||
|
// if (watched_fds[this_fd].revents & POLLHUP) {
|
||||||
|
// // this pipe has hung up
|
||||||
|
// close(watched_fds[this_fd].fd);
|
||||||
|
// break_out = true;
|
||||||
|
// }
|
||||||
if (watched_fds[this_fd].revents & POLLHUP) {
|
if (watched_fds[this_fd].revents & POLLHUP) {
|
||||||
// this pipe has hung up
|
// this pipe has hung up
|
||||||
close(watched_fds[this_fd].fd);
|
// don't close the file descriptor yet, there might still be data to read
|
||||||
break_out = true;
|
// instead, remove the POLLIN event to avoid getting a POLLHUP event in the next poll() call
|
||||||
|
watched_fds[this_fd].events &= ~POLLIN;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// wait for child to exit, capture status
|
// wait for child to exit, capture status
|
||||||
|
|
Loading…
Reference in New Issue