Commit c194420f authored by Aleix Pol Gonzalez's avatar Aleix Pol Gonzalez 🐧 Committed by Aleix Pol Gonzalez
Browse files

Fix handling of different signals (SIGTERM et al) by using KSignalHandler

When debugging something I realised that SIGTERM was always making KWin
crash like I'd never seen it crash. It turns out we are calling
QApplication::exit() on the signal handler which is highly forbidden as
the handler preempts the process altogether.
Use KSignalHandler instead which takes this issue into account.


(cherry picked from commit d7cba6b6)
parent 8516faa6
Pipeline #232587 failed with stage
in 1 minute and 47 seconds
......@@ -33,6 +33,7 @@
#include <KDesktopFile>
#include <KLocalizedString>
#include <KShell>
#include <KSignalHandler>
// Qt
#include <QCommandLineParser>
......@@ -90,11 +91,6 @@ static void restoreNofileLimit()
}
}
static void sighandler(int)
{
QApplication::exit();
}
void disableDrKonqi()
{
KCrash::setDrKonqiEnabled(false);
......@@ -288,15 +284,6 @@ int main(int argc, char *argv[])
KWin::Application::setupLocalizedString();
KWin::gainRealTime();
if (signal(SIGTERM, KWin::sighandler) == SIG_IGN) {
signal(SIGTERM, SIG_IGN);
}
if (signal(SIGINT, KWin::sighandler) == SIG_IGN) {
signal(SIGINT, SIG_IGN);
}
if (signal(SIGHUP, KWin::sighandler) == SIG_IGN) {
signal(SIGHUP, SIG_IGN);
}
signal(SIGPIPE, SIG_IGN);
// It's easy to exceed the file descriptor limit because many things are backed using fds
......@@ -319,6 +306,12 @@ int main(int argc, char *argv[])
// reset QT_QPA_PLATFORM so we don't propagate it to our children (e.g. apps launched from the overview effect)
qunsetenv("QT_QPA_PLATFORM");
KSignalHandler::self()->watchSignal(SIGTERM);
KSignalHandler::self()->watchSignal(SIGINT);
KSignalHandler::self()->watchSignal(SIGHUP);
QObject::connect(KSignalHandler::self(), &KSignalHandler::signalReceived,
&a, &QCoreApplication::exit);
KWin::Application::createAboutData();
QCommandLineOption xwaylandOption(QStringLiteral("xwayland"),
......
......@@ -24,6 +24,7 @@
#include <KCrash>
#include <KLocalizedString>
#include <KSelectionOwner>
#include <KSignalHandler>
#include <QComboBox>
#include <QCommandLineParser>
......@@ -51,11 +52,6 @@ Q_LOGGING_CATEGORY(KWIN_CORE, "kwin_core", QtWarningMsg)
namespace KWin
{
static void sighandler(int)
{
QApplication::exit();
}
class AlternativeWMDialog : public QDialog
{
public:
......@@ -339,15 +335,6 @@ int main(int argc, char *argv[])
KWin::Application::setupMalloc();
KWin::Application::setupLocalizedString();
if (signal(SIGTERM, KWin::sighandler) == SIG_IGN) {
signal(SIGTERM, SIG_IGN);
}
if (signal(SIGINT, KWin::sighandler) == SIG_IGN) {
signal(SIGINT, SIG_IGN);
}
if (signal(SIGHUP, KWin::sighandler) == SIG_IGN) {
signal(SIGHUP, SIG_IGN);
}
signal(SIGPIPE, SIG_IGN);
// Disable the glib event loop integration, since it seems to be responsible
......@@ -375,6 +362,12 @@ int main(int argc, char *argv[])
KWin::ApplicationX11 a(argc, argv);
a.setupTranslator();
KSignalHandler::self()->watchSignal(SIGTERM);
KSignalHandler::self()->watchSignal(SIGINT);
KSignalHandler::self()->watchSignal(SIGHUP);
QObject::connect(KSignalHandler::self(), &KSignalHandler::signalReceived,
&a, &QCoreApplication::exit);
KWin::Application::createAboutData();
QCommandLineOption replaceOption(QStringLiteral("replace"), i18n("Replace already-running ICCCM2.0-compliant window manager"));
......
Supports Markdown
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