summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2018-11-17 13:29:40 +0100
committerThomas Haller <thaller@redhat.com>2018-11-17 13:29:40 +0100
commit6b79af28d66a709a8feda9dc3824ac544db0e7bb (patch)
treed04b8c50a13649e61512aeae6f82a07a517adec6
parent3baf56b4741435b6092ec2b2d9a1c2704f685b95 (diff)
downloadNetworkManager-6b79af28d66a709a8feda9dc3824ac544db0e7bb.tar.gz
keep-alive: minor cleanup of nm_keep_alive_set_dbus_client_watch()
- always issue a _notify_alive(), just to be sure. At least in case where we clear a dbus-client watch, the alive state could change. - avoid the logging in cleanup_dbus_watch(), if there is nothing to cleanup.
-rw-r--r--src/nm-keep-alive.c46
1 files changed, 26 insertions, 20 deletions
diff --git a/src/nm-keep-alive.c b/src/nm-keep-alive.c
index cfad13e6a3..71cd43415c 100644
--- a/src/nm-keep-alive.c
+++ b/src/nm-keep-alive.c
@@ -179,14 +179,17 @@ cleanup_dbus_watch (NMKeepAlive *self)
{
NMKeepAlivePrivate *priv = NM_KEEP_ALIVE_GET_PRIVATE (self);
- _LOGD ("Cleanup DBus client watch");
+ if (!priv->dbus_client)
+ return;
- g_clear_pointer (&priv->dbus_client, g_free);
+ _LOGD ("Cleanup DBus client watch");
- if (priv->dbus_connection)
+ nm_clear_g_free (&priv->dbus_client);
+ if (priv->dbus_connection) {
g_dbus_connection_signal_unsubscribe (priv->dbus_connection,
priv->subscription_id);
- g_clear_object (&priv->dbus_connection);
+ g_clear_object (&priv->dbus_connection);
+ }
}
static void
@@ -221,23 +224,26 @@ nm_keep_alive_set_dbus_client_watch (NMKeepAlive *self,
cleanup_dbus_watch (self);
- if (client_address == NULL)
- return;
+ if (client_address) {
+ _LOGD ("Registering dbus client watch for keep alive");
+
+ priv->dbus_client = g_strdup (client_address);
+ priv->dbus_connection = g_object_ref (connection);
+ priv->subscription_id = g_dbus_connection_signal_subscribe (connection,
+ "org.freedesktop.DBus",
+ "org.freedesktop.DBus",
+ "NameOwnerChanged",
+ "/org/freedesktop/DBus",
+ priv->dbus_client,
+ G_DBUS_SIGNAL_FLAGS_NONE,
+ name_owner_changed_cb,
+ self,
+ NULL);
+ /* FIXME: is there are race here and is it possible that name-owner is already gone?
+ * Do we need a GetNameOwner first? */
+ }
- _LOGD ("Registering dbus client watch for keep alive");
-
- priv->dbus_client = g_strdup (client_address);
- priv->dbus_connection = g_object_ref (connection);
- priv->subscription_id = g_dbus_connection_signal_subscribe (connection,
- "org.freedesktop.DBus",
- "org.freedesktop.DBus",
- "NameOwnerChanged",
- "/org/freedesktop/DBus",
- priv->dbus_client,
- G_DBUS_SIGNAL_FLAGS_NONE,
- name_owner_changed_cb,
- self,
- NULL);
+ _notify_alive (self);
}
/*****************************************************************************/