From 0b1ce5db9e04b4c28713e87306fcea020c3e428b Mon Sep 17 00:00:00 2001 From: Uli Schlachter Date: Thu, 1 Nov 2012 18:40:37 +0100 Subject: XCB: Handle connection errors MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When the XCB connection breaks, all following XCB function calls will fail and function calls that are currently in progress will return. This means that xcb_wait_for_event() will return NULL and thus the QXcbEventReader thread will exit. This patch uses the above behavior to make sure that processXcbEvents() will be called. The error handling should always be done before normal event processing, because all XCB calls will fail once the connection is in an error state. This is especially unexpected for xcb_get_setup() which suddenly returns a NULL pointer. Task-number: QTBUG-27686 Change-Id: Ie3e4058f9d92bcbfc45934a8b36d9a7254e2b4bb Signed-off-by: Uli Schlachter Reviewed-by: Samuel Rødal Reviewed-by: Friedemann Kleint --- src/plugins/platforms/xcb/qxcbconnection.cpp | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src') diff --git a/src/plugins/platforms/xcb/qxcbconnection.cpp b/src/plugins/platforms/xcb/qxcbconnection.cpp index 85f6fc9213..e35954caf9 100644 --- a/src/plugins/platforms/xcb/qxcbconnection.cpp +++ b/src/plugins/platforms/xcb/qxcbconnection.cpp @@ -283,6 +283,7 @@ QXcbConnection::QXcbConnection(QXcbNativeInterface *nativeInterface, const char m_reader = new QXcbEventReader(this); #ifdef XCB_POLL_FOR_QUEUED_EVENT connect(m_reader, SIGNAL(eventPending()), this, SLOT(processXcbEvents()), Qt::QueuedConnection); + connect(m_reader, SIGNAL(finished()), this, SLOT(processXcbEvents())); m_reader->start(); #else QSocketNotifier *notifier = new QSocketNotifier(xcb_get_file_descriptor(xcb_connection()), QSocketNotifier::Read, this); @@ -919,6 +920,12 @@ xcb_timestamp_t QXcbConnection::getTimestamp() void QXcbConnection::processXcbEvents() { + int connection_error = xcb_connection_has_error(xcb_connection()); + if (connection_error) { + qWarning("The X11 connection broke (error %d). Did the X11 server die?", connection_error); + exit(1); + } + QXcbEventArray *eventqueue = m_reader->lock(); for(int i = 0; i < eventqueue->size(); ++i) { -- cgit v1.2.3