diff --git a/include/Nazara/Core/Process.hpp b/include/Nazara/Core/Process.hpp index e2fb35cd0..12d08a8d7 100644 --- a/include/Nazara/Core/Process.hpp +++ b/include/Nazara/Core/Process.hpp @@ -29,7 +29,9 @@ namespace Nz Process& operator=(const Process&) = delete; Process& operator=(Process&&) = delete; - static Result SpawnDetached(const std::filesystem::path& program, std::span arguments = {}, const std::filesystem::path& workingDirectory = {}); }; + static Pid GetCurrentPid(); + static Result SpawnDetached(const std::filesystem::path& program, std::span arguments = {}, const std::filesystem::path& workingDirectory = {}); + }; } #include diff --git a/src/Nazara/Core/Posix/ProcessImpl.cpp b/src/Nazara/Core/Posix/ProcessImpl.cpp index e61522a0e..6013c0a7a 100644 --- a/src/Nazara/Core/Posix/ProcessImpl.cpp +++ b/src/Nazara/Core/Posix/ProcessImpl.cpp @@ -15,6 +15,11 @@ namespace Nz::PlatformImpl { + Pid GetCurrentProcessId() + { + return ::getpid(); + } + Result SpawnDetachedProcess(const std::filesystem::path& program, std::span arguments, const std::filesystem::path& workingDirectory) { struct PidOrErr @@ -43,7 +48,8 @@ namespace Nz::PlatformImpl if (::chdir(workingDirectory.c_str()) != 0) { PidOrErr err; - err.pid = grandChildPid; + err.pid = -1; + err.err = errno; pipe.Write(&err, sizeof(err)); diff --git a/src/Nazara/Core/Posix/ProcessImpl.hpp b/src/Nazara/Core/Posix/ProcessImpl.hpp index 001355c4d..447d99107 100644 --- a/src/Nazara/Core/Posix/ProcessImpl.hpp +++ b/src/Nazara/Core/Posix/ProcessImpl.hpp @@ -12,7 +12,8 @@ namespace Nz::PlatformImpl { - NAZARA_CORE_API Result SpawnDetachedProcess(const std::filesystem::path& program, std::span arguments = {}, const std::filesystem::path& workingDirectory = {}); + Pid GetCurrentProcessId(); + Result SpawnDetachedProcess(const std::filesystem::path& program, std::span arguments = {}, const std::filesystem::path& workingDirectory = {}); } #endif // NAZARA_CORE_POSIX_PROCESSIMPL_HPP diff --git a/src/Nazara/Core/Process.cpp b/src/Nazara/Core/Process.cpp index 37273972a..3a8c53658 100644 --- a/src/Nazara/Core/Process.cpp +++ b/src/Nazara/Core/Process.cpp @@ -16,6 +16,11 @@ namespace Nz { + Pid Process::GetCurrentPid() + { + return PlatformImpl::GetCurrentProcessId(); + } + Result Process::SpawnDetached(const std::filesystem::path& program, std::span arguments, const std::filesystem::path& workingDirectory) { return PlatformImpl::SpawnDetachedProcess(program, arguments, workingDirectory); diff --git a/src/Nazara/Core/Win32/ProcessImpl.cpp b/src/Nazara/Core/Win32/ProcessImpl.cpp index 53ad91b29..5fce859d6 100644 --- a/src/Nazara/Core/Win32/ProcessImpl.cpp +++ b/src/Nazara/Core/Win32/ProcessImpl.cpp @@ -85,6 +85,11 @@ namespace Nz::PlatformImpl return commandLine; } + Pid GetCurrentProcessId() + { + return ::GetCurrentProcessId(); + } + Result SpawnDetachedProcess(const std::filesystem::path& program, std::span arguments, const std::filesystem::path& workingDirectory) { DWORD creationFlags = CREATE_UNICODE_ENVIRONMENT | CREATE_NEW_PROCESS_GROUP | DETACHED_PROCESS; @@ -100,7 +105,7 @@ namespace Nz::PlatformImpl }; PROCESS_INFORMATION processInfo; - BOOL success = CreateProcessW( + BOOL success = ::CreateProcessW( nullptr, // Application name commandLine.data(), // Command line nullptr, // Process attributes diff --git a/src/Nazara/Core/Win32/ProcessImpl.hpp b/src/Nazara/Core/Win32/ProcessImpl.hpp index b1471d602..698863380 100644 --- a/src/Nazara/Core/Win32/ProcessImpl.hpp +++ b/src/Nazara/Core/Win32/ProcessImpl.hpp @@ -12,7 +12,8 @@ namespace Nz::PlatformImpl { - NAZARA_CORE_API Result SpawnDetachedProcess(const std::filesystem::path& program, std::span arguments = {}, const std::filesystem::path& workingDirectory = {}); + Pid GetCurrentProcessId(); + Result SpawnDetachedProcess(const std::filesystem::path& program, std::span arguments = {}, const std::filesystem::path& workingDirectory = {}); } #endif // NAZARA_CORE_WIN32_PROCESSIMPL_HPP