File: 1004_make-reading-address-from-dbus-daemon-more-robust.patch

package info (click to toggle)
libqtdbustest 0.4.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 340 kB
  • sloc: cpp: 565; sh: 59; makefile: 28
file content (100 lines) | stat: -rw-r--r-- 4,144 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
From: Guido Berhoerster <guido+ubports@berhoerster.name>
Subject: Make reading address from dbus-daemon more robust
Forwarded: https://gitlab.com/ubports/development/core/libqtdbustest/-/merge_requests/6
Abstract:
 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
 environment 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);
+		}
 	}
 }