Prerequisite for looping over several module dirs and calculating deps separately for each. Signed-off-by: Keegan McAllister <keegan@xxxxxxxxxxx> --- depmod.c | 222 +++++++++++++++++++++++++++++++++----------------------------- 1 files changed, 119 insertions(+), 103 deletions(-) diff --git a/depmod.c b/depmod.c index 647e5e6..d4010bb 100644 --- a/depmod.c +++ b/depmod.c @@ -64,6 +64,9 @@ struct module_search static unsigned int skipchars; static unsigned int make_map_files = 1; /* default to on */ static unsigned int force_map_files = 0; /* default to on */ +static unsigned int all_modules = 0; /* default to off */ +static unsigned int maybe_all = 0; /* default to off */ +static unsigned int doing_stdout = 0; /* default to off */ #define SYMBOL_HASH_SIZE 1024 struct symbol @@ -1132,12 +1135,14 @@ static struct module_overrides *add_override(const char *modfile, static int parse_config_scan(const char *filename, const char *basedir, + const char *module_dir, const char *kernelversion, struct module_search **search, struct module_overrides **overrides); static int parse_config_file(const char *filename, const char *basedir, + const char *module_dir, const char *kernelversion, struct module_search **search, struct module_overrides **overrides) @@ -1179,7 +1184,7 @@ static int parse_config_file(const char *filename, continue; } nofail_asprintf(&dirname, "%s%s%s/%s", basedir, - MODULE_DIR, kernelversion, search_path); + module_dir, kernelversion, search_path); len = strlen(dirname); *search = add_search(dirname, len, *search); free(dirname); @@ -1194,7 +1199,7 @@ static int parse_config_file(const char *filename, continue; nofail_asprintf(&pathname, "%s%s%s/%s/%s.ko", basedir, - MODULE_DIR, kernelversion, subdir, modname); + module_dir, kernelversion, subdir, modname); *overrides = add_override(pathname, *overrides); free(pathname); @@ -1212,7 +1217,7 @@ static int parse_config_file(const char *filename, "the default, ignored\n"); } else { if (!parse_config_scan(newfilename, basedir, - kernelversion, + module_dir, kernelversion, search, overrides)) warn("Failed to open included" " config file %s: %s\n", @@ -1244,6 +1249,7 @@ static int parse_config_file(const char *filename, static int parse_config_scan(const char *filename, const char *basedir, + const char *module_dir, const char *kernelversion, struct module_search **search, struct module_overrides **overrides) @@ -1291,7 +1297,7 @@ static int parse_config_scan(const char *filename, char *cfgfile; nofail_asprintf(&cfgfile, "%s/%s", filename, fe->name); - if (!parse_config_file(cfgfile, basedir, kernelversion, + if (!parse_config_file(cfgfile, basedir, module_dir, kernelversion, search, overrides)) warn("Failed to open config file " "%s: %s\n", fe->name, strerror(errno)); @@ -1302,8 +1308,8 @@ static int parse_config_scan(const char *filename, ret = 1; } else { - if (parse_config_file(filename, basedir, kernelversion, search, - overrides)) + if (parse_config_file(filename, basedir, module_dir, kernelversion, + search, overrides)) ret = 1; } @@ -1312,40 +1318,132 @@ static int parse_config_scan(const char *filename, static void parse_toplevel_config(const char *filename, const char *basedir, + const char *module_dir, const char *kernelversion, struct module_search **search, struct module_overrides **overrides) { if (filename) { - if (!parse_config_scan(filename, basedir, kernelversion, search, - overrides)) + if (!parse_config_scan(filename, basedir, module_dir, kernelversion, + search, overrides)) fatal("Failed to open config file %s: %s\n", filename, strerror(errno)); return; } /* deprecated config file */ - if (parse_config_file("/etc/depmod.conf", basedir, kernelversion, - search, overrides) > 0) + if (parse_config_file("/etc/depmod.conf", basedir, module_dir, + kernelversion, search, overrides) > 0) warn("Deprecated config file /etc/depmod.conf, " "all config files belong into /etc/depmod.d/.\n"); /* default config */ - parse_config_scan("/etc/depmod.d", basedir, kernelversion, + parse_config_scan("/etc/depmod.d", basedir, module_dir, kernelversion, search, overrides); } -/* Local to main, but not freed on exit. Keep valgrind quiet. */ -struct module *list = NULL; -struct module_search *search = NULL; -struct module_overrides *overrides = NULL; +static void do_module_dir(const char *basedir, const char *config, + const char *version, const char *module_dir, + int argc, char *argv[]) +{ + struct module *list = NULL; + struct module_search *search = NULL; + struct module_overrides *overrides = NULL; + int i, opt; + char *dirname; + + nofail_asprintf(&dirname, "%s%s%s", basedir, module_dir, version); + + if (maybe_all) { + if (!doing_stdout && !depfile_out_of_date(dirname)) + exit(0); + all_modules = 1; + } + + parse_toplevel_config(config, basedir, module_dir, version, &search, &overrides); + + /* For backward compatibility add "updates" to the head of the search + * list here. But only if there was no "search" option specified. + */ + if (!search) { + char *dirname; + size_t len; + + nofail_asprintf(&dirname, "%s%s%s/updates", basedir, + module_dir, version); + len = strlen(dirname); + search = add_search(dirname, len, search); + } + + if (!all_modules) { + /* Do command line args. */ + for (opt = optind; opt < argc; opt++) { + struct module *new; + + if (argv[opt][0] != '/') + fatal("modules must be specified using absolute paths.\n" + "\"%s\" is a relative path\n", argv[opt]); + + new = grab_module(NULL, argv[opt]); + if (!new) { + /* cmd-line specified modules must exist */ + fatal("grab_module() failed for module %s\n", argv[opt]); + } + new->next = list; + list = new; + } + } else { + list = grab_basedir(dirname,search,overrides); + } + list = sort_modules(dirname,list); + list = parse_modules(list); + + for (i = 0; i < sizeof(depfiles)/sizeof(depfiles[0]); i++) { + FILE *out; + int res; + struct depfile *d = &depfiles[i]; + char depname[strlen(dirname) + 1 + strlen(d->name) + 1]; + char tmpname[strlen(dirname) + 1 + strlen(d->name) + + strlen(".temp") + 1]; + + if (d->map_file && !make_map_files && !force_map_files) + continue; + + sprintf(depname, "%s/%s", dirname, d->name); + sprintf(tmpname, "%s/%s.temp", dirname, d->name); + if (!doing_stdout) { + out = fopen(tmpname, "w"); + if (!out) + fatal("Could not open %s for writing: %s\n", + tmpname, strerror(errno)); + } else { + out = stdout; + if (ends_in(depname, ".bin")) + continue; + } + res = d->func(list, out, dirname); + if (doing_stdout) + continue; + fclose(out); + if (res) { + if (rename(tmpname, depname) < 0) + fatal("Could not rename %s into %s: %s\n", + tmpname, depname, strerror(errno)); + } else { + if (unlink(tmpname) < 0) + warn("Could not delete %s: %s\n", + tmpname, strerror(errno)); + } + } + + free(dirname); +} int main(int argc, char *argv[]) { - int opt, all = 0, maybe_all = 0, doing_stdout = 0; - char *basedir = "", *dirname, *version; + int opt; char *system_map = NULL, *module_symvers = NULL; - int i; + char *basedir = "", *version; const char *config = NULL; if (native_endianness() == 0) @@ -1355,7 +1453,7 @@ int main(int argc, char *argv[]) != -1) { switch (opt) { case 'a': - all = 1; + all_modules = 1; break; case 'A': maybe_all = 1; @@ -1434,92 +1532,10 @@ int main(int argc, char *argv[]) /* Depmod -a by default if no names. */ if (optind == argc) - all = 1; - - nofail_asprintf(&dirname, "%s%s%s", basedir, MODULE_DIR, version); - - if (maybe_all) { - if (!doing_stdout && !depfile_out_of_date(dirname)) - exit(0); - all = 1; - } - - parse_toplevel_config(config, basedir, version, &search, &overrides); - - /* For backward compatibility add "updates" to the head of the search - * list here. But only if there was no "search" option specified. - */ - if (!search) { - char *dirname; - size_t len; - - nofail_asprintf(&dirname, "%s%s%s/updates", basedir, - MODULE_DIR, version); - len = strlen(dirname); - search = add_search(dirname, len, search); - } - if (!all) { - /* Do command line args. */ - for (opt = optind; opt < argc; opt++) { - struct module *new; - - if (argv[opt][0] != '/') - fatal("modules must be specified using absolute paths.\n" - "\"%s\" is a relative path\n", argv[opt]); - - new = grab_module(NULL, argv[opt]); - if (!new) { - /* cmd-line specified modules must exist */ - fatal("grab_module() failed for module %s\n", argv[opt]); - } - new->next = list; - list = new; - } - } else { - list = grab_basedir(dirname,search,overrides); - } - list = sort_modules(dirname,list); - list = parse_modules(list); - - for (i = 0; i < sizeof(depfiles)/sizeof(depfiles[0]); i++) { - FILE *out; - int res; - struct depfile *d = &depfiles[i]; - char depname[strlen(dirname) + 1 + strlen(d->name) + 1]; - char tmpname[strlen(dirname) + 1 + strlen(d->name) + - strlen(".temp") + 1]; + all_modules = 1; - if (d->map_file && !make_map_files && !force_map_files) - continue; - - sprintf(depname, "%s/%s", dirname, d->name); - sprintf(tmpname, "%s/%s.temp", dirname, d->name); - if (!doing_stdout) { - out = fopen(tmpname, "w"); - if (!out) - fatal("Could not open %s for writing: %s\n", - tmpname, strerror(errno)); - } else { - out = stdout; - if (ends_in(depname, ".bin")) - continue; - } - res = d->func(list, out, dirname); - if (doing_stdout) - continue; - fclose(out); - if (res) { - if (rename(tmpname, depname) < 0) - fatal("Could not rename %s into %s: %s\n", - tmpname, depname, strerror(errno)); - } else { - if (unlink(tmpname) < 0) - warn("Could not delete %s: %s\n", - tmpname, strerror(errno)); - } - } + do_module_dir(basedir, config, version, MODULE_DIR, argc, argv); - free(dirname); free(version); return 0; -- 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