From c6766fe4f4c6b7145131ea6210fbb601571e961d Mon Sep 17 00:00:00 2001 From: Robin Burchell Date: Tue, 19 Aug 2014 18:24:56 +0200 Subject: [PATCH] QWaylandDisplay: Correctly intercept all errors when dispatching. A connection reset isn't the only form of error we may run into, so make sure we check for other exceptional circumstances through wl_display_get_error. This fixes my case of e.g. wl_drm throwing an error but QtWayland never quitting the client. Change-Id: I8c76dd7913640e58d03bd2fe52eb054a4daa0235 Reviewed-by: Giulio Camuffo --- .../platforms/wayland/qwaylanddisplay.cpp | 21 +++++++++++++++---- .../platforms/wayland/qwaylandeventthread.cpp | 10 +++++++-- 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/src/plugins/platforms/wayland/qwaylanddisplay.cpp b/src/plugins/platforms/wayland/qwaylanddisplay.cpp index 242a13a155a..74efbfda4c2 100644 --- a/src/plugins/platforms/wayland/qwaylanddisplay.cpp +++ b/src/plugins/platforms/wayland/qwaylanddisplay.cpp @@ -166,18 +166,31 @@ QWaylandDisplay::~QWaylandDisplay(void) void QWaylandDisplay::flushRequests() { - if (wl_display_dispatch_queue_pending(mDisplay, mEventQueue) == -1 && (errno == EPIPE || errno == ECONNRESET)) { - qWarning("The Wayland connection broke. Did the Wayland compositor die?"); + if (wl_display_dispatch_queue_pending(mDisplay, mEventQueue) < 0) { + int ecode = wl_display_get_error(mDisplay); + if ((ecode == EPIPE || ecode == ECONNRESET)) { + // special case this to provide a nicer error + qWarning("The Wayland connection broke. Did the Wayland compositor die?"); + } else { + qErrnoWarning(ecode, "The Wayland connection experienced a fatal error"); + } ::exit(1); } + wl_display_flush(mDisplay); } void QWaylandDisplay::blockingReadEvents() { - if (wl_display_dispatch_queue(mDisplay, mEventQueue) == -1 && (errno == EPIPE || errno == ECONNRESET)) { - qWarning("The Wayland connection broke. Did the Wayland compositor die?"); + if (wl_display_dispatch_queue(mDisplay, mEventQueue) < 0) { + int ecode = wl_display_get_error(mDisplay); + if ((ecode == EPIPE || ecode == ECONNRESET)) { + // special case this to provide a nicer error + qWarning("The Wayland connection broke. Did the Wayland compositor die?"); + } else { + qErrnoWarning(ecode, "The Wayland connection experienced a fatal error"); + } ::exit(1); } } diff --git a/src/plugins/platforms/wayland/qwaylandeventthread.cpp b/src/plugins/platforms/wayland/qwaylandeventthread.cpp index c6ac42bba8f..979aa6e0ebf 100644 --- a/src/plugins/platforms/wayland/qwaylandeventthread.cpp +++ b/src/plugins/platforms/wayland/qwaylandeventthread.cpp @@ -73,8 +73,14 @@ void QWaylandEventThread::displayConnect() void QWaylandEventThread::readWaylandEvents() { - if (wl_display_dispatch(m_display) == -1 && (errno == EPIPE || errno == ECONNRESET)) { - qWarning("The Wayland connection broke. Did the Wayland compositor die?"); + if (wl_display_dispatch(m_display) < 0) { + int ecode = wl_display_get_error(m_display); + if ((ecode == EPIPE || ecode == ECONNRESET)) { + // special case this to provide a nicer error + qWarning("The Wayland connection broke. Did the Wayland compositor die?"); + } else { + qErrnoWarning(ecode, "The Wayland connection experienced a fatal error"); + } ::exit(1); } emit newEventsRead();