diff options
author | Thomas Haller <thaller@redhat.com> | 2016-04-25 13:00:37 +0200 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2016-04-25 13:43:06 +0200 |
commit | 3fa3dba1b1b4a284dbb3e410fd947a4067bccdc7 (patch) | |
tree | 71b8b982a109207b25b49cef46a8f6a786a7ab38 | |
parent | 2919b9271d70dd8a21aec326c422088229cdf57b (diff) | |
download | NetworkManager-3fa3dba1b1b4a284dbb3e410fd947a4067bccdc7.tar.gz |
sleep-monitor: handle early destruction of NMSleepMonitor instance
When destroing the sleep monitor before the D-Bus proxy is created,
we must cancel creation of the proxy.
-rw-r--r-- | src/nm-sleep-monitor-systemd.c | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/src/nm-sleep-monitor-systemd.c b/src/nm-sleep-monitor-systemd.c index 25507a0287..978b459bc3 100644 --- a/src/nm-sleep-monitor-systemd.c +++ b/src/nm-sleep-monitor-systemd.c @@ -55,6 +55,7 @@ struct _NMSleepMonitor { GObject parent_instance; GDBusProxy *sd_proxy; + GCancellable *cancellable; gint inhibit_fd; }; @@ -205,13 +206,17 @@ on_proxy_acquired (GObject *object, { GError *error = NULL; char *owner; + GDBusProxy *sd_proxy; - self->sd_proxy = g_dbus_proxy_new_for_bus_finish (res, &error); - if (!self->sd_proxy) { - _LOGW ("Failed to acquire logind proxy: %s", error->message); + sd_proxy = g_dbus_proxy_new_for_bus_finish (res, &error); + if (!sd_proxy) { + if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) + _LOGW ("Failed to acquire logind proxy: %s", error->message); g_clear_error (&error); return; } + self->sd_proxy = sd_proxy; + g_clear_object (&self->cancellable); g_signal_connect (self->sd_proxy, "notify::g-name-owner", G_CALLBACK (name_owner_cb), self); _nm_dbus_signal_connect (self->sd_proxy, "PrepareForSleep", G_VARIANT_TYPE ("(b)"), @@ -227,12 +232,13 @@ static void nm_sleep_monitor_init (NMSleepMonitor *self) { self->inhibit_fd = -1; + self->cancellable = g_cancellable_new (); g_dbus_proxy_new_for_bus (G_BUS_TYPE_SYSTEM, G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START | G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES, NULL, SUSPEND_DBUS_NAME, SUSPEND_DBUS_PATH, SUSPEND_DBUS_INTERFACE, - NULL, + self->cancellable, (GAsyncReadyCallback) on_proxy_acquired, self); } @@ -243,6 +249,8 @@ dispose (GObject *object) drop_inhibitor (self); + nm_clear_g_cancellable (&self->cancellable); + g_clear_object (&self->sd_proxy); G_OBJECT_CLASS (nm_sleep_monitor_parent_class)->dispose (object); |