all: use nm_dbus_connection_signal_subscribe_name_owner_changed()

... and nm_dbus_connection_call_get_name_owner().
This commit is contained in:
Thomas Haller 2019-05-04 11:30:29 +02:00
parent 8ffa75685e
commit b9e2fcccf7
4 changed files with 50 additions and 93 deletions

View file

@ -27,6 +27,7 @@
#include <stdlib.h>
#include "nm-glib-aux/nm-secret-utils.h"
#include "nm-glib-aux/nm-dbus-aux.h"
#include "nm-enum-types.h"
#include "nm-utils.h"
#include "nm-connection.h"
@ -499,16 +500,11 @@ watch_peer (NMVpnServicePlugin *plugin,
GDBusConnection *connection = g_dbus_method_invocation_get_connection (context);
const char *peer = g_dbus_message_get_sender (g_dbus_method_invocation_get_message (context));
return g_dbus_connection_signal_subscribe (connection,
"org.freedesktop.DBus",
"org.freedesktop.DBus",
"NameOwnerChanged",
"/org/freedesktop/DBus",
peer,
G_DBUS_SIGNAL_FLAGS_NONE,
peer_vanished,
plugin,
NULL);
return nm_dbus_connection_signal_subscribe_name_owner_changed (connection,
peer,
peer_vanished,
plugin,
NULL);
}
static void

View file

@ -32,6 +32,7 @@
#include <linux/if.h>
#include "nm-glib-aux/nm-c-list.h"
#include "nm-glib-aux/nm-dbus-aux.h"
#include "nm-core-internal.h"
#include "platform/nm-platform.h"
#include "nm-utils.h"
@ -474,24 +475,17 @@ name_owner_changed_cb (GDBusConnection *connection,
}
static void
get_name_owner_cb (GObject *source,
GAsyncResult *res,
get_name_owner_cb (const char *name_owner,
GError *error,
gpointer user_data)
{
NMDnsSystemdResolved *self;
NMDnsSystemdResolvedPrivate *priv;
gs_unref_variant GVariant *ret = NULL;
gs_free_error GError *error = NULL;
const char *owner = NULL;
ret = g_dbus_connection_call_finish (G_DBUS_CONNECTION (source), res, &error);
if ( !ret
if ( !name_owner
&& g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
return;
if (ret)
g_variant_get (ret, "(&s)", &owner);
self = user_data;
priv = NM_DNS_SYSTEMD_RESOLVED_GET_PRIVATE (self);
@ -499,7 +493,7 @@ get_name_owner_cb (GObject *source,
priv->dbus_initied = TRUE;
name_owner_changed (self, owner);
name_owner_changed (self, name_owner);
}
/*****************************************************************************/
@ -533,29 +527,18 @@ nm_dns_systemd_resolved_init (NMDnsSystemdResolved *self)
return;
}
priv->name_owner_changed_id = g_dbus_connection_signal_subscribe (priv->dbus_connection,
DBUS_SERVICE_DBUS,
DBUS_INTERFACE_DBUS,
"NameOwnerChanged",
DBUS_PATH_DBUS,
SYSTEMD_RESOLVED_DBUS_SERVICE,
G_DBUS_SIGNAL_FLAGS_NONE,
name_owner_changed_cb,
self,
NULL);
priv->name_owner_changed_id = nm_dbus_connection_signal_subscribe_name_owner_changed (priv->dbus_connection,
SYSTEMD_RESOLVED_DBUS_SERVICE,
name_owner_changed_cb,
self,
NULL);
priv->cancellable = g_cancellable_new ();
g_dbus_connection_call (priv->dbus_connection,
DBUS_SERVICE_DBUS,
DBUS_PATH_DBUS,
DBUS_INTERFACE_DBUS,
"GetNameOwner",
g_variant_new ("(s)", SYSTEMD_RESOLVED_DBUS_SERVICE),
G_VARIANT_TYPE ("(s)"),
G_DBUS_CALL_FLAGS_NONE,
-1,
priv->cancellable,
get_name_owner_cb,
self);
nm_dbus_connection_call_get_name_owner (priv->dbus_connection,
SYSTEMD_RESOLVED_DBUS_SERVICE,
-1,
priv->cancellable,
get_name_owner_cb,
self);
}
NMDnsPlugin *

View file

@ -24,6 +24,7 @@
#include "nm-keep-alive.h"
#include "settings/nm-settings-connection.h"
#include "nm-glib-aux/nm-dbus-aux.h"
/*****************************************************************************/
@ -211,32 +212,24 @@ nm_keep_alive_set_settings_connection_watch_visible (NMKeepAlive *self,
/*****************************************************************************/
static void
get_name_owner_cb (GObject *source_object,
GAsyncResult *res,
get_name_owner_cb (const char *name_owner,
GError *error,
gpointer user_data)
{
NMKeepAlive *self = user_data;
NMKeepAlive *self;
NMKeepAlivePrivate *priv;
gs_free_error GError *error = NULL;
gs_unref_variant GVariant *result = NULL;
const char *name_owner;
result = g_dbus_connection_call_finish ((GDBusConnection *) source_object,
res,
&error);
if ( !result
if ( !name_owner
&& g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
return;
if (result) {
g_variant_get (result, "(&s)", &name_owner);
self = user_data;
priv = NM_KEEP_ALIVE_GET_PRIVATE (self);
priv = NM_KEEP_ALIVE_GET_PRIVATE (self);
if (nm_streq (name_owner, priv->dbus_client)) {
/* all good, the name is confirmed. */
return;
}
if ( name_owner
&& nm_streq (name_owner, priv->dbus_client)) {
/* all good, the name is confirmed. */
return;
}
_LOGD ("DBus client for keep alive is not on the bus");
@ -259,18 +252,12 @@ _is_alive_dbus_client (NMKeepAlive *self)
priv->dbus_client_confirmed = TRUE;
priv->dbus_client_confirm_cancellable = g_cancellable_new ();
g_dbus_connection_call (priv->dbus_connection,
"org.freedesktop.DBus",
"/org/freedesktop/DBus",
"org.freedesktop.DBus",
"GetNameOwner",
g_variant_new ("(s)", priv->dbus_client),
G_VARIANT_TYPE ("(s)"),
G_DBUS_CALL_FLAGS_NONE,
-1,
priv->dbus_client_confirm_cancellable,
get_name_owner_cb,
self);
nm_dbus_connection_call_get_name_owner (priv->dbus_connection,
priv->dbus_client,
-1,
priv->dbus_client_confirm_cancellable,
get_name_owner_cb,
self);
}
return TRUE;
}
@ -336,16 +323,11 @@ nm_keep_alive_set_dbus_client_watch (NMKeepAlive *self,
priv->dbus_client_watching = TRUE;
priv->dbus_client_confirmed = FALSE;
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);
priv->subscription_id = nm_dbus_connection_signal_subscribe_name_owner_changed (priv->dbus_connection,
priv->dbus_client,
name_owner_changed_cb,
self,
NULL);
} else
priv->dbus_client_watching = FALSE;

View file

@ -25,6 +25,7 @@
#include <sys/types.h>
#include <pwd.h>
#include "nm-glib-aux/nm-dbus-aux.h"
#include "nm-dbus-interface.h"
#include "nm-dbus-manager.h"
#include "nm-core-internal.h"
@ -749,16 +750,11 @@ nm_secret_agent_new (GDBusMethodInvocation *context,
G_CALLBACK (_on_disconnected_private_connection),
self);
} else {
priv->on_disconnected_id = g_dbus_connection_signal_subscribe (priv->connection,
"org.freedesktop.DBus", /* name */
"org.freedesktop.DBus", /* interface */
"NameOwnerChanged", /* signal name */
"/org/freedesktop/DBus", /* path */
priv->dbus_owner, /* arg0 */
G_DBUS_SIGNAL_FLAGS_NONE,
_on_disconnected_name_owner_changed,
self,
NULL);
priv->on_disconnected_id = nm_dbus_connection_signal_subscribe_name_owner_changed (priv->connection,
priv->dbus_owner,
_on_disconnected_name_owner_changed,
self,
NULL);
}
return self;