66 lines
1.6 KiB
C++
66 lines
1.6 KiB
C++
/***
|
|
Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved.
|
|
File: AuExit.Unix.cpp
|
|
Date: 2022-4-7
|
|
Author: Reece
|
|
***/
|
|
#include <Source/RuntimeInternal.hpp>
|
|
#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);
|
|
}
|
|
} |