J Reece Wilson
1c78c18997
[*] Treat SIGTERM the same as SIGINT. SIGINT is somewhat of an arachic signal meaning, "hey dumb unix app, fuck the process group, start reading from stdin to listen to the user." Nowadays, this doesn't mean anything other than "hey, a human asked us to terminate from a TTY" - basically the same as SIGTERM, except SIGTERM is more likely to be a scheduled or otherwise expected shutdown event.
59 lines
1.3 KiB
C++
59 lines
1.3 KiB
C++
/***
|
|
Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved.
|
|
File: Exit.Unix.cpp
|
|
Date: 2022-4-7
|
|
Author: Reece
|
|
***/
|
|
#include <Source/RuntimeInternal.hpp>
|
|
#include "Exit.hpp"
|
|
#include "Exit.Unix.hpp"
|
|
#include <Source/Grug/Grug.hpp>
|
|
|
|
namespace Aurora::Exit
|
|
{
|
|
static void SendExitSignal(Grug::Arrow *)
|
|
{
|
|
PostLevel(AuThreads::GetThread(), Exit::ETriggerLevel::eSigTerminate);
|
|
}
|
|
|
|
static void HandleSigTerminate(int sig)
|
|
{
|
|
static Grug::Arrow arrow;
|
|
|
|
if (sig == SIGINT)
|
|
{
|
|
Grug::HurlArrow(&arrow, {}, SendExitSignal);
|
|
}
|
|
else
|
|
{
|
|
Grug::HurlArrow(&arrow, SendExitSignal, {});
|
|
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);
|
|
}
|
|
|
|
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);
|
|
}
|
|
} |