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.
This commit is contained in:
Aleix Pol 2022-09-15 17:18:44 +02:00 committed by Aleix Pol Gonzalez
parent 48f684ca73
commit d7cba6b625
2 changed files with 14 additions and 28 deletions

View file

@ -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"),

View file

@ -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"));