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 ; : ; }
diff --git a/libkmod/libkmod-module.c b/libkmod/libkmod-module.c
index 637b792..69f1265 100644
--- a/libkmod/libkmod-module.c
+++ b/libkmod/libkmod-module.c
@@ -1192,7 +1192,17 @@
 		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 @@
 				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 @@
 								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