ack
parent
0561460b54
commit
e03a7e67b8
|
@ -6,4 +6,5 @@ cmake-build-debug
|
||||||
cmake-build-release
|
cmake-build-release
|
||||||
CMakeFiles
|
CMakeFiles
|
||||||
CMakeLists.txt
|
CMakeLists.txt
|
||||||
Makefile
|
Makefile
|
||||||
|
sample/logs/*
|
||||||
|
|
|
@ -18,6 +18,7 @@ void safe_perror( const char * msg, struct termios * ttyOrig )
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Executes the child process
|
* @brief Executes the child process
|
||||||
*
|
*
|
||||||
|
@ -210,13 +211,12 @@ int exec_pty(
|
||||||
// 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
|
// after the poll() call, add a check to see if both pipes are closed
|
||||||
if (!(watched_fds[CHILD_PIPE_NAMES::STDOUT_READ].events & POLLIN) &&
|
if (!(watched_fds[1].events & POLLIN) &&
|
||||||
!(watched_fds[CHILD_PIPE_NAMES::STDERR_READ].events & POLLIN)) {
|
!(watched_fds[2].events & POLLIN)) {
|
||||||
break_out = true;
|
break_out = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (num_files_readable == -1) {
|
if (num_files_readable == -1) {
|
||||||
// error occurred in poll()
|
// error occurred in poll()
|
||||||
safe_perror("poll", &ttyOrig );
|
safe_perror("poll", &ttyOrig );
|
||||||
|
@ -268,34 +268,17 @@ int exec_pty(
|
||||||
//break_out = true;
|
//break_out = true;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
// if (watched_fds[this_fd].revents & POLLHUP) {
|
|
||||||
// // this pipe has hung up
|
|
||||||
// close(watched_fds[this_fd].fd);
|
|
||||||
// break_out = true;
|
|
||||||
// break;
|
|
||||||
// }
|
|
||||||
if (watched_fds[this_fd].revents & POLLHUP) {
|
if (watched_fds[this_fd].revents & POLLHUP) {
|
||||||
// this pipe has hung up
|
// this pipe has hung up
|
||||||
// don't close the file descriptor yet, there might still be data to read
|
close(watched_fds[this_fd].fd);
|
||||||
// instead, remove the POLLIN event to avoid getting a POLLHUP event in the next poll() call
|
break_out = true;
|
||||||
watched_fds[this_fd].events &= ~POLLIN;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// wait for child to exit, capture status
|
// wait for child to exit, capture status
|
||||||
waitpid(pid, &status, 0);
|
waitpid(pid, &status, 0);
|
||||||
|
|
||||||
// Drain the pipes before exiting
|
|
||||||
//while ((byte_count = read(masterFd, buf, BUFFER_SIZE)) > 0) {
|
|
||||||
// write_all(stdout_log_fh->_fileno, buf, byte_count);
|
|
||||||
// write_all(STDOUT_FILENO, buf, byte_count);
|
|
||||||
//}
|
|
||||||
while ((byte_count = read(fd_child_stderr_pipe[READ_END], buf, BUFFER_SIZE)) > 0) {
|
|
||||||
write_all(stderr_log_fh->_fileno, buf, byte_count);
|
|
||||||
write_all(STDERR_FILENO, buf, byte_count);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
ttyResetExit( &ttyOrig);
|
ttyResetExit( &ttyOrig);
|
||||||
if WIFEXITED(status) {
|
if WIFEXITED(status) {
|
||||||
return WEXITSTATUS(status);
|
return WEXITSTATUS(status);
|
||||||
|
@ -304,5 +287,4 @@ int exec_pty(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue