]> git.ipfire.org Git - thirdparty/kmod.git/commitdiff
depmod: Fix handling relative moduledir
authorLucas De Marchi <lucas.de.marchi@gmail.com>
Thu, 14 Nov 2024 16:33:14 +0000 (10:33 -0600)
committerLucas De Marchi <lucas.de.marchi@gmail.com>
Thu, 21 Nov 2024 04:25:30 +0000 (22:25 -0600)
Make sure moduledir is always relative to the basedir and document it as
such.

Note: scdoc 1.11.3 produces a strange result when trying to render the
man page for the 2 examples. Workaround that by ending with an explicit
newline, which produces another stranger behavior (but visually correct)
of indenting the next line.

Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/243
man/depmod.8.scd
tools/depmod.c

index c3d44279c60e8661ac7307d378e9ca5f9f458c6b..a64ee97e9f3b97d0b2c007badc22487c4b5cfdb1 100644 (file)
@@ -56,6 +56,9 @@ rather than the current kernel version (as returned by *uname -r*).
        distribution vendor who needs to pre-generate the meta-data files rather
        than running *depmod* again later.
 
+       If a relative path is given, it's relative to the current working
+       directory.
+
        Example:
                depmod -b /my/build/staging/dir/
 
@@ -69,13 +72,27 @@ rather than the current kernel version (as returned by *uname -r*).
        building *modules.dep* file in _basedir_ for a system that uses a
        different prefix, e.g. _/usr/lib/modules_ vs _/lib/modules_.
 
-       Example:
-               depmod -b /tmp/build -m /kernel-modules
+       Relative and absolute paths are accepted, but they are always relative
+       to the _basedir_.
+
+       Examples:
+               depmod -b /tmp/build -m /kernel-modules++
+depmod -b /tmp/build -m kernel-modules
 
        This expects all input files under
        _/tmp/build/kernel-modules/$(uname -r)_ and generates index files under
        that same directory.
 
+       Without an accompanying *-b* argument, the moduledir is relative to _/_.
+       Example:
+
+               depmod -m foo/bar
+
+       This expects all input files under _/foo/bar/$(uname -r)_ and generates
+       index files under the same directory. Unless libkmod is prepared to
+       handle that arbitrary location, it won't work in runtime.
+
+
 *-o* _outdir_, *--outdir* _outdir_
        Set the output directory where *depmod* will store any generated file.
        _outdir_ serves as a root to that location, similar to how _basedir_ is
@@ -83,6 +100,9 @@ rather than the current kernel version (as returned by *uname -r*).
        _basedir_ it will result in the input being that directory, but the output
        being the one set by _outdir_.
 
+       If a relative path is given, it's relative to the current working
+       directory.
+
        Example:
                depmod -o /my/build/staging/dir/
 
index d85fa5423f6a15d8916f0a2c5f7203a8eabe7b80..2238e5cd562e961a15d416e8735286626509c28b 100644 (file)
@@ -36,7 +36,6 @@
 #define DEFAULT_VERBOSE LOG_WARNING
 static int verbose = DEFAULT_VERBOSE;
 
-static const char *module_directory = MODULE_DIRECTORY;
 static const char CFG_BUILTIN_KEY[] = "built-in";
 static const char CFG_EXTERNAL_KEY[] = "external";
 static const char *const default_cfg_paths[] = {
@@ -2924,6 +2923,7 @@ static int do_depmod(int argc, char *argv[])
        const char *module_symvers = NULL;
        const char *null_kmod_config = NULL;
        const char *root = "";
+       const char *module_directory = MODULE_DIRECTORY;
        struct utsname un;
        struct kmod_ctx *ctx = NULL;
        struct cfg cfg;
@@ -3033,19 +3033,22 @@ static int do_depmod(int argc, char *argv[])
                cfg.kversion = un.release;
        }
 
-       cfg.dirnamelen = snprintf(cfg.dirname, PATH_MAX, "%s%s/%s", root,
+       /* module directory is always relative to basedir/outdir */
+       while (module_directory[0] == '/')
+               module_directory++;
+
+       cfg.dirnamelen = snprintf(cfg.dirname, PATH_MAX, "%s/%s/%s", root,
                                  module_directory, cfg.kversion);
        if (cfg.dirnamelen >= PATH_MAX) {
-               ERR("Bad directory %s%s/%s: path too long\n", root,
-                   module_directory, cfg.kversion);
+               ERR("Bad directory %s/%s/%s: path too long\n", root, module_directory,
+                   cfg.kversion);
                goto cmdline_failed;
        }
 
-       cfg.outdirnamelen = snprintf(cfg.outdirname, PATH_MAX, "%s%s/%s",
-                                    out_root ?: root, module_directory,
-                                    cfg.kversion);
+       cfg.outdirnamelen = snprintf(cfg.outdirname, PATH_MAX, "%s/%s/%s",
+                                    out_root ?: root, module_directory, cfg.kversion);
        if (cfg.outdirnamelen >= PATH_MAX) {
-               ERR("Bad directory %s%s/%s: path too long\n", out_root ?: root,
+               ERR("Bad directory %s/%s/%s: path too long\n", out_root ?: root,
                    module_directory, cfg.kversion);
                goto cmdline_failed;
        }