From a2aed270244c872c58dfdd945d1e5452ab23d057 Mon Sep 17 00:00:00 2001 From: Robert Griebl Date: Wed, 10 May 2023 22:25:06 +0200 Subject: Force our session bus to be a file-based socket on Linux. (part 2) Detect if we are running against an old D-Bus library where the "unix:dir=..." syntax is not supported. Change-Id: Icc4ac38868e0bc2ea2675d86384c4ff33aa11cdb Pick-to: 6.5 6.2 5.15 Reviewed-by: Dominik Holland --- src/dbus-lib/dbusdaemon.cpp | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/src/dbus-lib/dbusdaemon.cpp b/src/dbus-lib/dbusdaemon.cpp index 6639f1c3..71fc23f3 100644 --- a/src/dbus-lib/dbusdaemon.cpp +++ b/src/dbus-lib/dbusdaemon.cpp @@ -8,6 +8,8 @@ #if defined(Q_OS_LINUX) # include # include +# include +# include #endif #include #include @@ -19,6 +21,24 @@ QT_BEGIN_NAMESPACE_AM +#if defined(Q_OS_LINUX) +static QVersionNumber dbusVersion() +{ + typedef void (*am_dbus_get_version_t)(int *, int *, int *); + static am_dbus_get_version_t am_dbus_get_version = nullptr; + + if (!am_dbus_get_version) + am_dbus_get_version = reinterpret_cast(dlsym(RTLD_DEFAULT, "dbus_get_version")); + + if (!am_dbus_get_version) + qFatal("ERROR: could not resolve 'dbus_get_version' from libdbus-1"); + + int major = 0, minor = 0, patch = 0; + am_dbus_get_version(&major, &minor, &patch); + return QVersionNumber(major, minor, patch); +} +#endif + DBusDaemonProcess::DBusDaemonProcess(QObject *parent) : QProcess(parent) { @@ -40,7 +60,12 @@ DBusDaemonProcess::DBusDaemonProcess(QObject *parent) // some dbus implementations create an abstract socket by default, while others create // a file based one. we need a file based one however, because that socket might get // mapped into a container. - arguments << qSL("--address=unix:dir=/tmp"); + if (dbusVersion() >= QVersionNumber(1, 11, 14)) { + arguments << qSL("--address=unix:dir=/tmp"); + } else { + arguments << QString(qSL("--address=unix:path=") + QDir::tempPath() + qSL("am-") + + QString::number(QCoreApplication::applicationPid()) + qSL("-session.bus")); + } #endif setProgram(program); setArguments(arguments); -- cgit v1.2.1