From: Lucas De Marchi Date: Thu, 14 Nov 2024 16:33:14 +0000 (-0600) Subject: depmod: Fix handling relative moduledir X-Git-Tag: v34~70 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a9e69c02d6c26edc9a8bae5ca2b7c4d9d21da9dc;p=thirdparty%2Fkmod.git depmod: Fix handling relative moduledir 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 Reviewed-by: Emil Velikov Link: https://github.com/kmod-project/kmod/pull/243 --- diff --git a/man/depmod.8.scd b/man/depmod.8.scd index c3d44279..a64ee97e 100644 --- a/man/depmod.8.scd +++ b/man/depmod.8.scd @@ -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/ diff --git a/tools/depmod.c b/tools/depmod.c index d85fa542..2238e5cd 100644 --- a/tools/depmod.c +++ b/tools/depmod.c @@ -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; }