mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2025-12-21 16:50:09 +01:00
settings: clean up connection visibility and session change handling
This commit is contained in:
parent
edbf4a3ca2
commit
b51cef3cba
5 changed files with 37 additions and 78 deletions
|
|
@ -369,7 +369,7 @@ nm_session_monitor_class_init (NMSessionMonitorClass *klass)
|
||||||
*
|
*
|
||||||
* Emitted when something changes.
|
* Emitted when something changes.
|
||||||
*/
|
*/
|
||||||
signals[CHANGED] = g_signal_new ("changed",
|
signals[CHANGED] = g_signal_new (NM_SESSION_MONITOR_CHANGED,
|
||||||
NM_TYPE_SESSION_MONITOR,
|
NM_TYPE_SESSION_MONITOR,
|
||||||
G_SIGNAL_RUN_LAST,
|
G_SIGNAL_RUN_LAST,
|
||||||
G_STRUCT_OFFSET (NMSessionMonitorClass, changed),
|
G_STRUCT_OFFSET (NMSessionMonitorClass, changed),
|
||||||
|
|
|
||||||
|
|
@ -32,6 +32,8 @@ G_BEGIN_DECLS
|
||||||
#define NM_IS_SESSION_MONITOR(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), NM_TYPE_SESSION_MONITOR))
|
#define NM_IS_SESSION_MONITOR(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), NM_TYPE_SESSION_MONITOR))
|
||||||
#define NM_IS_SESSION_MONITOR_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), NM_TYPE_SESSION_MONITOR))
|
#define NM_IS_SESSION_MONITOR_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), NM_TYPE_SESSION_MONITOR))
|
||||||
|
|
||||||
|
#define NM_SESSION_MONITOR_CHANGED "changed"
|
||||||
|
|
||||||
typedef struct _NMSessionMonitor NMSessionMonitor;
|
typedef struct _NMSessionMonitor NMSessionMonitor;
|
||||||
typedef struct _NMSessionMonitorClass NMSessionMonitorClass;
|
typedef struct _NMSessionMonitorClass NMSessionMonitorClass;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -76,7 +76,9 @@ typedef struct {
|
||||||
GSList *pending_auths; /* List of PendingAuth structs*/
|
GSList *pending_auths; /* List of PendingAuth structs*/
|
||||||
NMConnection *secrets;
|
NMConnection *secrets;
|
||||||
gboolean visible; /* Is this connection is visible by some session? */
|
gboolean visible; /* Is this connection is visible by some session? */
|
||||||
|
|
||||||
NMSessionMonitor *session_monitor;
|
NMSessionMonitor *session_monitor;
|
||||||
|
guint session_changed_id;
|
||||||
} NMSysconfigConnectionPrivate;
|
} NMSysconfigConnectionPrivate;
|
||||||
|
|
||||||
/**************************************************************/
|
/**************************************************************/
|
||||||
|
|
@ -236,6 +238,12 @@ nm_sysconfig_connection_recheck_visibility (NMSysconfigConnection *self)
|
||||||
set_visible (self, FALSE);
|
set_visible (self, FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
session_changed_cb (NMSessionMonitor *self, gpointer user_data)
|
||||||
|
{
|
||||||
|
nm_sysconfig_connection_recheck_visibility (NM_SYSCONFIG_CONNECTION (user_data));
|
||||||
|
}
|
||||||
|
|
||||||
/**************************************************************/
|
/**************************************************************/
|
||||||
|
|
||||||
/* Update the settings of this connection to match that of 'new', taking care to
|
/* Update the settings of this connection to match that of 'new', taking care to
|
||||||
|
|
@ -957,6 +965,10 @@ nm_sysconfig_connection_init (NMSysconfigConnection *self)
|
||||||
priv->visible = FALSE;
|
priv->visible = FALSE;
|
||||||
|
|
||||||
priv->session_monitor = nm_session_monitor_get ();
|
priv->session_monitor = nm_session_monitor_get ();
|
||||||
|
priv->session_changed_id = g_signal_connect (priv->session_monitor,
|
||||||
|
NM_SESSION_MONITOR_CHANGED,
|
||||||
|
G_CALLBACK (session_changed_cb),
|
||||||
|
self);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|
|
||||||
|
|
@ -36,7 +36,6 @@ G_BEGIN_DECLS
|
||||||
|
|
||||||
#define NM_SYSCONFIG_CONNECTION_UPDATED "updated"
|
#define NM_SYSCONFIG_CONNECTION_UPDATED "updated"
|
||||||
#define NM_SYSCONFIG_CONNECTION_REMOVED "removed"
|
#define NM_SYSCONFIG_CONNECTION_REMOVED "removed"
|
||||||
#define NM_SYSCONFIG_CONNECTION_PURGED "purged"
|
|
||||||
#define NM_SYSCONFIG_CONNECTION_VISIBLE "visible"
|
#define NM_SYSCONFIG_CONNECTION_VISIBLE "visible"
|
||||||
|
|
||||||
typedef struct _NMSysconfigConnection NMSysconfigConnection;
|
typedef struct _NMSysconfigConnection NMSysconfigConnection;
|
||||||
|
|
|
||||||
|
|
@ -102,9 +102,6 @@ typedef struct {
|
||||||
DBusGConnection *bus;
|
DBusGConnection *bus;
|
||||||
gboolean exported;
|
gboolean exported;
|
||||||
|
|
||||||
NMSessionMonitor *session_monitor;
|
|
||||||
guint session_monitor_id;
|
|
||||||
|
|
||||||
PolkitAuthority *authority;
|
PolkitAuthority *authority;
|
||||||
guint auth_changed_id;
|
guint auth_changed_id;
|
||||||
char *config_file;
|
char *config_file;
|
||||||
|
|
@ -113,8 +110,7 @@ typedef struct {
|
||||||
|
|
||||||
GSList *plugins;
|
GSList *plugins;
|
||||||
gboolean connections_loaded;
|
gboolean connections_loaded;
|
||||||
GHashTable *visible_connections;
|
GHashTable *connections;
|
||||||
GHashTable *all_connections;
|
|
||||||
GSList *unmanaged_specs;
|
GSList *unmanaged_specs;
|
||||||
} NMSysconfigSettingsPrivate;
|
} NMSysconfigSettingsPrivate;
|
||||||
|
|
||||||
|
|
@ -189,7 +185,7 @@ nm_sysconfig_settings_for_each_connection (NMSysconfigSettings *self,
|
||||||
|
|
||||||
load_connections (self);
|
load_connections (self);
|
||||||
|
|
||||||
g_hash_table_iter_init (&iter, priv->visible_connections);
|
g_hash_table_iter_init (&iter, priv->connections);
|
||||||
while (g_hash_table_iter_next (&iter, &key, NULL))
|
while (g_hash_table_iter_next (&iter, &key, NULL))
|
||||||
for_each_func (self, NM_SYSCONFIG_CONNECTION (key), user_data);
|
for_each_func (self, NM_SYSCONFIG_CONNECTION (key), user_data);
|
||||||
}
|
}
|
||||||
|
|
@ -205,8 +201,8 @@ impl_settings_list_connections (NMSysconfigSettings *self,
|
||||||
|
|
||||||
load_connections (self);
|
load_connections (self);
|
||||||
|
|
||||||
*connections = g_ptr_array_sized_new (g_hash_table_size (priv->visible_connections) + 1);
|
*connections = g_ptr_array_sized_new (g_hash_table_size (priv->connections) + 1);
|
||||||
g_hash_table_iter_init (&iter, priv->visible_connections);
|
g_hash_table_iter_init (&iter, priv->connections);
|
||||||
while (g_hash_table_iter_next (&iter, &key, NULL))
|
while (g_hash_table_iter_next (&iter, &key, NULL))
|
||||||
g_ptr_array_add (*connections, g_strdup (nm_connection_get_path (NM_CONNECTION (key))));
|
g_ptr_array_add (*connections, g_strdup (nm_connection_get_path (NM_CONNECTION (key))));
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
|
@ -227,7 +223,7 @@ nm_sysconfig_settings_get_connection_by_path (NMSysconfigSettings *self, const c
|
||||||
|
|
||||||
load_connections (self);
|
load_connections (self);
|
||||||
|
|
||||||
g_hash_table_iter_init (&iter, priv->visible_connections);
|
g_hash_table_iter_init (&iter, priv->connections);
|
||||||
while (g_hash_table_iter_next (&iter, &key, NULL)) {
|
while (g_hash_table_iter_next (&iter, &key, NULL)) {
|
||||||
if (!strcmp (nm_connection_get_path (NM_CONNECTION (key)), path))
|
if (!strcmp (nm_connection_get_path (NM_CONNECTION (key)), path))
|
||||||
return NM_SYSCONFIG_CONNECTION (key);
|
return NM_SYSCONFIG_CONNECTION (key);
|
||||||
|
|
@ -535,36 +531,11 @@ load_plugins (NMSysconfigSettings *self, const char *plugins, GError **error)
|
||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
|
||||||
session_monitor_changed_cb (NMSessionMonitor *monitor, gpointer user_data)
|
|
||||||
{
|
|
||||||
NMSysconfigSettings *self = NM_SYSCONFIG_SETTINGS (user_data);
|
|
||||||
NMSysconfigSettingsPrivate *priv = NM_SYSCONFIG_SETTINGS_GET_PRIVATE (self);
|
|
||||||
GHashTableIter iter;
|
|
||||||
gpointer data;
|
|
||||||
|
|
||||||
/* Update visibility on all connections */
|
|
||||||
g_hash_table_iter_init (&iter, priv->all_connections);
|
|
||||||
while (g_hash_table_iter_next (&iter, NULL, &data)) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
connection_removed (NMSysconfigConnection *connection,
|
connection_removed (NMSysconfigConnection *connection,
|
||||||
gpointer user_data)
|
gpointer user_data)
|
||||||
{
|
{
|
||||||
NMSysconfigSettingsPrivate *priv = NM_SYSCONFIG_SETTINGS_GET_PRIVATE (user_data);
|
g_hash_table_remove (NM_SYSCONFIG_SETTINGS_GET_PRIVATE (user_data)->connections, connection);
|
||||||
|
|
||||||
g_hash_table_remove (priv->visible_connections, connection);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
connection_purged (NMSysconfigConnection *connection,
|
|
||||||
gpointer user_data)
|
|
||||||
{
|
|
||||||
NMSysconfigSettingsPrivate *priv = NM_SYSCONFIG_SETTINGS_GET_PRIVATE (user_data);
|
|
||||||
|
|
||||||
g_hash_table_remove (priv->all_connections, connection);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|
@ -574,47 +545,37 @@ claim_connection (NMSysconfigSettings *self,
|
||||||
{
|
{
|
||||||
NMSysconfigSettingsPrivate *priv = NM_SYSCONFIG_SETTINGS_GET_PRIVATE (self);
|
NMSysconfigSettingsPrivate *priv = NM_SYSCONFIG_SETTINGS_GET_PRIVATE (self);
|
||||||
|
|
||||||
g_return_if_fail (NM_IS_SYSCONFIG_SETTINGS (self));
|
|
||||||
g_return_if_fail (NM_IS_SYSCONFIG_CONNECTION (connection));
|
g_return_if_fail (NM_IS_SYSCONFIG_CONNECTION (connection));
|
||||||
|
|
||||||
if (g_hash_table_lookup (priv->all_connections, connection))
|
if (g_hash_table_lookup (priv->connections, connection))
|
||||||
/* A plugin is lying to us. */
|
/* A plugin is lying to us. */
|
||||||
return;
|
return;
|
||||||
|
|
||||||
g_hash_table_insert (priv->all_connections, g_object_ref (connection), GINT_TO_POINTER (1));
|
g_hash_table_insert (priv->connections, g_object_ref (connection), GINT_TO_POINTER (1));
|
||||||
g_signal_connect (connection,
|
g_signal_connect (connection,
|
||||||
NM_SYSCONFIG_CONNECTION_REMOVED,
|
NM_SYSCONFIG_CONNECTION_REMOVED,
|
||||||
G_CALLBACK (connection_removed),
|
G_CALLBACK (connection_removed),
|
||||||
self);
|
self);
|
||||||
g_signal_connect (connection,
|
|
||||||
NM_SYSCONFIG_CONNECTION_PURGED,
|
|
||||||
G_CALLBACK (connection_purged),
|
|
||||||
self);
|
|
||||||
|
|
||||||
if (nm_sysconfig_connection_is_visible (connection)) {
|
/* Ensure it's initial visibility is up-to-date */
|
||||||
g_hash_table_insert (priv->visible_connections, connection, GINT_TO_POINTER (1));
|
nm_sysconfig_connection_recheck_visibility (connection);
|
||||||
g_signal_emit (self, signals[NEW_CONNECTION], 0, connection);
|
|
||||||
}
|
g_signal_emit (self, signals[NEW_CONNECTION], 0, connection);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO it seems that this is only ever used to remove a
|
// TODO it seems that this is only ever used to remove a
|
||||||
// NMDefaultWiredConnection, and it probably needs to stay that way. So this
|
// NMDefaultWiredConnection, and it probably needs to stay that way. So this
|
||||||
// *needs* a better name!
|
// *needs* a better name!
|
||||||
static void
|
static void
|
||||||
remove_connection (NMSysconfigSettings *self,
|
remove_default_wired_connection (NMSysconfigSettings *self,
|
||||||
NMSysconfigConnection *connection,
|
NMSysconfigConnection *connection,
|
||||||
gboolean do_signal)
|
gboolean do_signal)
|
||||||
{
|
{
|
||||||
NMSysconfigSettingsPrivate *priv = NM_SYSCONFIG_SETTINGS_GET_PRIVATE (self);
|
NMSysconfigSettingsPrivate *priv = NM_SYSCONFIG_SETTINGS_GET_PRIVATE (self);
|
||||||
|
|
||||||
if (g_hash_table_lookup (priv->visible_connections, connection)) {
|
if (g_hash_table_lookup (priv->connections, connection)) {
|
||||||
g_signal_emit_by_name (G_OBJECT (connection), NM_SYSCONFIG_CONNECTION_REMOVED);
|
g_signal_emit_by_name (G_OBJECT (connection), NM_SYSCONFIG_CONNECTION_REMOVED);
|
||||||
g_hash_table_remove (priv->visible_connections, connection);
|
g_hash_table_remove (priv->connections, connection);
|
||||||
}
|
|
||||||
|
|
||||||
if (g_hash_table_lookup (priv->all_connections, connection)) {
|
|
||||||
g_signal_emit_by_name (G_OBJECT (connection), NM_SYSCONFIG_CONNECTION_PURGED);
|
|
||||||
g_hash_table_remove (priv->all_connections, connection);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -927,7 +888,7 @@ have_connection_for_device (NMSysconfigSettings *self, GByteArray *mac)
|
||||||
g_return_val_if_fail (mac != NULL, FALSE);
|
g_return_val_if_fail (mac != NULL, FALSE);
|
||||||
|
|
||||||
/* Find a wired connection locked to the given MAC address, if any */
|
/* Find a wired connection locked to the given MAC address, if any */
|
||||||
g_hash_table_iter_init (&iter, priv->visible_connections);
|
g_hash_table_iter_init (&iter, priv->connections);
|
||||||
while (g_hash_table_iter_next (&iter, &key, NULL)) {
|
while (g_hash_table_iter_next (&iter, &key, NULL)) {
|
||||||
NMConnection *connection = NM_CONNECTION (key);
|
NMConnection *connection = NM_CONNECTION (key);
|
||||||
const char *connection_type;
|
const char *connection_type;
|
||||||
|
|
@ -1134,7 +1095,7 @@ default_wired_try_update (NMDefaultWiredConnection *wired,
|
||||||
id = nm_setting_connection_get_id (s_con);
|
id = nm_setting_connection_get_id (s_con);
|
||||||
g_assert (id);
|
g_assert (id);
|
||||||
|
|
||||||
remove_connection (self, NM_SYSCONFIG_CONNECTION (wired), FALSE);
|
remove_default_wired_connection (self, NM_SYSCONFIG_CONNECTION (wired), FALSE);
|
||||||
if (add_new_connection (self, NM_CONNECTION (wired), &error)) {
|
if (add_new_connection (self, NM_CONNECTION (wired), &error)) {
|
||||||
nm_sysconfig_connection_delete (NM_SYSCONFIG_CONNECTION (wired),
|
nm_sysconfig_connection_delete (NM_SYSCONFIG_CONNECTION (wired),
|
||||||
delete_cb,
|
delete_cb,
|
||||||
|
|
@ -1226,7 +1187,7 @@ nm_sysconfig_settings_device_removed (NMSysconfigSettings *self, NMDevice *devic
|
||||||
|
|
||||||
connection = (NMDefaultWiredConnection *) g_object_get_data (G_OBJECT (device), DEFAULT_WIRED_TAG);
|
connection = (NMDefaultWiredConnection *) g_object_get_data (G_OBJECT (device), DEFAULT_WIRED_TAG);
|
||||||
if (connection)
|
if (connection)
|
||||||
remove_connection (self, NM_SYSCONFIG_CONNECTION (connection), TRUE);
|
remove_default_wired_connection (self, NM_SYSCONFIG_CONNECTION (connection), TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
NMSysconfigSettings *
|
NMSysconfigSettings *
|
||||||
|
|
@ -1289,12 +1250,6 @@ dispose (GObject *object)
|
||||||
g_slist_free (priv->pk_calls);
|
g_slist_free (priv->pk_calls);
|
||||||
priv->pk_calls = NULL;
|
priv->pk_calls = NULL;
|
||||||
|
|
||||||
if (priv->session_monitor) {
|
|
||||||
g_signal_handler_disconnect (priv->session_monitor, priv->session_monitor_id);
|
|
||||||
g_object_unref (priv->session_monitor);
|
|
||||||
priv->session_monitor = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
G_OBJECT_CLASS (nm_sysconfig_settings_parent_class)->dispose (object);
|
G_OBJECT_CLASS (nm_sysconfig_settings_parent_class)->dispose (object);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1304,8 +1259,7 @@ finalize (GObject *object)
|
||||||
NMSysconfigSettings *self = NM_SYSCONFIG_SETTINGS (object);
|
NMSysconfigSettings *self = NM_SYSCONFIG_SETTINGS (object);
|
||||||
NMSysconfigSettingsPrivate *priv = NM_SYSCONFIG_SETTINGS_GET_PRIVATE (self);
|
NMSysconfigSettingsPrivate *priv = NM_SYSCONFIG_SETTINGS_GET_PRIVATE (self);
|
||||||
|
|
||||||
g_hash_table_destroy (priv->visible_connections);
|
g_hash_table_destroy (priv->connections);
|
||||||
g_hash_table_destroy (priv->all_connections);
|
|
||||||
|
|
||||||
clear_unmanaged_specs (self);
|
clear_unmanaged_specs (self);
|
||||||
|
|
||||||
|
|
@ -1439,8 +1393,7 @@ nm_sysconfig_settings_init (NMSysconfigSettings *self)
|
||||||
NMSysconfigSettingsPrivate *priv = NM_SYSCONFIG_SETTINGS_GET_PRIVATE (self);
|
NMSysconfigSettingsPrivate *priv = NM_SYSCONFIG_SETTINGS_GET_PRIVATE (self);
|
||||||
GError *error = NULL;
|
GError *error = NULL;
|
||||||
|
|
||||||
priv->visible_connections = g_hash_table_new (g_direct_hash, g_direct_equal);
|
priv->connections = g_hash_table_new_full (g_direct_hash, g_direct_equal, g_object_unref, NULL);
|
||||||
priv->all_connections = g_hash_table_new_full (g_direct_hash, g_direct_equal, g_object_unref, NULL);
|
|
||||||
|
|
||||||
priv->authority = polkit_authority_get_sync (NULL, &error);
|
priv->authority = polkit_authority_get_sync (NULL, &error);
|
||||||
if (!priv->authority) {
|
if (!priv->authority) {
|
||||||
|
|
@ -1449,12 +1402,5 @@ nm_sysconfig_settings_init (NMSysconfigSettings *self)
|
||||||
error && error->message ? error->message : "(unknown)");
|
error && error->message ? error->message : "(unknown)");
|
||||||
g_clear_error (&error);
|
g_clear_error (&error);
|
||||||
}
|
}
|
||||||
|
|
||||||
priv->session_monitor = nm_session_monitor_get ();
|
|
||||||
g_assert (priv->session_monitor);
|
|
||||||
priv->session_monitor_id = g_signal_connect (priv->session_monitor,
|
|
||||||
"changed",
|
|
||||||
G_CALLBACK (session_monitor_changed_cb),
|
|
||||||
self);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue