From 52c9eef1223a20e049b7fef08d3afffe40c85a81 Mon Sep 17 00:00:00 2001 From: Aleix Pol Date: Thu, 10 Feb 2022 18:50:16 +0100 Subject: [PATCH] kwin_wrapper: properly handle SIGTERM signals QCoreApplication is not signal trap safe, use KSignalHandler to do it properly. --- src/helpers/wayland_wrapper/CMakeLists.txt | 2 +- src/helpers/wayland_wrapper/kwin_wrapper.cpp | 13 +++++++------ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/helpers/wayland_wrapper/CMakeLists.txt b/src/helpers/wayland_wrapper/CMakeLists.txt index e3cfd39922..e1b1948385 100644 --- a/src/helpers/wayland_wrapper/CMakeLists.txt +++ b/src/helpers/wayland_wrapper/CMakeLists.txt @@ -15,6 +15,6 @@ ecm_qt_declare_logging_category(kwin_wayland_wrapper Warning ) -target_link_libraries(kwin_wayland_wrapper Qt5::Core Qt5::DBus KF5::DBusAddons KWinXwaylandCommon) +target_link_libraries(kwin_wayland_wrapper Qt5::Core Qt5::DBus KF5::DBusAddons KF5::CoreAddons KWinXwaylandCommon) set_property(TARGET kwin_wayland_wrapper PROPERTY C_STANDARD 11) install(TARGETS kwin_wayland_wrapper ${KDE_INSTALL_TARGETS_DEFAULT_ARGS}) diff --git a/src/helpers/wayland_wrapper/kwin_wrapper.cpp b/src/helpers/wayland_wrapper/kwin_wrapper.cpp index 74de94d786..67ab0c4ba7 100644 --- a/src/helpers/wayland_wrapper/kwin_wrapper.cpp +++ b/src/helpers/wayland_wrapper/kwin_wrapper.cpp @@ -27,6 +27,7 @@ #include #include +#include #include @@ -156,17 +157,17 @@ void KWinWrapper::run() }); } -void sigtermHandler(int) -{ - qApp->quit(); -} - int main(int argc, char **argv) { QCoreApplication app(argc, argv); app.setQuitLockEnabled(false); // don't exit when the first KJob finishes - signal(SIGTERM, sigtermHandler); + KSignalHandler::self()->watchSignal(SIGTERM); + QObject::connect(KSignalHandler::self(), &KSignalHandler::signalReceived, &app, [&app](int signal) { + if (signal == SIGTERM) { + app.quit(); + } + }); KWinWrapper wrapper(&app); wrapper.run();