Commit b8a16d4a authored by Vlad Zahorodnii's avatar Vlad Zahorodnii
Browse files

xwayland: Properly handle xcb_connect_to_fd() failures

xcb_connect_to_fd() will never return a NULL pointer, even if an error
has occurred.

Right after creating an xcb connection, xcb_connection_has_error() needs
to be called in order to determine if the connection has an error.
parent bfcf312e
......@@ -297,11 +297,14 @@ void Xwayland::handleXwaylandError(QProcess::ProcessError error)
void Xwayland::createX11Connection()
bool Xwayland::createX11Connection()
xcb_connection_t *connection = xcb_connect_to_fd(m_xcbConnectionFd, nullptr);
if (!connection) {
const int errorCode = xcb_connection_has_error(connection);
if (errorCode) {
qCDebug(KWIN_XWL, "Failed to establish the XCB connection (error %d)", errorCode);
return false;
xcb_screen_t *screen = xcb_setup_roots_iterator(xcb_get_setup(connection)).data;
......@@ -320,6 +323,8 @@ void Xwayland::createX11Connection()
// Note that it's very important to have valid x11RootWindow(), x11ScreenNumber(), and
// atoms when the rest of kwin is notified about the new X11 connection.
emit m_app->x11ConnectionChanged();
return true;
void Xwayland::destroyX11Connection()
......@@ -347,16 +352,14 @@ void Xwayland::destroyX11Connection()
void Xwayland::continueStartupWithX()
xcb_connection_t *xcbConn = m_app->x11Connection();
if (!xcbConn) {
if (!createX11Connection()) {
// about to quit
Q_EMIT criticalError(1);
// create selection owner for WM_S0 - magic X display number expected by XWayland
KSelectionOwner owner("WM_S0", xcbConn, m_app->x11RootWindow());
KSelectionOwner owner("WM_S0", kwinApp()->x11Connection(), kwinApp()->x11RootWindow());
......@@ -87,7 +87,7 @@ private:
void installSocketNotifier();
void uninstallSocketNotifier();
void createX11Connection();
bool createX11Connection();
void destroyX11Connection();
void continueStartupWithX();
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment