Merge lp:~mandel/ubuntu-download-manager/system-bus into lp:ubuntu-download-manager

Proposed by Manuel de la Peña
Status: Merged
Approved by: Manuel de la Peña
Approved revision: 117
Merged at revision: 133
Proposed branch: lp:~mandel/ubuntu-download-manager/system-bus
Merge into: lp:ubuntu-download-manager
Prerequisite: lp:~mandel/ubuntu-download-manager/network-errors-management
Diff against target: 423 lines (+159/-55)
13 files modified
debian/ubuntu-download-manager.install (+2/-1)
libubuntudownloadmanager/apparmor.cpp (+34/-11)
libubuntudownloadmanager/apparmor.h (+3/-0)
libubuntudownloadmanager/dbus_connection.cpp (+29/-29)
libubuntudownloadmanager/dbus_connection.h (+1/-0)
libubuntudownloadmanager/download_daemon.cpp (+4/-2)
libubuntudownloadmanager/download_manager.cpp (+1/-1)
libubuntudownloadmanager/logger.cpp (+39/-6)
libubuntudownloadmanager/logger.h (+10/-0)
ubuntu-download-manager-tests/irl_tests.py (+1/-1)
ubuntu-download-manager/com.canonical.applications.Downloader.conf (+18/-0)
ubuntu-download-manager/com.canonical.applications.Downloader.service (+4/-0)
ubuntu-download-manager/ubuntu-download-manager.pro (+13/-4)
To merge this branch: bzr merge lp:~mandel/ubuntu-download-manager/system-bus
Reviewer Review Type Date Requested Status
PS Jenkins bot continuous-integration Approve
Diego Sarmentero (community) Approve
Mike McCracken (community) Approve
Review via email: mp+186832@code.launchpad.net

Commit message

Provide system dbus API to be used by apps such as the image updates.

Description of the change

Provide system dbus API to be used by apps such as the image updates.

To post a comment you must log in.
Revision history for this message
Manuel de la Peña (mandel) wrote :

Please allow me to do the global approve, when this branch lands on trunk is very important due to deployment details.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Mike McCracken (mikemc) wrote :

irl_tests.py with system bus seems to work OK for me.
I was a little thrown by the parameters in progress_callback() being
backwards, though :)

really minor note - looks like the added calls to lastError() in
download_daemon.cpp don't add a space before they dump
"QDBUSError(whatever)", so maybe it'd be a good idea to pad the string
literal before them.

super nitpicky naming suggestion - initSessionBus() and
initSystemBus() sound like they are initializing the busses. Why not
name them after what they'll do, like openLogFile() and
openSyslogConnection() or something?

also, a note for the future branch where you add syslog - why not
separate generating the message (which looks the same for both cases)
from sending it to the logfile/syslog? logSystemMessage() and
logSessionMessage share a lot of code.

review: Approve
Revision history for this message
Mike McCracken (mikemc) wrote :

never mind the note about a space before lastError(). TIL qDebug does some padding of its own.

Revision history for this message
Mike McCracken (mikemc) wrote :

…and never mind the note about the progress_callback() parameters being flipped, I see the next branch fixes that

Revision history for this message
Manuel de la Peña (mandel) wrote :

> irl_tests.py with system bus seems to work OK for me.
> I was a little thrown by the parameters in progress_callback() being
> backwards, though :)
>
> really minor note - looks like the added calls to lastError() in
> download_daemon.cpp don't add a space before they dump
> "QDBUSError(whatever)", so maybe it'd be a good idea to pad the string
> literal before them.
>
> super nitpicky naming suggestion - initSessionBus() and
> initSystemBus() sound like they are initializing the busses. Why not
> name them after what they'll do, like openLogFile() and
> openSyslogConnection() or something?

Sure, lets do that is a goof idea and better now than never.

>
> also, a note for the future branch where you add syslog - why not
> separate generating the message (which looks the same for both cases)
> from sending it to the logfile/syslog? logSystemMessage() and
> logSessionMessage share a lot of code.

Lets do it know, same reason as above.

Revision history for this message
Diego Sarmentero (diegosarmentero) wrote :

+1

review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
117. By Manuel de la Peña

Merged with trunk.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'debian/ubuntu-download-manager.install'
2--- debian/ubuntu-download-manager.install 2013-07-21 20:16:06 +0000
3+++ debian/ubuntu-download-manager.install 2013-09-24 09:53:05 +0000
4@@ -1,3 +1,4 @@
5 usr/bin/ubuntu-download-manager
6 usr/share/dbus-1/services/ubuntu-download-manager.service
7-
8+usr/share/dbus-1/system-services/com.canonical.applications.Downloader.service
9+etc/dbus-1/system.d/com.canonical.applications.Downloader.conf
10
11=== modified file 'libubuntudownloadmanager/apparmor.cpp'
12--- libubuntudownloadmanager/apparmor.cpp 2013-09-18 10:18:24 +0000
13+++ libubuntudownloadmanager/apparmor.cpp 2013-09-24 09:53:05 +0000
14@@ -19,6 +19,8 @@
15 #include <errno.h>
16 #include <nih/alloc.h>
17 #include <libnih-dbus.h>
18+#include <sys/types.h>
19+#include <unistd.h>
20 #include <QDBusConnection>
21 #include <QDebug>
22 #include <QRegExp>
23@@ -35,13 +37,21 @@
24 Q_DECLARE_PUBLIC(AppArmor)
25
26 public:
27- explicit AppArmorPrivate(AppArmor* parent)
28+ AppArmorPrivate(AppArmor* parent)
29 : q_ptr(parent) {
30 _dbus = new DBusProxy("org.freedesktop.DBus", "/",
31 QDBusConnection::sessionBus());
32 _uuidFactory = new UuidFactory();
33 }
34
35+ AppArmorPrivate(QSharedPointer<DBusConnection> connection,
36+ AppArmor* parent)
37+ : q_ptr(parent) {
38+ _dbus = new DBusProxy("org.freedesktop.DBus", "/",
39+ connection->connection());
40+ _uuidFactory = new UuidFactory();
41+ }
42+
43 QString getUuidPath(QUuid id, QString path) {
44 qDebug() << __PRETTY_FUNCTION__ << path;
45 QString idString = path + "/" + id.toString().replace(
46@@ -65,17 +75,24 @@
47 }
48
49 QString getLocalPath(const QString& appId) {
50- QStringList pathComponents;
51- if (!appId.isEmpty()) {
52- QStringList appIdInfo = appId.split("_");
53- if (appIdInfo.count() > 0)
54- pathComponents << appIdInfo[0];
55- }
56+ // if the service is running as root we will always return /tmp
57+ // as the local path root
58+ if (getuid() == 0){
59+ qDebug() << "Running as system bus using /tmp for downloads";
60+ return QString("/tmp");
61+ } else {
62+ QStringList pathComponents;
63+ if (!appId.isEmpty()) {
64+ QStringList appIdInfo = appId.split("_");
65+ if (appIdInfo.count() > 0)
66+ pathComponents << appIdInfo[0];
67+ }
68
69- pathComponents << "Downloads";
70- QString localPath = XDGBasedir::saveDataPath(pathComponents);
71- qDebug() << "Local path is" << localPath;
72- return localPath;
73+ pathComponents << "Downloads";
74+ QString localPath = XDGBasedir::saveDataPath(pathComponents);
75+ qDebug() << "Local path is" << localPath;
76+ return localPath;
77+ } // not root
78 }
79
80 void getSecurePath(const QString& connName,
81@@ -159,6 +176,12 @@
82 d_ptr(new AppArmorPrivate(this)) {
83 }
84
85+AppArmor::AppArmor(QSharedPointer<DBusConnection> connection,
86+ QObject *parent)
87+ : QObject(parent),
88+ d_ptr(new AppArmorPrivate(connection, this)) {
89+}
90+
91 void
92 AppArmor::getDBusPath(QUuid& id, QString& dbusPath) {
93 Q_D(AppArmor);
94
95=== modified file 'libubuntudownloadmanager/apparmor.h'
96--- libubuntudownloadmanager/apparmor.h 2013-09-18 10:18:24 +0000
97+++ libubuntudownloadmanager/apparmor.h 2013-09-24 09:53:05 +0000
98@@ -22,7 +22,9 @@
99 #include <QObject>
100 #include <QPair>
101 #include <QString>
102+#include <QSharedPointer>
103 #include <QUuid>
104+#include "./dbus_connection.h"
105
106 class AppArmorPrivate;
107 class AppArmor : public QObject {
108@@ -31,6 +33,7 @@
109
110 public:
111 explicit AppArmor(QObject *parent = 0);
112+ AppArmor(QSharedPointer<DBusConnection> connection, QObject *parent = 0);
113
114 virtual void getDBusPath(QUuid& id, QString& dbusPath);
115
116
117=== modified file 'libubuntudownloadmanager/dbus_connection.cpp'
118--- libubuntudownloadmanager/dbus_connection.cpp 2013-07-23 15:25:55 +0000
119+++ libubuntudownloadmanager/dbus_connection.cpp 2013-09-24 09:53:05 +0000
120@@ -26,42 +26,37 @@
121 class DBusConnectionPrivate {
122 Q_DECLARE_PUBLIC(DBusConnection)
123 public:
124- explicit DBusConnectionPrivate(DBusConnection* parent);
125-
126- bool registerService(const QString& serviceName);
127- bool registerObject(const QString& path, QObject* object,
128- QDBusConnection::RegisterOptions options = QDBusConnection::ExportAdaptors); // NOLINT(whitespace/line_length)
129+ DBusConnectionPrivate(DBusConnection* parent)
130+ : _conn(QDBusConnection::connectToBus(QDBusConnection::ActivationBus, "DBUS")),
131+ q_ptr(parent) {
132+ }
133+
134+ bool registerService(const QString& serviceName) {
135+ return _conn.registerService(serviceName);
136+ }
137+
138+ bool registerObject(const QString& path,
139+ QObject* object,
140+ QDBusConnection::RegisterOptions options =
141+ QDBusConnection::ExportAdaptors) {
142+ return _conn.registerObject(path, object, options);
143+ }
144+
145 void unregisterObject(const QString& path,
146- QDBusConnection::UnregisterMode mode = QDBusConnection::UnregisterNode);
147+ QDBusConnection::UnregisterMode mode =
148+ QDBusConnection::UnregisterNode) {
149+ return _conn.unregisterObject(path, mode);
150+ }
151+
152+ QDBusConnection connection() {
153+ return _conn;
154+ }
155
156 private:
157 QDBusConnection _conn;
158 DBusConnection* q_ptr;
159 };
160
161-DBusConnectionPrivate::DBusConnectionPrivate(DBusConnection* parent)
162- : _conn(QDBusConnection::sessionBus()),
163- q_ptr(parent) {
164-}
165-
166-bool
167-DBusConnectionPrivate::registerService(const QString& serviceName) {
168- return _conn.registerService(serviceName);
169-}
170-
171-bool
172-DBusConnectionPrivate::registerObject(const QString& path,
173- QObject* object,
174- QDBusConnection::RegisterOptions options) { // NOLINT(whitespace/line_length)
175- return _conn.registerObject(path, object, options);
176-}
177-
178-void
179-DBusConnectionPrivate::unregisterObject(const QString& path,
180- QDBusConnection::UnregisterMode mode) {
181- return _conn.unregisterObject(path, mode);
182-}
183-
184 /*
185 * PUBLIC IMPLEMENTATION
186 */
187@@ -92,3 +87,8 @@
188 d->unregisterObject(path, mode);
189 }
190
191+QDBusConnection
192+DBusConnection::connection() {
193+ Q_D(DBusConnection);
194+ return d->connection();
195+}
196
197=== modified file 'libubuntudownloadmanager/dbus_connection.h'
198--- libubuntudownloadmanager/dbus_connection.h 2013-07-23 14:03:56 +0000
199+++ libubuntudownloadmanager/dbus_connection.h 2013-09-24 09:53:05 +0000
200@@ -34,6 +34,7 @@
201 QDBusConnection::RegisterOptions options = QDBusConnection::ExportAdaptors); // NOLINT(whitespace/line_length)
202 virtual void unregisterObject(const QString& path,
203 QDBusConnection::UnregisterMode mode = QDBusConnection::UnregisterNode);
204+ virtual QDBusConnection connection();
205
206 private:
207 DBusConnectionPrivate* d_ptr;
208
209=== modified file 'libubuntudownloadmanager/download_daemon.cpp'
210--- libubuntudownloadmanager/download_daemon.cpp 2013-09-18 10:38:59 +0000
211+++ libubuntudownloadmanager/download_daemon.cpp 2013-09-24 09:53:05 +0000
212@@ -83,12 +83,14 @@
213 ret = _conn->registerObject("/", _downInterface);
214 qDebug() << ret;
215 if (!ret) {
216- qDebug() << "Could not register interface";
217+ qDebug() << "Could not register interface"
218+ << _conn->connection().lastError();
219 _app->exit(-1);
220 }
221 return;
222 }
223- qDebug() << "Could not register service";
224+ qDebug() << "Could not register service"
225+ << _conn->connection().lastError();
226 _app->exit(-1);
227 }
228
229
230=== modified file 'libubuntudownloadmanager/download_manager.cpp'
231--- libubuntudownloadmanager/download_manager.cpp 2013-09-17 10:37:08 +0000
232+++ libubuntudownloadmanager/download_manager.cpp 2013-09-24 09:53:05 +0000
233@@ -37,7 +37,7 @@
234 : _throttle(0),
235 q_ptr(parent) {
236 _conn = connection;
237- _apparmor = QSharedPointer<AppArmor>(new AppArmor());
238+ _apparmor = QSharedPointer<AppArmor>(new AppArmor(connection));
239 _networkInfo = QSharedPointer<SystemNetworkInfo>(
240 new SystemNetworkInfo());
241 QSharedPointer<RequestFactory> nam = QSharedPointer<RequestFactory>(
242
243=== modified file 'libubuntudownloadmanager/logger.cpp'
244--- libubuntudownloadmanager/logger.cpp 2013-07-26 15:24:30 +0000
245+++ libubuntudownloadmanager/logger.cpp 2013-09-24 09:53:05 +0000
246@@ -16,6 +16,8 @@
247 * Boston, MA 02110-1301, USA.
248 */
249
250+#include <unistd.h>
251+#include <sys/types.h>
252 #include <QDateTime>
253 #include <QDir>
254 #include <QStandardPaths>
255@@ -37,6 +39,22 @@
256 }
257
258 Logger::Logger(const QString filename) {
259+ // decide if we are dealing with a system bus (that should use syslog)
260+ // or a session bus
261+ _isSystemBus = getuid() == 0;
262+ if (_isSystemBus) {
263+ openSyslogConnection();
264+ } else {
265+ openLogFile(filename);
266+ }
267+
268+ qInstallMessageHandler(_realMessageHandler);
269+
270+ _initialized = true;
271+}
272+
273+void
274+Logger::openLogFile(const QString& filename) {
275 if (filename == "") {
276 _logFileName = getLogDir() + "/ubuntu-download-manager.log";
277 } else {
278@@ -48,10 +66,11 @@
279 _logStream.setDevice(&_logFile);
280 _logStream.flush();
281 }
282-
283- qInstallMessageHandler(_realMessageHandler);
284-
285- _initialized = true;
286+}
287+
288+void
289+Logger::openSyslogConnection() {
290+ // TODO(mandel): init syslog
291 }
292
293 void
294@@ -106,6 +125,17 @@
295 }
296
297 void
298+Logger::logSessionMessage(const QString &message) {
299+ _logStream << message;
300+ _logStream.flush();
301+}
302+
303+void
304+Logger::logSystemMessage(const QString &message) {
305+ Q_UNUSED(message);
306+}
307+
308+void
309 Logger::logMessage(QtMsgType type,
310 const QMessageLogContext &context,
311 const QString &message) {
312@@ -132,8 +162,11 @@
313 }
314 _stdErr.device()->close();
315
316- _logStream << logMessage;
317- _logStream.flush();
318+ if (_isSystemBus) {
319+ logSystemMessage(logMessage);
320+ } else {
321+ logSessionMessage(logMessage);
322+ }
323
324 if (type == QtFatalMsg)
325 abort();
326
327=== modified file 'libubuntudownloadmanager/logger.h'
328--- libubuntudownloadmanager/logger.h 2013-07-25 21:15:08 +0000
329+++ libubuntudownloadmanager/logger.h 2013-09-24 09:53:05 +0000
330@@ -45,6 +45,16 @@
331 static QString getLogDir();
332
333 private:
334+ void openLogFile(const QString& filename);
335+
336+ void openSyslogConnection();
337+
338+ void logSessionMessage(const QString &message);
339+
340+ void logSystemMessage(const QString &message);
341+
342+ private:
343+ bool _isSystemBus = false;
344 bool _initialized = false;
345 QString _logFileName;
346 QFile _logFile;
347
348=== modified file 'ubuntu-download-manager-tests/irl_tests.py'
349--- ubuntu-download-manager-tests/irl_tests.py 2013-09-17 09:37:52 +0000
350+++ ubuntu-download-manager-tests/irl_tests.py 2013-09-24 09:53:05 +0000
351@@ -58,7 +58,7 @@
352
353 if __name__ == '__main__':
354
355- bus = dbus.SessionBus()
356+ bus = dbus.SystemBus()
357 loop = gobject.MainLoop()
358 manager = bus.get_object('com.canonical.applications.Downloader',
359 MANAGER_PATH)
360
361=== added file 'ubuntu-download-manager/com.canonical.applications.Downloader.conf'
362--- ubuntu-download-manager/com.canonical.applications.Downloader.conf 1970-01-01 00:00:00 +0000
363+++ ubuntu-download-manager/com.canonical.applications.Downloader.conf 2013-09-24 09:53:05 +0000
364@@ -0,0 +1,18 @@
365+<?xml version="1.0" encoding="UTF-8"?>
366+
367+<!DOCTYPE busconfig PUBLIC
368+ "-//freedesktop//DTD D-BUS Bus Configuration 1.0//EN"
369+ "http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd">
370+<busconfig>
371+ <policy user="root">
372+ <allow own="com.canonical.applications.Downloader"/>
373+ <allow send_destination="com.canonical.applications.Downloader"/>
374+ </policy>
375+
376+ <policy context="default">
377+ <allow send_destination="com.canonical.applications.Downloader"/>
378+ <allow send_destination="com.canonical.applications.Downloader"
379+ send_interface="org.freedesktop.DBus.Introspectable"/>
380+ </policy>
381+
382+</busconfig>
383
384=== added file 'ubuntu-download-manager/com.canonical.applications.Downloader.service'
385--- ubuntu-download-manager/com.canonical.applications.Downloader.service 1970-01-01 00:00:00 +0000
386+++ ubuntu-download-manager/com.canonical.applications.Downloader.service 2013-09-24 09:53:05 +0000
387@@ -0,0 +1,4 @@
388+[D-BUS Service]
389+Name=com.canonical.applications.Downloader
390+User=root
391+Exec=/usr/bin/ubuntu-download-manager
392
393=== modified file 'ubuntu-download-manager/ubuntu-download-manager.pro'
394--- ubuntu-download-manager/ubuntu-download-manager.pro 2013-08-22 20:49:57 +0000
395+++ ubuntu-download-manager/ubuntu-download-manager.pro 2013-09-24 09:53:05 +0000
396@@ -18,9 +18,17 @@
397
398 SOURCES += main.cpp
399
400-dbus_activation.path = /usr/share/dbus-1/services/
401-dbus_activation.files = ubuntu-download-manager.service
402-INSTALLS += dbus_activation
403+dbus_session_activation.path = /usr/share/dbus-1/services/
404+dbus_session_activation.files = ubuntu-download-manager.service
405+INSTALLS += dbus_session_activation
406+
407+dbus_system_activation.path = /usr/share/dbus-1/system-services/
408+dbus_system_activation.files = com.canonical.applications.Downloader.service
409+INSTALLS += dbus_system_activation
410+
411+dbus_system_conf.path = /etc/dbus-1/system.d/
412+dbus_system_conf.files = com.canonical.applications.Downloader.conf
413+INSTALLS += dbus_system_conf
414
415 target.path = /usr/bin/
416 INSTALLS += target
417@@ -31,4 +39,5 @@
418 DEPENDPATH += $$PWD/../libubuntudownloadmanager
419
420 OTHER_FILES += \
421- ubuntu-download-manager.service
422+ ubuntu-download-manager.service \
423+ com.canonical.applications.Downloader.conf

Subscribers

People subscribed via source and target branches