@@ -36,8 +36,6 @@ Documentation for C++ subprocessing library.
36
36
#ifndef BITCOIN_UTIL_SUBPROCESS_H
37
37
#define BITCOIN_UTIL_SUBPROCESS_H
38
38
39
- #include < util/fs.h>
40
- #include < util/strencodings.h>
41
39
#include < util/syserror.h>
42
40
43
41
#include < algorithm>
@@ -538,20 +536,6 @@ namespace util
538
536
* -------------------------------
539
537
*/
540
538
541
- /* !
542
- * Option to close all file descriptors
543
- * when the child process is spawned.
544
- * The close fd list does not include
545
- * input/output/error if they are explicitly
546
- * set as part of the Popen arguments.
547
- *
548
- * Default value is false.
549
- */
550
- struct close_fds {
551
- explicit close_fds (bool c): close_all(c) {}
552
- bool close_all = false ;
553
- };
554
-
555
539
/* !
556
540
* Base class for all arguments involving string value.
557
541
*/
@@ -749,7 +733,6 @@ struct ArgumentDeducer
749
733
void set_option (input&& inp);
750
734
void set_option (output&& out);
751
735
void set_option (error&& err);
752
- void set_option (close_fds&& cfds);
753
736
754
737
private:
755
738
Popen* popen_ = nullptr ;
@@ -1043,8 +1026,6 @@ class Popen
1043
1026
std::future<void > cleanup_future_;
1044
1027
#endif
1045
1028
1046
- bool close_fds_ = false ;
1047
-
1048
1029
std::string exe_name_;
1049
1030
1050
1031
// Command in string format
@@ -1288,10 +1269,6 @@ namespace detail {
1288
1269
if (err.rd_ch_ != -1 ) popen_->stream_ .err_read_ = err.rd_ch_ ;
1289
1270
}
1290
1271
1291
- inline void ArgumentDeducer::set_option (close_fds&& cfds) {
1292
- popen_->close_fds_ = cfds.close_all ;
1293
- }
1294
-
1295
1272
1296
1273
inline void Child::execute_child () {
1297
1274
#ifndef __USING_WINDOWS__
@@ -1338,41 +1315,6 @@ namespace detail {
1338
1315
if (stream.err_write_ != -1 && stream.err_write_ > 2 )
1339
1316
subprocess_close (stream.err_write_ );
1340
1317
1341
- // Close all the inherited fd's except the error write pipe
1342
- if (parent_->close_fds_ ) {
1343
- // If possible, try to get the list of open file descriptors from the
1344
- // operating system. This is more efficient, but not guaranteed to be
1345
- // available.
1346
- #ifdef __linux__
1347
- // For Linux, enumerate /proc/<pid>/fd.
1348
- try {
1349
- std::vector<int > fds_to_close;
1350
- for (const auto & it : fs::directory_iterator (strprintf (" /proc/%d/fd" , getpid ()))) {
1351
- auto fd{ToIntegral<uint64_t >(it.path ().filename ().native ())};
1352
- if (!fd || *fd > std::numeric_limits<int >::max ()) continue ;
1353
- if (*fd <= 2 ) continue ; // leave std{in,out,err} alone
1354
- if (*fd == static_cast <uint64_t >(err_wr_pipe_)) continue ;
1355
- fds_to_close.push_back (*fd);
1356
- }
1357
- for (const int fd : fds_to_close) {
1358
- close (fd);
1359
- }
1360
- } catch (const fs::filesystem_error &e) {
1361
- throw OSError (" /proc/<pid>/fd iteration failed" , e.code ().value ());
1362
- }
1363
- #else
1364
- // On other operating systems, iterate over all file descriptor slots
1365
- // and try to close them all.
1366
- int max_fd = sysconf (_SC_OPEN_MAX);
1367
- if (max_fd == -1 ) throw OSError (" sysconf failed" , errno);
1368
-
1369
- for (int i = 3 ; i < max_fd; i++) {
1370
- if (i == err_wr_pipe_) continue ;
1371
- close (i);
1372
- }
1373
- #endif
1374
- }
1375
-
1376
1318
// Replace the current image with the executable
1377
1319
sys_ret = execvp (parent_->exe_name_ .c_str (), parent_->cargv_ .data ());
1378
1320
0 commit comments