remove unneeded close_fds option from cpp-subprocess
This commit is contained in:
1 parent
62db8f8e5a
commit
79c3036373
1 file changed
-32
@@ -641,20 +641,6 @@ struct bufsize {
|
|||||||
int bufsiz = 0;
|
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.
|
* Base class for all arguments involving string value.
|
||||||
*/
|
*/
|
||||||
@@ -929,7 +915,6 @@ struct ArgumentDeducer
|
|||||||
void set_option(input&& inp);
|
void set_option(input&& inp);
|
||||||
void set_option(output&& out);
|
void set_option(output&& out);
|
||||||
void set_option(error&& err);
|
void set_option(error&& err);
|
||||||
void set_option(close_fds&& cfds);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Popen* popen_ = nullptr;
|
Popen* popen_ = nullptr;
|
||||||
@@ -1255,8 +1240,6 @@ private:
|
|||||||
std::future<void> cleanup_future_;
|
std::future<void> cleanup_future_;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
bool close_fds_ = false;
|
|
||||||
|
|
||||||
std::string exe_name_;
|
std::string exe_name_;
|
||||||
std::string cwd_;
|
std::string cwd_;
|
||||||
env_map_t env_;
|
env_map_t env_;
|
||||||
@@ -1572,10 +1555,6 @@ namespace detail {
|
|||||||
if (err.rd_ch_ != -1) popen_->stream_.err_read_ = err.rd_ch_;
|
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() {
|
inline void Child::execute_child() {
|
||||||
#ifndef __USING_WINDOWS__
|
#ifndef __USING_WINDOWS__
|
||||||
@@ -1622,17 +1601,6 @@ namespace detail {
|
|||||||
if (stream.err_write_ != -1 && stream.err_write_ > 2)
|
if (stream.err_write_ != -1 && stream.err_write_ > 2)
|
||||||
close(stream.err_write_);
|
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
|
// Change the working directory if provided
|
||||||
if (parent_->cwd_.length()) {
|
if (parent_->cwd_.length()) {
|
||||||
sys_ret = chdir(parent_->cwd_.c_str());
|
sys_ret = chdir(parent_->cwd_.c_str());
|
||||||
|
|||||||
Reference in new issue
Block a user