From 804e5b4039f808b44beb04bc0fa11f47d5f68621 Mon Sep 17 00:00:00 2001 From: Alan Jenkins Date: Wed, 30 Sep 2009 17:30:41 +0100 Subject: [PATCH] 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//initstate is not available. Signed-off-by: Alan Jenkins --- modprobe.c | 18 ++++++++++++++---- 1 file 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) { -- 2.11.4.GIT