Merge e4df534c60 into merged_master (Bitcoin PR #15382)

This commit is contained in:
Andrew Poelstra 2020-11-27 01:48:55 +00:00
commit 519f434cd7
24 changed files with 295 additions and 15 deletions

View file

@ -6,6 +6,10 @@
#include <sync.h>
#include <util/system.h>
#ifdef HAVE_BOOST_PROCESS
#include <boost/process.hpp>
#endif // HAVE_BOOST_PROCESS
#include <chainparamsbase.h>
#include <util/strencodings.h>
#include <util/string.h>
@ -1185,6 +1189,43 @@ void runCommand(const std::string& strCommand)
}
#endif
#ifdef HAVE_BOOST_PROCESS
UniValue RunCommandParseJSON(const std::string& str_command, const std::string& str_std_in)
{
namespace bp = boost::process;
UniValue result_json;
bp::opstream stdin_stream;
bp::ipstream stdout_stream;
bp::ipstream 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
);
if (!str_std_in.empty()) {
stdin_stream << str_std_in << std::endl;
}
stdin_stream.pipe().close();
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();
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);
return result_json;
}
#endif // HAVE_BOOST_PROCESS
void SetupEnvironment()
{
#ifdef HAVE_MALLOPT_ARENA_MAX