mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-01-18 02:50:30 +01:00
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.
This commit is contained in:
parent
f7fff62067
commit
309271ac17
4 changed files with 24 additions and 29 deletions
|
|
@ -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. */
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue