[PATCH 07/14] depmod: process a list of config_alternatives

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



So far the only alternative is one which provides the original depmod behavior.

Signed-off-by: Keegan McAllister <keegan@xxxxxxxxxxx>
---
 depmod.c |   42 ++++++++++++++++++++++++++++++++++++------
 1 files changed, 36 insertions(+), 6 deletions(-)

diff --git a/depmod.c b/depmod.c
index 8b03ac1..c6287f4 100644
--- a/depmod.c
+++ b/depmod.c
@@ -1336,6 +1336,8 @@ static void parse_toplevel_config(const char *filename,
 		return;
 	}
 
+	/* If filename == NULL, use the default config files. */
+
 	/* deprecated config file */
 	if (parse_config_file("/etc/depmod.conf", basedir, module_dir,
 			      kernelversion, search, overrides) > 0)
@@ -1347,8 +1349,15 @@ static void parse_toplevel_config(const char *filename,
 			  search, overrides);
 }
 
-static void do_module_dir(const char *basedir, const char *config,
-			  const char *version, const char *module_dir,
+struct config_alternative
+{
+	struct config_alternative *next;
+	char *module_dir;
+	char *config_file;
+};
+
+static void do_alternative(struct config_alternative *alt,
+			  const char *basedir, const char *version,
 			  int argc, char *argv[])
 {
 	struct module *list = NULL;
@@ -1359,7 +1368,7 @@ static void do_module_dir(const char *basedir, const char *config,
 
 	clear_symbolhash();
 
-	nofail_asprintf(&dirname, "%s%s%s", basedir, module_dir, version);
+	nofail_asprintf(&dirname, "%s%s%s", basedir, alt->module_dir, version);
 
 	if (maybe_all) {
 		if (!doing_stdout && !depfile_out_of_date(dirname))
@@ -1367,7 +1376,8 @@ static void do_module_dir(const char *basedir, const char *config,
 		all_modules = 1;
 	}
 
-	parse_toplevel_config(config, basedir, module_dir, version, &search, &overrides);
+	parse_toplevel_config(alt->config_file, basedir, alt->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.
@@ -1377,7 +1387,7 @@ static void do_module_dir(const char *basedir, const char *config,
 		size_t len;
 
 		nofail_asprintf(&dirname, "%s%s%s/updates", basedir,
-				module_dir, version);
+				alt->module_dir, version);
 		len = strlen(dirname);
 		search = add_search(dirname, len, search);
 	}
@@ -1452,6 +1462,7 @@ int main(int argc, char *argv[])
 	char *system_map = NULL, *module_symvers = NULL;
 	char *basedir = "", *version;
 	const char *config = NULL;
+	struct config_alternative *alts, *alt;
 
 	if (native_endianness() == 0)
 		abort();
@@ -1541,7 +1552,26 @@ int main(int argc, char *argv[])
 	if (optind == argc)
 		all_modules = 1;
 
-	do_module_dir(basedir, config, version, MODULE_DIR, argc, argv);
+	/* Make an alternative for the original depmod behavior.
+	   This is the alternative which -C affects.
+	   config_file = NULL specifies the default config files. */
+	alts = NOFAIL(malloc(sizeof(*alts)));
+	alts->next = NULL;
+	alts->module_dir = NOFAIL(strdup(MODULE_DIR));
+	alts->config_file = config ? NOFAIL(strdup(config)) : NULL;
+
+	/* Process each alternative */
+	for (alt = alts; alt; alt = alt->next)
+		do_alternative(alt, basedir, version, argc, argv);
+
+	/* Free the alternatives */
+	for (alt = alts; alt;) {
+		struct config_alternative *tmp = alt;
+		free(alt->module_dir);
+		free(alt->config_file);
+		alt = alt->next;
+		free(tmp);
+	}
 
 	free(version);
 	
-- 
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


[Index of Archives]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Big List of Linux Books]

  Powered by Linux