print posix_spawn errors

This commit is contained in:
Lion Kortlepel 2024-10-13 20:41:31 +02:00
parent 9ebd218856
commit 453b6b0e1b
No known key found for this signature in database
GPG Key ID: 4322FF2B4C71259B

View File

@ -6,6 +6,7 @@
/// Created by Anonymous275 on 7/19/2020 /// Created by Anonymous275 on 7/19/2020
/// ///
#include <cstring>
#if defined(_WIN32) #if defined(_WIN32)
#include <windows.h> #include <windows.h>
#include <shlobj.h> #include <shlobj.h>
@ -105,7 +106,6 @@ void StartGame(std::string Dir) {
} }
#elif defined(__linux__) #elif defined(__linux__)
void StartGame(std::string Dir) { void StartGame(std::string Dir) {
int status;
std::string filename = (Dir + "/BinLinux/BeamNG.drive.x64"); std::string filename = (Dir + "/BinLinux/BeamNG.drive.x64");
std::vector<const char*> argv; std::vector<const char*> argv;
argv.push_back(filename.data()); argv.push_back(filename.data());
@ -115,11 +115,24 @@ void StartGame(std::string Dir) {
argv.push_back(nullptr); argv.push_back(nullptr);
pid_t pid; pid_t pid;
posix_spawn_file_actions_t spawn_actions;
posix_spawn_file_actions_init(&spawn_actions); posix_spawn_file_actions_t file_actions;
posix_spawn_file_actions_addclose(&spawn_actions, STDOUT_FILENO); auto status = posix_spawn_file_actions_init(&file_actions);
posix_spawn_file_actions_addclose(&spawn_actions, STDERR_FILENO); // disable stdout
int result = posix_spawn(&pid, filename.c_str(), &spawn_actions, nullptr, const_cast<char**>(argv.data()), environ); if (status != 0) {
error(std::string("posix_spawn_file_actions_init failed: ") + std::strerror(errno));
}
status = posix_spawn_file_actions_addclose(&file_actions, STDOUT_FILENO);
if (status != 0) {
error(std::string("posix_spawn_file_actions_addclose for STDOUT failed: ") + std::strerror(errno));
}
status = posix_spawn_file_actions_addclose(&file_actions, STDERR_FILENO);
if (status != 0) {
error(std::string("posix_spawn_file_actions_addclose for STDERR failed: ") + std::strerror(errno));
}
// launch the game
int result = posix_spawn(&pid, filename.c_str(), &file_actions, NULL, const_cast<char**>(argv.data()), environ);
if (result != 0) { if (result != 0) {
error("Failed to Launch the game! launcher closing soon"); error("Failed to Launch the game! launcher closing soon");