]> git.ipfire.org Git - thirdparty/dracut.git/commitdiff
dracut-install: fallback to non-hostonly mode if lsmod fails
authorHarald Hoyer <harald@redhat.com>
Thu, 8 Sep 2016 13:55:21 +0000 (15:55 +0200)
committerHarald Hoyer <harald@redhat.com>
Thu, 13 Oct 2016 07:19:29 +0000 (09:19 +0200)
if libkmod fails to get the list of loaded modules, fallback
to non-hostonly mode, to at least try to assemble a working initrd.

install/dracut-install.c

index 0cffa399105a3a4d3a772b6b9e6295a0f65a64fc..fe30bbac0c5c76d0f0a197b9164217c54e7a61fa 100644 (file)
@@ -1288,38 +1288,40 @@ static int install_modules(int argc, char **argv)
 
         ctx = kmod_new(kerneldir, NULL);
 
-        err = kmod_module_new_from_loaded(ctx, &loaded_list);
-        if (err < 0) {
-                errno = err;
-                log_error("Could not get list of loaded modules: %m");
-                return err;
-        }
-
-        kmod_list_foreach(itr, loaded_list) {
-                _cleanup_kmod_module_unref_list_ struct kmod_list *modlist = NULL;
+        if (arg_hostonly) {
+                err = kmod_module_new_from_loaded(ctx, &loaded_list);
+                if (err < 0) {
+                        errno = err;
+                        log_error("Could not get list of loaded modules: %m. Switching to non-hostonly mode.");
+                        arg_hostonly = false;
+                } else {
+                        kmod_list_foreach(itr, loaded_list) {
+                                _cleanup_kmod_module_unref_list_ struct kmod_list *modlist = NULL;
 
-                struct kmod_module *mod = kmod_module_get_module(itr);
-                char *name = strdup(kmod_module_get_name(mod));
-                hashmap_put(modules_loaded, name, name);
-                kmod_module_unref(mod);
+                                struct kmod_module *mod = kmod_module_get_module(itr);
+                                char *name = strdup(kmod_module_get_name(mod));
+                                hashmap_put(modules_loaded, name, name);
+                                kmod_module_unref(mod);
 
-                /* also put the modules from the new kernel in the hashmap,
-                 * which resolve the name as an alias, in case a kernel module is
-                 * renamed.
-                 */
-                err = kmod_module_new_from_lookup(ctx, name, &modlist);
-                if (err < 0)
-                        continue;
-                if (!modlist)
-                        continue;
-                kmod_list_foreach(l, modlist) {
-                        mod = kmod_module_get_module(l);
-                        char *name = strdup(kmod_module_get_name(mod));
-                        hashmap_put(modules_loaded, name, name);
-                        kmod_module_unref(mod);
+                                /* also put the modules from the new kernel in the hashmap,
+                                 * which resolve the name as an alias, in case a kernel module is
+                                 * renamed.
+                                 */
+                                err = kmod_module_new_from_lookup(ctx, name, &modlist);
+                                if (err < 0)
+                                        continue;
+                                if (!modlist)
+                                        continue;
+                                kmod_list_foreach(l, modlist) {
+                                        mod = kmod_module_get_module(l);
+                                        char *name = strdup(kmod_module_get_name(mod));
+                                        hashmap_put(modules_loaded, name, name);
+                                        kmod_module_unref(mod);
+                                }
+                        }
+                        kmod_module_unref_list(loaded_list);
                 }
         }
-        kmod_module_unref_list(loaded_list);
 
         for (i = 0; i < argc; i++) {
                 int r = 0;