From 24b53fc84af301fff592e06723b980e29aa68289 Mon Sep 17 00:00:00 2001 From: Hennadii Stepanov <32963518+hebasto@users.noreply.github.com> Date: Fri, 10 May 2024 14:42:31 +0100 Subject: [PATCH 1/4] refactor, subprocess: Remove `Popen::pid()` --- src/util/subprocess.h | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/util/subprocess.h b/src/util/subprocess.h index af408b31d4..09b386a37a 100644 --- a/src/util/subprocess.h +++ b/src/util/subprocess.h @@ -902,7 +902,6 @@ private: * Command provided in a single string. * wait() - Wait for the child to exit. * retcode() - The return code of the exited child. - * pid() - PID of the spawned child. * poll() - Check the status of the running child. * send(...) - Send input to the input channel of the child. * communicate(...) - Get the output/error from the child and close the channels @@ -956,8 +955,6 @@ public: execute_process(); } - int pid() const noexcept { return child_pid_; } - int retcode() const noexcept { return retcode_; } int wait() noexcept(false); @@ -1068,7 +1065,7 @@ inline int Popen::wait() noexcept(false) return 0; #else int ret, status; - std::tie(ret, status) = util::wait_for_child_exit(pid()); + std::tie(ret, status) = util::wait_for_child_exit(child_pid_); if (ret == -1) { if (errno != ECHILD) throw OSError("waitpid failed", errno); return 0; From 9e1ccf55e178144804e30cfe94757b6da2a6ca28 Mon Sep 17 00:00:00 2001 From: Hennadii Stepanov <32963518+hebasto@users.noreply.github.com> Date: Fri, 10 May 2024 14:47:07 +0100 Subject: [PATCH 2/4] refactor, subprocess: Remove unused `Popen::poll()` --- src/util/subprocess.h | 53 ------------------------------------------- 1 file changed, 53 deletions(-) diff --git a/src/util/subprocess.h b/src/util/subprocess.h index 09b386a37a..37b77c1c56 100644 --- a/src/util/subprocess.h +++ b/src/util/subprocess.h @@ -902,7 +902,6 @@ private: * Command provided in a single string. * wait() - Wait for the child to exit. * retcode() - The return code of the exited child. - * poll() - Check the status of the running child. * send(...) - Send input to the input channel of the child. * communicate(...) - Get the output/error from the child and close the channels * from the parent side. @@ -959,8 +958,6 @@ public: int wait() noexcept(false); - int poll() noexcept(false); - void set_out_buf_cap(size_t cap) { stream_.set_out_buf_cap(cap); } void set_err_buf_cap(size_t cap) { stream_.set_err_buf_cap(cap); } @@ -1078,56 +1075,6 @@ inline int Popen::wait() noexcept(false) #endif } -inline int Popen::poll() noexcept(false) -{ -#ifdef __USING_WINDOWS__ - int ret = WaitForSingleObject(process_handle_, 0); - if (ret != WAIT_OBJECT_0) return -1; - - DWORD dretcode_; - if (FALSE == GetExitCodeProcess(process_handle_, &dretcode_)) - throw OSError("GetExitCodeProcess", 0); - - retcode_ = (int)dretcode_; - CloseHandle(process_handle_); - - return retcode_; -#else - if (!child_created_) return -1; // TODO: ?? - - int status; - - // Returns zero if child is still running - int ret = waitpid(child_pid_, &status, WNOHANG); - if (ret == 0) return -1; - - if (ret == child_pid_) { - if (WIFSIGNALED(status)) { - retcode_ = WTERMSIG(status); - } else if (WIFEXITED(status)) { - retcode_ = WEXITSTATUS(status); - } else { - retcode_ = 255; - } - return retcode_; - } - - if (ret == -1) { - // From subprocess.py - // This happens if SIGCHLD is set to be ignored - // or waiting for child process has otherwise been disabled - // for our process. This child is dead, we cannot get the - // status. - if (errno == ECHILD) retcode_ = 0; - else throw OSError("waitpid failed", errno); - } else { - retcode_ = ret; - } - - return retcode_; -#endif -} - inline void Popen::execute_process() noexcept(false) { #ifdef __USING_WINDOWS__ From 05b6f8793c6d5f17d1cb413e2884f1fb0f367ad8 Mon Sep 17 00:00:00 2001 From: Hennadii Stepanov <32963518+hebasto@users.noreply.github.com> Date: Fri, 10 May 2024 14:47:15 +0100 Subject: [PATCH 3/4] refactor, subprocess: Remove unused `Popen::child_created_` data member --- src/util/subprocess.h | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/util/subprocess.h b/src/util/subprocess.h index 37b77c1c56..ad49bac54b 100644 --- a/src/util/subprocess.h +++ b/src/util/subprocess.h @@ -1027,7 +1027,6 @@ private: std::vector vargs_; std::vector cargv_; - bool child_created_ = false; // Pid of the child process int child_pid_ = -1; @@ -1177,8 +1176,6 @@ inline void Popen::execute_process() noexcept(false) throw OSError("fork failed", errno); } - child_created_ = true; - if (child_pid_ == 0) { // Close descriptors belonging to parent From 5a11d3023f7d0cde777f3496c0f3aa381823d749 Mon Sep 17 00:00:00 2001 From: Hennadii Stepanov <32963518+hebasto@users.noreply.github.com> Date: Fri, 10 May 2024 14:58:27 +0100 Subject: [PATCH 4/4] refactor, subprocess: Remove unused stream API calls --- src/util/subprocess.h | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/src/util/subprocess.h b/src/util/subprocess.h index ad49bac54b..e76ced687c 100644 --- a/src/util/subprocess.h +++ b/src/util/subprocess.h @@ -905,12 +905,6 @@ private: * send(...) - Send input to the input channel of the child. * communicate(...) - Get the output/error from the child and close the channels * from the parent side. - * input() - Get the input channel/File pointer. Can be used for - * customizing the way of sending input to child. - * output() - Get the output channel/File pointer. Usually used - in case of redirection. See piping examples. - * error() - Get the error channel/File pointer. Usually used - in case of redirection. */ class Popen { @@ -995,15 +989,6 @@ public: return communicate(nullptr, 0); } - FILE* input() { return stream_.input(); } - FILE* output() { return stream_.output();} - FILE* error() { return stream_.error(); } - - /// Stream close APIs - void close_input() { stream_.input_.reset(); } - void close_output() { stream_.output_.reset(); } - void close_error() { stream_.error_.reset(); } - private: template void init_args(F&& farg, Args&&... args);