diff options
author | Robert Griebl <robert.griebl@qt.io> | 2023-05-10 22:25:06 +0200 |
---|---|---|
committer | Robert Griebl <robert.griebl@qt.io> | 2023-05-15 17:54:33 +0200 |
commit | b75fdf6a571ee13035b4cbccde280f5fe7c01249 (patch) | |
tree | cffe98176f71175188bba79589c21eff64fda160 | |
parent | 31f627f3ac6e2562e92680d103ed4c85ff03fcd2 (diff) | |
download | qtapplicationmanager-b75fdf6a571ee13035b4cbccde280f5fe7c01249.tar.gz |
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
Reviewed-by: Dominik Holland <dominik.holland@qt.io>
(cherry picked from commit a2aed270244c872c58dfdd945d1e5452ab23d057)
-rw-r--r-- | src/dbus-lib/dbusdaemon.cpp | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/src/dbus-lib/dbusdaemon.cpp b/src/dbus-lib/dbusdaemon.cpp index 41db1541..73f4cc66 100644 --- a/src/dbus-lib/dbusdaemon.cpp +++ b/src/dbus-lib/dbusdaemon.cpp @@ -45,6 +45,8 @@ #if defined(Q_OS_LINUX) # include <sys/prctl.h> # include <sys/signal.h> +# include <dlfcn.h> +# include <QVersionNumber> #endif #include <QCoreApplication> #include <QIODevice> @@ -56,6 +58,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<am_dbus_get_version_t>(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) { @@ -77,7 +97,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); |