summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKay Sievers <kay.sievers@vrfy.org>2011-08-28 22:41:46 +0200
committerKay Sievers <kay.sievers@vrfy.org>2011-08-28 22:45:34 +0200
commitc99b72121fb965920652ea5e7a1d7f962385626b (patch)
tree600e38bb9c1ddb8802acdf8d5f4d71c93f8725ec
parent1484205c47cf395fe21e0dac249b8534d03c3fe2 (diff)
libudev: list - properly sort linked list not only the index
<mgorny> it seems that udev-git is b0rked while tag '173' works fine for me <mgorny> the rule in question is: <mgorny> also, with >173 persistent-net rules seem to get constantly recreated for same devices <kay> mgorny: logic bug. we only sort the keys in an index, but we don't care about the index when reading the list, which doesn't work too well for the rules file list where we depend on the order
-rw-r--r--libudev/libudev-list.c13
1 files changed, 11 insertions, 2 deletions
diff --git a/libudev/libudev-list.c b/libudev/libudev-list.c
index 295ee682bc..f74a88ca49 100644
--- a/libudev/libudev-list.c
+++ b/libudev/libudev-list.c
@@ -180,7 +180,6 @@ struct udev_list_entry *udev_list_entry_add(struct udev_list *list, const char *
return NULL;
}
}
- udev_list_entry_append(entry, list);
if (list->unique) {
/* allocate or enlarge sorted array if needed */
@@ -199,12 +198,22 @@ struct udev_list_entry *udev_list_entry_add(struct udev_list *list, const char *
list->entries_max += add;
}
- /* insert into sorted array */
+ /* the negative i returned the insertion index */
i = (-i)-1;
+
+ /* insert into sorted list */
+ if ((unsigned int)i < list->entries_cur)
+ udev_list_entry_insert_before(entry, list->entries[i]);
+ else
+ udev_list_entry_append(entry, list);
+
+ /* insert into sorted array */
memmove(&list->entries[i+1], &list->entries[i],
(list->entries_cur - i) * sizeof(struct udev_list_entry *));
list->entries[i] = entry;
list->entries_cur++;
+ } else {
+ udev_list_entry_append(entry, list);
}
dbg(list->udev, "'%s=%s' added\n", entry->name, entry->value);