diff options
author | Kay Sievers <kay.sievers@suse.de> | 2005-08-27 16:15:41 +0200 |
---|---|---|
committer | Kay Sievers <kay.sievers@suse.de> | 2005-08-27 16:15:41 +0200 |
commit | fb17920701dcba0d94e3fde566788a868e41d1ad (patch) | |
tree | 7667c49dd48312ec58ab12d4da92cb9206bb6b69 | |
parent | 314edf3ca44b268fa70a7a87a106322e2dd461af (diff) |
add and use name_list_cleanup() for cleaning up the string lists
Signed-off-by: Kay Sievers <kay.sievers@suse.de>
-rw-r--r-- | udev_device.c | 18 | ||||
-rw-r--r-- | udev_rules.c | 24 | ||||
-rw-r--r-- | udev_utils.c | 11 | ||||
-rw-r--r-- | udev_utils.h | 1 | ||||
-rw-r--r-- | udevinfo.c | 8 |
5 files changed, 21 insertions, 41 deletions
diff --git a/udev_device.c b/udev_device.c index 45bb6a2876..db72d3007d 100644 --- a/udev_device.c +++ b/udev_device.c @@ -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); } diff --git a/udev_rules.c b/udev_rules.c index 8db7fd377a..3cbcad55c1 100644 --- a/udev_rules.c +++ b/udev_rules.c @@ -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); diff --git a/udev_utils.c b/udev_utils.c index de43dee30d..fc1e2e1f7e 100644 --- a/udev_utils.c +++ b/udev_utils.c @@ -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) { diff --git a/udev_utils.h b/udev_utils.h index a3fc283203..0a307526b7 100644 --- a/udev_utils.h +++ b/udev_utils.h @@ -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, diff --git a/udevinfo.c b/udevinfo.c index b546488c7e..fadfaec945 100644 --- a/udevinfo.c +++ b/udevinfo.c @@ -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[]) |