on xenial help sign in
Don't keep a long-lived connection open to upstart when we only use it for
89bbd72Steve Langasek
plugins/Unity/Indicators/indicatorsmanager.cpp+20−24
@@ -47,34 +47,13 @@ public:
47IndicatorsManager::IndicatorsManager(QObject* parent)
47IndicatorsManager::IndicatorsManager(QObject* parent)
48 : QObject(parent)
48 : QObject(parent)
49 , m_loaded(false)
49 , m_loaded(false)
50− , m_upstart(NULL)
51{
50{
52− auto upstartsession = qgetenv("UPSTART_SESSION");
53− if (!upstartsession.isNull()) {
54− DBusConnection * conn = NULL;
55− conn = dbus_connection_open(upstartsession.constData(), NULL);
56− if (conn != NULL) {
57− m_upstart = nih_dbus_proxy_new(NULL, conn,
58− NULL,
59− DBUS_PATH_UPSTART,
60− NULL, NULL);
61− dbus_connection_unref(conn);
62− }
63− }
64−
65− if (m_upstart != NULL) {
66− m_upstart->auto_start = FALSE;
67− }
68}
51}
69
52
70IndicatorsManager::~IndicatorsManager()
53IndicatorsManager::~IndicatorsManager()
71{
54{
72 unload();
55 unload();
73
56
74− if (m_upstart != NULL) {
75− nih_unref(m_upstart, NULL);
76− m_upstart = NULL;
77− }
78}
57}
79
58
80void IndicatorsManager::load()
59void IndicatorsManager::load()
@@ -235,17 +214,34 @@ void IndicatorsManager::setLoaded(bool loaded)
235 m_loaded = loaded;
214 m_loaded = loaded;
236 Q_EMIT loadedChanged(m_loaded);
215 Q_EMIT loadedChanged(m_loaded);
237
216
238− if (m_upstart != NULL) {
217+ auto upstartsession = qgetenv("UPSTART_SESSION");
218+ NihDBusProxy * upstart = NULL;
219+
220+ if (!upstartsession.isNull()) {
221+ DBusConnection * conn = NULL;
222+ conn = dbus_connection_open(upstartsession.constData(), NULL);
223+ if (conn != NULL) {
224+ upstart = nih_dbus_proxy_new(NULL, conn,
225+ NULL,
226+ DBUS_PATH_UPSTART,
227+ NULL, NULL);
228+ dbus_connection_unref(conn);
229+ }
230+ }
231+
232+ if (upstart != NULL) {
239 int event_sent = 0;
233 int event_sent = 0;
240 if (m_loaded) {
234 if (m_loaded) {
241− event_sent = upstart_emit_event_sync(NULL, m_upstart, "indicator-services-start", NULL, 0);
235+ event_sent = upstart_emit_event_sync(NULL, upstart, "indicator-services-start", NULL, 0);
242 } else {
236 } else {
243− event_sent = upstart_emit_event_sync(NULL, m_upstart, "indicator-services-end", NULL, 0);
237+ event_sent = upstart_emit_event_sync(NULL, upstart, "indicator-services-end", NULL, 0);
244 }
238 }
245
239
246 if (event_sent != 0) {
240 if (event_sent != 0) {
247 qWarning() << "Unable to send indicator event to Upstart";
241 qWarning() << "Unable to send indicator event to Upstart";
248 }
242 }
243+ nih_unref(upstart, NULL);
244+ upstart = NULL;
249 }
245 }
250 }
246 }
251}
247}
plugins/Unity/Indicators/indicatorsmanager.h−1
@@ -71,7 +71,6 @@ private:
71 QHash<QString, IndicatorData*> m_indicatorsData;
71 QHash<QString, IndicatorData*> m_indicatorsData;
72 QSharedPointer<QFileSystemWatcher> m_fsWatcher;
72 QSharedPointer<QFileSystemWatcher> m_fsWatcher;
73 bool m_loaded;
73 bool m_loaded;
74− NihDBusProxy * m_upstart;
75};
74};
76
75
77#endif // INDICATORS_MANAGER_H
76#endif // INDICATORS_MANAGER_H