Exit immediately on repeated SIGINT/SIGTERM without progress
This commit is contained in:
parent
6f4ced5ed6
commit
f0626e8cae
1 changed files with 18 additions and 0 deletions
18
app/main.cpp
18
app/main.cpp
|
|
@ -342,6 +342,9 @@ int SDLCALL signalHandlerThread(void* data)
|
||||||
{
|
{
|
||||||
Q_UNUSED(data);
|
Q_UNUSED(data);
|
||||||
|
|
||||||
|
Session* lastSession = nullptr;
|
||||||
|
bool requestedQuit = false;
|
||||||
|
|
||||||
int sig;
|
int sig;
|
||||||
while (recv(signalFds[1], &sig, sizeof(sig), MSG_WAITALL) == sizeof(sig)) {
|
while (recv(signalFds[1], &sig, sizeof(sig), MSG_WAITALL) == sizeof(sig)) {
|
||||||
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "Received signal: %d", sig);
|
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "Received signal: %d", sig);
|
||||||
|
|
@ -353,17 +356,32 @@ int SDLCALL signalHandlerThread(void* data)
|
||||||
// Check if we have an active streaming session
|
// Check if we have an active streaming session
|
||||||
session = Session::get();
|
session = Session::get();
|
||||||
if (session != nullptr) {
|
if (session != nullptr) {
|
||||||
|
// Exit immediately if we haven't changed state since last attempt
|
||||||
|
if (session == lastSession || requestedQuit) {
|
||||||
|
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "Exiting immediately on second signal");
|
||||||
|
_exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
if (sig == SIGTERM) {
|
if (sig == SIGTERM) {
|
||||||
// If this is a SIGTERM, set the flag to quit
|
// If this is a SIGTERM, set the flag to quit
|
||||||
session->setShouldExit();
|
session->setShouldExit();
|
||||||
|
requestedQuit = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Stop the streaming session
|
// Stop the streaming session
|
||||||
session->interrupt();
|
session->interrupt();
|
||||||
|
lastSession = session;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
// Exit immediately if we haven't changed state since last attempt
|
||||||
|
if (requestedQuit) {
|
||||||
|
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "Exiting immediately on second signal");
|
||||||
|
_exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
// If we're not streaming, we'll close the whole app
|
// If we're not streaming, we'll close the whole app
|
||||||
QCoreApplication::instance()->quit();
|
QCoreApplication::instance()->quit();
|
||||||
|
requestedQuit = true;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue