aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorShauren <shauren.trinity@gmail.com>2020-07-15 19:33:12 +0200
committerShauren <shauren.trinity@gmail.com>2022-01-23 20:39:15 +0100
commit2b312c7bd23710ede145d2ec2ccd04ea4f1fc5bf (patch)
treeeef9d410330eed25f6bd02152287d98217c26625 /src
parent596bf2b77218e6b959c1bf7de848c6f09d5a91f0 (diff)
Dep: Switch to boost process instead of old standalone version
(cherry picked from commit 524d16739861d0b2279e2270e319b0c77ec9b03b)
Diffstat (limited to 'src')
-rw-r--r--src/common/CMakeLists.txt1
-rw-r--r--src/common/Utilities/StartProcess.cpp79
-rw-r--r--src/common/Utilities/Util.cpp2
-rw-r--r--src/common/Utilities/Util.h2
-rw-r--r--src/server/database/Updater/DBUpdater.cpp31
-rw-r--r--src/server/game/Scripting/ScriptReloadMgr.cpp4
6 files changed, 59 insertions, 60 deletions
diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt
index 0fc7d1d5b47..5258258a7c6 100644
--- a/src/common/CMakeLists.txt
+++ b/src/common/CMakeLists.txt
@@ -60,7 +60,6 @@ target_include_directories(common
target_link_libraries(common
PRIVATE
- process
trinity-core-interface
PUBLIC
argon2
diff --git a/src/common/Utilities/StartProcess.cpp b/src/common/Utilities/StartProcess.cpp
index 241eee2361f..3fb6cf3488a 100644
--- a/src/common/Utilities/StartProcess.cpp
+++ b/src/common/Utilities/StartProcess.cpp
@@ -24,10 +24,15 @@
#include <boost/algorithm/string/join.hpp>
#include <boost/iostreams/copy.hpp>
-#include <boost/process.hpp>
+#include <boost/process/args.hpp>
+#include <boost/process/child.hpp>
+#include <boost/process/env.hpp>
+#include <boost/process/exe.hpp>
+#include <boost/process/io.hpp>
+#include <boost/process/pipe.hpp>
+#include <boost/process/search_path.hpp>
using namespace boost::process;
-using namespace boost::process::initializers;
using namespace boost::iostreams;
namespace Trinity
@@ -48,7 +53,10 @@ public:
std::streamsize write(char const* str, std::streamsize size)
{
- callback_(std::string(str, size));
+ std::string consoleStr(str, size);
+ std::string utf8;
+ if (consoleToUtf8(consoleStr, utf8))
+ callback_(utf8);
return size;
}
};
@@ -62,62 +70,60 @@ auto MakeTCLogSink(T&& callback)
template<typename T>
static int CreateChildProcess(T waiter, std::string const& executable,
- std::vector<std::string> const& args,
+ std::vector<std::string> const& argsVector,
std::string const& logger, std::string const& input,
bool secure)
{
- auto outPipe = create_pipe();
- auto errPipe = create_pipe();
-
- Optional<file_descriptor_source> inputSource;
+ ipstream outStream;
+ ipstream errStream;
if (!secure)
{
TC_LOG_TRACE(logger, "Starting process \"%s\" with arguments: \"%s\".",
- executable.c_str(), boost::algorithm::join(args, " ").c_str());
+ executable.c_str(), boost::algorithm::join(argsVector, " ").c_str());
}
// Start the child process
- child c = [&]
+ child c = [&]()
{
if (!input.empty())
{
- inputSource = file_descriptor_source(input);
-
// With binding stdin
- return execute(run_exe(boost::filesystem::absolute(executable)),
- set_args(args),
- inherit_env(),
- bind_stdin(*inputSource),
- bind_stdout(file_descriptor_sink(outPipe.sink, close_handle)),
- bind_stderr(file_descriptor_sink(errPipe.sink, close_handle)));
+ return child{
+ exe = boost::filesystem::absolute(executable).string(),
+ args = argsVector,
+ env = environment(boost::this_process::environment()),
+ std_in = input,
+ std_out = outStream,
+ std_err = errStream
+ };
}
else
{
// Without binding stdin
- return execute(run_exe(boost::filesystem::absolute(executable)),
- set_args(args),
- inherit_env(),
- bind_stdout(file_descriptor_sink(outPipe.sink, close_handle)),
- bind_stderr(file_descriptor_sink(errPipe.sink, close_handle)));
+ return child{
+ exe = boost::filesystem::absolute(executable).string(),
+ args = argsVector,
+ env = environment(boost::this_process::environment()),
+ std_in = boost::process::close,
+ std_out = outStream,
+ std_err = errStream
+ };
}
}();
- file_descriptor_source outFd(outPipe.source, close_handle);
- file_descriptor_source errFd(errPipe.source, close_handle);
-
- auto outInfo = MakeTCLogSink([&](std::string msg)
+ auto outInfo = MakeTCLogSink([&](std::string const& msg)
{
TC_LOG_INFO(logger, "%s", msg.c_str());
});
- auto outError = MakeTCLogSink([&](std::string msg)
+ auto outError = MakeTCLogSink([&](std::string const& msg)
{
TC_LOG_ERROR(logger, "%s", msg.c_str());
});
- copy(outFd, outInfo);
- copy(errFd, outError);
+ copy(outStream, outInfo);
+ copy(errStream, outError);
// Call the waiter in the current scope to prevent
// the streams from closing too early on leaving the scope.
@@ -129,9 +135,6 @@ static int CreateChildProcess(T waiter, std::string const& executable,
executable.c_str(), result);
}
- if (inputSource)
- inputSource->close();
-
return result;
}
@@ -142,7 +145,8 @@ int StartProcess(std::string const& executable, std::vector<std::string> const&
{
try
{
- return wait_for_exit(c);
+ c.wait();
+ return c.exit_code();
}
catch (...)
{
@@ -190,7 +194,8 @@ public:
try
{
- result = wait_for_exit(c);
+ c.wait();
+ result = c.exit_code();
}
catch (...)
{
@@ -224,7 +229,7 @@ public:
was_terminated = true;
try
{
- terminate(my_child->get());
+ my_child->get().terminate();
}
catch(...)
{
@@ -249,7 +254,7 @@ std::string SearchExecutableInPath(std::string const& filename)
{
try
{
- return search_path(filename);
+ return search_path(filename).string();
}
catch (...)
{
diff --git a/src/common/Utilities/Util.cpp b/src/common/Utilities/Util.cpp
index c8898faeed3..e443e77125b 100644
--- a/src/common/Utilities/Util.cpp
+++ b/src/common/Utilities/Util.cpp
@@ -416,7 +416,7 @@ bool Utf8toWStr(const std::string& utf8str, std::wstring& wstr)
return true;
}
-bool WStrToUtf8(wchar_t* wstr, size_t size, std::string& utf8str)
+bool WStrToUtf8(wchar_t const* wstr, size_t size, std::string& utf8str)
{
try
{
diff --git a/src/common/Utilities/Util.h b/src/common/Utilities/Util.h
index c61036d13ef..f34b6d6ad96 100644
--- a/src/common/Utilities/Util.h
+++ b/src/common/Utilities/Util.h
@@ -122,7 +122,7 @@ inline bool Utf8toWStr(const std::string& utf8str, wchar_t* wstr, size_t& wsize)
TC_COMMON_API bool WStrToUtf8(std::wstring const& wstr, std::string& utf8str);
// size==real string size
-TC_COMMON_API bool WStrToUtf8(wchar_t* wstr, size_t size, std::string& utf8str);
+TC_COMMON_API bool WStrToUtf8(wchar_t const* wstr, size_t size, std::string& utf8str);
// set string to "" if invalid utf8 sequence
TC_COMMON_API size_t utf8length(std::string& utf8str);
diff --git a/src/server/database/Updater/DBUpdater.cpp b/src/server/database/Updater/DBUpdater.cpp
index 3c5cca95a05..34b3fc8f8a6 100644
--- a/src/server/database/Updater/DBUpdater.cpp
+++ b/src/server/database/Updater/DBUpdater.cpp
@@ -364,46 +364,43 @@ void DBUpdater<T>::ApplyFile(DatabaseWorkerPool<T>& pool, std::string const& hos
Path const& path)
{
std::vector<std::string> args;
- args.reserve(8);
-
- // args[0] represents the program name
- args.push_back("mysql");
+ args.reserve(7);
// CLI Client connection info
- args.push_back("-h" + host);
- args.push_back("-u" + user);
+ args.emplace_back("-h" + host);
+ args.emplace_back("-u" + user);
if (!password.empty())
- args.push_back("-p" + password);
+ args.emplace_back("-p" + password);
// Check if we want to connect through ip or socket (Unix only)
#ifdef _WIN32
if (host == ".")
- args.push_back("--protocol=PIPE");
+ args.emplace_back("--protocol=PIPE");
else
- args.push_back("-P" + port_or_socket);
+ args.emplace_back("-P" + port_or_socket);
#else
if (!std::isdigit(port_or_socket[0]))
{
// We can't check if host == "." here, because it is named localhost if socket option is enabled
- args.push_back("-P0");
- args.push_back("--protocol=SOCKET");
- args.push_back("-S" + port_or_socket);
+ args.emplace_back("-P0");
+ args.emplace_back("--protocol=SOCKET");
+ args.emplace_back("-S" + port_or_socket);
}
else
// generic case
- args.push_back("-P" + port_or_socket);
+ args.emplace_back("-P" + port_or_socket);
#endif
// Set the default charset to utf8
- args.push_back("--default-character-set=utf8");
+ args.emplace_back("--default-character-set=utf8");
// Set max allowed packet to 1 GB
- args.push_back("--max-allowed-packet=1GB");
+ args.emplace_back("--max-allowed-packet=1GB");
#if !defined(MARIADB_VERSION_ID) && MYSQL_VERSION_ID >= 80000
@@ -413,13 +410,13 @@ void DBUpdater<T>::ApplyFile(DatabaseWorkerPool<T>& pool, std::string const& hos
#else
if (ssl == "ssl")
- args.push_back("--ssl");
+ args.emplace_back("--ssl");
#endif
// Database
if (!database.empty())
- args.push_back(database);
+ args.emplace_back(database);
// Invokes a mysql process which doesn't leak credentials to logs
int const ret = Trinity::StartProcess(DBUpdaterUtil::GetCorrectedMySQLExecutable(), args,
diff --git a/src/server/game/Scripting/ScriptReloadMgr.cpp b/src/server/game/Scripting/ScriptReloadMgr.cpp
index 47275a2d74d..9cec0ced064 100644
--- a/src/server/game/Scripting/ScriptReloadMgr.cpp
+++ b/src/server/game/Scripting/ScriptReloadMgr.cpp
@@ -371,7 +371,6 @@ static int InvokeCMakeCommand(T&&... args)
{
auto const executable = BuiltInConfig::GetCMakeCommand();
return Trinity::StartProcess(executable, {
- executable,
std::forward<T>(args)...
}, "scripts.hotswap");
}
@@ -382,7 +381,6 @@ static std::shared_ptr<Trinity::AsyncProcessResult> InvokeAsyncCMakeCommand(T&&.
{
auto const executable = BuiltInConfig::GetCMakeCommand();
return Trinity::StartAsyncProcess(executable, {
- executable,
std::forward<T>(args)...
}, "scripts.hotswap");
}
@@ -1361,7 +1359,7 @@ private:
return;
TC_LOG_INFO("scripts.hotswap", ">> Found outdated CMAKE_INSTALL_PREFIX (\"%s\"), "
- "worldserver is currently installed at %s...",
+ "worldserver is currently installed at %s",
value.generic_string().c_str(), current_path.generic_string().c_str());
}
else