From b80d2a00c073d4514104a628be4315e81acf1853 Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Tue, 23 Dec 2025 01:09:21 -0600 Subject: [PATCH] Fix SIGTERM unexpectedly quitting the host app --- app/main.cpp | 2 +- app/streaming/input/keyboard.cpp | 2 +- app/streaming/session.cpp | 19 +++++++++++++------ app/streaming/session.h | 4 ++-- 4 files changed, 17 insertions(+), 10 deletions(-) diff --git a/app/main.cpp b/app/main.cpp index 34eac3cc..2629b765 100644 --- a/app/main.cpp +++ b/app/main.cpp @@ -351,7 +351,7 @@ int SDLCALL signalHandlerThread(void* data) if (session != nullptr) { if (sig == SIGTERM) { // If this is a SIGTERM, set the flag to quit - session->setShouldExitAfterQuit(); + session->setShouldExit(); } // Stop the streaming session diff --git a/app/streaming/input/keyboard.cpp b/app/streaming/input/keyboard.cpp index 98001a98..273816f4 100644 --- a/app/streaming/input/keyboard.cpp +++ b/app/streaming/input/keyboard.cpp @@ -144,7 +144,7 @@ void SdlInputHandler::performSpecialKeyCombo(KeyCombo combo) "Detected quitAndExit key combo"); // Indicate that we want to exit afterwards - Session::get()->setShouldExitAfterQuit(); + Session::get()->setShouldExit(true); // Push a quit event to the main loop SDL_Event quitExitEvent; diff --git a/app/streaming/session.cpp b/app/streaming/session.cpp index fd184c54..09397be0 100644 --- a/app/streaming/session.cpp +++ b/app/streaming/session.cpp @@ -580,7 +580,7 @@ Session::Session(NvComputer* computer, NvApp& app, StreamingPreferences *prefere m_InputHandler(nullptr), m_MouseEmulationRefCount(0), m_FlushingWindowEventsRef(0), - m_ShouldExitAfterQuit(false), + m_ShouldExit(false), m_AsyncConnectionSuccess(false), m_PortTestResults(0), m_OpusDecoder(nullptr), @@ -1279,8 +1279,7 @@ private: // Only quit the running app if our session terminated gracefully bool shouldQuit = !m_Session->m_UnexpectedTermination && - (m_Session->m_Preferences->quitAppAfter || - m_Session->m_ShouldExitAfterQuit); + m_Session->m_Preferences->quitAppAfter; // Notify the UI if (shouldQuit) { @@ -1310,7 +1309,7 @@ private: } // Exit the entire program if requested - if (m_Session->m_ShouldExitAfterQuit) { + if (m_Session->m_ShouldExit) { QCoreApplication::instance()->quit(); } @@ -1725,9 +1724,17 @@ void Session::flushWindowEvents() SDL_PushEvent(&flushEvent); } -void Session::setShouldExitAfterQuit() +void Session::setShouldExit(bool quitHostApp) { - m_ShouldExitAfterQuit = true; + // If the caller has explicitly asked us to quit the host app, + // override whatever the preferences say and do it. If the + // caller doesn't override to force quit, let the preferences + // dictate what we do. + if (quitHostApp) { + m_Preferences->quitAppAfter = true; + } + + m_ShouldExit = true; } void Session::start() diff --git a/app/streaming/session.h b/app/streaming/session.h index 0aba6595..d709e36a 100644 --- a/app/streaming/session.h +++ b/app/streaming/session.h @@ -123,7 +123,7 @@ public: void flushWindowEvents(); - void setShouldExitAfterQuit(); + void setShouldExit(bool quitHostApp = false); signals: void stageStarting(QString stage); @@ -262,7 +262,7 @@ private: int m_MouseEmulationRefCount; int m_FlushingWindowEventsRef; QStringList m_LaunchWarnings; - bool m_ShouldExitAfterQuit; + bool m_ShouldExit; bool m_AsyncConnectionSuccess; int m_PortTestResults;