From 309271ac176bda188ac739e7d38ea595e52b19a4 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sat, 4 May 2019 11:53:55 +0200 Subject: [PATCH] all: use nm_clear_g_dbus_connection_signal() helper I also like this because it's non-obvious that subscription IDs from GDBusConnection are "guint" (contrary to signal handler IDs which are "gulong"). So, by using this API you get a compiler error when using the wrong type. In the past, when switching to nm_clear_g_signal_handler() this uncovered multiple bugs where the wrong type was used to hold the ID. --- libnm/nm-vpn-service-plugin.c | 7 ++---- src/dns/nm-dns-systemd-resolved.c | 6 ++--- src/nm-keep-alive.c | 2 +- src/settings/nm-secret-agent.c | 38 +++++++++++++++---------------- 4 files changed, 24 insertions(+), 29 deletions(-) diff --git a/libnm/nm-vpn-service-plugin.c b/libnm/nm-vpn-service-plugin.c index 3bc49f58cc..31cda37671 100644 --- a/libnm/nm-vpn-service-plugin.c +++ b/libnm/nm-vpn-service-plugin.c @@ -1186,11 +1186,8 @@ state_changed (NMVpnServicePlugin *plugin, NMVpnServiceState state) nm_vpn_service_plugin_emit_quit (plugin); else schedule_quit_timer (plugin); - if (priv->peer_watch_id) { - g_dbus_connection_signal_unsubscribe (nm_vpn_service_plugin_get_connection (plugin), - priv->peer_watch_id); - priv->peer_watch_id = 0; - } + nm_clear_g_dbus_connection_signal (nm_vpn_service_plugin_get_connection (plugin), + &priv->peer_watch_id); break; default: /* Clean up all timers we might have set up. */ diff --git a/src/dns/nm-dns-systemd-resolved.c b/src/dns/nm-dns-systemd-resolved.c index 33387a6913..f4d742844b 100644 --- a/src/dns/nm-dns-systemd-resolved.c +++ b/src/dns/nm-dns-systemd-resolved.c @@ -555,10 +555,8 @@ dispose (GObject *object) free_pending_updates (self); - if (priv->name_owner_changed_id != 0) { - g_dbus_connection_signal_unsubscribe (priv->dbus_connection, - nm_steal_int (&priv->name_owner_changed_id)); - } + nm_clear_g_dbus_connection_signal (priv->dbus_connection, + &priv->name_owner_changed_id); nm_clear_g_cancellable (&priv->cancellable); diff --git a/src/nm-keep-alive.c b/src/nm-keep-alive.c index 4c8a480f62..1390971c93 100644 --- a/src/nm-keep-alive.c +++ b/src/nm-keep-alive.c @@ -276,7 +276,7 @@ cleanup_dbus_watch (NMKeepAlive *self) nm_clear_g_free (&priv->dbus_client); if (priv->dbus_connection) { g_dbus_connection_signal_unsubscribe (priv->dbus_connection, - priv->subscription_id); + nm_steal_int (&priv->subscription_id)); g_clear_object (&priv->dbus_connection); } } diff --git a/src/settings/nm-secret-agent.c b/src/settings/nm-secret-agent.c index 7af40b36ee..97ffbfeef3 100644 --- a/src/settings/nm-secret-agent.c +++ b/src/settings/nm-secret-agent.c @@ -55,7 +55,10 @@ typedef struct { NMDBusManager *bus_mgr; GDBusConnection *connection; CList requests; - gulong on_disconnected_id; + union { + gulong obj_signal; + guint dbus_signal; + } on_disconnected_id; bool connection_is_private:1; } NMSecretAgentPrivate; @@ -615,15 +618,12 @@ nm_secret_agent_delete_secrets (NMSecretAgent *self, static void _on_disconnected_cleanup (NMSecretAgentPrivate *priv) { - if (priv->on_disconnected_id) { - if (priv->connection_is_private) { - g_signal_handler_disconnect (priv->bus_mgr, - priv->on_disconnected_id); - } else { - g_dbus_connection_signal_unsubscribe (priv->connection, - priv->on_disconnected_id); - } - priv->on_disconnected_id = 0; + if (priv->connection_is_private) { + nm_clear_g_signal_handler (priv->bus_mgr, + &priv->on_disconnected_id.obj_signal); + } else { + nm_clear_g_dbus_connection_signal (priv->connection, + &priv->on_disconnected_id.dbus_signal); } g_clear_object (&priv->connection); @@ -745,16 +745,16 @@ nm_secret_agent_new (GDBusMethodInvocation *context, /* we cannot subscribe to notify::g-name-owner because that doesn't work * for unique names and it doesn't work for private connections. */ if (priv->connection_is_private) { - priv->on_disconnected_id = g_signal_connect (priv->bus_mgr, - NM_DBUS_MANAGER_PRIVATE_CONNECTION_DISCONNECTED, - G_CALLBACK (_on_disconnected_private_connection), - self); + priv->on_disconnected_id.obj_signal = g_signal_connect (priv->bus_mgr, + NM_DBUS_MANAGER_PRIVATE_CONNECTION_DISCONNECTED, + G_CALLBACK (_on_disconnected_private_connection), + self); } else { - priv->on_disconnected_id = nm_dbus_connection_signal_subscribe_name_owner_changed (priv->connection, - priv->dbus_owner, - _on_disconnected_name_owner_changed, - self, - NULL); + priv->on_disconnected_id.dbus_signal = nm_dbus_connection_signal_subscribe_name_owner_changed (priv->connection, + priv->dbus_owner, + _on_disconnected_name_owner_changed, + self, + NULL); } return self;