summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Griebl <robert.griebl@qt.io>2023-05-10 22:25:06 +0200
committerRobert Griebl <robert.griebl@qt.io>2023-05-11 12:01:50 +0200
commita2aed270244c872c58dfdd945d1e5452ab23d057 (patch)
tree39ac24f93282985d7d66d8446e1c4ba7a1080317
parent77abca601078e643550bb662d4d7e61b0647beed (diff)
downloadqtapplicationmanager-a2aed270244c872c58dfdd945d1e5452ab23d057.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 Pick-to: 6.5 6.2 5.15 Reviewed-by: Dominik Holland <dominik.holland@qt.io>
-rw-r--r--src/dbus-lib/dbusdaemon.cpp27
1 files changed, 26 insertions, 1 deletions
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 <sys/prctl.h>
# include <sys/signal.h>
+# include <dlfcn.h>
+# include <QVersionNumber>
#endif
#include <QCoreApplication>
#include <QIODevice>
@@ -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<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)
{
@@ -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);