libkmod-module: probe: check if module exists for install cmds
authorLucas De Marchi <lucas.demarchi@profusion.mobi>
Sun, 19 Feb 2012 06:20:30 +0000 (04:20 -0200)
committerLucas De Marchi <lucas.demarchi@profusion.mobi>
Wed, 22 Feb 2012 15:06:56 +0000 (13:06 -0200)
Mimic what module-init-tools was doing before running install commands:
check if a module with the same name is already loaded in kerne, and if
it is, bail out.

This fixes the issue with some install commands used in Debian with
alsa-base package:

install snd /sbin/modprobe --ignore-install snd && { /sbin/modprobe --quiet snd-ioctl32 ; /sbin/modprobe --quiet snd-seq ; }
install snd_rawmidi /sbin/modprobe --ignore-install snd-rawmidi && { /sbin/modprobe --quiet snd-seq-midi ; : ; }
install snd_emu10k1 /sbin/modprobe --ignore-install snd-emu10k1 && { /sbin/modprobe --quiet snd-emu10k1-synth ; : ; }
install snd_pcm modprobe --ignore-install snd-pcm $CMDLINE_OPTS && { modprobe --quiet snd-pcm-oss ; : ; }
install snd_mixer modprobe --ignore-install snd-mixer $CMDLINE_OPTS && { modprobe --quiet snd-mixer-oss ; : ; }
install snd_seq modprobe --ignore-install snd-seq $CMDLINE_OPTS && { modprobe --quiet snd-seq-midi ; modprobe --quiet snd-seq-oss ; : ; }

libkmod/libkmod-module.c

index 637b792..69f1265 100644 (file)
@@ -1192,7 +1192,17 @@ KMOD_EXPORT int kmod_module_probe_insert_module(struct kmod_module *mod,
                struct kmod_module *m = l->data;
                const char *moptions = kmod_module_get_options(m);
                const char *cmd = kmod_module_get_install_commands(m);
-               char *options = module_options_concat(moptions,
+               char *options;
+
+               if (!(flags & KMOD_PROBE_IGNORE_LOADED)
+                                               && module_is_inkernel(m)) {
+                       DBG(mod->ctx, "Ignoring module '%s': already loaded\n",
+                                                               m->name);
+                       err = -EEXIST;
+                       goto finish_module;
+               }
+
+               options = module_options_concat(moptions,
                                        m == mod ? extra_options : NULL);
 
                if (cmd != NULL && !m->ignorecmd) {
@@ -1203,13 +1213,6 @@ KMOD_EXPORT int kmod_module_probe_insert_module(struct kmod_module *mod,
                                err = module_do_install_commands(m, options,
                                                                        &cb);
                } else {
-                       if (!(flags & KMOD_PROBE_IGNORE_LOADED)
-                                               && module_is_inkernel(m)) {
-                               DBG(mod->ctx, "Ignoring module '%s': "
-                                               "already loaded\n", m->name);
-                               err = -EEXIST;
-                               goto finish_module;
-                       }
                        if (print_action != NULL)
                                print_action(m, false, options ?: "");
 
@@ -1218,9 +1221,9 @@ KMOD_EXPORT int kmod_module_probe_insert_module(struct kmod_module *mod,
                                                                options);
                }
 
-finish_module:
                free(options);
 
+finish_module:
                /*
                 * Treat "already loaded" error. If we were told to stop on
                 * already loaded and the module being loaded is not a softdep