From affcbac7e7c3edeb457d5ea3d800d37ab1b6263f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Gr=C3=A4=C3=9Flin?= Date: Tue, 10 Nov 2015 14:21:48 +0100 Subject: [PATCH] [wayland] Destroy Xwayland's ClientConnection on tear down We need to destroy the ClientConnections we create. Also we need to disconnect our Xwayland error handling before destroying it, otherwise it would trigger the abort for crashing Xwayland. --- autotests/wayland/kwin_wayland_test.cpp | 1 + main_wayland.cpp | 1 + wayland_server.cpp | 16 +++++++++++++--- wayland_server.h | 8 ++++++-- 4 files changed, 21 insertions(+), 5 deletions(-) diff --git a/autotests/wayland/kwin_wayland_test.cpp b/autotests/wayland/kwin_wayland_test.cpp index 88facd1faf..ef08c985ff 100644 --- a/autotests/wayland/kwin_wayland_test.cpp +++ b/autotests/wayland/kwin_wayland_test.cpp @@ -61,6 +61,7 @@ WaylandTestApplication::~WaylandTestApplication() if (m_xwaylandProcess) { m_xwaylandProcess->terminate(); m_xwaylandProcess->waitForFinished(); + waylandServer()->destroyXWaylandConnection(); } waylandServer()->destroyInternalConnection(); destroyCompositor(); diff --git a/main_wayland.cpp b/main_wayland.cpp index 41fc7e5158..071a25fd55 100644 --- a/main_wayland.cpp +++ b/main_wayland.cpp @@ -85,6 +85,7 @@ ApplicationWayland::~ApplicationWayland() if (m_xwaylandProcess) { m_xwaylandProcess->terminate(); m_xwaylandProcess->waitForFinished(); + waylandServer()->destroyXWaylandConnection(); } waylandServer()->destroyInternalConnection(); destroyCompositor(); diff --git a/wayland_server.cpp b/wayland_server.cpp index 786899166c..d8d216ab81 100644 --- a/wayland_server.cpp +++ b/wayland_server.cpp @@ -125,7 +125,7 @@ void WaylandServer::init(const QByteArray &socketName, InitalizationFlags flags) // it's possible that a Surface gets created before Workspace is created return; } - if (surface->client() == m_xwaylandConnection) { + if (surface->client() == m_xwayland.client) { // skip Xwayland clients, those are created using standard X11 way return; } @@ -261,8 +261,8 @@ int WaylandServer::createXWaylandConnection() qCWarning(KWIN_CORE) << "Could not create socket"; return -1; } - m_xwaylandConnection = m_display->createClient(sx[0]); - connect(m_xwaylandConnection, &KWayland::Server::ClientConnection::disconnected, this, + m_xwayland.client = m_display->createClient(sx[0]); + m_xwayland.destroyConnection = connect(m_xwayland.client, &KWayland::Server::ClientConnection::disconnected, this, [] { qFatal("Xwayland Connection died"); } @@ -270,6 +270,16 @@ int WaylandServer::createXWaylandConnection() return sx[1]; } +void WaylandServer::destroyXWaylandConnection() +{ + if (!m_xwayland.client) { + return; + } + disconnect(m_xwayland.destroyConnection); + m_xwayland.client->destroy(); + m_xwayland.client = nullptr; +} + int WaylandServer::createInputMethodConnection() { int sx[2]; diff --git a/wayland_server.h b/wayland_server.h index 02d752af31..0dbe91dec6 100644 --- a/wayland_server.h +++ b/wayland_server.h @@ -109,6 +109,7 @@ public: * @returns file descriptor for Xwayland to connect to. **/ int createXWaylandConnection(); + void destroyXWaylandConnection(); /** * @returns file descriptor to the input method server's socket. @@ -120,7 +121,7 @@ public: void initWorkspace(); KWayland::Server::ClientConnection *xWaylandConnection() const { - return m_xwaylandConnection; + return m_xwayland.client; } KWayland::Server::ClientConnection *inputMethodConnection() const { return m_inputMethodServerConnection; @@ -156,7 +157,10 @@ private: KWayland::Server::PlasmaShellInterface *m_plasmaShell = nullptr; KWayland::Server::PlasmaWindowManagementInterface *m_windowManagement = nullptr; KWayland::Server::QtSurfaceExtensionInterface *m_qtExtendedSurface = nullptr; - KWayland::Server::ClientConnection *m_xwaylandConnection = nullptr; + struct { + KWayland::Server::ClientConnection *client = nullptr; + QMetaObject::Connection destroyConnection; + } m_xwayland; KWayland::Server::ClientConnection *m_inputMethodServerConnection = nullptr; KWayland::Server::ClientConnection *m_screenLockerClientConnection = nullptr; struct {