Implement clean shutdown after receiving Unix signals, resolves #169

The database wasn't saved properly and lockfiles were not removed when receiving the signals SIGINT, SIGTERM, SIGQUIT or SIGHUP. This patch implements signal handling and performs a clean shutdown after receiving SIGINT SIGTERM or SIGQUIT and ignores SIGHUP.

Since this uses POSIX syscalls for signal and socket handling, there is no Windows implementation at the moment.
This commit is contained in:
Janek Bevendorff 2017-01-18 00:15:33 +01:00
parent 72b81bf403
commit 198691182b
No known key found for this signature in database
GPG key ID: CFEC2F6850BFFA53
3 changed files with 83 additions and 3 deletions

View file

@ -21,6 +21,8 @@
#include <QApplication>
class QSocketNotifier;
class Application : public QApplication
{
Q_OBJECT
@ -34,8 +36,21 @@ public:
Q_SIGNALS:
void openFile(const QString& filename);
private:
private Q_SLOTS:
void quitBySignal();
private:
QWidget* m_mainWindow;
#if defined(Q_OS_UNIX)
/**
* Register Unix signals such as SIGINT and SIGTERM for clean shutdown.
*/
void registerUnixSignals();
QSocketNotifier* m_unixSignalNotifier;
static void handleUnixSignal(int sig);
static int unixSignalSocket[2];
#endif
};
#endif // KEEPASSX_APPLICATION_H