[*] Other POSIX systems (non-linux) are probably going to need this improved eSpawnChildProcessWorker awareness
This commit is contained in:
parent
2fd41d4142
commit
9393c17564
@ -12,6 +12,12 @@
|
||||
|
||||
#if defined(AURORA_IS_POSIX_DERIVED)
|
||||
#include "AuExit.Unix.hpp"
|
||||
|
||||
namespace Aurora::Processes
|
||||
{
|
||||
void PosixProcessShutdown();
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#include <Source/Debug/MemoryCrunch.hpp>
|
||||
@ -50,6 +56,13 @@ namespace Aurora::Exit
|
||||
}
|
||||
}
|
||||
|
||||
static void UnsafeProcessShutdownHook()
|
||||
{
|
||||
#if defined(AURORA_IS_POSIX_DERIVED)
|
||||
Processes::PosixProcessShutdown();
|
||||
#endif
|
||||
}
|
||||
|
||||
void PostLevel(AuThreads::IAuroraThread *thread, ETriggerLevel level)
|
||||
{
|
||||
AU_DEBUG_MEMCRUNCH;
|
||||
@ -121,6 +134,13 @@ namespace Aurora::Exit
|
||||
gHasSentTerminate |= isTerminate;
|
||||
}
|
||||
|
||||
if ((level == ETriggerLevel::eSigTerminate && !gHasCanceled) ||
|
||||
level == ETriggerLevel::eFatalException ||
|
||||
level == ETriggerLevel::eSafeTermination)
|
||||
{
|
||||
UnsafeProcessShutdownHook();
|
||||
}
|
||||
|
||||
// Force exit after calling the subscribers, should the level be eSigTerminate
|
||||
if (level == ETriggerLevel::eSigTerminate)
|
||||
{
|
||||
|
@ -50,7 +50,7 @@
|
||||
|
||||
namespace Aurora::Processes
|
||||
{
|
||||
static AuThreadPrimitives::RWLockUnique_t gRWLock;
|
||||
static AuRWLock gRWLock;
|
||||
static AuHashMap<pid_t, ProcessImpl *> gPidLookupMap;
|
||||
|
||||
struct ProcessAliveLoopSource : AuLoop::LSEvent
|
||||
@ -716,6 +716,14 @@ namespace Aurora::Processes
|
||||
return true;
|
||||
}
|
||||
|
||||
void ProcessImpl::HookMainDeath()
|
||||
{
|
||||
if (this->type_ == ESpawnType::eSpawnChildProcessWorker)
|
||||
{
|
||||
this->Terminate();
|
||||
}
|
||||
}
|
||||
|
||||
AUKN_SYM IProcess *SpawnNew(StartupParameters &¶ms)
|
||||
{
|
||||
auto ret = _new ProcessImpl(AuMove(params));
|
||||
@ -778,8 +786,6 @@ namespace Aurora::Processes
|
||||
|
||||
void InitUnix()
|
||||
{
|
||||
gRWLock = AuThreadPrimitives::RWLockUnique();
|
||||
|
||||
struct sigaction action =
|
||||
{
|
||||
.sa_handler = SigChldHandler,
|
||||
@ -790,6 +796,18 @@ namespace Aurora::Processes
|
||||
::sigaction(SIGCHLD, &action, nullptr);
|
||||
}
|
||||
|
||||
void PosixProcessShutdown()
|
||||
{
|
||||
#if !defined(AURORA_IS_LINUX_DERIVED)
|
||||
AU_LOCK_GUARD(gRWLock->AsReadable());
|
||||
|
||||
for (const auto &[pid, pProcess] : gPidLookupMap)
|
||||
{
|
||||
pProcess->Terminate();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void DeinitUnix()
|
||||
{
|
||||
struct sigaction action =
|
||||
@ -801,6 +819,6 @@ namespace Aurora::Processes
|
||||
::sigemptyset(&action.sa_mask);
|
||||
::sigaction(SIGCHLD, &action, nullptr);
|
||||
|
||||
gRWLock.reset();
|
||||
PosixProcessShutdown();
|
||||
}
|
||||
}
|
@ -59,6 +59,7 @@ namespace Aurora::Processes
|
||||
void ByeLol(AuSInt code);
|
||||
void ForkMain();
|
||||
|
||||
void HookMainDeath();
|
||||
private:
|
||||
|
||||
int pipeStdOut_[2] { -1, -1 };
|
||||
|
Loading…
Reference in New Issue
Block a user