From fb6e14cf3f602a840bee66c27dfcb754872f1525 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 4 Mar 2020 13:38:49 +0100 Subject: [PATCH] core: return ifindex from nm_manager_write_device_state() nm_manager_write_device_state() writes the device state to a file. The ifindex is here important, because that is the identifier for the device and is also used as file name. Return the ifindex that was used, instead of letting the caller reimplement the knowledge which ifindex was used. (cherry picked from commit 5477847eed9654727df5b70767a2a6498da1cb67) --- src/nm-manager.c | 34 +++++++++++++++++++++------------- src/nm-manager.h | 2 +- 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/src/nm-manager.c b/src/nm-manager.c index 1022e866f5..3649c87e0f 100644 --- a/src/nm-manager.c +++ b/src/nm-manager.c @@ -1515,7 +1515,7 @@ manager_device_state_changed (NMDevice *device, NM_DEVICE_STATE_UNMANAGED, NM_DEVICE_STATE_DISCONNECTED, NM_DEVICE_STATE_ACTIVATED)) - nm_manager_write_device_state (self, device); + nm_manager_write_device_state (self, device, NULL); if (NM_IN_SET (new_state, NM_DEVICE_STATE_UNAVAILABLE, @@ -6514,7 +6514,7 @@ start_factory (NMDeviceFactory *factory, gpointer user_data) } gboolean -nm_manager_write_device_state (NMManager *self, NMDevice *device) +nm_manager_write_device_state (NMManager *self, NMDevice *device, int *out_ifindex) { NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (self); int ifindex; @@ -6530,6 +6530,8 @@ nm_manager_write_device_state (NMManager *self, NMDevice *device) const char *next_server = NULL; const char *root_path = NULL; + NM_SET_OUT (out_ifindex, 0); + ifindex = nm_device_get_ip_ifindex (device); if (ifindex <= 0) return FALSE; @@ -6570,15 +6572,19 @@ nm_manager_write_device_state (NMManager *self, NMDevice *device) next_server = nm_dhcp4_config_get_option (dhcp4_config, "next_server"); } - return nm_config_device_state_write (ifindex, - managed_type, - perm_hw_addr_fake, - uuid, - nm_owned, - route_metric_default_aspired, - route_metric_default_effective, - next_server, - root_path); + if (!nm_config_device_state_write (ifindex, + managed_type, + perm_hw_addr_fake, + uuid, + nm_owned, + route_metric_default_aspired, + route_metric_default_effective, + next_server, + root_path)) + return FALSE; + + NM_SET_OUT (out_ifindex, ifindex); + return TRUE; } void @@ -6591,9 +6597,11 @@ nm_manager_write_device_state_all (NMManager *self) preserve_ifindexes = g_hash_table_new (nm_direct_hash, NULL); c_list_for_each_entry (device, &priv->devices_lst_head, devices_lst) { - if (nm_manager_write_device_state (self, device)) { + int ifindex; + + if (nm_manager_write_device_state (self, device, &ifindex)) { g_hash_table_add (preserve_ifindexes, - GINT_TO_POINTER (nm_device_get_ip_ifindex (device))); + GINT_TO_POINTER (ifindex)); } } diff --git a/src/nm-manager.h b/src/nm-manager.h index ad06e318f4..5873abd24b 100644 --- a/src/nm-manager.h +++ b/src/nm-manager.h @@ -103,7 +103,7 @@ NMSettingsConnection **nm_manager_get_activatable_connections (NMManager *manage guint *out_len); void nm_manager_write_device_state_all (NMManager *manager); -gboolean nm_manager_write_device_state (NMManager *manager, NMDevice *device); +gboolean nm_manager_write_device_state (NMManager *manager, NMDevice *device, int *out_ifindex); /* Device handling */