From abd5557bd178a1813faace87b585a316892c60ee Mon Sep 17 00:00:00 2001 From: Lucas De Marchi Date: Sun, 19 Feb 2012 04:20:30 -0200 Subject: [PATCH] libkmod-module: probe: check if module exists for install cmds 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 | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/libkmod/libkmod-module.c b/libkmod/libkmod-module.c index 637b7921..69f1265f 100644 --- a/libkmod/libkmod-module.c +++ b/libkmod/libkmod-module.c @@ -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 -- 2.47.2