dns/resolved: use nm_utils_hash_to_array_with_buffer() in NMDnsSystemdResolved's update()

We copy the content of the hash table to an array, so that we can sort
the entries and they have a defined order.

We are not only interested in the keys, but the keys and the values.
Hence, use nm_utils_hash_to_array_with_buffer() which gives both at
the same time.
This commit is contained in:
Thomas Haller
2022-02-11 18:22:15 +01:00
parent 51cec67253
commit eb25c9ecd2

View File

@@ -561,10 +561,12 @@ update(NMDnsPlugin *plugin,
const char *hostdomain, const char *hostdomain,
GError **error) GError **error)
{ {
NMDnsSystemdResolved *self = NM_DNS_SYSTEMD_RESOLVED(plugin); NMDnsSystemdResolved *self = NM_DNS_SYSTEMD_RESOLVED(plugin);
NMDnsSystemdResolvedPrivate *priv = NM_DNS_SYSTEMD_RESOLVED_GET_PRIVATE(self); NMDnsSystemdResolvedPrivate *priv = NM_DNS_SYSTEMD_RESOLVED_GET_PRIVATE(self);
gs_unref_hashtable GHashTable *interfaces = NULL; gs_unref_hashtable GHashTable *interfaces = NULL;
gs_free gpointer *interfaces_keys = NULL; const NMUtilsNamedValue *interfaces_arr;
NMUtilsNamedValue interfaces_arr_stack[50];
gs_free NMUtilsNamedValue *interfaces_arr_heap = NULL;
guint interfaces_len; guint interfaces_len;
gpointer pointer; gpointer pointer;
NMDnsConfigIPData *ip_data; NMDnsConfigIPData *ip_data;
@@ -595,11 +597,14 @@ update(NMDnsPlugin *plugin,
free_pending_updates(self); free_pending_updates(self);
interfaces_keys = interfaces_arr = nm_utils_hash_to_array_with_buffer(interfaces,
nm_utils_hash_keys_to_array(interfaces, nm_cmp_int2ptr_p_with_data, NULL, &interfaces_len); &interfaces_len,
nm_cmp_int2ptr_p_with_data,
NULL,
interfaces_arr_stack,
&interfaces_arr_heap);
for (i = 0; i < interfaces_len; i++) { for (i = 0; i < interfaces_len; i++) {
const InterfaceConfig *ic = const InterfaceConfig *ic = interfaces_arr[i].value_ptr;
g_hash_table_lookup(interfaces, GINT_TO_POINTER(interfaces_keys[i]));
if (prepare_one_interface(self, ic)) if (prepare_one_interface(self, ic))
g_hash_table_add(priv->dirty_interfaces, GINT_TO_POINTER(ic->ifindex)); g_hash_table_add(priv->dirty_interfaces, GINT_TO_POINTER(ic->ifindex));