diff options
author | Thiago Macieira <thiago.macieira@intel.com> | 2017-08-11 12:01:12 -0700 |
---|---|---|
committer | Thiago Macieira <thiago.macieira@intel.com> | 2017-08-16 15:52:02 +0000 |
commit | cdc79f5ebc0ec1898e3845acb9c880b5e69e593b (patch) | |
tree | 18f2b3a12d77d33b6cc859b502358976c169264d /src/plugins/platforms | |
parent | baf1158c48c3342f4e90d83c3b93236535aac285 (diff) |
XCB: Don't core-dump if we can't connect to the X displayName
Exit with error, but don't crash.
Change-Id: Ie05c6480d8a44fda817ffffd14d9dfd8c951beef
Reviewed-by: Paul Olav Tvete <paul.tvete@qt.io>
Diffstat (limited to 'src/plugins/platforms')
-rw-r--r-- | src/plugins/platforms/xcb/qxcbconnection.cpp | 20 | ||||
-rw-r--r-- | src/plugins/platforms/xcb/qxcbconnection.h | 1 | ||||
-rw-r--r-- | src/plugins/platforms/xcb/qxcbintegration.cpp | 17 |
3 files changed, 30 insertions, 8 deletions
diff --git a/src/plugins/platforms/xcb/qxcbconnection.cpp b/src/plugins/platforms/xcb/qxcbconnection.cpp index e167ba1231..d36a14b920 100644 --- a/src/plugins/platforms/xcb/qxcbconnection.cpp +++ b/src/plugins/platforms/xcb/qxcbconnection.cpp @@ -571,9 +571,10 @@ QXcbConnection::QXcbConnection(QXcbNativeInterface *nativeInterface, bool canGra m_connection = xcb_connect(m_displayName.constData(), &m_primaryScreenNumber); #endif // QT_CONFIG(xcb_xlib) - if (Q_UNLIKELY(!m_connection || xcb_connection_has_error(m_connection))) - qFatal("QXcbConnection: Could not connect to display %s", m_displayName.constData()); - + if (Q_UNLIKELY(!m_connection || xcb_connection_has_error(m_connection))) { + qCWarning(lcQpaScreen, "QXcbConnection: Could not connect to display %s", m_displayName.constData()); + return; + } m_reader = new QXcbEventReader(this); m_reader->start(); @@ -668,7 +669,7 @@ QXcbConnection::~QXcbConnection() finalizeXInput2(); #endif - if (m_reader->isRunning()) { + if (m_reader && m_reader->isRunning()) { sendConnectionEvent(QXcbAtom::_QT_CLOSE_CONNECTION); m_reader->wait(); } @@ -685,15 +686,22 @@ QXcbConnection::~QXcbConnection() delete m_glIntegration; + if (isConnected()) { #if QT_CONFIG(xcb_xlib) - XCloseDisplay(static_cast<Display *>(m_xlib_display)); + XCloseDisplay(static_cast<Display *>(m_xlib_display)); #else - xcb_disconnect(xcb_connection()); + xcb_disconnect(xcb_connection()); #endif + } delete m_keyboard; } +bool QXcbConnection::isConnected() const +{ + return m_connection && !xcb_connection_has_error(m_connection); +} + QXcbScreen *QXcbConnection::primaryScreen() const { if (!m_screens.isEmpty()) { diff --git a/src/plugins/platforms/xcb/qxcbconnection.h b/src/plugins/platforms/xcb/qxcbconnection.h index 1129090eca..edbc8d846e 100644 --- a/src/plugins/platforms/xcb/qxcbconnection.h +++ b/src/plugins/platforms/xcb/qxcbconnection.h @@ -388,6 +388,7 @@ public: ~QXcbConnection(); QXcbConnection *connection() const { return const_cast<QXcbConnection *>(this); } + bool isConnected() const; const QList<QXcbVirtualDesktop *> &virtualDesktops() const { return m_virtualDesktops; } const QList<QXcbScreen *> &screens() const { return m_screens; } diff --git a/src/plugins/platforms/xcb/qxcbintegration.cpp b/src/plugins/platforms/xcb/qxcbintegration.cpp index b372ecd7c4..c9ecdceb0d 100644 --- a/src/plugins/platforms/xcb/qxcbintegration.cpp +++ b/src/plugins/platforms/xcb/qxcbintegration.cpp @@ -178,12 +178,25 @@ QXcbIntegration::QXcbIntegration(const QStringList ¶meters, int &argc, char const int numParameters = parameters.size(); m_connections.reserve(1 + numParameters / 2); - m_connections << new QXcbConnection(m_nativeInterface.data(), m_canGrab, m_defaultVisualId, displayName); + auto conn = new QXcbConnection(m_nativeInterface.data(), m_canGrab, m_defaultVisualId, displayName); + if (conn->isConnected()) + m_connections << conn; + else + delete conn; for (int i = 0; i < numParameters - 1; i += 2) { qCDebug(lcQpaScreen) << "connecting to additional display: " << parameters.at(i) << parameters.at(i+1); QString display = parameters.at(i) + QLatin1Char(':') + parameters.at(i+1); - m_connections << new QXcbConnection(m_nativeInterface.data(), m_canGrab, m_defaultVisualId, display.toLatin1().constData()); + conn = new QXcbConnection(m_nativeInterface.data(), m_canGrab, m_defaultVisualId, display.toLatin1().constData()); + if (conn->isConnected()) + m_connections << conn; + else + delete conn; + } + + if (m_connections.isEmpty()) { + qCritical("Could not connect to any X display."); + exit(1); } m_fontDatabase.reset(new QGenericUnixFontDatabase()); |