From 957c473ed82455969dde581036afcf8d8c58e156 Mon Sep 17 00:00:00 2001 From: Manuel Nickschas Date: Wed, 20 Jun 2018 22:12:25 +0200 Subject: [PATCH] quassel: Install signal handlers in init() rather than ctor Unix signal handlers require e.g. command line options, which are not available at construction time of the Quassel instance. Move signal handler registration into init(). Add TODO comments to remind us of the fact that we're not supposed to use unsafe methods in signal handlers (which we currently do), and should rework signal handling to be safe. --- src/common/quassel.cpp | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/src/common/quassel.cpp b/src/common/quassel.cpp index 67eac802..92b03e2a 100644 --- a/src/common/quassel.cpp +++ b/src/common/quassel.cpp @@ -62,6 +62,17 @@ Quassel *Quassel::instance() Quassel::Quassel() { +} + + +bool Quassel::init() +{ + if (instance()->_initialized) + return true; // allow multiple invocations because of MonolithicApplication + + // Setup signal handling + // TODO: Don't use unsafe methods, see handleSignal() + // We catch SIGTERM and SIGINT (caused by Ctrl+C) to graceful shutdown Quassel. signal(SIGTERM, handleSignal); signal(SIGINT, handleSignal); @@ -70,13 +81,6 @@ Quassel::Quassel() // Windows does not support SIGHUP signal(SIGHUP, handleSignal); #endif -} - - -bool Quassel::init() -{ - if (instance()->_initialized) - return true; // allow multiple invocations because of MonolithicApplication if (instance()->_handleCrashes) { // we have crashhandler for win32 and unix (based on execinfo). @@ -88,12 +92,12 @@ bool Quassel::init() if (rc == -1 || !((long)limit->rlim_cur > 0 || limit->rlim_cur == RLIM_INFINITY)) { # endif /* Q_OS_WIN */ - signal(SIGABRT, handleSignal); - signal(SIGSEGV, handleSignal); + signal(SIGABRT, handleSignal); + signal(SIGSEGV, handleSignal); # ifndef Q_OS_WIN - signal(SIGBUS, handleSignal); - } - free(limit); + signal(SIGBUS, handleSignal); + } + free(limit); # endif /* Q_OS_WIN */ #endif /* Q_OS_WIN || HAVE_EXECINFO */ } @@ -356,6 +360,8 @@ const Quassel::BuildInfo &Quassel::buildInfo() //! Signal handler for graceful shutdown. +//! @todo: Ensure this doesn't use unsafe methods (it does currently) +//! cf. QSocketNotifier, UnixSignalWatcher void Quassel::handleSignal(int sig) { switch (sig) { -- 2.20.1