From 48a09b10be84880b3d6e9d53687d40f521d7deca Mon Sep 17 00:00:00 2001 From: MihailRis Date: Mon, 3 Aug 2026 20:02:30 +0300 Subject: [PATCH] update platform::new_engine_instance --- src/logic/scripting/lua/libs/libapp.cpp | 9 ++++----- src/util/platform.cpp | 9 +++++++-- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/logic/scripting/lua/libs/libapp.cpp b/src/logic/scripting/lua/libs/libapp.cpp index 9157b33a6..4885915ad 100644 --- a/src/logic/scripting/lua/libs/libapp.cpp +++ b/src/logic/scripting/lua/libs/libapp.cpp @@ -403,6 +403,7 @@ static int l_start_background_instance(lua::State* L) { "--script", io::resolve(scriptPath).u8string(), "--sub-depth", std::to_string(engine->getCoreParameters() .subProcessDepth + 1), + "--log", io::resolve(outputPath), }; args.emplace_back("--project"); args.emplace_back(io::resolve(engine->getProject().path).u8string()); @@ -417,11 +418,9 @@ static int l_start_background_instance(lua::State* L) { if (handle == -1) { throw std::runtime_error("sub-processes limit exceeded"); } - ::processes[handle] = platform::new_engine_instance( - std::move(args), - outputPath.empty() ? "" : io::resolve(outputPath), - true - ); + ::processes[handle] = + platform::new_engine_instance(std::move(args), "", true); + return lua::pushinteger(L, handle); } diff --git a/src/util/platform.cpp b/src/util/platform.cpp index 7b08639e9..c7b945510 100644 --- a/src/util/platform.cpp +++ b/src/util/platform.cpp @@ -28,6 +28,8 @@ #include #endif +using namespace std::literals; + namespace platform::internal { std::filesystem::path get_executable_path(); } @@ -356,7 +358,7 @@ std::unique_ptr platform::new_engine_instance( if (!outputFile.empty()) { si.dwFlags |= STARTF_USESTDHANDLES; si.hStdOutput = CreateFileW( - toWString(outputFile.u8string()).data(), + toWString(outputFile.empty() ? outputFile.u8string() : "NUL"s,).data(), GENERIC_WRITE, FILE_SHARE_WRITE | FILE_SHARE_READ, nullptr, @@ -434,9 +436,12 @@ std::unique_ptr platform::new_engine_instance( if (subProcess) { pid_t pid = fork(); + if (outputFile.empty()) { + outputFile = "/dev/null"; + } int fd = open( outputFile.string().c_str(), O_WRONLY | O_CREAT | O_TRUNC, 0644 - ); + ); if (pid == 0) { prctl(PR_SET_PDEATHSIG, SIGTERM);