Hi, I've fixed some problems I found with the patch you suggested. Is it ok to include your Signed-off-by on this version, to credit you for the idea and the original patch? Thanks! Alan ----------- >From cecbd735024ae3e03a1d8e34d0be5edd7fa85b11 Mon Sep 17 00:00:00 2001 From: Alan Jenkins <alan-jenkins@xxxxxxxxxxxxxx> Date: Mon, 28 Sep 2009 20:32:12 +0100 Subject: [PATCH] modprobe: Ignore custom install commands if module_in_kernel() doesn't work Custom install commands rely on a working module_in_kernel() to avoid an infinite fork-loop. This fails when /sys/module/<module>/initstate is not available (e.g. before sysfs is mounted). For example: install snd-pcm /sbin/modprobe --ignore-install snd-pcm && \ { /sbin/modprobe --quiet snd-pcm-oss ; : ; } The snd-pcm-oss module depends on snd-pcm. If we can't tell that snd-pcm is already loaded when we load snd-pcm-oss, we end up running the entire install command again, ad infinitim. The original patch needed some fixes - is_loaded would never be set to -1 due to operator precedence - passing a warning message to error() would abort the process when the error function is fatal (use warn() instead). - the fd of the module file would be leaked. I have also tried to make the warning message more explicit about what causes the warning. Signed-off-by: Modestas Vainius <modestas@xxxxxxxxxx> Signed-off-by: Alan Jenkins <alan-jenkins@xxxxxxxxxxxxxx> --- modprobe.c | 21 +++++++++++++++------ 1 files changed, 15 insertions(+), 6 deletions(-) diff --git a/modprobe.c b/modprobe.c index 21a3111..34eaf20 100644 --- a/modprobe.c +++ b/modprobe.c @@ -1095,6 +1095,7 @@ static int insmod(struct list_head *list, const char *command; struct module *mod = list_entry(list->next, struct module, list); int rc = 0; + int already_loaded; /* Take us off the list. */ list_del(&mod->list); @@ -1121,8 +1122,9 @@ static int insmod(struct list_head *list, } /* Don't do ANYTHING if already in kernel. */ - if (!(flags & mit_ignore_loaded) - && module_in_kernel(newname ?: mod->modname, NULL) == 1) { + already_loaded = module_in_kernel(newname ?: mod->modname, NULL); + + if (!(flags & mit_ignore_loaded) && already_loaded == 1) { if (flags & mit_first_time) error("Module %s already in kernel.\n", newname ?: mod->modname); @@ -1131,10 +1133,17 @@ static int insmod(struct list_head *list, command = find_command(mod->modname, commands); if (command && !(flags & mit_ignore_commands)) { - close_file(fd); - do_command(mod->modname, command, flags & mit_dry_run, error, - "install", cmdline_opts); - goto out_optstring; + if (already_loaded == -1) { + warn("Failed to read /sys/module/*/initstate.\n"); + warn("Ignoring install commands for %s" + " in case it is already loaded.\n", + newname ?: mod->modname); + } else { + close_file(fd); + do_command(mod->modname, command, flags & mit_dry_run, + error, "install", cmdline_opts); + goto out_optstring; + } } module = grab_elf_file_fd(mod->filename, fd); -- 1.6.3.2 -- 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