]> git.ipfire.org Git - thirdparty/dracut.git/commitdiff
dracut-install: fix relative paths in --kerneldir 284/head
authorArtem Savkov <asavkov@redhat.com>
Thu, 21 Sep 2017 08:36:58 +0000 (10:36 +0200)
committerArtem Savkov <asavkov@redhat.com>
Thu, 21 Sep 2017 09:27:23 +0000 (11:27 +0200)
kerneldirlen is used to modify absolute path returned by
kmod_module_get_path() while it is calculated on user-supplied
--kerneldir argument which can be a relative path.

Use kmod_get_dirname() to convert user-supplied path to the same format
as used by kmod_module_get_path().

This also allows to get rid of now useless strcmp checks that seem to
imply that /lib and /usr/lib are linked which is not always true.

install/dracut-install.c

index 2c20b4915eafeae5ada701cc0b6446afd32eb30f..95425e8dd011b78aaeed0af6e1da2de5c57aaa1a 100644 (file)
@@ -933,13 +933,6 @@ static int parse_argv(int argc, char *argv[])
                         break;
                 case ARG_KERNELDIR:
                         kerneldir = strdup(optarg);
-                        if ((strncmp("/lib/modules/", kerneldir, 13) != 0)
-                            && (strncmp("/usr/lib/modules/", kerneldir, 17) != 0)) {
-                                char *p;
-                                p = strstr(kerneldir, "/lib/modules/");
-                                if (p != NULL)
-                                        kerneldirlen = p - kerneldir;
-                        }
                         break;
                 case ARG_FIRMWAREDIRS:
                         firmwaredirs = strv_split(optarg, ":");
@@ -1399,9 +1392,17 @@ static int install_modules(int argc, char **argv)
         struct kmod_module *mod = NULL, *mod_o = NULL;
 
         const char *modname = NULL;
+        char *abskpath = NULL;
+        char *p;
         int i;
 
         ctx = kmod_new(kerneldir, NULL);
+        abskpath = kmod_get_dirname(ctx);
+
+        p = strstr(abskpath, "/lib/modules/");
+        if (p != NULL)
+                kerneldirlen = p - abskpath;
+
         if (arg_hostonly) {
                 char *modalias_file;
                 modalias_file = getenv("DRACUT_KERNEL_MODALIASES");