From 8ef5af2db83cea4b7d2d02f1fed71fca82f9e20d Mon Sep 17 00:00:00 2001 From: Kay Sievers Date: Sat, 9 Aug 2008 14:05:01 +0200 Subject: ignore duplicated rules file names --- udev/udev_rules_parse.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) (limited to 'udev/udev_rules_parse.c') diff --git a/udev/udev_rules_parse.c b/udev/udev_rules_parse.c index 273f92f486..bf833bae54 100644 --- a/udev/udev_rules_parse.c +++ b/udev/udev_rules_parse.c @@ -741,11 +741,8 @@ int udev_rules_init(struct udev_rules *rules, int resolve_names) /* custom rules location for testing */ add_matching_files(&name_list, udev_rules_dir, ".rules"); } else { - /* read default rules */ - add_matching_files(&name_list, UDEV_PREFIX "/lib/udev/rules.d", ".rules"); - /* read user/custom rules */ - add_matching_files(&sort_list, SYSCONFDIR "/udev/rules.d", ".rules"); + add_matching_files(&name_list, SYSCONFDIR "/udev/rules.d", ".rules"); /* read dynamic/temporary rules */ strlcpy(filename, udev_root, sizeof(filename)); @@ -758,6 +755,9 @@ int udev_rules_init(struct udev_rules *rules, int resolve_names) } add_matching_files(&sort_list, filename, ".rules"); + /* read default rules */ + add_matching_files(&sort_list, UDEV_PREFIX "/lib/udev/rules.d", ".rules"); + /* sort all rules files by basename into list of files */ list_for_each_entry_safe(sort_loop, sort_tmp, &sort_list, node) { const char *sort_base = strrchr(sort_loop->name, '/'); @@ -771,10 +771,20 @@ int udev_rules_init(struct udev_rules *rules, int resolve_names) if (name_base == NULL) continue; + if (strcmp(name_base, sort_base) == 0) { + info("rule file '%s' already added, ignoring '%s'\n", + name_loop->name, sort_loop->name); + list_del(&sort_loop->node); + free(sort_loop); + sort_loop = NULL; + continue; + } + if (strcmp(name_base, sort_base) > 0) break; } - list_move_tail(&sort_loop->node, &name_loop->node); + if (sort_loop != NULL) + list_move_tail(&sort_loop->node, &name_loop->node); } } -- cgit v1.2.3-54-g00ecf