[PATCH 4/6] depmod: add pre-run hooks for alternatives

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

 



This lets us specify a script to run just before an alternative is processed.

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

diff --git a/depmod.c b/depmod.c
index 105df1c..6e33f5c 100644
--- a/depmod.c
+++ b/depmod.c
@@ -1366,6 +1366,7 @@ struct config_alternative
 	struct config_alternative *next;
 	char *module_dir;
 	char *config_file;
+	char *pre_run;
 };
 
 static void parse_alternative(const char *filename,
@@ -1375,7 +1376,7 @@ static void parse_alternative(const char *filename,
 	unsigned int linenum = 0;
 	FILE *cfile;
 	struct config_alternative *alt;
-	char *module_dir = NULL, *config_file = NULL;
+	char *module_dir = NULL, *config_file = NULL, *pre_run = NULL;
 
 	cfile = fopen(filename, "r");
 	if (!cfile) {
@@ -1409,6 +1410,13 @@ static void parse_alternative(const char *filename,
 			if (!tmp || *tmp == '\0' || config_file)
 				goto bad_file;
 			config_file = NOFAIL(strdup(tmp));
+		} else if (streq(cmd, "pre-run")) {
+			if (!ptr)
+				goto bad_file;
+			tmp = ptr + strspn(ptr, "\t ");
+			if (*tmp == '\0' || pre_run)
+				goto bad_file;
+			pre_run = NOFAIL(strdup(tmp));
 		} else {
 			goto bad_file;
 		}
@@ -1424,6 +1432,7 @@ static void parse_alternative(const char *filename,
 	alt = NOFAIL(malloc(sizeof(*alt)));
 	alt->module_dir = module_dir;
 	alt->config_file = config_file;
+	alt->pre_run = pre_run;
 
 	alt->next = *alts;
 	*alts = alt;
@@ -1468,10 +1477,22 @@ static void do_alternative(struct config_alternative *alt,
 	struct module *list = NULL;
 	struct module_search *search = NULL;
 	struct module_overrides *overrides = NULL;
-	int i, opt;
+	int i, opt, ret;
 	char *dirname;
 	int all_modules_here = all_modules;
 
+	if (alt->pre_run) {
+		if (doing_stdout)
+			warn("doing dry run, skipping pre-run command: %s\n", alt->pre_run);
+		else {
+			ret = system(alt->pre_run);
+			if (ret == -1 || !WIFEXITED(ret) || WEXITSTATUS(ret)) {
+				warn("skipping alternative due to failed pre-run command: %s\n", alt->pre_run);
+				return;
+			}
+		}
+	}
+
 	clear_symbolhash();
 
 	nofail_asprintf(&dirname, "%s%s/%s", basedir, alt->module_dir, version);
@@ -1665,6 +1686,7 @@ int main(int argc, char *argv[])
 	alts->next = NULL;
 	alts->module_dir = NOFAIL(strdup(MODULE_DIR));
 	alts->config_file = config ? NOFAIL(strdup(config)) : NULL;
+	alts->pre_run = NULL;
 
 	/* Read more alternatives from a directory, if present. */
 	parse_alternatives_dir("/etc/depmod.alternatives", &alts);
@@ -1678,6 +1700,7 @@ int main(int argc, char *argv[])
 		struct config_alternative *tmp = alt;
 		free(alt->module_dir);
 		free(alt->config_file);
+		free(alt->pre_run);
 		alt = alt->next;
 		free(tmp);
 	}
-- 
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