--- src/qsynthMainForm.cpp.orig 2018-11-24 22:22:05.379321811 +0000 +++ src/qsynthMainForm.cpp 2018-11-24 22:34:10.000440303 +0000 @@ -578,7 +578,8 @@ // Make and set a proper setup step. void qsynthMainForm::setup ( qsynthOptions *pOptions ) { - // Finally, fix settings descriptor + catchUnixSignals({SIGQUIT, SIGINT, SIGTERM, SIGHUP}); + // Finally, fix settings descriptor // and stabilize the form. m_pOptions = pOptions; @@ -2607,6 +2608,26 @@ m_ui.TabBar->setCurrentIndex(iTab); } +void qsynthMainForm::catchUnixSignals(std::initializer_list quitSignals) { + auto handler = [](int sig) -> void { + // blocking and not aysnc-signal-safe func are valid + printf("\nquit the application by signal(%d).\n", sig); + QCoreApplication::quit(); + }; + + sigset_t blocking_mask; + sigemptyset(&blocking_mask); + for (auto sig : quitSignals) + sigaddset(&blocking_mask, sig); + + struct sigaction sa; + sa.sa_handler = handler; + sa.sa_mask = blocking_mask; + sa.sa_flags = 0; + + for (auto sig : quitSignals) + sigaction(sig, &sa, nullptr); +} // Close main form slot. void qsynthMainForm::quitMainForm (void) --- src/qsynthMainForm.h.orig 2018-09-18 10:24:10.194784815 +0100 +++ src/qsynthMainForm.h 2018-11-24 22:30:22.009465089 +0000 @@ -115,7 +115,8 @@ void chorusChanged(int); void activateEnginesMenu(QAction*); - + + void catchUnixSignals(std::initializer_list quitSignals); void quitMainForm(); void commitData(QSessionManager& sm);