| 47 | |
| 48 | namespace { |
| 49 | void shutdownGracefully(int sig) |
| 50 | { |
| 51 | static volatile std::sig_atomic_t handlingSignal = 0; |
| 52 | |
| 53 | if ( !handlingSignal ) { |
| 54 | handlingSignal = 1; |
| 55 | qCDebug(SHELL) << "signal " << sig << " received, shutting down gracefully"; |
| 56 | QCoreApplication* app = QCoreApplication::instance(); |
| 57 | if (auto* guiApp = qobject_cast<QApplication*>(app)) { |
| 58 | guiApp->closeAllWindows(); |
| 59 | } |
| 60 | app->quit(); |
| 61 | return; |
| 62 | } |
| 63 | |
| 64 | // re-raise signal with default handler and trigger program termination |
| 65 | std::signal(sig, SIG_DFL); |
| 66 | std::raise(sig); |
| 67 | } |
| 68 | |
| 69 | void installSignalHandler() |
| 70 | { |