Commit ab85e957 authored by Martin Flöser's avatar Martin Flöser
Browse files

[server] Handle no XDG_RUNTIME_DIR situation more gracefully

Summary:
Even if the XDG_RUNTIME_DIR is not set, KWayland should not crash
if methods are invoked which only make sense after the server was
started successfully. This was not yet the case for
Display::dispatchEvents.

Also the wl_display was not destroyed in the situation that creating
the socket failed.

Test Plan:
Test case added which simulates the situation of no
XDG_RUNTIME_DIR being set.

Reviewers: #plasma_on_wayland

Subscribers: plasma-devel

Tags: #plasma_on_wayland

Differential Revision: https://phabricator.kde.org/D2077
parent cd77833c
......@@ -38,3 +38,11 @@ add_executable(testQtSurfaceExtension ${testQtSurfaceExtension_SRCS})
target_link_libraries( testQtSurfaceExtension Qt5::Test Qt5::Gui KF5::WaylandServer)
add_test(kwayland-testQtSurfaceExtension testQtSurfaceExtension)
ecm_mark_as_test(testQtSurfaceExtension)
########################################################
# Test No XDG_RUNTIME_DIR
########################################################
add_executable(testNoXdgRuntimeDir test_no_xdg_runtime_dir.cpp)
target_link_libraries( testNoXdgRuntimeDir Qt5::Test KF5::WaylandServer)
add_test(kwayland-testNoXdgRuntimeDir testNoXdgRuntimeDir)
ecm_mark_as_test(testNoXdgRuntimeDir)
/********************************************************************
Copyright 2016 Martin Gräßlin <mgraesslin@kde.org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) version 3, or any
later version accepted by the membership of KDE e.V. (or its
successor approved by the membership of KDE e.V.), which shall
act as a proxy defined in Section 6 of version 3 of the license.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library. If not, see <http://www.gnu.org/licenses/>.
*********************************************************************/
// Qt
#include <QtTest/QtTest>
// WaylandServer
#include "../../src/server/display.h"
using namespace KWayland::Server;
class NoXdgRuntimeDirTest : public QObject
{
Q_OBJECT
private Q_SLOTS:
void initTestCase();
void testCreate();
};
void NoXdgRuntimeDirTest::initTestCase()
{
qunsetenv("XDG_RUNTIME_DIR");
}
void NoXdgRuntimeDirTest::testCreate()
{
// this test verifies that not having an XDG_RUNTIME_DIR is handled gracefully
// the server cannot start, but should not crash
const QString testSocketName = QStringLiteral("kwayland-test-no-xdg-runtime-dir-0");
Display display;
QSignalSpy runningSpy(&display, &Display::runningChanged);
QVERIFY(runningSpy.isValid());
display.setSocketName(testSocketName);
QVERIFY(!display.isRunning());
display.start();
QVERIFY(!display.isRunning());
// call into dispatchEvents should not crash
display.dispatchEvents();
}
QTEST_GUILESS_MAIN(NoXdgRuntimeDirTest)
#include "test_no_xdg_runtime_dir.moc"
......@@ -109,6 +109,9 @@ Display::Display(QObject *parent)
Display::~Display()
{
terminate();
if (d->display) {
wl_display_destroy(d->display);
}
}
void Display::Private::flush()
......@@ -150,6 +153,7 @@ void Display::start(StartMode mode)
d->display = wl_display_create();
if (mode == StartMode::ConnectToSocket) {
if (wl_display_add_socket(d->display, qPrintable(d->socketName)) != 0) {
qCWarning(KWAYLAND_SERVER) << "Failed to create Wayland socket";
return;
}
}
......@@ -170,7 +174,7 @@ void Display::dispatchEvents(int msecTimeout)
Q_ASSERT(d->display);
if (d->running) {
d->dispatch();
} else {
} else if (d->loop) {
wl_event_loop_dispatch(d->loop, msecTimeout);
wl_display_flush_clients(d->display);
}
......
Supports Markdown
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