From 03bed40d638d09f36deb9e0ec3ad1fe1d10e139f Mon Sep 17 00:00:00 2001 From: Raghav Gururajan Date: Fri, 3 Apr 2020 17:13:20 -0400 Subject: [PATCH] test 2 --- .../single-application/SingleApplication.cpp | 63 ++----------------- .../SingleApplicationPrivate.hpp | 3 - 2 files changed, 5 insertions(+), 61 deletions(-) diff --git a/src/app/single-application/SingleApplication.cpp b/src/app/single-application/SingleApplication.cpp index 29538ae3..1e6ab396 100644 --- a/src/app/single-application/SingleApplication.cpp +++ b/src/app/single-application/SingleApplication.cpp @@ -35,7 +35,6 @@ #ifdef Q_OS_UNIX #include - #include #endif // ifdef Q_OS_UNIX #ifdef Q_OS_WIN @@ -135,10 +134,9 @@ void SingleApplicationPrivate::genBlockServerName (int timeout) { void SingleApplicationPrivate::startPrimary (bool resetMemory) { #ifdef Q_OS_UNIX - // Handle any further termination signals to ensure the - // QSharedMemory block is deleted even if the process crashes - crashHandler(); + signal(SIGINT, SingleApplicationPrivate::terminate); #endif // ifdef Q_OS_UNIX + // Successful creation means that no main process exists // So we start a QLocalServer to listen for connections QLocalServer::removeServer(blockServerName); @@ -178,9 +176,7 @@ void SingleApplicationPrivate::startPrimary (bool resetMemory) { void SingleApplicationPrivate::startSecondary () { #ifdef Q_OS_UNIX - // Handle any further termination signals to ensure the - // QSharedMemory block is deleted even if the process crashes - crashHandler(); + signal(SIGINT, SingleApplicationPrivate::terminate); #endif // ifdef Q_OS_UNIX } @@ -222,60 +218,11 @@ void SingleApplicationPrivate::connectToPrimary (int msecs, char connectionType) } #ifdef Q_OS_UNIX - void SingleApplicationPrivate::crashHandler () { - // This guarantees the program will work even with multiple - // instances of SingleApplication in different threads. - // Which in my opinion is idiotic, but lets handle that too. - { - sharedMemMutex.lock(); - sharedMem.append(this); - sharedMemMutex.unlock(); - } - - // Handle any further termination signals to ensure the - // QSharedMemory block is deleted even if the process crashes - 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(); - return; - } - - // Dangerous signals. Exit directly after shared memory destruction. - // Don't touch sockets => avoid dead locks. - for (int crashSig : { SIGABRT, SIGBUS, SIGSEGV }) - if (signum == crashSig) { - for (SingleApplicationPrivate *d : sharedMem) - delete d->memory; - goto forceExit; - } - - while (!sharedMem.empty()) { - delete sharedMem.back(); - sharedMem.pop_back(); - } - - forceExit: - ::exit(128 + signum); + Q_UNUSED(signum); + SingleApplication::instance()->quit(); } - - QList SingleApplicationPrivate::sharedMem; - QMutex SingleApplicationPrivate::sharedMemMutex; #endif // ifdef Q_OS_UNIX /** diff --git a/src/app/single-application/SingleApplicationPrivate.hpp b/src/app/single-application/SingleApplicationPrivate.hpp index d0dfc10e..db2d8cf5 100644 --- a/src/app/single-application/SingleApplicationPrivate.hpp +++ b/src/app/single-application/SingleApplicationPrivate.hpp @@ -59,10 +59,7 @@ public: void connectToPrimary (int msecs, char connectionType); #ifdef Q_OS_UNIX - void crashHandler (); static void terminate (int signum); - static QList sharedMem; - static QMutex sharedMemMutex; #endif // ifdef Q_OS_UNIX QSharedMemory *memory; -- 2.17.1