summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Griebl <robert.griebl@qt.io>2023-05-10 22:25:06 +0200
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2023-05-11 10:32:06 +0000
commitec8fe9eb7e5ef657fd624bce880a220ee5c6ab57 (patch)
tree47d5f12449939ae0804a211e2e211703ccaf1480
parent17a67d4d1a6276eae25e0f815727fc40753d9d77 (diff)
downloadqtapplicationmanager-ec8fe9eb7e5ef657fd624bce880a220ee5c6ab57.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) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-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);