Core/Common: Capsule boost process into helper functions
* For easier usage, the processes output it routed correctly to the TC logger line by line now. * Add support for asynchronous process execution and process termination.
This commit is contained in:
1 parent
e0cb17f098
commit
a75d2b01fb
6 files changed
+350
-61
No files matched your search
@@ -22,19 +22,11 @@
|
||||
#include "DatabaseLoader.h"
|
||||
#include "Config.h"
|
||||
#include "BuiltInConfig.h"
|
||||
#include "StartProcess.h"
|
||||
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <unordered_map>
|
||||
#include <boost/process.hpp>
|
||||
#include <boost/iostreams/stream.hpp>
|
||||
#include <boost/iostreams/copy.hpp>
|
||||
#include <boost/iostreams/device/file_descriptor.hpp>
|
||||
#include <boost/system/system_error.hpp>
|
||||
|
||||
using namespace boost::process;
|
||||
using namespace boost::process::initializers;
|
||||
using namespace boost::iostreams;
|
||||
|
||||
std::string DBUpdaterUtil::GetCorrectedMySQLExecutable()
|
||||
{
|
||||
@@ -51,19 +43,16 @@ bool DBUpdaterUtil::CheckExecutable()
|
||||
{
|
||||
exe.clear();
|
||||
|
||||
try
|
||||
if (auto path = Trinity::SearchExecutableInPath("mysql"))
|
||||
{
|
||||
exe = search_path("mysql");
|
||||
}
|
||||
catch (std::runtime_error&)
|
||||
{
|
||||
}
|
||||
exe = std::move(*path);
|
||||
|
||||
if (!exe.empty() && exists(exe))
|
||||
{
|
||||
// Correct the path to the cli
|
||||
corrected_path() = absolute(exe).generic_string();
|
||||
return true;
|
||||
if (!exe.empty() && exists(exe))
|
||||
{
|
||||
// Correct the path to the cli
|
||||
corrected_path() = absolute(exe).generic_string();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
TC_LOG_FATAL("sql.updates", "Didn't find any executable MySQL binary at \'%s\' or in path, correct the path in the *.conf (\"MySQLExecutable\").",
|
||||
@@ -387,44 +376,9 @@ void DBUpdater<T>::ApplyFile(DatabaseWorkerPool<T>& pool, std::string const& hos
|
||||
if (!database.empty())
|
||||
args.push_back(database);
|
||||
|
||||
// ToDo: use the existing query in memory as virtual file if possible
|
||||
file_descriptor_source source(path);
|
||||
|
||||
uint32 ret;
|
||||
try
|
||||
{
|
||||
boost::process::pipe outPipe = create_pipe();
|
||||
boost::process::pipe errPipe = create_pipe();
|
||||
|
||||
child c = execute(run_exe(
|
||||
boost::filesystem::absolute(DBUpdaterUtil::GetCorrectedMySQLExecutable()).generic_string()),
|
||||
set_args(args), bind_stdin(source), throw_on_error(),
|
||||
bind_stdout(file_descriptor_sink(outPipe.sink, close_handle)),
|
||||
bind_stderr(file_descriptor_sink(errPipe.sink, close_handle)));
|
||||
|
||||
file_descriptor_source mysqlOutfd(outPipe.source, close_handle);
|
||||
file_descriptor_source mysqlErrfd(errPipe.source, close_handle);
|
||||
|
||||
stream<file_descriptor_source> mysqlOutStream(mysqlOutfd);
|
||||
stream<file_descriptor_source> mysqlErrStream(mysqlErrfd);
|
||||
|
||||
std::stringstream out;
|
||||
std::stringstream err;
|
||||
|
||||
copy(mysqlOutStream, out);
|
||||
copy(mysqlErrStream, err);
|
||||
|
||||
TC_LOG_INFO("sql.updates", "%s", out.str().c_str());
|
||||
TC_LOG_ERROR("sql.updates", "%s", err.str().c_str());
|
||||
|
||||
ret = wait_for_exit(c);
|
||||
}
|
||||
catch (boost::system::system_error&)
|
||||
{
|
||||
ret = EXIT_FAILURE;
|
||||
}
|
||||
|
||||
source.close();
|
||||
// Invokes a mysql process which doesn't leak credentials to logs
|
||||
int const ret = Trinity::StartProcess(DBUpdaterUtil::GetCorrectedMySQLExecutable(), args,
|
||||
"sql.updates", path.generic_string(), true);
|
||||
|
||||
if (ret != EXIT_SUCCESS)
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user