aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlan Jenkins <alan-jenkins@tuffmail.co.uk>2009-09-30 17:30:41 +0100
committerAlan Jenkins <alan-jenkins@tuffmail.co.uk>2009-10-01 10:15:40 +0100
commit804e5b4039f808b44beb04bc0fa11f47d5f68621 (patch)
treec73f8e929d2e19d8e29afa0927be2ff4c5779605
parenta23b80e3d3f18a88630a6f01f06d4e5ba6acec43 (diff)
downloadmodule-init-tools-804e5b4039f808b44beb04bc0fa11f47d5f68621.tar.gz
modprobe: ignore custom remove commands if module_in_kernel() doesnt work
If we're not sure whether a module is present, we can't be sure that it is safe to run its remove command. This patch follows logically from the previous two patches. It provides the same safeguard which has been added for install commands, in case /sys/module/<module>/initstate is not available. Signed-off-by: Alan Jenkins <alan-jenkins@tuffmail.co.uk>
-rw-r--r--modprobe.c18
1 files changed, 14 insertions, 4 deletions
diff --git a/modprobe.c b/modprobe.c
index 8067e5c..9d1bb51 100644
--- a/modprobe.c
+++ b/modprobe.c
@@ -1286,6 +1286,7 @@ static void rmmod(struct list_head *list,
const char *command;
unsigned int usecount = 0;
struct module *mod = list_entry(list->next, struct module, list);
+ int exists;
/* Take first one off the list. */
list_del(&mod->list);
@@ -1294,15 +1295,24 @@ static void rmmod(struct list_head *list,
name = mod->modname;
/* Don't do ANYTHING if not loaded. */
- if (module_in_kernel(name, &usecount) == 0)
+ exists = module_in_kernel(name, &usecount);
+ if (exists == 0)
goto nonexistent_module;
/* Even if renamed, find commands to orig. name. */
command = find_command(mod->modname, commands);
if (command && !(flags & mit_ignore_commands)) {
- do_command(mod->modname, command, flags & mit_dry_run, error,
- "remove", cmdline_opts);
- goto remove_rest;
+ if (exists == -1) {
+ warn("/sys/module/ not present or too old,"
+ " and /proc/modules does not exist.\n");
+ warn("Ignoring remove commands for %s"
+ " in case it is not loaded.\n",
+ mod->modname);
+ } else {
+ do_command(mod->modname, command, flags & mit_dry_run,
+ error, "remove", cmdline_opts);
+ goto remove_rest;
+ }
}
if (usecount != 0) {