From 633e45b2e2728efcb0637afa94fcbd5756dfbe76 Mon Sep 17 00:00:00 2001 From: Sebastian Falbesoner Date: Fri, 12 Apr 2024 01:42:57 +0200 Subject: [PATCH 1/8] remove unneeded shell option from cpp-subprocess We don't use this option and it's not supported on Windows anyways, so we can get as well rid of it. --- src/util/subprocess.hpp | 43 ----------------------------------------- 1 file changed, 43 deletions(-) diff --git a/src/util/subprocess.hpp b/src/util/subprocess.hpp index 0fcc9397ea..96444ad1e7 100644 --- a/src/util/subprocess.hpp +++ b/src/util/subprocess.hpp @@ -431,26 +431,6 @@ namespace util } - /*! - * Function: join - * Parameters: - * [in] vec : Vector of strings which needs to be joined to form - * a single string with words separated by a separator char. - * [in] sep : String used to separate 2 words in the joined string. - * Default constructed to ' ' (space). - * [out] string: Joined string. - */ - static inline - std::string join(const std::vector& vec, - const std::string& sep = " ") - { - std::string res; - for (auto& elem : vec) res.append(elem + sep); - res.erase(--res.end()); - return res; - } - - #ifndef __USING_WINDOWS__ /*! * Function: set_clo_on_exec @@ -696,11 +676,6 @@ struct session_leader { bool leader_ = false; }; -struct shell { - explicit shell(bool s): shell_(s) {} - bool shell_ = false; -}; - /*! * Base class for all arguments involving string value. */ @@ -1011,7 +986,6 @@ struct ArgumentDeducer void set_option(bufsize&& bsiz); void set_option(environment&& env); void set_option(defer_spawn&& defer); - void set_option(shell&& sh); void set_option(input&& inp); void set_option(output&& out); void set_option(error&& err); @@ -1350,7 +1324,6 @@ private: bool defer_process_start_ = false; bool close_fds_ = false; bool has_preexec_fn_ = false; - bool shell_ = false; bool session_leader_ = false; std::string exe_name_; @@ -1492,10 +1465,6 @@ inline void Popen::kill(int sig_num) inline void Popen::execute_process() noexcept(false) { #ifdef __USING_WINDOWS__ - if (this->shell_) { - throw OSError("shell not currently supported on windows", 0); - } - void* environment_string_table_ptr = nullptr; env_vector_t environment_string_vector; if(this->env_.size()){ @@ -1588,14 +1557,6 @@ inline void Popen::execute_process() noexcept(false) int err_rd_pipe, err_wr_pipe; std::tie(err_rd_pipe, err_wr_pipe) = util::pipe_cloexec(); - if (shell_) { - auto new_cmd = util::join(vargs_); - vargs_.clear(); - vargs_.insert(vargs_.begin(), {"/bin/sh", "-c"}); - vargs_.push_back(new_cmd); - populate_c_argv(); - } - if (exe_name_.length()) { vargs_.insert(vargs_.begin(), exe_name_); populate_c_argv(); @@ -1678,10 +1639,6 @@ namespace detail { popen_->defer_process_start_ = defer.defer; } - inline void ArgumentDeducer::set_option(shell&& sh) { - popen_->shell_ = sh.shell_; - } - inline void ArgumentDeducer::set_option(session_leader&& sleader) { popen_->session_leader_ = sleader.leader_; } From cececad7b29e2ca3de1216db1c541dba6dc81bfa Mon Sep 17 00:00:00 2001 From: Sebastian Falbesoner Date: Fri, 12 Apr 2024 01:48:08 +0200 Subject: [PATCH 2/8] remove unneeded preexec function option from cpp-subprocess We don't seem to ever need this, so remove it. --- src/util/subprocess.hpp | 50 ----------------------------------------- 1 file changed, 50 deletions(-) diff --git a/src/util/subprocess.hpp b/src/util/subprocess.hpp index 96444ad1e7..1a98be3e1d 100644 --- a/src/util/subprocess.hpp +++ b/src/util/subprocess.hpp @@ -845,44 +845,6 @@ struct error int wr_ch_ = -1; }; -// Impoverished, meager, needy, truly needy -// version of type erasure to store function pointers -// needed to provide the functionality of preexec_func -// ATTN: Can be used only to execute functions with no -// arguments and returning void. -// Could have used more efficient methods, ofcourse, but -// that won't yield me the consistent syntax which I am -// aiming for. If you know, then please do let me know. - -class preexec_func -{ -public: - preexec_func() {} - - template - explicit preexec_func(Func f): holder_(new FuncHolder(std::move(f))) - {} - - void operator()() { - (*holder_)(); - } - -private: - struct HolderBase { - virtual void operator()() const = 0; - virtual ~HolderBase(){}; - }; - template - struct FuncHolder: HolderBase { - FuncHolder(T func): func_(std::move(func)) {} - void operator()() const override { func_(); } - // The function pointer/reference - T func_; - }; - - std::unique_ptr holder_ = nullptr; -}; - // ~~~~ End Popen Args ~~~~ @@ -990,7 +952,6 @@ struct ArgumentDeducer void set_option(output&& out); void set_option(error&& err); void set_option(close_fds&& cfds); - void set_option(preexec_func&& prefunc); void set_option(session_leader&& sleader); private: @@ -1323,13 +1284,11 @@ private: bool defer_process_start_ = false; bool close_fds_ = false; - bool has_preexec_fn_ = false; bool session_leader_ = false; std::string exe_name_; std::string cwd_; env_map_t env_; - preexec_func preexec_fn_; // Command in string format std::string args_; @@ -1669,11 +1628,6 @@ namespace detail { popen_->close_fds_ = cfds.close_all; } - inline void ArgumentDeducer::set_option(preexec_func&& prefunc) { - popen_->preexec_fn_ = std::move(prefunc); - popen_->has_preexec_fn_ = true; - } - inline void Child::execute_child() { #ifndef __USING_WINDOWS__ @@ -1737,10 +1691,6 @@ namespace detail { if (sys_ret == -1) throw OSError("chdir failed", errno); } - if (parent_->has_preexec_fn_) { - parent_->preexec_fn_(); - } - if (parent_->session_leader_) { sys_ret = setsid(); if (sys_ret == -1) throw OSError("setsid failed", errno); From 80d008c66d00d3496cd8549daee6775cf2c6b782 Mon Sep 17 00:00:00 2001 From: Sebastian Falbesoner Date: Sat, 13 Apr 2024 11:43:02 +0200 Subject: [PATCH 3/8] remove unneeded defer_spawn option from cpp-subprocess For our use-case, there doesn't seem to be any need for this. --- src/util/subprocess.hpp | 40 +++------------------------------------- 1 file changed, 3 insertions(+), 37 deletions(-) diff --git a/src/util/subprocess.hpp b/src/util/subprocess.hpp index 1a98be3e1d..dd0789b72c 100644 --- a/src/util/subprocess.hpp +++ b/src/util/subprocess.hpp @@ -641,16 +641,6 @@ struct bufsize { int bufsiz = 0; }; -/*! - * Option to defer spawning of the child process - * till `Popen::start_process` API is called. - * Default value is false. - */ -struct defer_spawn { - explicit defer_spawn(bool d): defer(d) {} - bool defer = false; -}; - /*! * Option to close all file descriptors * when the child process is spawned. @@ -947,7 +937,6 @@ struct ArgumentDeducer void set_option(cwd&& cwdir); void set_option(bufsize&& bsiz); void set_option(environment&& env); - void set_option(defer_spawn&& defer); void set_option(input&& inp); void set_option(output&& out); void set_option(error&& err); @@ -1153,8 +1142,6 @@ private: in case of redirection. See piping examples. *12. error() - Get the error channel/File pointer. Usually used in case of redirection. - *13. start_process() - Start the child process. Only to be used when - * `defer_spawn` option was provided in Popen constructor. */ class Popen { @@ -1172,7 +1159,7 @@ public: // Setup the communication channels of the Popen class stream_.setup_comm_channels(); - if (!defer_process_start_) execute_process(); + execute_process(); } template @@ -1184,7 +1171,7 @@ public: // Setup the communication channels of the Popen class stream_.setup_comm_channels(); - if (!defer_process_start_) execute_process(); + execute_process(); } template @@ -1195,7 +1182,7 @@ public: // Setup the communication channels of the Popen class stream_.setup_comm_channels(); - if (!defer_process_start_) execute_process(); + execute_process(); } /* @@ -1207,8 +1194,6 @@ public: } */ - void start_process() noexcept(false); - int pid() const noexcept { return child_pid_; } int retcode() const noexcept { return retcode_; } @@ -1282,7 +1267,6 @@ private: std::future cleanup_future_; #endif - bool defer_process_start_ = false; bool close_fds_ = false; bool session_leader_ = false; @@ -1323,20 +1307,6 @@ inline void Popen::populate_c_argv() cargv_.push_back(nullptr); } -inline void Popen::start_process() noexcept(false) -{ - // The process was started/tried to be started - // in the constructor itself. - // For explicitly calling this API to start the - // process, 'defer_spawn' argument must be set to - // true in the constructor. - if (!defer_process_start_) { - assert (0); - return; - } - execute_process(); -} - inline int Popen::wait() noexcept(false) { #ifdef __USING_WINDOWS__ @@ -1594,10 +1564,6 @@ namespace detail { popen_->env_ = std::move(env.env_); } - inline void ArgumentDeducer::set_option(defer_spawn&& defer) { - popen_->defer_process_start_ = defer.defer; - } - inline void ArgumentDeducer::set_option(session_leader&& sleader) { popen_->session_leader_ = sleader.leader_; } From 62db8f8e5a6cfe19d905afc91731d6bc8a665f61 Mon Sep 17 00:00:00 2001 From: Sebastian Falbesoner Date: Tue, 16 Apr 2024 12:53:07 +0200 Subject: [PATCH 4/8] remove unneeded session_leader option from cpp-subprocess --- src/util/subprocess.hpp | 25 +------------------------ 1 file changed, 1 insertion(+), 24 deletions(-) diff --git a/src/util/subprocess.hpp b/src/util/subprocess.hpp index dd0789b72c..56f17c771f 100644 --- a/src/util/subprocess.hpp +++ b/src/util/subprocess.hpp @@ -655,17 +655,6 @@ struct close_fds { bool close_all = false; }; -/*! - * Option to make the child process as the - * session leader and thus the process - * group leader. - * Default value is false. - */ -struct session_leader { - explicit session_leader(bool sl): leader_(sl) {} - bool leader_ = false; -}; - /*! * Base class for all arguments involving string value. */ @@ -941,7 +930,6 @@ struct ArgumentDeducer void set_option(output&& out); void set_option(error&& err); void set_option(close_fds&& cfds); - void set_option(session_leader&& sleader); private: Popen* popen_ = nullptr; @@ -1268,7 +1256,6 @@ private: #endif bool close_fds_ = false; - bool session_leader_ = false; std::string exe_name_; std::string cwd_; @@ -1385,8 +1372,7 @@ inline void Popen::kill(int sig_num) throw OSError("TerminateProcess", 0); } #else - if (session_leader_) killpg(child_pid_, sig_num); - else ::kill(child_pid_, sig_num); + ::kill(child_pid_, sig_num); #endif } @@ -1564,10 +1550,6 @@ namespace detail { popen_->env_ = std::move(env.env_); } - inline void ArgumentDeducer::set_option(session_leader&& sleader) { - popen_->session_leader_ = sleader.leader_; - } - inline void ArgumentDeducer::set_option(input&& inp) { if (inp.rd_ch_ != -1) popen_->stream_.read_from_parent_ = inp.rd_ch_; if (inp.wr_ch_ != -1) popen_->stream_.write_to_child_ = inp.wr_ch_; @@ -1657,11 +1639,6 @@ namespace detail { if (sys_ret == -1) throw OSError("chdir failed", errno); } - if (parent_->session_leader_) { - sys_ret = setsid(); - if (sys_ret == -1) throw OSError("setsid failed", errno); - } - // Replace the current image with the executable if (parent_->env_.size()) { for (auto& kv : parent_->env_) { From 79c30363733503a1fb7d4c98aa0d56ced0be6e32 Mon Sep 17 00:00:00 2001 From: Sebastian Falbesoner Date: Tue, 16 Apr 2024 12:55:55 +0200 Subject: [PATCH 5/8] remove unneeded close_fds option from cpp-subprocess --- src/util/subprocess.hpp | 32 -------------------------------- 1 file changed, 32 deletions(-) diff --git a/src/util/subprocess.hpp b/src/util/subprocess.hpp index 56f17c771f..ea555c58a4 100644 --- a/src/util/subprocess.hpp +++ b/src/util/subprocess.hpp @@ -641,20 +641,6 @@ struct bufsize { int bufsiz = 0; }; -/*! - * Option to close all file descriptors - * when the child process is spawned. - * The close fd list does not include - * input/output/error if they are explicitly - * set as part of the Popen arguments. - * - * Default value is false. - */ -struct close_fds { - explicit close_fds(bool c): close_all(c) {} - bool close_all = false; -}; - /*! * Base class for all arguments involving string value. */ @@ -929,7 +915,6 @@ struct ArgumentDeducer void set_option(input&& inp); void set_option(output&& out); void set_option(error&& err); - void set_option(close_fds&& cfds); private: Popen* popen_ = nullptr; @@ -1255,8 +1240,6 @@ private: std::future cleanup_future_; #endif - bool close_fds_ = false; - std::string exe_name_; std::string cwd_; env_map_t env_; @@ -1572,10 +1555,6 @@ namespace detail { if (err.rd_ch_ != -1) popen_->stream_.err_read_ = err.rd_ch_; } - inline void ArgumentDeducer::set_option(close_fds&& cfds) { - popen_->close_fds_ = cfds.close_all; - } - inline void Child::execute_child() { #ifndef __USING_WINDOWS__ @@ -1622,17 +1601,6 @@ namespace detail { if (stream.err_write_ != -1 && stream.err_write_ > 2) close(stream.err_write_); - // Close all the inherited fd's except the error write pipe - if (parent_->close_fds_) { - int max_fd = sysconf(_SC_OPEN_MAX); - if (max_fd == -1) throw OSError("sysconf failed", errno); - - for (int i = 3; i < max_fd; i++) { - if (i == err_wr_pipe_) continue; - close(i); - } - } - // Change the working directory if provided if (parent_->cwd_.length()) { sys_ret = chdir(parent_->cwd_.c_str()); From 03ffb09c31aa04cc296c0ce10d07109e22a8dd75 Mon Sep 17 00:00:00 2001 From: Sebastian Falbesoner Date: Tue, 16 Apr 2024 14:11:21 +0200 Subject: [PATCH 6/8] remove unneeded bufsize option from cpp-subprocess --- src/util/subprocess.hpp | 29 +---------------------------- 1 file changed, 1 insertion(+), 28 deletions(-) diff --git a/src/util/subprocess.hpp b/src/util/subprocess.hpp index ea555c58a4..f54223855a 100644 --- a/src/util/subprocess.hpp +++ b/src/util/subprocess.hpp @@ -631,16 +631,6 @@ namespace util * ------------------------------- */ -/*! - * The buffer size of the stdin/stdout/stderr - * streams of the child process. - * Default value is 0. - */ -struct bufsize { - explicit bufsize(int sz): bufsiz(sz) {} - int bufsiz = 0; -}; - /*! * Base class for all arguments involving string value. */ @@ -910,7 +900,6 @@ struct ArgumentDeducer void set_option(executable&& exe); void set_option(cwd&& cwdir); - void set_option(bufsize&& bsiz); void set_option(environment&& env); void set_option(input&& inp); void set_option(output&& out); @@ -1065,9 +1054,6 @@ public:// Yes they are public HANDLE g_hChildStd_ERR_Wr = nullptr; #endif - // Buffer size for the IO streams - int bufsiz_ = 0; - // Pipes for communicating with child // Emulates stdin @@ -1525,10 +1511,6 @@ namespace detail { popen_->cwd_ = std::move(cwdir.arg_value); } - inline void ArgumentDeducer::set_option(bufsize&& bsiz) { - popen_->stream_.bufsiz_ = bsiz.bufsiz; - } - inline void ArgumentDeducer::set_option(environment&& env) { popen_->env_ = std::move(env.env_); } @@ -1658,16 +1640,7 @@ namespace detail { for (auto& h : handles) { if (h == nullptr) continue; - switch (bufsiz_) { - case 0: - setvbuf(h, nullptr, _IONBF, BUFSIZ); - break; - case 1: - setvbuf(h, nullptr, _IONBF, BUFSIZ); - break; - default: - setvbuf(h, nullptr, _IOFBF, bufsiz_); - }; + setvbuf(h, nullptr, _IONBF, BUFSIZ); } #endif } From 2088777ba0f9ad3f6d4ab8b0b6ff8aad71117307 Mon Sep 17 00:00:00 2001 From: Sebastian Falbesoner Date: Tue, 16 Apr 2024 14:13:08 +0200 Subject: [PATCH 7/8] remove unneeded cwd option from cpp-subprocess --- src/util/subprocess.hpp | 28 ++-------------------------- 1 file changed, 2 insertions(+), 26 deletions(-) diff --git a/src/util/subprocess.hpp b/src/util/subprocess.hpp index f54223855a..3591c65cc7 100644 --- a/src/util/subprocess.hpp +++ b/src/util/subprocess.hpp @@ -656,18 +656,6 @@ struct executable: string_arg executable(T&& arg): string_arg(std::forward(arg)) {} }; -/*! - * Option to set the current working directory - * of the spawned process. - * - * Eg: cwd{"/some/path/x"} - */ -struct cwd: string_arg -{ - template - cwd(T&& arg): string_arg(std::forward(arg)) {} -}; - /*! * Option to specify environment variables required by * the spawned process. @@ -899,7 +887,6 @@ struct ArgumentDeducer ArgumentDeducer(Popen* p): popen_(p) {} void set_option(executable&& exe); - void set_option(cwd&& cwdir); void set_option(environment&& env); void set_option(input&& inp); void set_option(output&& out); @@ -1083,9 +1070,9 @@ private: * interface to the client. * * API's provided by the class: - * 1. Popen({"cmd"}, output{..}, error{..}, cwd{..}, ....) + * 1. Popen({"cmd"}, output{..}, error{..}, ....) * Command provided as a sequence. - * 2. Popen("cmd arg1"m output{..}, error{..}, cwd{..}, ....) + * 2. Popen("cmd arg1"m output{..}, error{..}, ....) * Command provided in a single string. * 3. wait() - Wait for the child to exit. * 4. retcode() - The return code of the exited child. @@ -1227,7 +1214,6 @@ private: #endif std::string exe_name_; - std::string cwd_; env_map_t env_; // Command in string format @@ -1507,10 +1493,6 @@ namespace detail { popen_->exe_name_ = std::move(exe.arg_value); } - inline void ArgumentDeducer::set_option(cwd&& cwdir) { - popen_->cwd_ = std::move(cwdir.arg_value); - } - inline void ArgumentDeducer::set_option(environment&& env) { popen_->env_ = std::move(env.env_); } @@ -1583,12 +1565,6 @@ namespace detail { if (stream.err_write_ != -1 && stream.err_write_ > 2) close(stream.err_write_); - // Change the working directory if provided - if (parent_->cwd_.length()) { - sys_ret = chdir(parent_->cwd_.c_str()); - if (sys_ret == -1) throw OSError("chdir failed", errno); - } - // Replace the current image with the executable if (parent_->env_.size()) { for (auto& kv : parent_->env_) { From 13adbf733f09c73c3cf0025d94c52f9cec5dba3b Mon Sep 17 00:00:00 2001 From: Sebastian Falbesoner Date: Tue, 16 Apr 2024 14:22:30 +0200 Subject: [PATCH 8/8] remove unneeded environment option from cpp-subprocess --- src/util/subprocess.hpp | 147 +--------------------------------------- 1 file changed, 2 insertions(+), 145 deletions(-) diff --git a/src/util/subprocess.hpp b/src/util/subprocess.hpp index 3591c65cc7..7a5ed5f3d6 100644 --- a/src/util/subprocess.hpp +++ b/src/util/subprocess.hpp @@ -154,19 +154,6 @@ public: {} }; -//-------------------------------------------------------------------- - -//Environment Variable types -#ifndef _MSC_VER - using env_string_t = std::string; - using env_char_t = char; -#else - using env_string_t = std::wstring; - using env_char_t = wchar_t; -#endif -using env_map_t = std::map; -using env_vector_t = std::vector; - //-------------------------------------------------------------------- namespace util { @@ -305,100 +292,6 @@ namespace util if (!SetHandleInformation(*child_handle, HANDLE_FLAG_INHERIT, 0)) throw OSError("SetHandleInformation", 0); } - - // env_map_t MapFromWindowsEnvironment() - // * Imports current Environment in a C-string table - // * Parses the strings by splitting on the first "=" per line - // * Creates a map of the variables - // * Returns the map - inline env_map_t MapFromWindowsEnvironment(){ - wchar_t *variable_strings_ptr; - wchar_t *environment_strings_ptr; - std::wstring delimiter(L"="); - int del_len = delimiter.length(); - env_map_t mapped_environment; - - // Get a pointer to the environment block. - environment_strings_ptr = GetEnvironmentStringsW(); - // If the returned pointer is NULL, exit. - if (environment_strings_ptr == NULL) - { - throw OSError("GetEnvironmentStringsW", 0); - } - - // Variable strings are separated by NULL byte, and the block is - // terminated by a NULL byte. - - variable_strings_ptr = (wchar_t *) environment_strings_ptr; - - //Since the environment map ends with a null, we can loop until we find it. - while (*variable_strings_ptr) - { - // Create a string from Variable String - env_string_t current_line(variable_strings_ptr); - // Find the first "equals" sign. - auto pos = current_line.find(delimiter); - // Assuming it's not missing ... - if(pos!=std::wstring::npos){ - // ... parse the key and value. - env_string_t key = current_line.substr(0, pos); - env_string_t value = current_line.substr(pos + del_len); - // Map the entry. - mapped_environment[key] = value; - } - // Jump to next line in the environment map. - variable_strings_ptr += std::wcslen(variable_strings_ptr) + 1; - } - // We're done with the old environment map buffer. - FreeEnvironmentStringsW(environment_strings_ptr); - - // Return the map. - return mapped_environment; - } - - // env_vector_t WindowsEnvironmentVectorFromMap(const env_map_t &source_map) - // * Creates a vector buffer for the new environment string table - // * Copies in the mapped variables - // * Returns the vector - inline env_vector_t WindowsEnvironmentVectorFromMap(const env_map_t &source_map) - { - // Make a new environment map buffer. - env_vector_t environment_map_buffer; - // Give it some space. - environment_map_buffer.reserve(4096); - - // And fill'er up. - for(auto kv: source_map){ - // Create the line - env_string_t current_line(kv.first); current_line += L"="; current_line += kv.second; - // Add the line to the buffer. - std::copy(current_line.begin(), current_line.end(), std::back_inserter(environment_map_buffer)); - // Append a null - environment_map_buffer.push_back(0); - } - // Append one last null because of how Windows does it's environment maps. - environment_map_buffer.push_back(0); - - return environment_map_buffer; - } - - // env_vector_t CreateUpdatedWindowsEnvironmentVector(const env_map_t &changes_map) - // * Merges host environment with new mapped variables - // * Creates and returns string vector based on map - inline env_vector_t CreateUpdatedWindowsEnvironmentVector(const env_map_t &changes_map){ - // Import the environment map - env_map_t environment_map = MapFromWindowsEnvironment(); - // Merge in the changes with overwrite - for(auto& it: changes_map) - { - environment_map[it.first] = it.second; - } - // Create a Windows-usable Environment Map Buffer - env_vector_t environment_map_strings_vector = WindowsEnvironmentVectorFromMap(environment_map); - - return environment_map_strings_vector; - } - #endif /*! @@ -656,22 +549,6 @@ struct executable: string_arg executable(T&& arg): string_arg(std::forward(arg)) {} }; -/*! - * Option to specify environment variables required by - * the spawned process. - * - * Eg: environment{{ {"K1", "V1"}, {"K2", "V2"},... }} - */ -struct environment -{ - environment(env_map_t&& env): - env_(std::move(env)) {} - explicit environment(const env_map_t& env): - env_(env) {} - env_map_t env_; -}; - - /*! * Used for redirecting input/output/error */ @@ -887,7 +764,6 @@ struct ArgumentDeducer ArgumentDeducer(Popen* p): popen_(p) {} void set_option(executable&& exe); - void set_option(environment&& env); void set_option(input&& inp); void set_option(output&& out); void set_option(error&& err); @@ -1214,7 +1090,6 @@ private: #endif std::string exe_name_; - env_map_t env_; // Command in string format std::string args_; @@ -1335,13 +1210,6 @@ inline void Popen::kill(int sig_num) inline void Popen::execute_process() noexcept(false) { #ifdef __USING_WINDOWS__ - void* environment_string_table_ptr = nullptr; - env_vector_t environment_string_vector; - if(this->env_.size()){ - environment_string_vector = util::CreateUpdatedWindowsEnvironmentVector(env_); - environment_string_table_ptr = (void*)environment_string_vector.data(); - } - if (exe_name_.length()) { this->vargs_.insert(this->vargs_.begin(), this->exe_name_); this->populate_c_argv(); @@ -1388,7 +1256,7 @@ inline void Popen::execute_process() noexcept(false) NULL, // primary thread security attributes TRUE, // handles are inherited creation_flags, // creation flags - environment_string_table_ptr, // use provided environment + NULL, // use parent's environment NULL, // use parent's current directory &siStartInfo, // STARTUPINFOW pointer &piProcInfo); // receives PROCESS_INFORMATION @@ -1493,10 +1361,6 @@ namespace detail { popen_->exe_name_ = std::move(exe.arg_value); } - inline void ArgumentDeducer::set_option(environment&& env) { - popen_->env_ = std::move(env.env_); - } - inline void ArgumentDeducer::set_option(input&& inp) { if (inp.rd_ch_ != -1) popen_->stream_.read_from_parent_ = inp.rd_ch_; if (inp.wr_ch_ != -1) popen_->stream_.write_to_child_ = inp.wr_ch_; @@ -1566,14 +1430,7 @@ namespace detail { close(stream.err_write_); // Replace the current image with the executable - if (parent_->env_.size()) { - for (auto& kv : parent_->env_) { - setenv(kv.first.c_str(), kv.second.c_str(), 1); - } - sys_ret = execvp(parent_->exe_name_.c_str(), parent_->cargv_.data()); - } else { - sys_ret = execvp(parent_->exe_name_.c_str(), parent_->cargv_.data()); - } + sys_ret = execvp(parent_->exe_name_.c_str(), parent_->cargv_.data()); if (sys_ret == -1) throw OSError("execve failed", errno);