parse_config_scan contained code to read and sort a list of *.conf files from a directory. This moves that code into its own function. Signed-off-by: Keegan McAllister <keegan@xxxxxxxxxxx> --- depmod.c | 80 +++++++++++++++++++++++++++++++++++-------------------------- 1 files changed, 46 insertions(+), 34 deletions(-) diff --git a/depmod.c b/depmod.c index c6287f4..d9652b3 100644 --- a/depmod.c +++ b/depmod.c @@ -1138,6 +1138,50 @@ static struct module_overrides *add_override(const char *modfile, } +struct file_entry +{ + struct list_head node; + char name[]; +}; + +static int read_config_dir(const char *dirname, struct list_head *files_list) +{ + struct file_entry *fe, *fe_tmp; + struct dirent *i; + DIR *dir; + + dir = opendir(dirname); + if (!dir) + return 0; + + /* sort files from directory into list */ + while ((i = readdir(dir)) != NULL) { + size_t len; + + if (i->d_name[0] == '.') + continue; + if (!config_filter(i->d_name)) + continue; + + len = strlen(i->d_name); + if (len < 6 || strcmp(&i->d_name[len-5], ".conf") != 0) + warn("All config files need .conf: %s/%s, " + "it will be ignored in a future release.\n", + dirname, i->d_name); + fe = malloc(sizeof(struct file_entry) + len + 1); + if (fe == NULL) + continue; + strcpy(fe->name, i->d_name); + list_for_each_entry(fe_tmp, files_list, node) + if (strcmp(fe_tmp->name, fe->name) >= 0) + break; + list_add_tail(&fe->node, &fe_tmp->node); + } + closedir(dir); + + return 1; +} + static int parse_config_scan(const char *filename, const char *basedir, const char *module_dir, @@ -1259,43 +1303,11 @@ static int parse_config_scan(const char *filename, struct module_search **search, struct module_overrides **overrides) { - DIR *dir; int ret = 0; - dir = opendir(filename); - if (dir) { - struct file_entry { - struct list_head node; - char name[]; - }; - LIST_HEAD(files_list); + LIST_HEAD(files_list); + if (read_config_dir(filename, &files_list)) { struct file_entry *fe, *fe_tmp; - struct dirent *i; - - /* sort files from directory into list */ - while ((i = readdir(dir)) != NULL) { - size_t len; - - if (i->d_name[0] == '.') - continue; - if (!config_filter(i->d_name)) - continue; - - len = strlen(i->d_name); - if (len < 6 || strcmp(&i->d_name[len-5], ".conf") != 0) - warn("All config files need .conf: %s/%s, " - "it will be ignored in a future release.\n", - filename, i->d_name); - fe = malloc(sizeof(struct file_entry) + len + 1); - if (fe == NULL) - continue; - strcpy(fe->name, i->d_name); - list_for_each_entry(fe_tmp, &files_list, node) - if (strcmp(fe_tmp->name, fe->name) >= 0) - break; - list_add_tail(&fe->node, &fe_tmp->node); - } - closedir(dir); /* parse list of files */ list_for_each_entry_safe(fe, fe_tmp, &files_list, node) { -- 1.7.2.3 -- To unsubscribe from this list: send the line "unsubscribe linux-modules" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html