From e9fd8c80bc922a4a7f7a0bb7b2814ea3e8a49e42 Mon Sep 17 00:00:00 2001 From: phanes Date: Thu, 8 Feb 2024 15:04:52 -0500 Subject: [PATCH] possible fix for buffering issue --- sample/components/independent_test_1.bash | 2 +- src/lcpex/vpty/libclpex_tty.cpp | 15 +++++++++------ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/sample/components/independent_test_1.bash b/sample/components/independent_test_1.bash index e98115f..32dd3e9 100755 --- a/sample/components/independent_test_1.bash +++ b/sample/components/independent_test_1.bash @@ -1,7 +1,7 @@ #!/usr/bin/bash # echo test from script -#/usr/bin/dialog --title "This should be one argument" --inputbox "Enter your name:" 0 0 +/usr/bin/dialog --title "This should be one argument" --inputbox "Enter your name:" 0 0 diff --git a/src/lcpex/vpty/libclpex_tty.cpp b/src/lcpex/vpty/libclpex_tty.cpp index cacf7a6..065012e 100644 --- a/src/lcpex/vpty/libclpex_tty.cpp +++ b/src/lcpex/vpty/libclpex_tty.cpp @@ -235,13 +235,11 @@ int exec_pty( byte_count = read(watched_fds[this_fd].fd, buf, BUFFER_SIZE); if (byte_count == -1) { - if (errno == EAGAIN) { - // no data to read - continue; + if (errno == EAGAIN) { continue; } else { + // error reading from pipe + safe_perror("read", &ttyOrig ); + exit(EXIT_FAILURE); } - // error reading from pipe - safe_perror("read", &ttyOrig ); - exit(EXIT_FAILURE); } else if (byte_count == 0) { // reached EOF on one of the streams but not a HUP // we've read all we can this cycle, so go to the next fd in the for loop @@ -289,6 +287,11 @@ int exec_pty( // wait for child to exit, capture status waitpid(pid, &status, 0); + while ((byte_count = read(watched_fds[1].fd, 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);