@@ -77,6 +77,7 @@ extern string opt_starting_profile;
7777
7878#ifndef _WIN32
7979int OBSApp::sigintFd[2 ];
80+ int OBSApp::sigtermFd[2 ];
8081#endif
8182
8283// GPU hint exports for AMD/NVIDIA laptops
@@ -928,9 +929,14 @@ OBSApp::OBSApp(int &argc, char **argv, profiler_name_store_t *store)
928929 socketpair (AF_UNIX, SOCK_STREAM, 0 , sigintFd);
929930 snInt = new QSocketNotifier (sigintFd[1 ], QSocketNotifier::Read, this );
930931 connect (snInt, &QSocketNotifier::activated, this , &OBSApp::ProcessSigInt);
931- #else
932- connect (qApp, &QGuiApplication::commitDataRequest, this , &OBSApp::commitData, Qt::DirectConnection);
932+
933+ /* Handle SIGTERM */
934+ socketpair (AF_UNIX, SOCK_STREAM, 0 , sigtermFd);
935+ snTerm = new QSocketNotifier (sigtermFd[1 ], QSocketNotifier::Read, this );
936+ connect (snTerm, &QSocketNotifier::activated, this , &OBSApp::ProcessSigTerm);
933937#endif
938+ connect (qApp, &QGuiApplication::commitDataRequest, this , &OBSApp::commitData, Qt::DirectConnection);
939+
934940 if (multi) {
935941 crashHandler_ = std::make_unique<OBS::CrashHandler>();
936942 } else {
@@ -1810,6 +1816,14 @@ void OBSApp::SigIntSignalHandler(int s)
18101816 char a = 1 ;
18111817 send (sigintFd[0 ], &a, sizeof (a), 0 );
18121818}
1819+
1820+ void OBSApp::SigTermSignalHandler (int s)
1821+ {
1822+ UNUSED_PARAMETER (s);
1823+
1824+ char a = 1 ;
1825+ send (sigtermFd[0 ], &a, sizeof (a), 0 );
1826+ }
18131827#endif
18141828
18151829void OBSApp::ProcessSigInt (void )
@@ -1828,15 +1842,33 @@ void OBSApp::ProcessSigInt(void)
18281842#endif
18291843}
18301844
1831- #ifdef _WIN32
1845+ void OBSApp::ProcessSigTerm (void )
1846+ {
1847+ #ifndef _WIN32
1848+ char tmp;
1849+ recv (sigtermFd[1 ], &tmp, sizeof (tmp), 0 );
1850+
1851+ OBSBasic *main = OBSBasic::Get ();
1852+ if (main) {
1853+ main->saveAll ();
1854+ }
1855+
1856+ quit ();
1857+ #endif
1858+ }
1859+
18321860void OBSApp::commitData (QSessionManager &manager)
18331861{
18341862 OBSBasic *main = OBSBasic::Get ();
18351863 if (main) {
18361864 main->saveAll ();
1865+
1866+ if (manager.allowsInteraction () && main->shouldPromptForClose ()) {
1867+ blog (LOG_INFO, " [OBSApp] SessionManager::cancel()" );
1868+ manager.cancel ();
1869+ }
18371870 }
18381871}
1839- #endif
18401872
18411873void OBSApp::applicationShutdown () noexcept
18421874{
@@ -1848,6 +1880,10 @@ void OBSApp::applicationShutdown() noexcept
18481880 delete snInt;
18491881 close (sigintFd[0 ]);
18501882 close (sigintFd[1 ]);
1883+
1884+ delete snTerm;
1885+ close (sigtermFd[0 ]);
1886+ close (sigtermFd[1 ]);
18511887#endif
18521888
18531889#ifdef __APPLE__
0 commit comments