diff options
-rw-r--r-- | src/common/Utilities/StartProcess.cpp | 42 | ||||
-rw-r--r-- | src/server/database/Updater/DBUpdater.cpp | 2 |
2 files changed, 30 insertions, 14 deletions
diff --git a/src/common/Utilities/StartProcess.cpp b/src/common/Utilities/StartProcess.cpp index 26d5f876abc..b3d79cde516 100644 --- a/src/common/Utilities/StartProcess.cpp +++ b/src/common/Utilities/StartProcess.cpp @@ -19,13 +19,18 @@ #include "Errors.h" #include "Log.h" #include "Optional.h" +#ifndef BOOST_ALLOW_DEPRECATED_HEADERS +#define BOOST_ALLOW_DEPRECATED_HEADERS #include <boost/process/args.hpp> #include <boost/process/child.hpp> #include <boost/process/env.hpp> +#include <boost/process/error.hpp> #include <boost/process/exe.hpp> #include <boost/process/io.hpp> #include <boost/process/pipe.hpp> #include <boost/process/search_path.hpp> +#undef BOOST_ALLOW_DEPRECATED_HEADERS +#endif #include <fmt/ranges.h> namespace bp = boost::process; @@ -61,7 +66,7 @@ public: ~AsyncProcessResultImplementation() = default; - int StartProcess() + int32 StartProcess() { ASSERT(!my_child, "Process started already!"); @@ -83,15 +88,22 @@ public: #pragma warning(pop) #endif - if (!is_secure) + if (is_secure) + { + TC_LOG_TRACE(logger, R"(Starting process "{}".)", + executable); + } + else { - TC_LOG_TRACE(logger, "Starting process \"{}\" with arguments: \"{}\".", + TC_LOG_TRACE(logger, R"(Starting process "{}" with arguments: "{}".)", executable, fmt::join(args, " ")); } // prepare file with only read permission (boost process opens with read_write) auto inputFile = std::shared_ptr<FILE>(!input_file.empty() ? fopen(input_file.c_str(), "rb") : nullptr, [](FILE* f) { if (f) fclose(f); }); + std::error_code ec; + // Start the child process if (inputFile) { @@ -101,7 +113,8 @@ public: bp::env = bp::environment(boost::this_process::environment()), bp::std_in = inputFile.get(), bp::std_out = outStream, - bp::std_err = errStream + bp::std_err = errStream, + bp::error = ec ); } else @@ -110,12 +123,19 @@ public: bp::exe = boost::filesystem::absolute(executable).string(), bp::args = args, bp::env = bp::environment(boost::this_process::environment()), - bp::std_in = boost::process::close, + bp::std_in = bp::close, bp::std_out = outStream, - bp::std_err = errStream + bp::std_err = errStream, + bp::error = ec ); } + if (ec) + { + TC_LOG_ERROR(logger, R"(>> Failed to start process "{}": {})", executable, ec.message()); + return EXIT_FAILURE; + } + std::future<void> stdOutReader = std::async(std::launch::async, [&] { std::string line; @@ -138,7 +158,6 @@ public: } }); - std::error_code ec; my_child->wait(ec); int32 const result = !ec && !was_terminated ? my_child->exit_code() : EXIT_FAILURE; my_child.reset(); @@ -146,11 +165,8 @@ public: stdOutReader.wait(); stdErrReader.wait(); - if (!is_secure) - { - TC_LOG_TRACE(logger, ">> Process \"{}\" finished with return value {}.", - executable, result); - } + TC_LOG_TRACE(logger, R"(>> Process "{}" finished with return value {}.)", + executable, result); return result; } @@ -180,7 +196,7 @@ public: } }; -int StartProcess(std::string executable, std::vector<std::string> args, +int32 StartProcess(std::string executable, std::vector<std::string> args, std::string logger, std::string input_file, bool secure) { AsyncProcessResultImplementation handle( diff --git a/src/server/database/Updater/DBUpdater.cpp b/src/server/database/Updater/DBUpdater.cpp index bd34ba4f211..92325ea4b5e 100644 --- a/src/server/database/Updater/DBUpdater.cpp +++ b/src/server/database/Updater/DBUpdater.cpp @@ -391,7 +391,7 @@ void DBUpdater<T>::ApplyFile(DatabaseWorkerPool<T>& pool, std::string const& hos args.emplace_back(database); // Invokes a mysql process which doesn't leak credentials to logs - int const ret = Trinity::StartProcess(DBUpdaterUtil::GetCorrectedMySQLExecutable(), std::move(args), + int32 const ret = Trinity::StartProcess(DBUpdaterUtil::GetCorrectedMySQLExecutable(), std::move(args), "sql.updates", "", true); if (ret != EXIT_SUCCESS) |