AuroraRuntime/Source/Exit/AuExit.Unix.cpp

66 lines
1.6 KiB
C++
Raw Normal View History

/***
Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved.
2022-11-17 07:46:07 +00:00
File: AuExit.Unix.cpp
Date: 2022-4-7
Author: Reece
***/
#include <Source/RuntimeInternal.hpp>
2022-11-17 07:46:07 +00:00
#include "AuExit.hpp"
#include "AuExit.Unix.hpp"
#include <Source/Grug/AuGrug.hpp>
namespace Aurora::Exit
{
static void SendExitSignal(Grug::Arrow *)
{
PostLevel(AuThreads::GetThread(), Exit::ETriggerLevel::eSigTerminate);
}
static void SendExitNowSignal(Grug::Arrow *)
{
PostLevel(AuThreads::GetThread(), Exit::ETriggerLevel::eSigQuitNow);
}
static void HandleSigTerminate(int sig)
{
static Grug::Arrow arrow;
if (sig == SIGINT)
{
Grug::HurlArrow(&arrow, {}, SendExitSignal);
}
else
{
Grug::HurlArrow(&arrow, SendExitNowSignal, {});
Grug::ArrowWait(&arrow);
}
}
void InitUnix()
{
struct sigaction action =
{
.sa_handler = HandleSigTerminate,
.sa_flags = SA_ONSTACK
};
sigemptyset(&action.sa_mask);
sigaction(SIGINT, &action, nullptr);
sigaction(SIGTERM, &action, nullptr);
sigaction(SIGTSTP, &action, nullptr);
}
void DeinitUnix()
{
struct sigaction action =
{
.sa_handler = SIG_DFL,
.sa_flags = SA_ONSTACK
};
sigemptyset(&action.sa_mask);
sigaction(SIGINT, &action, nullptr);
sigaction(SIGTERM, &action, nullptr);
sigaction(SIGTSTP, &action, nullptr);
}
}