From 9863390f67f1c44a66540b281aee66c6a561f046 Mon Sep 17 00:00:00 2001 From: Chris Punches Date: Wed, 7 Apr 2021 19:14:29 -0400 Subject: [PATCH] dropping ncurses for newt --- src/Sproc/Sproc.cpp | 33 ++++++++++++++++++++++++++---- test/components/curses_dialog.bash | 2 +- 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/src/Sproc/Sproc.cpp b/src/Sproc/Sproc.cpp index bc32b13..4ecfe4b 100644 --- a/src/Sproc/Sproc.cpp +++ b/src/Sproc/Sproc.cpp @@ -160,6 +160,7 @@ int set_identity_context( std::string task_name, std::string user_name, std::str return SPROC_RETURN_CODES::SUCCESS; } + /// Sproc::execute /// /// \param input - The commandline input to execute. @@ -255,6 +256,26 @@ int Sproc::execute(std::string shell, std::string environment_file, std::string slog.log(E_DEBUG, "[ '" + task_name + "' ] file descriptors piped."); } + if (fcntl(child_stdout_pipe[READ_END], F_SETFD, FD_CLOEXEC) == -1) { + perror("fcntl"); + exit(1); + } + + if (fcntl(child_stdout_pipe[WRITE_END], F_SETFD, FD_CLOEXEC) == -1) { + perror("fcntl"); + exit(1); + } + + if (fcntl(child_stderr_pipe[READ_END], F_SETFD, FD_CLOEXEC) == -1) { + perror("fcntl"); + exit(1); + } + + if (fcntl(child_stderr_pipe[WRITE_END], F_SETFD, FD_CLOEXEC) == -1) { + perror("fcntl"); + exit(1); + } + // fork a process pid_t pid = fork(); slog.log( E_DEBUG, "[ '" + task_name + "' ] Process forked. Reporting. (PID: " + std::to_string(pid) + ")" ); @@ -311,8 +332,8 @@ int Sproc::execute(std::string shell, std::string environment_file, std::string close(child_stderr_pipe[WRITE_END]); // buffers for reading from child fd's - char stdout_buf[1] = {0}; - char stderr_buf[1] = {0}; + char stdout_buf[4096] = {0}; + char stderr_buf[4096] = {0}; // will contain a set of file descriptors to monitor representing stdout and stderr of the child process fd_set readfds; @@ -402,12 +423,16 @@ int Sproc::execute(std::string shell, std::string environment_file, std::string } // end select/if } - // wait for the child to exit - while ( ( pid = waitpid(pid, &exit_code_raw, 0 ) ) == -1 ) {} + close( child_stderr_pipe[READ_END] ); + close( child_stdout_pipe[READ_END] ); // clean up Tee stdout_log.close(); stderr_log.close(); + + // wait for the child to exit + while ( ( pid = waitpid(pid, &exit_code_raw, 0 ) ) == -1 ) {} + } } return WEXITSTATUS( exit_code_raw ); diff --git a/test/components/curses_dialog.bash b/test/components/curses_dialog.bash index 24f2945..35afdaf 100755 --- a/test/components/curses_dialog.bash +++ b/test/components/curses_dialog.bash @@ -2,6 +2,6 @@ echo CURSES DIALOG TEST echo "This is a test of how curses dialogs are handled. Expect freaky behaviour." -dialog --title "Dialog title" --inputbox "Enter your name:" 0 0 +whiptail --title "Dialog title" --inputbox "Enter your name:" 0 0 exit $?