Package: libqtdbustest
Version: 0.2+bzr42+repack1-12
Some consumers set the session or system configuration file argument
passed to the DBusTestRunner to 0, possibly with the intention to
avoid the unnecessary startup of either dbus-daemon instance. This
worked before the patch from bug #1019458 by accident since it
resulted in an empty string passed to --config-file making
dbus-daemon quit with an error message which was erroneously
interpreted as the bus address.
The attached updated patch restores this behavior by checking
whether the configuration file passed in is empty and refraining
from starting dbus-daemon in that case.
In addition it fixes a copy & paste error in the address check of
system instances of dbus-daemon.
--
Guido Berhoerster
From: Guido Berhoerster <[email protected]>
Subject: Make reading address from dbus-daemon more robust
After starting dbus-daemon DBusTestRunner attempts to read the address from
stdout and puts it into DBUS_SESSION_BUS_ADDRESS and DBUS_SYSTEM_BUS_ADDRESS
environemnt variables. Unfortunately it sets the process channel mode of the
QProcess to QProcess::MergedChannels which results in stdout and stderr being
merged. Therefore any warnings dbus-daemon prints to stderr will end up in
those environment variables instead of the actual address causing non-obvious
problems later on.
Remove this and read exactly one line from stdout which should contain the
address. Add an extra sanity check the trimmed output is not empty.
Some consumers also set the session or system configuration file argument
passed to the DBusTestRunner to 0, possibly with the intention to avoid
the unnecessary startup of either dbus-daemon instance. This worked by
accident since it resulted in an empty string passed to --config-file making
dbus-daemon quit with an error message which was erroneously interpreted as the
bus address. In order to keep this behavior, add a check whether the
configuration file passed in is empty and refrain from starting dbus-daemon in
that case.
--- libqtdbustest-0.2+bzr42.orig/src/libqtdbustest/DBusTestRunner.cpp
+++ libqtdbustest-0.2+bzr42/src/libqtdbustest/DBusTestRunner.cpp
@@ -60,37 +60,45 @@ DBusTestRunner::DBusTestRunner(const QSt
} else {
// session bus setup
- d->m_sessionDBus.setProcessChannelMode(QProcess::MergedChannels);
- d->m_sessionDBus.start("dbus-daemon",
- QStringList() << "--config-file" << dbusSessionConfigFile
- << "--print-address");
- Q_ASSERT(d->m_sessionDBus.waitForStarted(-1));
-
- d->m_sessionDBus.waitForReadyRead();
- d->m_sessionBus = d->m_sessionDBus.readAll().trimmed();
-
- qputenv("DBUS_SESSION_BUS_ADDRESS", d->m_sessionBus.toUtf8());
- qputenv("DBUS_STARTER_ADDRESS", d->m_sessionBus.toUtf8());
- qputenv("DBUS_STARTER_BUS_TYPE", "session");
-
- d->m_sessionConnection = QDBusConnection::connectToBus(d->m_sessionBus,
- d->m_sessionBus);
+ if (!dbusSessionConfigFile.isEmpty()) {
+ d->m_sessionDBus.start("dbus-daemon",
+ QStringList() << "--config-file" << dbusSessionConfigFile
+ << "--print-address");
+ Q_ASSERT(d->m_sessionDBus.waitForStarted(-1));
+
+ d->m_sessionDBus.waitForReadyRead();
+ d->m_sessionBus = d->m_sessionDBus.readLine().trimmed();
+ if (d->m_sessionBus.isEmpty()) {
+ qFatal("dbus-daemon (session) did not return an address");
+ }
+
+ qputenv("DBUS_SESSION_BUS_ADDRESS", d->m_sessionBus.toUtf8());
+ qputenv("DBUS_STARTER_ADDRESS", d->m_sessionBus.toUtf8());
+ qputenv("DBUS_STARTER_BUS_TYPE", "session");
+
+ d->m_sessionConnection = QDBusConnection::connectToBus(d->m_sessionBus,
+ d->m_sessionBus);
+ }
// system bus setup
- d->m_systemDBus.setProcessChannelMode(QProcess::MergedChannels);
- d->m_systemDBus.start("dbus-daemon",
- QStringList() << "--config-file" << dbusSystemConfigFile
- << "--print-address");
- Q_ASSERT(d->m_systemDBus.waitForStarted(-1));
-
- d->m_systemDBus.waitForReadyRead();
- d->m_systemBus = d->m_systemDBus.readAll().trimmed();
-
- qputenv("DBUS_SYSTEM_BUS_ADDRESS", d->m_systemBus.toUtf8());
-
- d->m_systemConnection = QDBusConnection::connectToBus(d->m_systemBus,
- d->m_systemBus);
+ if (!dbusSystemConfigFile.isEmpty()) {
+ d->m_systemDBus.start("dbus-daemon",
+ QStringList() << "--config-file" << dbusSystemConfigFile
+ << "--print-address");
+ Q_ASSERT(d->m_systemDBus.waitForStarted(-1));
+
+ d->m_systemDBus.waitForReadyRead();
+ d->m_systemBus = d->m_systemDBus.readLine().trimmed();
+ if (d->m_systemBus.isEmpty()) {
+ qFatal("dbus-daemon (system) did not return an address");
+ }
+
+ qputenv("DBUS_SYSTEM_BUS_ADDRESS", d->m_systemBus.toUtf8());
+
+ d->m_systemConnection = QDBusConnection::connectToBus(d->m_systemBus,
+ d->m_systemBus);
+ }
}
}