diff options
author | Thomas Haller <thaller@redhat.com> | 2019-02-18 15:01:05 +0100 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2019-02-18 15:01:05 +0100 |
commit | 074103f92d3612055e2a3bc0ba2a664ae856dc74 (patch) | |
tree | 00156a3665c38452fcfa3aaab43df9adcdc94592 | |
parent | 080f5ee76b037287ca7d104c8a2e4d3df265278e (diff) | |
parent | 9ae71bf55537b1d39c6cf341108f23cc32c87bd9 (diff) | |
download | NetworkManager-074103f92d3612055e2a3bc0ba2a664ae856dc74.tar.gz |
all: merge branch 'th/c-list-move'
https://github.com/NetworkManager/NetworkManager/pull/298
-rw-r--r-- | shared/nm-utils/nm-c-list.h | 36 | ||||
-rw-r--r-- | shared/nm-utils/nm-dedup-multi.c | 55 | ||||
-rw-r--r-- | src/platform/nm-linux-platform.c | 4 |
3 files changed, 51 insertions, 44 deletions
diff --git a/shared/nm-utils/nm-c-list.h b/shared/nm-utils/nm-c-list.h index b43d144197..5c73f57475 100644 --- a/shared/nm-utils/nm-c-list.h +++ b/shared/nm-utils/nm-c-list.h @@ -78,4 +78,40 @@ nm_c_list_elem_free_all (CList *head, GDestroyNotify free_fcn) } } +/*****************************************************************************/ + +static inline gboolean +nm_c_list_move_before (CList *lst, CList *elem) +{ + nm_assert (lst); + nm_assert (elem); + nm_assert (c_list_contains (lst, elem)); + + if ( lst != elem + && lst->prev != elem) { + c_list_unlink_stale (elem); + c_list_link_before (lst, elem); + return TRUE; + } + return FALSE; +} +#define nm_c_list_move_tail(lst, elem) nm_c_list_move_before (lst, elem) + +static inline gboolean +nm_c_list_move_after (CList *lst, CList *elem) +{ + nm_assert (lst); + nm_assert (elem); + nm_assert (c_list_contains (lst, elem)); + + if ( lst != elem + && lst->next != elem) { + c_list_unlink_stale (elem); + c_list_link_after (lst, elem); + return TRUE; + } + return FALSE; +} +#define nm_c_list_move_front(lst, elem) nm_c_list_move_after (lst, elem) + #endif /* __NM_C_LIST_H__ */ diff --git a/shared/nm-utils/nm-dedup-multi.c b/shared/nm-utils/nm-dedup-multi.c index 852c207c7f..5bdc3e3c03 100644 --- a/shared/nm-utils/nm-dedup-multi.c +++ b/shared/nm-utils/nm-dedup-multi.c @@ -24,6 +24,7 @@ #include "nm-dedup-multi.h" #include "nm-hash-utils.h" +#include "nm-c-list.h" /*****************************************************************************/ @@ -260,44 +261,27 @@ _add (NMDedupMultiIndex *self, nm_dedup_multi_entry_set_dirty (entry, FALSE); nm_assert (!head_existing || entry->head == head_existing); - - if (entry_order) { - nm_assert (entry_order->head == entry->head); - nm_assert (c_list_contains (&entry->lst_entries, &entry_order->lst_entries)); - nm_assert (c_list_contains (&entry_order->lst_entries, &entry->lst_entries)); - } + nm_assert (!entry_order || entry_order->head == entry->head); + nm_assert (!entry_order || c_list_contains (&entry->lst_entries, &entry_order->lst_entries)); + nm_assert (!entry_order || c_list_contains (&entry_order->lst_entries, &entry->lst_entries)); switch (mode) { case NM_DEDUP_MULTI_IDX_MODE_PREPEND_FORCE: if (entry_order) { - if ( entry_order != entry - && entry->lst_entries.next != &entry_order->lst_entries) { - c_list_unlink_stale (&entry->lst_entries); - c_list_link_before ((CList *) &entry_order->lst_entries, &entry->lst_entries); + if (nm_c_list_move_before ((CList *) &entry_order->lst_entries, &entry->lst_entries)) changed = TRUE; - } } else { - if (entry->lst_entries.prev != &entry->head->lst_entries_head) { - c_list_unlink_stale (&entry->lst_entries); - c_list_link_front ((CList *) &entry->head->lst_entries_head, &entry->lst_entries); + if (nm_c_list_move_front ((CList *) &entry->head->lst_entries_head, &entry->lst_entries)) changed = TRUE; - } } break; case NM_DEDUP_MULTI_IDX_MODE_APPEND_FORCE: if (entry_order) { - if ( entry_order != entry - && entry->lst_entries.prev != &entry_order->lst_entries) { - c_list_unlink_stale (&entry->lst_entries); - c_list_link_after ((CList *) &entry_order->lst_entries, &entry->lst_entries); + if (nm_c_list_move_after ((CList *) &entry_order->lst_entries, &entry->lst_entries)) changed = TRUE; - } } else { - if (entry->lst_entries.next != &entry->head->lst_entries_head) { - c_list_unlink_stale (&entry->lst_entries); - c_list_link_tail ((CList *) &entry->head->lst_entries_head, &entry->lst_entries); + if (nm_c_list_move_tail ((CList *) &entry->head->lst_entries_head, &entry->lst_entries)) changed = TRUE; - } } break; case NM_DEDUP_MULTI_IDX_MODE_PREPEND: @@ -1022,33 +1006,20 @@ nm_dedup_multi_entry_reorder (const NMDedupMultiEntry *entry, if (!entry_order) { const NMDedupMultiHeadEntry *head_entry = entry->head; - nm_assert (c_list_contains (&head_entry->lst_entries_head, &entry->lst_entries)); if (order_after) { - if (head_entry->lst_entries_head.prev != &entry->lst_entries) { - c_list_unlink_stale ((CList *) &entry->lst_entries); - c_list_link_tail ((CList *) &head_entry->lst_entries_head, (CList *) &entry->lst_entries); + if (nm_c_list_move_tail ((CList *) &head_entry->lst_entries_head, (CList *) &entry->lst_entries)) return TRUE; - } } else { - if (head_entry->lst_entries_head.next != &entry->lst_entries) { - c_list_unlink_stale ((CList *) &entry->lst_entries); - c_list_link_front ((CList *) &head_entry->lst_entries_head, (CList *) &entry->lst_entries); + if (nm_c_list_move_front ((CList *) &head_entry->lst_entries_head, (CList *) &entry->lst_entries)) return TRUE; - } } - } else if (entry != entry_order) { + } else { if (order_after) { - if (entry_order->lst_entries.next != &entry->lst_entries) { - c_list_unlink_stale ((CList *) &entry->lst_entries); - c_list_link_after ((CList *) &entry_order->lst_entries, (CList *) &entry->lst_entries); + if (nm_c_list_move_after ((CList *) &entry_order->lst_entries, (CList *) &entry->lst_entries)) return TRUE; - } } else { - if (entry_order->lst_entries.prev != &entry->lst_entries) { - c_list_unlink_stale ((CList *) &entry->lst_entries); - c_list_link_before ((CList *) &entry_order->lst_entries, (CList *) &entry->lst_entries); + if (nm_c_list_move_before ((CList *) &entry_order->lst_entries, (CList *) &entry->lst_entries)) return TRUE; - } } } diff --git a/src/platform/nm-linux-platform.c b/src/platform/nm-linux-platform.c index a7daebf821..8777867841 100644 --- a/src/platform/nm-linux-platform.c +++ b/src/platform/nm-linux-platform.c @@ -44,6 +44,7 @@ #include "nm-setting-vlan.h" #include "nm-utils/nm-secret-utils.h" +#include "nm-utils/nm-c-list.h" #include "nm-netlink.h" #include "nm-core-utils.h" #include "nmp-object.h" @@ -4237,8 +4238,7 @@ _log_dbg_sysctl_get_impl (NMPlatform *platform, const char *pathid, const char * g_free (entry->value); entry->value = g_strdup (contents); } - c_list_unlink_stale (&entry->lst); - c_list_link_front (&priv->sysctl_list, &entry->lst); + nm_c_list_move_front (&priv->sysctl_list, &entry->lst); } else { gs_free char *contents_escaped = g_strescape (contents, NULL); SysctlCacheEntry *old; |