Commit 068ea212 authored by Ronan's avatar Ronan Committed by Ronan

feat(SingleApplicationDBus): handle signals to quit properly app on GNU/Linux

parent ef43fac6
......@@ -20,6 +20,8 @@
* Author: Ghislain MARY
*/
#include <signal.h>
#include <QDBusInterface>
#include "config.h"
......@@ -44,15 +46,41 @@ QDBusConnection SingleApplicationPrivate::getBus () const {
}
void SingleApplicationPrivate::startPrimary () {
crashHandler();
if (!getBus().registerObject("/", this, QDBusConnection::ExportAllSlots))
qWarning() << QStringLiteral("Failed to register single application object on DBus.");
instanceNumber = 0;
}
void SingleApplicationPrivate::startSecondary () {
crashHandler();
instanceNumber = 1;
}
void SingleApplicationPrivate::crashHandler () {
signal(SIGHUP, SingleApplicationPrivate::terminate); // 1
signal(SIGINT, SingleApplicationPrivate::terminate); // 2
signal(SIGQUIT, SingleApplicationPrivate::terminate); // 3
signal(SIGILL, SingleApplicationPrivate::terminate); // 4
signal(SIGABRT, SingleApplicationPrivate::terminate); // 6
signal(SIGFPE, SingleApplicationPrivate::terminate); // 8
signal(SIGBUS, SingleApplicationPrivate::terminate); // 10
signal(SIGSEGV, SingleApplicationPrivate::terminate); // 11
signal(SIGSYS, SingleApplicationPrivate::terminate); // 12
signal(SIGPIPE, SingleApplicationPrivate::terminate); // 13
signal(SIGALRM, SingleApplicationPrivate::terminate); // 14
signal(SIGTERM, SingleApplicationPrivate::terminate); // 15
signal(SIGXCPU, SingleApplicationPrivate::terminate); // 24
signal(SIGXFSZ, SingleApplicationPrivate::terminate); // 25
}
void SingleApplicationPrivate::terminate (int signum) {
if (signum == SIGINT)
SingleApplication::instance()->quit();
else
::exit(128 + signum);
}
SingleApplication::SingleApplication (int &argc, char *argv[], bool allowSecondary, Options options, int)
: QApplication(argc, argv), d_ptr(new SingleApplicationPrivate(this)) {
Q_D(SingleApplication);
......
......@@ -47,6 +47,9 @@ public:
void startPrimary ();
void startSecondary ();
void crashHandler ();
static void terminate (int signum);
SingleApplication *q_ptr;
SingleApplication::Options options;
quint32 instanceNumber;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment