chiark / gitweb /
add and use name_list_cleanup() for cleaning up the string lists
authorKay Sievers <kay.sievers@suse.de>
Sat, 27 Aug 2005 14:15:41 +0000 (16:15 +0200)
committerKay Sievers <kay.sievers@suse.de>
Sat, 27 Aug 2005 14:15:41 +0000 (16:15 +0200)
Signed-off-by: Kay Sievers <kay.sievers@suse.de>
udev_device.c
udev_rules.c
udev_utils.c
udev_utils.h
udevinfo.c

index 45bb6a2..db72d30 100644 (file)
@@ -103,19 +103,7 @@ int udev_init_device(struct udevice *udev, const char* devpath, const char *subs
 
 void udev_cleanup_device(struct udevice *udev)
 {
-       struct name_entry *name_loop;
-       struct name_entry *temp_loop;
-
-       list_for_each_entry_safe(name_loop, temp_loop, &udev->symlink_list, node) {
-               list_del(&name_loop->node);
-               free(name_loop);
-       }
-       list_for_each_entry_safe(name_loop, temp_loop, &udev->run_list, node) {
-               list_del(&name_loop->node);
-               free(name_loop);
-       }
-       list_for_each_entry_safe(name_loop, temp_loop, &udev->env_list, node) {
-               list_del(&name_loop->node);
-               free(name_loop);
-       }
+       name_list_cleanup(&udev->symlink_list);
+       name_list_cleanup(&udev->run_list);
+       name_list_cleanup(&udev->env_list);
 }
index 8db7fd3..3cbcad5 100644 (file)
@@ -964,14 +964,8 @@ int udev_rules_get_name(struct udev_rules *rules, struct udevice *udev, struct s
                                if (rule->symlink.operation == KEY_OP_ASSIGN_FINAL)
                                        udev->symlink_final = 1;
                                if (rule->symlink.operation == KEY_OP_ASSIGN || rule->symlink.operation == KEY_OP_ASSIGN_FINAL) {
-                                       struct name_entry *name_loop;
-                                       struct name_entry *temp_loop;
-
                                        info("reset symlink list");
-                                       list_for_each_entry_safe(name_loop, temp_loop, &udev->symlink_list, node) {
-                                               list_del(&name_loop->node);
-                                               free(name_loop);
-                                       }
+                                       name_list_cleanup(&udev->symlink_list);
                                }
                                strlcpy(temp, key_val(rule, &rule->symlink), sizeof(temp));
                                apply_format(udev, temp, sizeof(temp), class_dev, sysfs_device);
@@ -1015,14 +1009,8 @@ int udev_rules_get_name(struct udev_rules *rules, struct udevice *udev, struct s
                                if (rule->run.operation == KEY_OP_ASSIGN_FINAL)
                                        udev->run_final = 1;
                                if (rule->run.operation == KEY_OP_ASSIGN || rule->run.operation == KEY_OP_ASSIGN_FINAL) {
-                                       struct name_entry *name_loop;
-                                       struct name_entry *temp_loop;
-
                                        info("reset run list");
-                                       list_for_each_entry_safe(name_loop, temp_loop, &udev->run_list, node) {
-                                               list_del(&name_loop->node);
-                                               free(name_loop);
-                                       }
+                                       name_list_cleanup(&udev->run_list);
                                }
                                strlcpy(program, key_val(rule, &rule->run), sizeof(program));
                                apply_format(udev, program, sizeof(program), class_dev, sysfs_device);
@@ -1096,14 +1084,8 @@ int udev_rules_get_run(struct udev_rules *rules, struct udevice *udev,
                                char program[PATH_SIZE];
 
                                if (rule->run.operation == KEY_OP_ASSIGN || rule->run.operation == KEY_OP_ASSIGN_FINAL) {
-                                       struct name_entry *name_loop;
-                                       struct name_entry *temp_loop;
-
                                        info("reset run list");
-                                       list_for_each_entry_safe(name_loop, temp_loop, &udev->run_list, node) {
-                                               list_del(&name_loop->node);
-                                               free(name_loop);
-                                       }
+                                       name_list_cleanup(&udev->run_list);
                                }
                                strlcpy(program, key_val(rule, &rule->run), sizeof(program));
                                apply_format(udev, program, sizeof(program), class_dev, sysfs_dev);
index de43dee..fc1e2e1 100644 (file)
@@ -224,6 +224,17 @@ int name_list_key_add(struct list_head *name_list, const char *key, const char *
        return 0;
 }
 
+void name_list_cleanup(struct list_head *name_list)
+{
+       struct name_entry *name_loop;
+       struct name_entry *temp_loop;
+
+       list_for_each_entry_safe(name_loop, temp_loop, name_list, node) {
+               list_del(&name_loop->node);
+               free(name_loop);
+       }
+}
+
 /* calls function for every file found in specified directory */
 int add_matching_files(struct list_head *name_list, const char *dirname, const char *suffix)
 {
index a3fc283..0a30752 100644 (file)
@@ -45,6 +45,7 @@ extern void remove_trailing_char(char *path, char c);
 extern void replace_untrusted_chars(char *string);
 extern int name_list_add(struct list_head *name_list, const char *name, int sort);
 extern int name_list_key_add(struct list_head *name_list, const char *key, const char *value);
+extern void name_list_cleanup(struct list_head *name_list);
 extern int add_matching_files(struct list_head *name_list, const char *dirname, const char *suffix);
 extern int pass_env_to_socket(const char *name, const char *devpath, const char *action);
 extern int run_program(const char *command, const char *subsystem,
index b546488..fadfaec 100644 (file)
@@ -170,19 +170,17 @@ exit:
 static void dump_names(void) {
        LIST_HEAD(name_list);
        struct name_entry *name_loop;
-       struct name_entry *tmp_loop;
 
        udev_db_get_all_entries(&name_list);
-       list_for_each_entry_safe(name_loop, tmp_loop, &name_list, node) {
+       list_for_each_entry(name_loop, &name_list, node) {
                struct udevice udev_db;
 
                udev_init_device(&udev_db, NULL, NULL, NULL);
-               if (udev_db_get_device(&udev_db, name_loop->name) == 0) {
+               if (udev_db_get_device(&udev_db, name_loop->name) == 0)
                        printf("%s=%s/%s\n", udev_db.devpath, udev_root, udev_db.name);
-                       free(name_loop);
-               }
                udev_cleanup_device(&udev_db);
        }
+       name_list_cleanup(&name_list);
 }
 
 int main(int argc, char *argv[], char *envp[])