From 14b9046ad2ae7d4b9e3ffda996b2112fae3690c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Gr=C3=A4=C3=9Flin?= Date: Tue, 15 Dec 2015 10:22:03 +0100 Subject: [PATCH] Unblock signals in child processes We need to unblock the signals blocked with pthread_sigmask. This caused kdeinit to block, because it relies on SIGUSR1. BUG: 356580 FIXED-IN: 5.5.1 REVIEW: 126361 --- main_wayland.cpp | 8 ++++---- rules.cpp | 2 +- useractions.cpp | 2 +- utils.cpp | 18 ++++++++++++++++++ utils.h | 15 +++++++++++++++ 5 files changed, 39 insertions(+), 6 deletions(-) diff --git a/main_wayland.cpp b/main_wayland.cpp index c52c8c7a6d..b99e638cbc 100644 --- a/main_wayland.cpp +++ b/main_wayland.cpp @@ -197,7 +197,7 @@ void ApplicationWayland::continueStartupWithX() environment.insert(QStringLiteral("QT_QPA_PLATFORM"), QStringLiteral("wayland")); environment.remove("DISPLAY"); environment.remove("WAYLAND_DISPLAY"); - QProcess *p = new QProcess(this); + QProcess *p = new Process(this); p->setProcessChannelMode(QProcess::ForwardedErrorChannel); auto finishedSignal = static_cast(&QProcess::finished); connect(p, finishedSignal, this, @@ -217,7 +217,7 @@ void ApplicationWayland::continueStartupWithX() m_environment.insert(QStringLiteral("DISPLAY"), QString::fromUtf8(qgetenv("DISPLAY"))); // start session if (!m_sessionArgument.isEmpty()) { - QProcess *p = new QProcess(this); + QProcess *p = new Process(this); p->setProcessChannelMode(QProcess::ForwardedErrorChannel); p->setProcessEnvironment(m_environment); auto finishedSignal = static_cast(&QProcess::finished); @@ -229,7 +229,7 @@ void ApplicationWayland::continueStartupWithX() for (const QString &application: m_applicationsToStart) { // note: this will kill the started process when we exit // this is going to happen anyway as we are the wayland and X server the app connects to - QProcess *p = new QProcess(this); + QProcess *p = new Process(this); p->setProcessChannelMode(QProcess::ForwardedErrorChannel); p->setProcessEnvironment(m_environment); p->start(application); @@ -299,7 +299,7 @@ void ApplicationWayland::startXwaylandServer() m_xcbConnectionFd = sx[0]; - m_xwaylandProcess = new QProcess(kwinApp()); + m_xwaylandProcess = new Process(kwinApp()); m_xwaylandProcess->setProcessChannelMode(QProcess::ForwardedErrorChannel); m_xwaylandProcess->setProgram(QStringLiteral("Xwayland")); QProcessEnvironment env = m_environment; diff --git a/rules.cpp b/rules.cpp index 79fa1dff80..93fcd1ad06 100644 --- a/rules.cpp +++ b/rules.cpp @@ -1007,7 +1007,7 @@ void RuleBook::edit(AbstractClient* c, bool whole_app) args << QStringLiteral("--wid") << QString::number(c->window()); if (whole_app) args << QStringLiteral("--whole-app"); - QProcess *p = new QProcess(this); + QProcess *p = new Process(this); p->setArguments(args); p->setProcessEnvironment(kwinApp()->processStartupEnvironment()); p->setProgram(QStringLiteral(KWIN_RULES_DIALOG_BIN)); diff --git a/useractions.cpp b/useractions.cpp index 25706ba6d8..d19278048b 100755 --- a/useractions.cpp +++ b/useractions.cpp @@ -330,7 +330,7 @@ void UserActionsMenu::init() // opens the KWin configuration QStringList args; args << QStringLiteral("--icon") << QStringLiteral("preferences-system-windows") << configModules(false); - QProcess *p = new QProcess(this); + QProcess *p = new Process(this); p->setArguments(args); p->setProcessEnvironment(kwinApp()->processStartupEnvironment()); p->setProgram(QStringLiteral("kcmshell5")); diff --git a/utils.cpp b/utils.cpp index 991539cb6b..5d81f6c6ff 100644 --- a/utils.cpp +++ b/utils.cpp @@ -42,6 +42,8 @@ along with this program. If not, see . #include "atoms.h" #include "workspace.h" +#include + #endif Q_LOGGING_CATEGORY(KWIN_CORE, "kwin_core", QtCriticalMsg) @@ -142,6 +144,22 @@ void ungrabXKeyboard() xcb_ungrab_keyboard(connection(), XCB_TIME_CURRENT_TIME); } +Process::Process(QObject *parent) + : QProcess(parent) +{ +} + +Process::~Process() = default; + +void Process::setupChildProcess() +{ + sigset_t userSiganls; + sigemptyset(&userSiganls); + sigaddset(&userSiganls, SIGUSR1); + sigaddset(&userSiganls, SIGUSR2); + pthread_sigmask(SIG_UNBLOCK, &userSiganls, nullptr); +} + #endif // converting between X11 mouse/keyboard state mask and Qt button/keyboard states diff --git a/utils.h b/utils.h index 3ec977bc75..96543d8a7e 100644 --- a/utils.h +++ b/utils.h @@ -35,6 +35,7 @@ along with this program. If not, see . #include #include #include +#include // system #include Q_DECLARE_LOGGING_CATEGORY(KWIN_CORE) @@ -227,6 +228,20 @@ private: bool m_valid = false; }; +/** + * QProcess subclass which unblocks SIGUSR in the child process. + **/ +class KWIN_EXPORT Process : public QProcess +{ + Q_OBJECT +public: + explicit Process(QObject *parent = nullptr); + virtual ~Process(); + +protected: + void setupChildProcess() override; +}; + } // namespace // Must be outside namespace