From b13a74c908d7b1c7957e2e309fc7aef55ecfbc21 Mon Sep 17 00:00:00 2001 From: Vlad Zahorodnii Date: Tue, 8 Sep 2020 11:18:31 +0300 Subject: [PATCH] xwayland: Replace criticalError() signal with a less fatal signal If the Xwayland executable can't be found, the whole session will die because a criticalError() signal will be emitted. This change replaces the criticalError() signal with a less severe signal. If the errorOccurred() signal has been emitted during the startup sequence, kwin won't die and will just continue with spawning the session process. --- autotests/integration/kwin_wayland_test.cpp | 8 ++------ main_wayland.cpp | 8 ++------ xwl/xwayland.cpp | 15 +++++++-------- xwl/xwayland.h | 7 +++++-- 4 files changed, 16 insertions(+), 22 deletions(-) diff --git a/autotests/integration/kwin_wayland_test.cpp b/autotests/integration/kwin_wayland_test.cpp index 02469b1c63..8bfa215e44 100644 --- a/autotests/integration/kwin_wayland_test.cpp +++ b/autotests/integration/kwin_wayland_test.cpp @@ -151,6 +151,7 @@ void WaylandTestApplication::continueStartupWithScreens() void WaylandTestApplication::finalizeStartup() { if (m_xwayland) { + disconnect(m_xwayland, &Xwl::Xwayland::errorOccurred, this, &WaylandTestApplication::finalizeStartup); disconnect(m_xwayland, &Xwl::Xwayland::started, this, &WaylandTestApplication::finalizeStartup); } notifyStarted(); @@ -172,12 +173,7 @@ void WaylandTestApplication::continueStartupWithScene() } m_xwayland = new Xwl::Xwayland(this); - connect(m_xwayland, &Xwl::Xwayland::criticalError, this, [](int code) { - // we currently exit on Xwayland errors always directly - // TODO: restart Xwayland - std::cerr << "Xwayland had a critical error. Going to exit now." << std::endl; - exit(code); - }); + connect(m_xwayland, &Xwl::Xwayland::errorOccurred, this, &WaylandTestApplication::finalizeStartup); connect(m_xwayland, &Xwl::Xwayland::started, this, &WaylandTestApplication::finalizeStartup); m_xwayland->start(); } diff --git a/main_wayland.cpp b/main_wayland.cpp index a0b5e2327c..bd2128e997 100644 --- a/main_wayland.cpp +++ b/main_wayland.cpp @@ -180,6 +180,7 @@ void ApplicationWayland::continueStartupWithScreens() void ApplicationWayland::finalizeStartup() { if (m_xwayland) { + disconnect(m_xwayland, &Xwl::Xwayland::errorOccurred, this, &ApplicationWayland::finalizeStartup); disconnect(m_xwayland, &Xwl::Xwayland::started, this, &ApplicationWayland::finalizeStartup); } startSession(); @@ -203,12 +204,7 @@ void ApplicationWayland::continueStartupWithScene() } m_xwayland = new Xwl::Xwayland(this); - connect(m_xwayland, &Xwl::Xwayland::criticalError, this, [](int code) { - // we currently exit on Xwayland errors always directly - // TODO: restart Xwayland - std::cerr << "Xwayland had a critical error. Going to exit now." << std::endl; - exit(code); - }); + connect(m_xwayland, &Xwl::Xwayland::errorOccurred, this, &ApplicationWayland::finalizeStartup); connect(m_xwayland, &Xwl::Xwayland::started, this, &ApplicationWayland::finalizeStartup); m_xwayland->start(); } diff --git a/xwl/xwayland.cpp b/xwl/xwayland.cpp index 8f60f0f802..74f4a1cbb2 100644 --- a/xwl/xwayland.cpp +++ b/xwl/xwayland.cpp @@ -91,32 +91,32 @@ void Xwayland::start() int pipeFds[2]; if (pipe(pipeFds) != 0) { std::cerr << "FATAL ERROR failed to create pipe to start Xwayland " << std::endl; - Q_EMIT criticalError(1); + emit errorOccurred(); return; } int sx[2]; if (socketpair(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0, sx) < 0) { std::cerr << "FATAL ERROR: failed to open socket to open XCB connection" << std::endl; - Q_EMIT criticalError(1); + emit errorOccurred(); return; } int fd = dup(sx[1]); if (fd < 0) { std::cerr << "FATAL ERROR: failed to open socket to open XCB connection" << std::endl; - Q_EMIT criticalError(20); + emit errorOccurred(); return; } const int waylandSocket = waylandServer()->createXWaylandConnection(); if (waylandSocket == -1) { std::cerr << "FATAL ERROR: failed to open socket for Xwayland" << std::endl; - Q_EMIT criticalError(1); + emit errorOccurred(); return; } const int wlfd = dup(waylandSocket); if (wlfd < 0) { std::cerr << "FATAL ERROR: failed to open socket for Xwayland" << std::endl; - Q_EMIT criticalError(20); + emit errorOccurred(); return; } @@ -279,7 +279,6 @@ void Xwayland::handleXwaylandError(QProcess::ProcessError error) switch (error) { case QProcess::FailedToStart: qCWarning(KWIN_XWL) << "Xwayland process failed to start"; - emit criticalError(1); return; case QProcess::Crashed: qCWarning(KWIN_XWL) << "Xwayland process crashed"; @@ -295,6 +294,7 @@ void Xwayland::handleXwaylandError(QProcess::ProcessError error) qCWarning(KWIN_XWL) << "An unknown error has occurred in Xwayland"; break; } + emit errorOccurred(); } bool Xwayland::createX11Connection() @@ -353,8 +353,7 @@ void Xwayland::destroyX11Connection() void Xwayland::continueStartupWithX() { if (!createX11Connection()) { - // about to quit - Q_EMIT criticalError(1); + emit errorOccurred(); return; } diff --git a/xwl/xwayland.h b/xwl/xwayland.h index f54f59fb7a..4b12735210 100644 --- a/xwl/xwayland.h +++ b/xwl/xwayland.h @@ -40,7 +40,7 @@ public Q_SLOTS: * Starts the Xwayland server. * * This method will spawn an Xwayland process and will establish a new XCB connection to it. - * If a fatal error has occurred during the startup, the criticalError() signal is going to + * If an error has occurred during the startup, the errorOccurred() signal is going to * be emitted. If the Xwayland server has started successfully, the started() signal will be * emitted. * @@ -72,7 +72,10 @@ Q_SIGNALS: * ready to accept and manage X11 clients. */ void started(); - void criticalError(int code); + /** + * This signal is emitted when an error occurs with the Xwayland server. + */ + void errorOccurred(); private Q_SLOTS: void dispatchEvents();