Merge lp:~ted/libertine/qtdbus-connection into lp:libertine/trunk

Proposed by Ted Gould
Status: Rejected
Rejected by: Christopher Townsend
Proposed branch: lp:~ted/libertine/qtdbus-connection
Merge into: lp:libertine/trunk
Diff against target: 163 lines (+45/-34)
3 files modified
liblibertine/libertined.cpp (+31/-15)
python/libertine/ContainersConfig.py (+13/-14)
tools/libertine-container-manager (+1/-5)
To merge this branch: bzr merge lp:~ted/libertine/qtdbus-connection
Reviewer Review Type Date Requested Status
Christopher Townsend Disapprove
Review via email: mp+317237@code.launchpad.net

Commit message

Ensure we don't leak references to the DBus session bus.

To post a comment you must log in.
Revision history for this message
Christopher Townsend (townsend) wrote :

This was branched from lp:libertine instead of lp:libertine/trunk and we needed a fixed branch quickly, so I made https://code.launchpad.net/~townsend/libertine/qtdbus-connection/+merge/317244 to remedy that.

No need for this MP anymore.

review: Disapprove

Unmerged revisions

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'liblibertine/libertined.cpp'
2--- liblibertine/libertined.cpp 2017-01-24 16:03:25 +0000
3+++ liblibertine/libertined.cpp 2017-02-14 17:15:01 +0000
4@@ -30,6 +30,22 @@
5 static const auto SERVICE_INTERFACE = "com.canonical.libertine.Service";
6 static const auto PROGRESS_INTERFACE = "com.canonical.libertine.Service.Progress";
7
8+/* Class to handle making sure the session bus isn't a singleton
9+ which is how QtDBus does it by default. This is a bad thing for
10+ a library to do, so we'll make sure we aren't causing global leaks */
11+class SessionBus {
12+public:
13+ QDBusConnection bus;
14+ SessionBus() :
15+ /* NOTE: Must get the envvar each time or Qt caches that too */
16+ bus{QDBusConnection::connectToBus(getenv("DBUS_SESSION_BUS_ADDRESS"), "libertined")}
17+ {
18+ }
19+ ~SessionBus() {
20+ QDBusConnection::disconnectFromBus("libertined");
21+ }
22+};
23+
24 static QVariantList
25 dbusCall(QDBusConnection const& bus, QString const& iface, QString const& path,
26 QString const& method, QVariantList const& args = QVariantList())
27@@ -119,65 +135,65 @@
28 QString
29 container_info(char const* container_id, QString const& key)
30 {
31- auto bus = QDBusConnection::sessionBus();
32- auto path = call(bus, "container_info", QVariantList{QVariant(container_id)});
33+ SessionBus session;
34+ auto path = call(session.bus, "container_info", QVariantList{QVariant(container_id)});
35
36- if (!waitForFinish(bus, path))
37+ if (!waitForFinish(session.bus, path))
38 {
39 return QString();
40 }
41
42- auto error = lastError(bus, path);
43+ auto error = lastError(session.bus, path);
44 if (!error.isEmpty())
45 {
46 qWarning() << "error:" << error;
47 return QString();
48 }
49
50- return QJsonDocument::fromJson(result(bus, path).toLatin1()).object().value(key).toString();
51+ return QJsonDocument::fromJson(result(session.bus, path).toLatin1()).object().value(key).toString();
52 }
53 }
54
55 QJsonArray
56 libertined_list()
57 {
58- auto bus = QDBusConnection::sessionBus();
59- auto path = call(bus, "list", QVariantList());
60+ SessionBus session;
61+ auto path = call(session.bus, "list", QVariantList());
62
63- if (!waitForFinish(bus, path))
64+ if (!waitForFinish(session.bus, path))
65 {
66 return QJsonArray();
67 }
68
69- auto error = lastError(bus, path);
70+ auto error = lastError(session.bus, path);
71 if (!error.isEmpty())
72 {
73 qWarning() << "error:" << error;
74 return QJsonArray();
75 }
76
77- return QJsonDocument::fromJson(result(bus, path).toLatin1()).array();
78+ return QJsonDocument::fromJson(result(session.bus, path).toLatin1()).array();
79 }
80
81 QJsonArray
82 libertined_list_app_ids(char const* container_id)
83 {
84- auto bus = QDBusConnection::sessionBus();
85- auto path = call(bus, "list_app_ids", QVariantList{QVariant(container_id)});
86+ SessionBus session;
87+ auto path = call(session.bus, "list_app_ids", QVariantList{QVariant(container_id)});
88
89- if (!waitForFinish(bus, path))
90+ if (!waitForFinish(session.bus, path))
91 {
92 return QJsonArray();
93 }
94
95- auto error = lastError(bus, path);
96+ auto error = lastError(session.bus, path);
97 if (!error.isEmpty())
98 {
99 qWarning() << "error:" << error;
100 return QJsonArray();
101 }
102
103- return QJsonDocument::fromJson(result(bus, path).toLatin1()).array();
104+ return QJsonDocument::fromJson(result(session.bus, path).toLatin1()).array();
105 }
106
107 QString
108
109=== modified file 'python/libertine/ContainersConfig.py'
110--- python/libertine/ContainersConfig.py 2017-01-25 18:48:36 +0000
111+++ python/libertine/ContainersConfig.py 2017-02-14 17:15:01 +0000
112@@ -102,21 +102,20 @@
113 if not container:
114 return
115
116- if (type(value) is str or
117- type(value) is bool):
118- container[key] = value
119- elif type(value) is dict:
120- if key not in container:
121- container[key] = [value]
122- else:
123- container[key].append(value)
124- elif type(value) is list:
125- if key not in container:
126- container[key] = value
127- else:
128- container[key] = container[key] + value
129+ if type(value) is dict:
130+ if key not in container:
131+ newvalue = [value]
132+ else:
133+ newvalue = container[key].copy()
134+ newvalue.append(value)
135+ elif type(value) is list and key in container:
136+ newvalue = container[key] + value
137+ else:
138+ newvalue = value
139
140- write_container_config_file(self.container_list)
141+ if container.get(key, None) != newvalue:
142+ container[key] = newvalue
143+ write_container_config_file(self.container_list)
144
145 def _set_array_object_value_by_key(self, container_id, array_key, object_key, matcher, key, value):
146 container = self._get_container_entry(container_id)
147
148=== modified file 'tools/libertine-container-manager'
149--- tools/libertine-container-manager 2017-02-07 12:35:48 +0000
150+++ tools/libertine-container-manager 2017-02-14 17:15:01 +0000
151@@ -345,11 +345,7 @@
152 libertine.utils.get_logger().error("Configuring freeze is only valid on LXC and LXD container types.")
153 sys.exit(1)
154
155- current_freeze = self.containers_config.get_freeze_on_stop(container_id)
156- config_freeze = args.freeze == 'enable'
157-
158- if current_freeze != config_freeze:
159- self.containers_config.update_freeze_on_stop(container_id, config_freeze)
160+ self.containers_config.update_freeze_on_stop(container_id, args.freeze == 'enable')
161
162 else:
163 libertine.utils.get_logger().error("Configure called with no subcommand. See configure --help for usage.")

Subscribers

People subscribed via source and target branches