From 648270d46939aa7de8a87f4b2b63b92f5fb5278b Mon Sep 17 00:00:00 2001 From: Dan Williams Date: Tue, 21 Oct 2014 19:43:34 -0500 Subject: [PATCH] libnm: cancel NMRemoteSettings/NMManager property reload when NM quits If the operation isn't canceled it returns an error, printing this: /libnm/client-nm-running: (/home/dcbw/Development/fdo/NetworkManager/libnm/tests/.libs/lt-test-nm-client:17983): libnm-WARNING **: updated_properties: error reading NMRemoteSettings properties: GDBus.Error:org.freedesktop.DBus.Error.NoReply: Message did not receive a reply (timeout by message bus) /bin/sh: line 5: 17983 Trace/breakpoint trap ./libnm-test-launch.sh ${dir}$tst FAIL: test-nm-client which screws up testcases because they don't expect this message. And in this case, since libnm knows that NM is exiting and will just clear out the properties anyway, it's useless to print the message. --- libnm-core/nm-core-internal.h | 6 ++++++ libnm/nm-device.c | 1 + libnm/nm-manager.c | 12 ++++++++++-- libnm/nm-object-private.h | 1 + libnm/nm-object.c | 9 ++++++--- libnm/nm-remote-settings.c | 11 +++++++++-- 6 files changed, 33 insertions(+), 7 deletions(-) diff --git a/libnm-core/nm-core-internal.h b/libnm-core/nm-core-internal.h index 48295f7821..fced4ffe3d 100644 --- a/libnm-core/nm-core-internal.h +++ b/libnm-core/nm-core-internal.h @@ -68,6 +68,12 @@ #include "nm-version.h" #include "nm-vpn-dbus-interface.h" +#define NM_UTILS_CLEAR_CANCELLABLE(c) \ + if (c) { \ + g_cancellable_cancel (c); \ + g_clear_object (&c); \ + } + const char *_nm_setting_ip4_config_get_address_label (NMSettingIP4Config *setting, guint32 i); gboolean _nm_setting_ip4_config_add_address_with_label (NMSettingIP4Config *setting, diff --git a/libnm/nm-device.c b/libnm/nm-device.c index 5999ed23d2..5a1caf6d9f 100644 --- a/libnm/nm-device.c +++ b/libnm/nm-device.c @@ -275,6 +275,7 @@ device_state_changed (NMDBusDevice *proxy, data->new_state = new_state; data->reason = reason; _nm_object_reload_properties_async (NM_OBJECT (user_data), + NULL, device_state_change_reloaded, data); } diff --git a/libnm/nm-manager.c b/libnm/nm-manager.c index 3f6ef585c0..d60845edc9 100644 --- a/libnm/nm-manager.c +++ b/libnm/nm-manager.c @@ -53,6 +53,7 @@ G_DEFINE_TYPE_WITH_CODE (NMManager, nm_manager, NM_TYPE_OBJECT, typedef struct { NMDBusManager *manager_proxy; + GCancellable *props_cancellable; char *version; NMState state; gboolean startup; @@ -1207,7 +1208,8 @@ updated_properties (GObject *object, GAsyncResult *result, gpointer user_data) GError *error = NULL; if (!_nm_object_reload_properties_finish (NM_OBJECT (object), result, &error)) { - g_warning ("%s: error reading NMManager properties: %s", __func__, error->message); + if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) + g_warning ("%s: error reading NMManager properties: %s", __func__, error->message); g_error_free (error); } @@ -1223,6 +1225,8 @@ nm_running_changed_cb (GObject *object, NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (manager); if (!nm_manager_get_nm_running (manager)) { + NM_UTILS_CLEAR_CANCELLABLE (priv->props_cancellable); + priv->state = NM_STATE_UNKNOWN; priv->startup = FALSE; _nm_object_queue_notify (NM_OBJECT (manager), NM_MANAGER_NM_RUNNING); @@ -1246,7 +1250,11 @@ nm_running_changed_cb (GObject *object, _nm_object_cache_clear (); } else { _nm_object_suppress_property_updates (NM_OBJECT (manager), FALSE); - _nm_object_reload_properties_async (NM_OBJECT (manager), updated_properties, manager); + + NM_UTILS_CLEAR_CANCELLABLE (priv->props_cancellable); + priv->props_cancellable = g_cancellable_new (); + _nm_object_reload_properties_async (NM_OBJECT (manager), priv->props_cancellable, updated_properties, manager); + manager_recheck_permissions (priv->manager_proxy, manager); } } diff --git a/libnm/nm-object-private.h b/libnm/nm-object-private.h index 82e38f4d21..fa8b21d6c1 100644 --- a/libnm/nm-object-private.h +++ b/libnm/nm-object-private.h @@ -43,6 +43,7 @@ void _nm_object_register_properties (NMObject *object, gboolean _nm_object_reload_properties (NMObject *object, GError **error); void _nm_object_reload_properties_async (NMObject *object, + GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data); gboolean _nm_object_reload_properties_finish (NMObject *object, diff --git a/libnm/nm-object.c b/libnm/nm-object.c index f4162f8bbc..cda7729fe4 100644 --- a/libnm/nm-object.c +++ b/libnm/nm-object.c @@ -246,7 +246,7 @@ init_async_got_proxy (GObject *object, GAsyncResult *result, gpointer user_data) NM_OBJECT_GET_CLASS (self)->init_dbus (self); - _nm_object_reload_properties_async (init_data->object, init_async_got_properties, init_data); + _nm_object_reload_properties_async (init_data->object, init_data->cancellable, init_async_got_properties, init_data); } static void @@ -1550,7 +1550,10 @@ reload_got_properties (GObject *proxy, } void -_nm_object_reload_properties_async (NMObject *object, GAsyncReadyCallback callback, gpointer user_data) +_nm_object_reload_properties_async (NMObject *object, + GCancellable *cancellable, + GAsyncReadyCallback callback, + gpointer user_data) { NMObjectPrivate *priv = NM_OBJECT_GET_PRIVATE (object); GSimpleAsyncResult *simple; @@ -1583,7 +1586,7 @@ _nm_object_reload_properties_async (NMObject *object, GAsyncReadyCallback callba "GetAll", g_variant_new ("(s)", interface), G_DBUS_CALL_FLAGS_NONE, -1, - NULL, + cancellable, reload_got_properties, object); } } diff --git a/libnm/nm-remote-settings.c b/libnm/nm-remote-settings.c index a37cbe9f8b..754fbe1303 100644 --- a/libnm/nm-remote-settings.c +++ b/libnm/nm-remote-settings.c @@ -44,6 +44,7 @@ typedef struct { NMDBusSettings *proxy; GPtrArray *all_connections; GPtrArray *visible_connections; + GCancellable *props_cancellable; /* AddConnectionInfo objects that are waiting for the connection to become initialized */ GSList *add_list; @@ -604,7 +605,8 @@ updated_properties (GObject *object, GAsyncResult *result, gpointer user_data) GError *error = NULL; if (!_nm_object_reload_properties_finish (NM_OBJECT (object), result, &error)) { - g_warning ("%s: error reading NMRemoteSettings properties: %s", __func__, error->message); + if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) + g_warning ("%s: error reading NMRemoteSettings properties: %s", __func__, error->message); g_error_free (error); } } @@ -623,6 +625,8 @@ nm_running_changed (GObject *object, GPtrArray *connections; int i; + NM_UTILS_CLEAR_CANCELLABLE (priv->props_cancellable); + /* Clear connections */ connections = priv->all_connections; priv->all_connections = g_ptr_array_new (); @@ -645,7 +649,10 @@ nm_running_changed (GObject *object, _nm_object_suppress_property_updates (NM_OBJECT (self), TRUE); } else { _nm_object_suppress_property_updates (NM_OBJECT (self), FALSE); - _nm_object_reload_properties_async (NM_OBJECT (self), updated_properties, self); + + NM_UTILS_CLEAR_CANCELLABLE (priv->props_cancellable); + priv->props_cancellable = g_cancellable_new (); + _nm_object_reload_properties_async (NM_OBJECT (self), priv->props_cancellable, updated_properties, self); } g_object_thaw_notify (object);