Add POSIX equivalent for detecting parent termination
This commit is contained in:
parent
e66c4eed35
commit
6a963ffcc9
@ -44,6 +44,10 @@
|
||||
#include "states_screens/state_manager.hpp"
|
||||
#include "utils/profiler.hpp"
|
||||
|
||||
#ifndef WIN32
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
MainLoop* main_loop = 0;
|
||||
|
||||
MainLoop::MainLoop(unsigned parent_pid)
|
||||
@ -323,6 +327,10 @@ void MainLoop::run()
|
||||
if (WaitForSingleObject(parent, 0) != WAIT_TIMEOUT)
|
||||
m_abort = true;
|
||||
}
|
||||
#else
|
||||
// POSIX equivalent
|
||||
if (m_parent_pid != 0 && getppid() != (int)m_parent_pid)
|
||||
m_abort = true;
|
||||
#endif
|
||||
m_is_last_substep = false;
|
||||
PROFILER_PUSH_CPU_MARKER("Main loop", 0xFF, 0x00, 0xF7);
|
||||
|
@ -253,6 +253,9 @@ bool SeparateProcess::createChildProcess(const std::string& exe,
|
||||
}
|
||||
}
|
||||
|
||||
std::string parent_pid = "--parent-process=";
|
||||
int current_pid = getpid();
|
||||
parent_pid += StringUtils::toString(current_pid);
|
||||
child = fork();
|
||||
if (child == 0)
|
||||
{
|
||||
@ -289,6 +292,7 @@ bool SeparateProcess::createChildProcess(const std::string& exe,
|
||||
argv.push_back(const_cast<char*>(exe_file.c_str()));
|
||||
for (unsigned i = 0; i < rest_argv.size(); i++)
|
||||
argv.push_back(const_cast<char*>(rest_argv[i].c_str()));
|
||||
argv.push_back(const_cast<char*>(parent_pid.c_str()));
|
||||
argv.push_back(NULL);
|
||||
execvp(exe.c_str(), argv.data());
|
||||
Log::error("SeparateProcess", "Error in execl: errnp %d", errno);
|
||||
|
Loading…
x
Reference in New Issue
Block a user