on xenial help sign in
Don't keep a long-lived connection open to upstart when we only use it for

two events, one at load time and one at unload time.

commit0b96624bc0a5d577b7bba5d912145e81883ad26b authorSteve Langasek <steve.langasek@canonical.com> dateThu 10 Oct 2013, 10:11 (13 years ago) parenta7b1d56
2 files changed+20−25
plugins/Unity/Indicators/indicatorsmanager.cpp+20−24 plugins/Unity/Indicators/indicatorsmanager.h−1
plugins/Unity/Indicators/indicatorsmanager.cpp+20−24
@@ -47,34 +47,13 @@ public:
4747IndicatorsManager::IndicatorsManager(QObject* parent)
4848 : QObject(parent)
4949 , m_loaded(false)
50− , m_upstart(NULL)
5150{
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− }
6851}
6952
7053IndicatorsManager::~IndicatorsManager()
7154{
7255 unload();
7356
74− if (m_upstart != NULL) {
75− nih_unref(m_upstart, NULL);
76− m_upstart = NULL;
77− }
7857}
7958
8059void IndicatorsManager::load()
@@ -235,17 +214,34 @@ void IndicatorsManager::setLoaded(bool loaded)
235214 m_loaded = loaded;
236215 Q_EMIT loadedChanged(m_loaded);
237216
238− if (m_upstart != NULL) {
217+ auto upstartsession = qgetenv("UPSTART_SESSION");
218+ NihDBusProxy * upstart;
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) {
239233 int event_sent = 0;
240234 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);
242236 } 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);
244238 }
245239
246240 if (event_sent != 0) {
247241 qWarning() << "Unable to send indicator event to Upstart";
248242 }
243+ nih_unref(upstart, NULL);
244+ upstart = NULL;
249245 }
250246 }
251247}
plugins/Unity/Indicators/indicatorsmanager.h−1
@@ -71,7 +71,6 @@ private:
7171 QHash<QString, IndicatorData*> m_indicatorsData;
7272 QSharedPointer<QFileSystemWatcher> m_fsWatcher;
7373 bool m_loaded;
74− NihDBusProxy * m_upstart;
7574};
7675
7776#endif // INDICATORS_MANAGER_H