aboutsummaryrefslogtreecommitdiff
path: root/src/common
diff options
context:
space:
mode:
authorSebastian Falbesoner <sebastian.falbesoner@gmail.com>2023-03-12 18:59:25 +0100
committerHennadii Stepanov <32963518+hebasto@users.noreply.github.com>2024-03-27 14:16:37 +0000
commit70434b1c443d9251a880d0193af771f574c40617 (patch)
tree9aa7de8e249485bad0f05df4769c547bd79a73af /src/common
parentcc8b9875b104c31f0a5b5e4195a8278ec55f35f7 (diff)
downloadbitcoin-70434b1c443d9251a880d0193af771f574c40617.tar.xz
external_signer: replace boost::process with cpp-subprocess
This primarily affects the `RunCommandParseJSON` utility function.
Diffstat (limited to 'src/common')
-rw-r--r--src/common/run_command.cpp25
1 files changed, 10 insertions, 15 deletions
diff --git a/src/common/run_command.cpp b/src/common/run_command.cpp
index 8bd5febd53..e5356490ef 100644
--- a/src/common/run_command.cpp
+++ b/src/common/run_command.cpp
@@ -12,39 +12,34 @@
#include <univalue.h>
#ifdef ENABLE_EXTERNAL_SIGNER
-#include <boost/process.hpp>
+#include <util/subprocess.hpp>
#endif // ENABLE_EXTERNAL_SIGNER
UniValue RunCommandParseJSON(const std::string& str_command, const std::string& str_std_in)
{
#ifdef ENABLE_EXTERNAL_SIGNER
- namespace bp = boost::process;
+ namespace sp = subprocess;
UniValue result_json;
- bp::opstream stdin_stream;
- bp::ipstream stdout_stream;
- bp::ipstream stderr_stream;
+ std::istringstream stdout_stream;
+ std::istringstream stderr_stream;
if (str_command.empty()) return UniValue::VNULL;
- bp::child c(
- str_command,
- bp::std_out > stdout_stream,
- bp::std_err > stderr_stream,
- bp::std_in < stdin_stream
- );
+ auto c = sp::Popen(str_command, sp::input{sp::PIPE}, sp::output{sp::PIPE}, sp::error{sp::PIPE});
if (!str_std_in.empty()) {
- stdin_stream << str_std_in << std::endl;
+ c.send(str_std_in);
}
- stdin_stream.pipe().close();
+ auto [out_res, err_res] = c.communicate();
+ stdout_stream.str(std::string{out_res.buf.begin(), out_res.buf.end()});
+ stderr_stream.str(std::string{err_res.buf.begin(), err_res.buf.end()});
std::string result;
std::string error;
std::getline(stdout_stream, result);
std::getline(stderr_stream, error);
- c.wait();
- const int n_error = c.exit_code();
+ const int n_error = c.retcode();
if (n_error) throw std::runtime_error(strprintf("RunCommandParseJSON error: process(%s) returned %d: %s\n", str_command, n_error, error));
if (!result_json.read(result)) throw std::runtime_error("Unable to parse JSON: " + result);