diff --git a/src/util/subprocess.h b/src/util/subprocess.h index af408b31d4..e76ced687c 100644 --- a/src/util/subprocess.h +++ b/src/util/subprocess.h @@ -902,17 +902,9 @@ 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 * 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 { @@ -956,14 +948,10 @@ public: execute_process(); } - int pid() const noexcept { return child_pid_; } - int retcode() const noexcept { return retcode_; } 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); } @@ -1001,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); @@ -1033,7 +1012,6 @@ private: std::vector vargs_; std::vector cargv_; - bool child_created_ = false; // Pid of the child process int child_pid_ = -1; @@ -1068,7 +1046,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; @@ -1081,56 +1059,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__ @@ -1233,8 +1161,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