From cb784d4f70cd49565a934bfae87373fe495adec8 Mon Sep 17 00:00:00 2001 From: Michal Suchanek Date: Fri, 26 May 2023 10:38:05 +0200 Subject: [PATCH 8/9] libkmod, depmod, modprobe: Search for kernel modules under ${module_prefix} modprobe.d is now searched under ${prefix}/lib, add ${module_prefix} to specify the directory where to search for kernel modules. With this distributions that do not want to ship files in /lib can also move kernel modules to /usr while others can keep them in /lib. Signed-off-by: Michal Suchanek --- Makefile.am | 3 configure.ac | 7 ++ libkmod/libkmod.c | 6 - man/Makefile.am | 1 man/depmod.d.xml | 6 - man/depmod.xml | 4 - man/modinfo.xml | 2 man/modprobe.xml | 2 man/modules.dep.xml | 6 - testsuite/module-playground/Makefile | 2 testsuite/setup-rootfs.sh | 109 +++++++++++++++++++---------------- testsuite/test-depmod.c | 16 ++--- testsuite/test-testsuite.c | 8 +- tools/depmod.c | 13 +++- tools/kmod.c | 1 tools/modinfo.c | 4 - tools/modprobe.c | 4 - tools/static-nodes.c | 6 - 18 files changed, 116 insertions(+), 84 deletions(-) Index: kmod-30/Makefile.am =================================================================== --- kmod-30.orig/Makefile.am +++ kmod-30/Makefile.am @@ -20,6 +20,7 @@ AM_CPPFLAGS = \ -I$(top_srcdir) \ -DSYSCONFDIR=\""$(sysconfdir)"\" \ -DPREFIX=\""$(prefix)"\" \ + -DMODULE_PREFIX=\""$(module_prefix)"\" \ ${zlib_CFLAGS} AM_CFLAGS = $(OUR_CFLAGS) @@ -247,7 +248,7 @@ EXTRA_DIST += testsuite/setup-rootfs.sh MODULE_PLAYGROUND = testsuite/module-playground ROOTFS = testsuite/rootfs ROOTFS_PRISTINE = $(top_srcdir)/testsuite/rootfs-pristine -CREATE_ROOTFS = $(AM_V_GEN) $(top_srcdir)/testsuite/setup-rootfs.sh $(ROOTFS_PRISTINE) $(ROOTFS) $(MODULE_PLAYGROUND) $(top_builddir)/config.h $(sysconfdir) +CREATE_ROOTFS = $(AM_V_GEN) MODULE_PREFIX=$(module_prefix) $(top_srcdir)/testsuite/setup-rootfs.sh $(ROOTFS_PRISTINE) $(ROOTFS) $(MODULE_PLAYGROUND) $(top_builddir)/config.h $(sysconfdir) build-module-playground: $(AM_V_GEN)if test "$(top_srcdir)" != "$(top_builddir)"; then \ Index: kmod-30/configure.ac =================================================================== --- kmod-30.orig/configure.ac +++ kmod-30/configure.ac @@ -83,6 +83,12 @@ AC_ARG_WITH([rootlibdir], [], [with_rootlibdir=$libdir]) AC_SUBST([rootlibdir], [$with_rootlibdir]) +# Ideally this would be $prefix but default to empty for compatibility with earlier versions +AC_ARG_WITH([module_prefix], + AS_HELP_STRING([--with-module-prefix=DIR], [directory in which to look for /lib/modules directory with kernel modules - typically '' or ${prefix}]), + [], [with_module_prefix=]) +AC_SUBST([module_prefix], [$with_module_prefix]) + AC_ARG_WITH([zstd], AS_HELP_STRING([--with-zstd], [handle Zstandard-compressed modules @<:@default=disabled@:>@]), [], [with_zstd=no]) @@ -302,6 +308,7 @@ AC_MSG_RESULT([ ======= prefix: ${prefix} + module_prefix: ${module_prefix} sysconfdir: ${sysconfdir} libdir: ${libdir} rootlibdir: ${rootlibdir} Index: kmod-30/libkmod/libkmod.c =================================================================== --- kmod-30.orig/libkmod/libkmod.c +++ kmod-30/libkmod/libkmod.c @@ -209,7 +209,7 @@ static int log_priority(const char *prio return 0; } -static const char *dirname_default_prefix = "/lib/modules"; +static const char *dirname_default_prefix = MODULE_PREFIX "/lib/modules"; static char *get_kernel_release(const char *dirname) { @@ -231,14 +231,14 @@ static char *get_kernel_release(const ch /** * kmod_new: * @dirname: what to consider as linux module's directory, if NULL - * defaults to /lib/modules/`uname -r`. If it's relative, + * defaults to ${module_prefix}/lib/modules/`uname -r`. If it's relative, * it's treated as relative to the current working directory. * Otherwise, give an absolute dirname. * @config_paths: ordered array of paths (directories or files) where * to load from user-defined configuration parameters such as * alias, blacklists, commands (install, remove). If NULL * defaults to /etc/modprobe.d, /run/modprobe.d, - * /usr/local/lib/modprobe.d and PREFIX/lib/modprobe.d. Give an empty + * /usr/local/lib/modprobe.d and ${module_prefix}/lib/modprobe.d. Give an empty * vector if configuration should not be read. This array must * be null terminated. * Index: kmod-30/man/Makefile.am =================================================================== --- kmod-30.orig/man/Makefile.am +++ kmod-30/man/Makefile.am @@ -22,6 +22,7 @@ CLEANFILES = $(dist_man_MANS) else \ sed -e '/@PREFIX@/d' $< ; \ fi | \ + sed -e 's|@MODULE_PREFIX@|$(module_prefix)|g' | \ $(XSLT) \ -o $@ \ --nonet \ Index: kmod-30/man/depmod.d.xml =================================================================== --- kmod-30.orig/man/depmod.d.xml +++ kmod-30/man/depmod.d.xml @@ -70,7 +70,7 @@ - This allows you to specify the order in which /lib/modules + This allows you to specify the order in which @MODULE_PREFIX@/lib/modules (or other configured module location) subdirectories will be processed by depmod. Directories are listed in order, with the highest priority given to the @@ -101,7 +101,7 @@ depmod command. It is possible to specify one kernel or all kernels using the * wildcard. modulesubdirectory is the - name of the subdirectory under /lib/modules (or other + name of the subdirectory under @MODULE_PREFIX@/lib/modules (or other module location) where the target module is installed. @@ -110,7 +110,7 @@ specifying the following command: "override kmod * extra". This will ensure that any matching module name installed under the extra subdirectory within - /lib/modules (or other module location) will take priority + @MODULE_PREFIX@/lib/modules (or other module location) will take priority over any likenamed module already provided by the kernel. Index: kmod-30/man/depmod.xml =================================================================== --- kmod-30.orig/man/depmod.xml +++ kmod-30/man/depmod.xml @@ -80,7 +80,7 @@ depmod creates a list of module dependencies by reading each module under - /lib/modules/version and + @MODULE_PREFIX@/lib/modules/version and determining what symbols it exports and what symbols it needs. By default, this list is written to modules.dep, and a binary hashed version named modules.dep.bin, in the @@ -141,7 +141,7 @@ If your modules are not currently in the (normal) directory - /lib/modules/version, + @MODULE_PREFIX@/lib/modules/version, but in a staging area, you can specify a basedir which is prepended to the directory name. This basedir is Index: kmod-30/man/modinfo.xml =================================================================== --- kmod-30.orig/man/modinfo.xml +++ kmod-30/man/modinfo.xml @@ -54,7 +54,7 @@ modinfo extracts information from the Linux Kernel modules given on the command line. If the module name is not a filename, then the - /lib/modules/version + @MODULE_PREFIX@/lib/modules/version directory is searched, as is also done by modprobe8 when loading kernel modules. Index: kmod-30/man/modprobe.xml =================================================================== --- kmod-30.orig/man/modprobe.xml +++ kmod-30/man/modprobe.xml @@ -78,7 +78,7 @@ is no difference between _ and - in module names (automatic underscore conversion is performed). modprobe looks in the module directory - /lib/modules/`uname -r` for all + @MODULE_PREFIX@/lib/modules/`uname -r` for all the modules and other files, except for the optional configuration files in the /etc/modprobe.d directory Index: kmod-30/man/modules.dep.xml =================================================================== --- kmod-30.orig/man/modules.dep.xml +++ kmod-30/man/modules.dep.xml @@ -34,8 +34,8 @@ - /lib/modules/modules.dep - /lib/modules/modules.dep.bin + @MODULE_PREFIX@/lib/modules/modules.dep + @MODULE_PREFIX@/lib/modules/modules.dep.bin DESCRIPTION @@ -43,7 +43,7 @@ modules.dep.bin is a binary file generated by depmod listing the dependencies for every module in the directories under - /lib/modules/version. + @MODULE_PREFIX@/lib/modules/version. It is used by kmod tools such as modprobe and libkmod. Index: kmod-30/testsuite/module-playground/Makefile =================================================================== --- kmod-30.orig/testsuite/module-playground/Makefile +++ kmod-30/testsuite/module-playground/Makefile @@ -47,7 +47,7 @@ endif else # normal makefile -KDIR ?= /lib/modules/`uname -r`/build +KDIR ?= $(module_prefix)/lib/modules/`uname -r`/build KVER ?= `uname -r` ifeq ($(FAKE_BUILD),) FAKE_BUILD=0 Index: kmod-30/testsuite/setup-rootfs.sh =================================================================== --- kmod-30.orig/testsuite/setup-rootfs.sh +++ kmod-30/testsuite/setup-rootfs.sh @@ -16,6 +16,19 @@ create_rootfs() { cp -r "$ROOTFS_PRISTINE" "$ROOTFS" find "$ROOTFS" -type d -exec chmod +w {} \; find "$ROOTFS" -type f -name .gitignore -exec rm -f {} \; + if [ -n "$MODULE_PREFIX" ] ; then + sed -i -e "s|/lib/modules|$MODULE_PREFIX/lib/modules|g" $(find "$ROOTFS" -name \*.txt -o -name \*.conf -o -name \*.dep) + sed -i -e "s|$MODULE_PREFIX/lib/modules/external|/lib/modules/external|g" $(find "$ROOTFS" -name \*.txt -o -name \*.conf -o -name \*.dep) + for i in "$ROOTFS"/*/lib/modules/* "$ROOTFS"/*/*/lib/modules/* ; do + version=$(basename $i) + [ $version != 'external' ] || continue + i=$(dirname $i) + lib="$(dirname $i)" + up="$(dirname $lib)$MODULE_PREFIX" + mkdir -p "$up" + mv "$lib" "$up" + done + fi if [ "$SYSCONFDIR" != "/etc" ]; then find "$ROOTFS" -type d -name etc -printf "%h\n" | while read -r e; do @@ -32,55 +45,55 @@ feature_enabled() { declare -A map map=( - ["test-depmod/search-order-simple/lib/modules/4.4.4/kernel/crypto/"]="mod-simple.ko" - ["test-depmod/search-order-simple/lib/modules/4.4.4/updates/"]="mod-simple.ko" - ["test-depmod/search-order-same-prefix/lib/modules/4.4.4/foo/"]="mod-simple.ko" - ["test-depmod/search-order-same-prefix/lib/modules/4.4.4/foobar/"]="mod-simple.ko" - ["test-depmod/detect-loop/lib/modules/4.4.4/kernel/mod-loop-a.ko"]="mod-loop-a.ko" - ["test-depmod/detect-loop/lib/modules/4.4.4/kernel/mod-loop-b.ko"]="mod-loop-b.ko" - ["test-depmod/detect-loop/lib/modules/4.4.4/kernel/mod-loop-c.ko"]="mod-loop-c.ko" - ["test-depmod/detect-loop/lib/modules/4.4.4/kernel/mod-loop-d.ko"]="mod-loop-d.ko" - ["test-depmod/detect-loop/lib/modules/4.4.4/kernel/mod-loop-e.ko"]="mod-loop-e.ko" - ["test-depmod/detect-loop/lib/modules/4.4.4/kernel/mod-loop-f.ko"]="mod-loop-f.ko" - ["test-depmod/detect-loop/lib/modules/4.4.4/kernel/mod-loop-g.ko"]="mod-loop-g.ko" - ["test-depmod/detect-loop/lib/modules/4.4.4/kernel/mod-loop-h.ko"]="mod-loop-h.ko" - ["test-depmod/detect-loop/lib/modules/4.4.4/kernel/mod-loop-i.ko"]="mod-loop-i.ko" - ["test-depmod/detect-loop/lib/modules/4.4.4/kernel/mod-loop-j.ko"]="mod-loop-j.ko" - ["test-depmod/detect-loop/lib/modules/4.4.4/kernel/mod-loop-k.ko"]="mod-loop-k.ko" - ["test-depmod/search-order-external-first/lib/modules/4.4.4/foo/"]="mod-simple.ko" - ["test-depmod/search-order-external-first/lib/modules/4.4.4/foobar/"]="mod-simple.ko" + ["test-depmod/search-order-simple$MODULE_PREFIX/lib/modules/4.4.4/kernel/crypto/"]="mod-simple.ko" + ["test-depmod/search-order-simple$MODULE_PREFIX/lib/modules/4.4.4/updates/"]="mod-simple.ko" + ["test-depmod/search-order-same-prefix$MODULE_PREFIX/lib/modules/4.4.4/foo/"]="mod-simple.ko" + ["test-depmod/search-order-same-prefix$MODULE_PREFIX/lib/modules/4.4.4/foobar/"]="mod-simple.ko" + ["test-depmod/detect-loop$MODULE_PREFIX/lib/modules/4.4.4/kernel/mod-loop-a.ko"]="mod-loop-a.ko" + ["test-depmod/detect-loop$MODULE_PREFIX/lib/modules/4.4.4/kernel/mod-loop-b.ko"]="mod-loop-b.ko" + ["test-depmod/detect-loop$MODULE_PREFIX/lib/modules/4.4.4/kernel/mod-loop-c.ko"]="mod-loop-c.ko" + ["test-depmod/detect-loop$MODULE_PREFIX/lib/modules/4.4.4/kernel/mod-loop-d.ko"]="mod-loop-d.ko" + ["test-depmod/detect-loop$MODULE_PREFIX/lib/modules/4.4.4/kernel/mod-loop-e.ko"]="mod-loop-e.ko" + ["test-depmod/detect-loop$MODULE_PREFIX/lib/modules/4.4.4/kernel/mod-loop-f.ko"]="mod-loop-f.ko" + ["test-depmod/detect-loop$MODULE_PREFIX/lib/modules/4.4.4/kernel/mod-loop-g.ko"]="mod-loop-g.ko" + ["test-depmod/detect-loop$MODULE_PREFIX/lib/modules/4.4.4/kernel/mod-loop-h.ko"]="mod-loop-h.ko" + ["test-depmod/detect-loop$MODULE_PREFIX/lib/modules/4.4.4/kernel/mod-loop-i.ko"]="mod-loop-i.ko" + ["test-depmod/detect-loop$MODULE_PREFIX/lib/modules/4.4.4/kernel/mod-loop-j.ko"]="mod-loop-j.ko" + ["test-depmod/detect-loop$MODULE_PREFIX/lib/modules/4.4.4/kernel/mod-loop-k.ko"]="mod-loop-k.ko" + ["test-depmod/search-order-external-first$MODULE_PREFIX/lib/modules/4.4.4/foo/"]="mod-simple.ko" + ["test-depmod/search-order-external-first$MODULE_PREFIX/lib/modules/4.4.4/foobar/"]="mod-simple.ko" ["test-depmod/search-order-external-first/lib/modules/external/"]="mod-simple.ko" - ["test-depmod/search-order-external-last/lib/modules/4.4.4/foo/"]="mod-simple.ko" - ["test-depmod/search-order-external-last/lib/modules/4.4.4/foobar/"]="mod-simple.ko" + ["test-depmod/search-order-external-last$MODULE_PREFIX/lib/modules/4.4.4/foo/"]="mod-simple.ko" + ["test-depmod/search-order-external-last$MODULE_PREFIX/lib/modules/4.4.4/foobar/"]="mod-simple.ko" ["test-depmod/search-order-external-last/lib/modules/external/"]="mod-simple.ko" - ["test-depmod/search-order-override/lib/modules/4.4.4/foo/"]="mod-simple.ko" - ["test-depmod/search-order-override/lib/modules/4.4.4/override/"]="mod-simple.ko" - ["test-dependencies/lib/modules/4.0.20-kmod/kernel/fs/foo/"]="mod-foo-b.ko" - ["test-dependencies/lib/modules/4.0.20-kmod/kernel/"]="mod-foo-c.ko" - ["test-dependencies/lib/modules/4.0.20-kmod/kernel/lib/"]="mod-foo-a.ko" - ["test-dependencies/lib/modules/4.0.20-kmod/kernel/fs/"]="mod-foo.ko" + ["test-depmod/search-order-override$MODULE_PREFIX/lib/modules/4.4.4/foo/"]="mod-simple.ko" + ["test-depmod/search-order-override$MODULE_PREFIX/lib/modules/4.4.4/override/"]="mod-simple.ko" + ["test-dependencies$MODULE_PREFIX/lib/modules/4.0.20-kmod/kernel/fs/foo/"]="mod-foo-b.ko" + ["test-dependencies$MODULE_PREFIX/lib/modules/4.0.20-kmod/kernel/"]="mod-foo-c.ko" + ["test-dependencies$MODULE_PREFIX/lib/modules/4.0.20-kmod/kernel/lib/"]="mod-foo-a.ko" + ["test-dependencies$MODULE_PREFIX/lib/modules/4.0.20-kmod/kernel/fs/"]="mod-foo.ko" ["test-init/"]="mod-simple.ko" ["test-remove/"]="mod-simple.ko" - ["test-modprobe/show-depends/lib/modules/4.4.4/kernel/mod-loop-a.ko"]="mod-loop-a.ko" - ["test-modprobe/show-depends/lib/modules/4.4.4/kernel/mod-loop-b.ko"]="mod-loop-b.ko" - ["test-modprobe/show-depends/lib/modules/4.4.4/kernel/mod-simple.ko"]="mod-simple.ko" + ["test-modprobe/show-depends$MODULE_PREFIX/lib/modules/4.4.4/kernel/mod-loop-a.ko"]="mod-loop-a.ko" + ["test-modprobe/show-depends$MODULE_PREFIX/lib/modules/4.4.4/kernel/mod-loop-b.ko"]="mod-loop-b.ko" + ["test-modprobe/show-depends$MODULE_PREFIX/lib/modules/4.4.4/kernel/mod-simple.ko"]="mod-simple.ko" ["test-modprobe/show-exports/mod-loop-a.ko"]="mod-loop-a.ko" - ["test-modprobe/softdep-loop/lib/modules/4.4.4/kernel/mod-loop-a.ko"]="mod-loop-a.ko" - ["test-modprobe/softdep-loop/lib/modules/4.4.4/kernel/mod-loop-b.ko"]="mod-loop-b.ko" - ["test-modprobe/install-cmd-loop/lib/modules/4.4.4/kernel/mod-loop-a.ko"]="mod-loop-a.ko" - ["test-modprobe/install-cmd-loop/lib/modules/4.4.4/kernel/mod-loop-b.ko"]="mod-loop-b.ko" - ["test-modprobe/force/lib/modules/4.4.4/kernel/"]="mod-simple.ko" - ["test-modprobe/oldkernel/lib/modules/3.3.3/kernel/"]="mod-simple.ko" - ["test-modprobe/oldkernel-force/lib/modules/3.3.3/kernel/"]="mod-simple.ko" - ["test-modprobe/alias-to-none/lib/modules/4.4.4/kernel/"]="mod-simple.ko" - ["test-modprobe/module-param-kcmdline/lib/modules/4.4.4/kernel/"]="mod-simple.ko" + ["test-modprobe/softdep-loop$MODULE_PREFIX/lib/modules/4.4.4/kernel/mod-loop-a.ko"]="mod-loop-a.ko" + ["test-modprobe/softdep-loop$MODULE_PREFIX/lib/modules/4.4.4/kernel/mod-loop-b.ko"]="mod-loop-b.ko" + ["test-modprobe/install-cmd-loop$MODULE_PREFIX/lib/modules/4.4.4/kernel/mod-loop-a.ko"]="mod-loop-a.ko" + ["test-modprobe/install-cmd-loop$MODULE_PREFIX/lib/modules/4.4.4/kernel/mod-loop-b.ko"]="mod-loop-b.ko" + ["test-modprobe/force$MODULE_PREFIX/lib/modules/4.4.4/kernel/"]="mod-simple.ko" + ["test-modprobe/oldkernel$MODULE_PREFIX/lib/modules/3.3.3/kernel/"]="mod-simple.ko" + ["test-modprobe/oldkernel-force$MODULE_PREFIX/lib/modules/3.3.3/kernel/"]="mod-simple.ko" + ["test-modprobe/alias-to-none$MODULE_PREFIX/lib/modules/4.4.4/kernel/"]="mod-simple.ko" + ["test-modprobe/module-param-kcmdline$MODULE_PREFIX/lib/modules/4.4.4/kernel/"]="mod-simple.ko" ["test-modprobe/external/lib/modules/external/"]="mod-simple.ko" - ["test-depmod/modules-order-compressed/lib/modules/4.4.4/kernel/drivers/block/cciss.ko"]="mod-fake-cciss.ko" - ["test-depmod/modules-order-compressed/lib/modules/4.4.4/kernel/drivers/scsi/hpsa.ko"]="mod-fake-hpsa.ko" - ["test-depmod/modules-order-compressed/lib/modules/4.4.4/kernel/drivers/scsi/scsi_mod.ko"]="mod-fake-scsi-mod.ko" - ["test-depmod/modules-outdir/lib/modules/4.4.4/kernel/drivers/block/cciss.ko"]="mod-fake-cciss.ko" - ["test-depmod/modules-outdir/lib/modules/4.4.4/kernel/drivers/scsi/hpsa.ko"]="mod-fake-hpsa.ko" - ["test-depmod/modules-outdir/lib/modules/4.4.4/kernel/drivers/scsi/scsi_mod.ko"]="mod-fake-scsi-mod.ko" + ["test-depmod/modules-order-compressed$MODULE_PREFIX/lib/modules/4.4.4/kernel/drivers/block/cciss.ko"]="mod-fake-cciss.ko" + ["test-depmod/modules-order-compressed$MODULE_PREFIX/lib/modules/4.4.4/kernel/drivers/scsi/hpsa.ko"]="mod-fake-hpsa.ko" + ["test-depmod/modules-order-compressed$MODULE_PREFIX/lib/modules/4.4.4/kernel/drivers/scsi/scsi_mod.ko"]="mod-fake-scsi-mod.ko" + ["test-depmod/modules-outdir$MODULE_PREFIX/lib/modules/4.4.4/kernel/drivers/block/cciss.ko"]="mod-fake-cciss.ko" + ["test-depmod/modules-outdir$MODULE_PREFIX/lib/modules/4.4.4/kernel/drivers/scsi/hpsa.ko"]="mod-fake-hpsa.ko" + ["test-depmod/modules-outdir$MODULE_PREFIX/lib/modules/4.4.4/kernel/drivers/scsi/scsi_mod.ko"]="mod-fake-scsi-mod.ko" ["test-modinfo/mod-simple-i386.ko"]="mod-simple-i386.ko" ["test-modinfo/mod-simple-x86_64.ko"]="mod-simple-x86_64.ko" ["test-modinfo/mod-simple-sparc64.ko"]="mod-simple-sparc64.ko" @@ -88,20 +101,20 @@ map=( ["test-modinfo/mod-simple-sha256.ko"]="mod-simple.ko" ["test-modinfo/mod-simple-pkcs7.ko"]="mod-simple.ko" ["test-modinfo/external/lib/modules/external/mod-simple.ko"]="mod-simple.ko" - ["test-tools/insert/lib/modules/4.4.4/kernel/"]="mod-simple.ko" - ["test-tools/remove/lib/modules/4.4.4/kernel/"]="mod-simple.ko" + ["test-tools/insert$MODULE_PREFIX/lib/modules/4.4.4/kernel/"]="mod-simple.ko" + ["test-tools/remove$MODULE_PREFIX/lib/modules/4.4.4/kernel/"]="mod-simple.ko" ) gzip_array=( - "test-depmod/modules-order-compressed/lib/modules/4.4.4/kernel/drivers/block/cciss.ko" + "test-depmod/modules-order-compressed$MODULE_PREFIX/lib/modules/4.4.4/kernel/drivers/block/cciss.ko" ) xz_array=( - "test-depmod/modules-order-compressed/lib/modules/4.4.4/kernel/drivers/scsi/scsi_mod.ko" + "test-depmod/modules-order-compressed$MODULE_PREFIX/lib/modules/4.4.4/kernel/drivers/scsi/scsi_mod.ko" ) zstd_array=( - "test-depmod/modules-order-compressed/lib/modules/4.4.4/kernel/drivers/scsi/hpsa.ko" + "test-depmod/modules-order-compressed$MODULE_PREFIX/lib/modules/4.4.4/kernel/drivers/scsi/hpsa.ko" ) attach_sha256_array=( Index: kmod-30/testsuite/test-depmod.c =================================================================== --- kmod-30.orig/testsuite/test-depmod.c +++ kmod-30/testsuite/test-depmod.c @@ -27,7 +27,7 @@ #define MODULES_UNAME "4.4.4" #define MODULES_ORDER_ROOTFS TESTSUITE_ROOTFS "test-depmod/modules-order-compressed" -#define MODULES_ORDER_LIB_MODULES MODULES_ORDER_ROOTFS "/lib/modules/" MODULES_UNAME +#define MODULES_ORDER_LIB_MODULES MODULES_ORDER_ROOTFS MODULE_PREFIX "/lib/modules/" MODULES_UNAME static noreturn int depmod_modules_order_for_compressed(const struct test *t) { const char *progname = ABS_TOP_BUILDDIR "/tools/depmod"; @@ -55,8 +55,8 @@ DEFINE_TEST(depmod_modules_order_for_com }); #define MODULES_OUTDIR_ROOTFS TESTSUITE_ROOTFS "test-depmod/modules-outdir" -#define MODULES_OUTDIR_LIB_MODULES_OUTPUT MODULES_OUTDIR_ROOTFS "/outdir/lib/modules/" MODULES_UNAME -#define MODULES_OUTDIR_LIB_MODULES_INPUT MODULES_OUTDIR_ROOTFS "/lib/modules/" MODULES_UNAME +#define MODULES_OUTDIR_LIB_MODULES_OUTPUT MODULES_OUTDIR_ROOTFS "/outdir" MODULE_PREFIX "/lib/modules/" MODULES_UNAME +#define MODULES_OUTDIR_LIB_MODULES_INPUT MODULES_OUTDIR_ROOTFS MODULE_PREFIX "/lib/modules/" MODULES_UNAME static noreturn int depmod_modules_outdir(const struct test *t) { const char *progname = ABS_TOP_BUILDDIR "/tools/depmod"; @@ -87,7 +87,7 @@ DEFINE_TEST(depmod_modules_outdir, }); #define SEARCH_ORDER_SIMPLE_ROOTFS TESTSUITE_ROOTFS "test-depmod/search-order-simple" -#define SEARCH_ORDER_SIMPLE_LIB_MODULES SEARCH_ORDER_SIMPLE_ROOTFS "/lib/modules/" MODULES_UNAME +#define SEARCH_ORDER_SIMPLE_LIB_MODULES SEARCH_ORDER_SIMPLE_ROOTFS MODULE_PREFIX "/lib/modules/" MODULES_UNAME static noreturn int depmod_search_order_simple(const struct test *t) { const char *progname = ABS_TOP_BUILDDIR "/tools/depmod"; @@ -114,7 +114,7 @@ DEFINE_TEST(depmod_search_order_simple, }); #define SEARCH_ORDER_SAME_PREFIX_ROOTFS TESTSUITE_ROOTFS "test-depmod/search-order-same-prefix" -#define SEARCH_ORDER_SAME_PREFIX_LIB_MODULES SEARCH_ORDER_SAME_PREFIX_ROOTFS "/lib/modules/" MODULES_UNAME +#define SEARCH_ORDER_SAME_PREFIX_LIB_MODULES SEARCH_ORDER_SAME_PREFIX_ROOTFS MODULE_PREFIX "/lib/modules/" MODULES_UNAME static noreturn int depmod_search_order_same_prefix(const struct test *t) { const char *progname = ABS_TOP_BUILDDIR "/tools/depmod"; @@ -164,7 +164,7 @@ DEFINE_TEST(depmod_detect_loop, }); #define SEARCH_ORDER_EXTERNAL_FIRST_ROOTFS TESTSUITE_ROOTFS "test-depmod/search-order-external-first" -#define SEARCH_ORDER_EXTERNAL_FIRST_LIB_MODULES SEARCH_ORDER_EXTERNAL_FIRST_ROOTFS "/lib/modules/" MODULES_UNAME +#define SEARCH_ORDER_EXTERNAL_FIRST_LIB_MODULES SEARCH_ORDER_EXTERNAL_FIRST_ROOTFS MODULE_PREFIX "/lib/modules/" MODULES_UNAME static noreturn int depmod_search_order_external_first(const struct test *t) { const char *progname = ABS_TOP_BUILDDIR "/tools/depmod"; @@ -191,7 +191,7 @@ DEFINE_TEST(depmod_search_order_external }); #define SEARCH_ORDER_EXTERNAL_LAST_ROOTFS TESTSUITE_ROOTFS "test-depmod/search-order-external-last" -#define SEARCH_ORDER_EXTERNAL_LAST_LIB_MODULES SEARCH_ORDER_EXTERNAL_LAST_ROOTFS "/lib/modules/" MODULES_UNAME +#define SEARCH_ORDER_EXTERNAL_LAST_LIB_MODULES SEARCH_ORDER_EXTERNAL_LAST_ROOTFS MODULE_PREFIX "/lib/modules/" MODULES_UNAME static noreturn int depmod_search_order_external_last(const struct test *t) { const char *progname = ABS_TOP_BUILDDIR "/tools/depmod"; @@ -218,7 +218,7 @@ DEFINE_TEST(depmod_search_order_external }); #define SEARCH_ORDER_OVERRIDE_ROOTFS TESTSUITE_ROOTFS "test-depmod/search-order-override" -#define SEARCH_ORDER_OVERRIDE_LIB_MODULES SEARCH_ORDER_OVERRIDE_ROOTFS "/lib/modules/" MODULES_UNAME +#define SEARCH_ORDER_OVERRIDE_LIB_MODULES SEARCH_ORDER_OVERRIDE_ROOTFS MODULE_PREFIX "/lib/modules/" MODULES_UNAME static noreturn int depmod_search_order_override(const struct test *t) { const char *progname = ABS_TOP_BUILDDIR "/tools/depmod"; Index: kmod-30/testsuite/test-testsuite.c =================================================================== --- kmod-30.orig/testsuite/test-testsuite.c +++ kmod-30/testsuite/test-testsuite.c @@ -64,7 +64,7 @@ static int testsuite_rootfs_fopen(const char s[100]; int n; - fp = fopen("/lib/modules/a", "r"); + fp = fopen(MODULE_PREFIX "/lib/modules/a", "r"); if (fp == NULL) return EXIT_FAILURE;; @@ -89,7 +89,7 @@ static int testsuite_rootfs_open(const s char buf[100]; int fd, done; - fd = open("/lib/modules/a", O_RDONLY); + fd = open(MODULE_PREFIX "/lib/modules/a", O_RDONLY); if (fd < 0) return EXIT_FAILURE; @@ -121,12 +121,12 @@ static int testsuite_rootfs_stat_access( { struct stat st; - if (access("/lib/modules/a", F_OK) < 0) { + if (access(MODULE_PREFIX "/lib/modules/a", F_OK) < 0) { ERR("access failed: %m\n"); return EXIT_FAILURE; } - if (stat("/lib/modules/a", &st) < 0) { + if (stat(MODULE_PREFIX "/lib/modules/a", &st) < 0) { ERR("stat failed: %m\n"); return EXIT_FAILURE; } Index: kmod-30/tools/depmod.c =================================================================== --- kmod-30.orig/tools/depmod.c +++ kmod-30/tools/depmod.c @@ -911,7 +911,7 @@ struct vertex; struct mod { struct kmod_module *kmod; char *path; - const char *relpath; /* path relative to '$ROOT/lib/modules/$VER/' */ + const char *relpath; /* path relative to '$ROOT$MODULE_PREFIX/lib/modules/$VER/' */ char *uncrelpath; /* same as relpath but ending in .ko */ struct kmod_list *info_list; struct kmod_list *dep_sym_list; @@ -3024,12 +3024,21 @@ static int do_depmod(int argc, char *arg } cfg.dirnamelen = snprintf(cfg.dirname, PATH_MAX, - "%s/lib/modules/%s", + "%s" MODULE_PREFIX "/lib/modules/%s", root ?: "", cfg.kversion); cfg.outdirnamelen = snprintf(cfg.outdirname, PATH_MAX, + "%s" MODULE_PREFIX "/lib/modules/%s", + out_root ?: (root ?: ""), cfg.kversion); + struct stat sb; + if (stat(cfg.dirname, &sb) != 0) { + cfg.dirnamelen = snprintf(cfg.dirname, PATH_MAX, + "%s/lib/modules/%s", + root ?: "", cfg.kversion); + cfg.outdirnamelen = snprintf(cfg.outdirname, PATH_MAX, "%s/lib/modules/%s", out_root ?: (root ?: ""), cfg.kversion); + } if (optind == argc) all = 1; Index: kmod-30/tools/kmod.c =================================================================== --- kmod-30.orig/tools/kmod.c +++ kmod-30/tools/kmod.c @@ -114,6 +114,7 @@ static int kmod_config(int argc, char *a { unsigned i; printf("{\"prefix\":\"" PREFIX "\"" + ",\"module_prefix\":\"" MODULE_PREFIX "\"" ",\"module_compression\":["); for(i = 0; compressions[i]; i++) { printf("%s\"%s\"", i ? "," : "", compressions[i]); Index: kmod-30/tools/modinfo.c =================================================================== --- kmod-30.orig/tools/modinfo.c +++ kmod-30/tools/modinfo.c @@ -367,7 +367,7 @@ static void help(void) "\t-m, --modname Handle argument as module name instead of alias or filename\n" "\t-F, --field=FIELD Print only provided FIELD\n" "\t-k, --set-version=VERSION Use VERSION instead of `uname -r`\n" - "\t-b, --basedir=DIR Use DIR as filesystem root for /lib/modules\n" + "\t-b, --basedir=DIR Use DIR as filesystem root for " MODULE_PREFIX "/lib/modules\n" "\t-V, --version Show version\n" "\t-h, --help Show this help\n", program_invocation_short_name); @@ -462,7 +462,7 @@ static int do_modinfo(int argc, char *ar } kversion = u.release; } - snprintf(dirname_buf, sizeof(dirname_buf), "%s/lib/modules/%s", + snprintf(dirname_buf, sizeof(dirname_buf), "%s" MODULE_PREFIX "/lib/modules/%s", root, kversion); dirname = dirname_buf; } Index: kmod-30/tools/modprobe.c =================================================================== --- kmod-30.orig/tools/modprobe.c +++ kmod-30/tools/modprobe.c @@ -146,7 +146,7 @@ static void help(void) "\t-n, --show Same as --dry-run\n" "\t-C, --config=FILE Use FILE instead of default search paths\n" - "\t-d, --dirname=DIR Use DIR as filesystem root for /lib/modules\n" + "\t-d, --dirname=DIR Use DIR as filesystem root for " MODULE_PREFIX "/lib/modules\n" "\t-S, --set-version=VERSION Use VERSION instead of `uname -r`\n" "\t-s, --syslog print to syslog, not stderr\n" @@ -983,7 +983,7 @@ static int do_modprobe(int argc, char ** kversion = u.release; } snprintf(dirname_buf, sizeof(dirname_buf), - "%s/lib/modules/%s", root, + "%s" MODULE_PREFIX "/lib/modules/%s", root, kversion); dirname = dirname_buf; } Index: kmod-30/tools/static-nodes.c =================================================================== --- kmod-30.orig/tools/static-nodes.c +++ kmod-30/tools/static-nodes.c @@ -212,15 +212,15 @@ static int do_static_nodes(int argc, cha goto finish; } - snprintf(modules, sizeof(modules), "/lib/modules/%s/modules.devname", kernel.release); + snprintf(modules, sizeof(modules), MODULE_PREFIX "/lib/modules/%s/modules.devname", kernel.release); in = fopen(modules, "re"); if (in == NULL) { if (errno == ENOENT) { - fprintf(stderr, "Warning: /lib/modules/%s/modules.devname not found - ignoring\n", + fprintf(stderr, "Warning: " MODULE_PREFIX "/lib/modules/%s/modules.devname not found - ignoring\n", kernel.release); ret = EXIT_SUCCESS; } else { - fprintf(stderr, "Error: could not open /lib/modules/%s/modules.devname - %m\n", + fprintf(stderr, "Error: could not open " MODULE_PREFIX "/lib/modules/%s/modules.devname - %m\n", kernel.release); ret = EXIT_FAILURE; }