2022-04-07 04:35:17 +00:00
|
|
|
/***
|
|
|
|
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
|
2022-04-07 04:35:17 +00:00
|
|
|
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"
|
2022-12-16 00:41:01 +00:00
|
|
|
#include <Source/Grug/AuGrug.hpp>
|
2022-04-07 04:35:17 +00:00
|
|
|
|
|
|
|
namespace Aurora::Exit
|
|
|
|
{
|
|
|
|
static void SendExitSignal(Grug::Arrow *)
|
|
|
|
{
|
|
|
|
PostLevel(AuThreads::GetThread(), Exit::ETriggerLevel::eSigTerminate);
|
|
|
|
}
|
|
|
|
|
2024-03-05 11:06:29 +00:00
|
|
|
static void SendExitNowSignal(Grug::Arrow *)
|
|
|
|
{
|
|
|
|
PostLevel(AuThreads::GetThread(), Exit::ETriggerLevel::eSigQuitNow);
|
|
|
|
}
|
|
|
|
|
2022-04-07 04:35:17 +00:00
|
|
|
static void HandleSigTerminate(int sig)
|
|
|
|
{
|
2022-04-07 05:22:50 +00:00
|
|
|
static Grug::Arrow arrow;
|
|
|
|
|
|
|
|
if (sig == SIGINT)
|
|
|
|
{
|
|
|
|
Grug::HurlArrow(&arrow, {}, SendExitSignal);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2024-03-05 11:06:29 +00:00
|
|
|
Grug::HurlArrow(&arrow, SendExitNowSignal, {});
|
2022-04-07 05:22:50 +00:00
|
|
|
Grug::ArrowWait(&arrow);
|
|
|
|
}
|
2022-04-07 04:35:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void InitUnix()
|
|
|
|
{
|
|
|
|
struct sigaction action =
|
|
|
|
{
|
|
|
|
.sa_handler = HandleSigTerminate,
|
|
|
|
.sa_flags = SA_ONSTACK
|
|
|
|
};
|
|
|
|
sigemptyset(&action.sa_mask);
|
|
|
|
|
|
|
|
sigaction(SIGINT, &action, nullptr);
|
2024-03-05 11:06:29 +00:00
|
|
|
sigaction(SIGTERM, &action, nullptr);
|
|
|
|
sigaction(SIGTSTP, &action, nullptr);
|
2022-04-07 04:35:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DeinitUnix()
|
|
|
|
{
|
|
|
|
struct sigaction action =
|
|
|
|
{
|
|
|
|
.sa_handler = SIG_DFL,
|
|
|
|
.sa_flags = SA_ONSTACK
|
|
|
|
};
|
|
|
|
sigemptyset(&action.sa_mask);
|
|
|
|
|
|
|
|
sigaction(SIGINT, &action, nullptr);
|
2024-03-05 11:06:29 +00:00
|
|
|
sigaction(SIGTERM, &action, nullptr);
|
|
|
|
sigaction(SIGTSTP, &action, nullptr);
|
2022-04-07 04:35:17 +00:00
|
|
|
}
|
|
|
|
}
|