From 0d15048e552f75e71e441850ccbdea8d0e02e494 Mon Sep 17 00:00:00 2001 From: Alex Richardson Date: Tue, 20 Jul 2021 00:16:39 +0100 Subject: [PATCH] Avoid crashing on startup if DBus isn't running I am trying to run Okular on a minimal FreeBSD CHERI-RISC-V QEMU instance and I haven't got DBus running. Without this change, I get crashes because QDBusConnection::sessionBus().interface() returns NULL if DBus isn't running. --- shell/okular_main.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/shell/okular_main.cpp b/shell/okular_main.cpp index 0a986076c..ffcbba7ef 100644 --- a/shell/okular_main.cpp +++ b/shell/okular_main.cpp @@ -48,7 +48,12 @@ static bool attachExistingInstance(const QStringList &paths, const QString &seri if (ShellUtils::showPrintDialogAndExit(serializedOptions)) return false; - const QStringList services = QDBusConnection::sessionBus().interface()->registeredServiceNames().value(); + // If DBus isn't running, we can't attach to an existing instance. + auto *sessionInterface = QDBusConnection::sessionBus().interface(); + if (!sessionInterface) + return false; + + const QStringList services = sessionInterface->registeredServiceNames().value(); // Don't match the service without trailing "-" (unique instance) const QString pattern = QStringLiteral("org.kde.okular-");