From: Kay Sievers Date: Sat, 27 Aug 2005 14:15:41 +0000 (+0200) Subject: add and use name_list_cleanup() for cleaning up the string lists X-Git-Tag: 174~2593 X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=commitdiff_plain;h=fb17920701dcba0d94e3fde566788a868e41d1ad add and use name_list_cleanup() for cleaning up the string lists Signed-off-by: Kay Sievers --- diff --git a/udev_device.c b/udev_device.c index 45bb6a287..db72d3007 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 8db7fd377..3cbcad55c 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 de43dee30..fc1e2e1f7 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 a3fc28320..0a307526b 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 b546488c7..fadfaec94 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[])