From 2ee8799fac7d361c85e11bbbf9d0b3aa485672a3 Mon Sep 17 00:00:00 2001 From: Richard Maw Date: Fri, 24 Feb 2012 16:28:27 +0000 Subject: kmod.morph: add It has some hacks to get around not using gtk-doc --- kmod.morph | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 kmod.morph diff --git a/kmod.morph b/kmod.morph new file mode 100644 index 0000000..346d237 --- /dev/null +++ b/kmod.morph @@ -0,0 +1,16 @@ +{ + "name": "kmod", + "kind": "chunk", + "configure-commands": [ + "rm -rf libkmod/docs", + "sed -i -e'/SUBDIRS/s/\\S*doc\\S*//' Makefile.am", + "sed -i -e'/AC_CONFIG_FILES(\\[/,/])/{/docs/d}' configure.ac", + "./configure --prefix=/usr --bindir=/bin --libdir=/lib --sysconfdir=/etc --with-xz --with-zlib" + ], + "build-commands": [ + "make" + ], + "install-commands": [ + "make DESTDIR=\"$DESTDIR\" install" + ] +} -- cgit v1.2.1 From 759e075128ea71fea0d7dcac921243ce0505c66a Mon Sep 17 00:00:00 2001 From: Richard Maw Date: Fri, 24 Feb 2012 16:31:30 +0000 Subject: kmod.morph: run autoreconf before configure --- kmod.morph | 1 + 1 file changed, 1 insertion(+) diff --git a/kmod.morph b/kmod.morph index 346d237..1474782 100644 --- a/kmod.morph +++ b/kmod.morph @@ -5,6 +5,7 @@ "rm -rf libkmod/docs", "sed -i -e'/SUBDIRS/s/\\S*doc\\S*//' Makefile.am", "sed -i -e'/AC_CONFIG_FILES(\\[/,/])/{/docs/d}' configure.ac", + "autoreconf -fiv", "./configure --prefix=/usr --bindir=/bin --libdir=/lib --sysconfdir=/etc --with-xz --with-zlib" ], "build-commands": [ -- cgit v1.2.1 From 775e223edb5cbcd1895e401a4de9119d1810c4a3 Mon Sep 17 00:00:00 2001 From: Richard Maw Date: Fri, 24 Feb 2012 16:37:42 +0000 Subject: kmod.morph: remove man dir from makefile --- kmod.morph | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kmod.morph b/kmod.morph index 1474782..5fdf48c 100644 --- a/kmod.morph +++ b/kmod.morph @@ -3,7 +3,7 @@ "kind": "chunk", "configure-commands": [ "rm -rf libkmod/docs", - "sed -i -e'/SUBDIRS/s/\\S*doc\\S*//' Makefile.am", + "sed -i -e'/SUBDIRS/{s/\\S*doc\\S*//;s/\\S*man\\S*//}' Makefile.am", "sed -i -e'/AC_CONFIG_FILES(\\[/,/])/{/docs/d}' configure.ac", "autoreconf -fiv", "./configure --prefix=/usr --bindir=/bin --libdir=/lib --sysconfdir=/etc --with-xz --with-zlib" -- cgit v1.2.1 From 82a6f0dac13086ac790142eb44b17da955dda383 Mon Sep 17 00:00:00 2001 From: Richard Maw Date: Fri, 24 Feb 2012 16:42:41 +0000 Subject: kmod.morph: install pkg-config in right place --- kmod.morph | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kmod.morph b/kmod.morph index 5fdf48c..77a0727 100644 --- a/kmod.morph +++ b/kmod.morph @@ -12,6 +12,6 @@ "make" ], "install-commands": [ - "make DESTDIR=\"$DESTDIR\" install" + "make DESTDIR=\"$DESTDIR\" pkgconfigdir=/usr/lib/pkgconfig install" ] } -- cgit v1.2.1 From baacc7dbd72193796b941fe58e72f99925767caa Mon Sep 17 00:00:00 2001 From: Richard Maw Date: Wed, 2 May 2012 17:34:27 +0100 Subject: kmod.morph: don't use xz kmod can use xz to read lzma compressed modules, however kmod is needed in foundation, which doesn't have xz --- kmod.morph | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kmod.morph b/kmod.morph index 77a0727..8e44931 100644 --- a/kmod.morph +++ b/kmod.morph @@ -6,7 +6,7 @@ "sed -i -e'/SUBDIRS/{s/\\S*doc\\S*//;s/\\S*man\\S*//}' Makefile.am", "sed -i -e'/AC_CONFIG_FILES(\\[/,/])/{/docs/d}' configure.ac", "autoreconf -fiv", - "./configure --prefix=/usr --bindir=/bin --libdir=/lib --sysconfdir=/etc --with-xz --with-zlib" + "./configure --prefix=/usr --bindir=/bin --libdir=/lib --sysconfdir=/etc --without-xz --with-zlib" ], "build-commands": [ "make" -- cgit v1.2.1 From 47fddef72fdd6c0e6a192026b673305fb67dc361 Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Thu, 27 Jun 2013 13:46:54 +0100 Subject: Add symlinks for the different command names (insmod, etc) --- kmod.morph | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/kmod.morph b/kmod.morph index 8e44931..af8d1d0 100644 --- a/kmod.morph +++ b/kmod.morph @@ -12,6 +12,12 @@ "make" ], "install-commands": [ - "make DESTDIR=\"$DESTDIR\" pkgconfigdir=/usr/lib/pkgconfig install" + "make DESTDIR=\"$DESTDIR\" pkgconfigdir=/usr/lib/pkgconfig install", + "ln -s kmod \"$DESTDIR\"/bin/modprobe", + "ln -s kmod \"$DESTDIR\"/bin/lsmod", + "ln -s kmod \"$DESTDIR\"/bin/rmmod", + "ln -s kmod \"$DESTDIR\"/bin/insmod", + "ln -s kmod \"$DESTDIR\"/bin/modinfo", + "ln -s kmod \"$DESTDIR\"/bin/depmod" ] } -- cgit v1.2.1 From a62b193df9fba04635e62e2fb29a0501866d0da0 Mon Sep 17 00:00:00 2001 From: Tiago Gomes Date: Mon, 1 Jul 2013 19:45:56 +0000 Subject: Disable building the manpages --- kmod.morph | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kmod.morph b/kmod.morph index af8d1d0..6a4be49 100644 --- a/kmod.morph +++ b/kmod.morph @@ -6,7 +6,7 @@ "sed -i -e'/SUBDIRS/{s/\\S*doc\\S*//;s/\\S*man\\S*//}' Makefile.am", "sed -i -e'/AC_CONFIG_FILES(\\[/,/])/{/docs/d}' configure.ac", "autoreconf -fiv", - "./configure --prefix=/usr --bindir=/bin --libdir=/lib --sysconfdir=/etc --without-xz --with-zlib" + "./configure --prefix=/usr --bindir=/bin --libdir=/lib --sysconfdir=/etc --without-xz --with-zlib --disable-manpages" ], "build-commands": [ "make" -- cgit v1.2.1 From c29425dc9180e571158313904d28d3b6589b9d59 Mon Sep 17 00:00:00 2001 From: Tiago Gomes Date: Mon, 1 Jul 2013 20:15:36 +0000 Subject: Revert "Disable building the manpages" This reverts commit a62b193df9fba04635e62e2fb29a0501866d0da0. Pushed by accident. --- kmod.morph | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kmod.morph b/kmod.morph index 6a4be49..af8d1d0 100644 --- a/kmod.morph +++ b/kmod.morph @@ -6,7 +6,7 @@ "sed -i -e'/SUBDIRS/{s/\\S*doc\\S*//;s/\\S*man\\S*//}' Makefile.am", "sed -i -e'/AC_CONFIG_FILES(\\[/,/])/{/docs/d}' configure.ac", "autoreconf -fiv", - "./configure --prefix=/usr --bindir=/bin --libdir=/lib --sysconfdir=/etc --without-xz --with-zlib --disable-manpages" + "./configure --prefix=/usr --bindir=/bin --libdir=/lib --sysconfdir=/etc --without-xz --with-zlib" ], "build-commands": [ "make" -- cgit v1.2.1 From b0982258a9fb1c7714e79bd0a7356c6211785b4d Mon Sep 17 00:00:00 2001 From: Tiago Gomes Date: Mon, 1 Jul 2013 20:16:34 +0000 Subject: Revert "Merge remote-tracking branch 'origin/master' into baserock/morph" This reverts commit 64e277a1bbe8ace86e159fb2d81e77629b9f9a42, reversing changes made to 47fddef72fdd6c0e6a192026b673305fb67dc361. --- .gitignore | 1 - .travis.yml | 17 - CODING-STYLE | 9 +- Makefile.am | 103 +- NEWS | 148 -- README | 5 +- TODO | 46 +- bootstrap | 2 +- bootstrap-configure | 2 +- configure.ac | 194 +- libkmod/docs/libkmod-docs.xml | 13 +- libkmod/docs/libkmod-sections.txt | 1 - libkmod/libkmod-array.c | 2 +- libkmod/libkmod-array.h | 5 +- libkmod/libkmod-config.c | 64 +- libkmod/libkmod-elf.c | 76 +- libkmod/libkmod-file.c | 39 +- libkmod/libkmod-hash.c | 26 +- libkmod/libkmod-hash.h | 5 +- libkmod/libkmod-index.c | 63 +- libkmod/libkmod-index.h | 9 +- libkmod/libkmod-list.c | 2 +- libkmod/libkmod-module.c | 395 ++- libkmod/libkmod-private.h | 79 +- libkmod/libkmod-signature.c | 141 - libkmod/libkmod-util.c | 67 +- libkmod/libkmod-util.h | 44 +- libkmod/libkmod.c | 113 +- libkmod/libkmod.h | 4 +- libkmod/libkmod.sym | 1 + libkmod/macro.h | 53 +- libkmod/missing.h | 34 - m4/attributes.m4 | 85 +- man/Makefile.am | 7 +- man/depmod.xml | 68 +- man/modinfo.xml | 42 +- man/modprobe.d.xml | 2 +- man/modprobe.xml | 90 +- man/rmmod.xml | 18 +- test/WARNING | 3 + test/test-blacklist.c | 76 + test/test-elf.c | 106 + test/test-get-dependencies.c | 52 + test/test-invalidate-config.c | 49 + test/test-lookup.c | 184 ++ test/test-mod-double-ref.c | 78 + test/test-path-from-name.c | 48 + test/test-probe.c | 118 + test/test.conf | 0 testsuite/.gitignore | 26 +- testsuite/COPYING | 504 ---- testsuite/delete_module.c | 19 +- testsuite/init_module.c | 211 +- testsuite/mkdir.c | 70 - testsuite/mkdir.h | 24 - testsuite/path.c | 224 +- testsuite/rootfs-pristine/test-alias/correct.txt | 25 - .../test-blacklist/etc/modprobe.d/modprobe.conf | 2 - .../lib/modules/4.0.20-kmod/kernel/fs/jbd2/jbd2.ko | Bin 159175 -> 0 bytes .../lib/modules/4.0.20-kmod/kernel/fs/mbcache.ko | Bin 18431 -> 0 bytes .../lib/modules/4.0.20-kmod/kernel/lib/crc16.ko | Bin 4374 -> 0 bytes .../lib/modules/4.0.20-kmod/modules.alias | 1 - .../lib/modules/4.0.20-kmod/modules.alias.bin | Bin 12 -> 0 bytes .../lib/modules/4.0.20-kmod/modules.builtin | 0 .../lib/modules/4.0.20-kmod/modules.builtin.bin | Bin 12 -> 0 bytes .../lib/modules/4.0.20-kmod/modules.dep | 4 - .../lib/modules/4.0.20-kmod/modules.dep.bin | Bin 265 -> 0 bytes .../lib/modules/4.0.20-kmod/modules.devname | 1 - .../lib/modules/4.0.20-kmod/modules.order | 7 - .../lib/modules/4.0.20-kmod/modules.softdep | 2 - .../lib/modules/4.0.20-kmod/modules.symbols | 58 - .../lib/modules/4.0.20-kmod/modules.symbols.bin | Bin 2584 -> 0 bytes .../lib/modules/3.5.4-1-ARCH/correct-modules.alias | 37 - .../3.5.4-1-ARCH/kernel/drivers/block/cciss.ko.gz | Bin 33491 -> 0 bytes .../3.5.4-1-ARCH/kernel/drivers/scsi/hpsa.ko.gz | Bin 32672 -> 0 bytes .../kernel/drivers/scsi/scsi_mod.ko.gz | Bin 81188 -> 0 bytes .../lib/modules/3.5.4-1-ARCH/modules.builtin | 0 .../lib/modules/3.5.4-1-ARCH/modules.order | 7 - testsuite/rootfs-pristine/test-init/correct.txt | 28 - testsuite/rootfs-pristine/test-init/ext4-i686.ko | Bin 437788 -> 0 bytes testsuite/rootfs-pristine/test-init/ext4-ppc64.ko | Bin 704776 -> 0 bytes testsuite/rootfs-pristine/test-init/ext4-s390x.ko | Bin 773856 -> 0 bytes testsuite/rootfs-pristine/test-init/ext4-x86_64.ko | Bin 627040 -> 0 bytes testsuite/rootfs-pristine/test-loaded/correct.txt | 2 - testsuite/rootfs-pristine/test-loaded/proc/modules | 1 - .../test-loaded/sys/module/btusb/drivers/usb:btusb | 1 - .../sys/module/btusb/holders/.gitignore | 0 .../test-loaded/sys/module/btusb/initstate | 1 - .../sys/module/btusb/notes/.note.gnu.build-id | Bin 36 -> 0 bytes .../sys/module/btusb/parameters/disable_scofix | 1 - .../sys/module/btusb/parameters/force_scofix | 1 - .../sys/module/btusb/parameters/ignore_csr | 1 - .../sys/module/btusb/parameters/ignore_dga | 1 - .../sys/module/btusb/parameters/ignore_sniffer | 1 - .../test-loaded/sys/module/btusb/parameters/reset | 1 - .../test-loaded/sys/module/btusb/refcnt | 1 - .../test-loaded/sys/module/btusb/sections/.bss | 1 - .../test-loaded/sys/module/btusb/sections/.data | 1 - .../sys/module/btusb/sections/.exit.text | 1 - .../btusb/sections/.gnu.linkonce.this_module | 1 - .../sys/module/btusb/sections/.init.text | 1 - .../sys/module/btusb/sections/.note.gnu.build-id | 1 - .../test-loaded/sys/module/btusb/sections/.rodata | 1 - .../sys/module/btusb/sections/.rodata.str1.1 | 1 - .../sys/module/btusb/sections/.rodata.str1.8 | 1 - .../sys/module/btusb/sections/.smp_locks | 1 - .../test-loaded/sys/module/btusb/sections/.strtab | 1 - .../test-loaded/sys/module/btusb/sections/.symtab | 1 - .../test-loaded/sys/module/btusb/sections/.text | 1 - .../test-loaded/sys/module/btusb/sections/__param | 1 - .../test-loaded/sys/module/btusb/srcversion | 1 - .../test-loaded/sys/module/btusb/version | 1 - testsuite/rootfs-pristine/test-modinfo/correct.txt | 52 - .../rootfs-pristine/test-modinfo/ext4-i686.ko | Bin 437788 -> 0 bytes .../rootfs-pristine/test-modinfo/ext4-ppc64.ko | Bin 704776 -> 0 bytes .../rootfs-pristine/test-modinfo/ext4-s390x.ko | Bin 773856 -> 0 bytes .../test-modinfo/ext4-x86_64-sha1.ko | Bin 729451 -> 0 bytes .../test-modinfo/ext4-x86_64-sha256.ko | Bin 729451 -> 0 bytes .../rootfs-pristine/test-modinfo/ext4-x86_64.ko | Bin 627040 -> 0 bytes .../alias-to-none/correct-psmouse.txt | 0 .../alias-to-none/etc/modprobe.d/bogus.conf | 1 - .../4.4.4/kernel/drivers/input/mouse/psmouse.ko | Bin 95649 -> 0 bytes .../alias-to-none/lib/modules/4.4.4/modules.alias | 3 - .../lib/modules/4.4.4/modules.alias.bin | Bin 101 -> 0 bytes .../lib/modules/4.4.4/modules.builtin.bin | 0 .../alias-to-none/lib/modules/4.4.4/modules.dep | 1 - .../lib/modules/4.4.4/modules.dep.bin | Bin 72 -> 0 bytes .../lib/modules/4.4.4/modules.devname | 1 - .../lib/modules/4.4.4/modules.softdep | 2 - .../lib/modules/4.4.4/modules.symbols | 1 - .../lib/modules/4.4.4/modules.symbols.bin | Bin 12 -> 0 bytes .../test-modprobe/alias-to-none/proc/modules | 0 .../builtin/lib/modules/4.4.4/modules.alias | 1 - .../builtin/lib/modules/4.4.4/modules.alias.bin | Bin 12 -> 0 bytes .../builtin/lib/modules/4.4.4/modules.builtin | 1 - .../builtin/lib/modules/4.4.4/modules.builtin.bin | Bin 31 -> 0 bytes .../builtin/lib/modules/4.4.4/modules.dep | 0 .../builtin/lib/modules/4.4.4/modules.dep.bin | Bin 12 -> 0 bytes .../builtin/lib/modules/4.4.4/modules.devname | 1 - .../builtin/lib/modules/4.4.4/modules.softdep | 2 - .../builtin/lib/modules/4.4.4/modules.symbols | 1 - .../builtin/lib/modules/4.4.4/modules.symbols.bin | Bin 12 -> 0 bytes .../etc/modprobe.d/dumb-instal-loop.conf | 1 - .../modules/4.4.4/kernel/sound/core/snd-pcm.ko.gz | Bin 46263 -> 0 bytes .../lib/modules/4.4.4/kernel/sound/core/snd.ko.gz | Bin 38351 -> 0 bytes .../lib/modules/4.4.4/modules.alias | 2 - .../lib/modules/4.4.4/modules.alias.bin | Bin 46 -> 0 bytes .../install-cmd-loop/lib/modules/4.4.4/modules.dep | 2 - .../lib/modules/4.4.4/modules.dep.bin | Bin 137 -> 0 bytes .../lib/modules/4.4.4/modules.devname | 1 - .../lib/modules/4.4.4/modules.softdep | 2 - .../lib/modules/4.4.4/modules.symbols | 133 - .../lib/modules/4.4.4/modules.symbols.bin | Bin 6131 -> 0 bytes .../test-modprobe/show-depends/correct-psmouse.txt | 1 - .../test-modprobe/show-depends/correct.txt | 2 - .../4.4.4/kernel/drivers/bluetooth/btusb.ko | Bin 28134 -> 0 bytes .../4.4.4/kernel/drivers/input/mouse/psmouse.ko | Bin 95649 -> 0 bytes .../4.4.4/kernel/net/bluetooth/bluetooth.ko | Bin 284834 -> 0 bytes .../show-depends/lib/modules/4.4.4/modules.alias | 21 - .../lib/modules/4.4.4/modules.alias.bin | Bin 1227 -> 0 bytes .../show-depends/lib/modules/4.4.4/modules.dep | 3 - .../show-depends/lib/modules/4.4.4/modules.dep.bin | Bin 298 -> 0 bytes .../show-depends/lib/modules/4.4.4/modules.devname | 1 - .../show-depends/lib/modules/4.4.4/modules.softdep | 2 - .../show-depends/lib/modules/4.4.4/modules.symbols | 45 - .../lib/modules/4.4.4/modules.symbols.bin | Bin 2390 -> 0 bytes .../test-modprobe/show-depends/proc/modules | 2 - .../show-depends/sys/module/bluetooth/coresize | 1 - .../sys/module/bluetooth/holders/btusb | 1 - .../show-depends/sys/module/bluetooth/initsize | 1 - .../show-depends/sys/module/bluetooth/initstate | 1 - .../sys/module/bluetooth/notes/.note.gnu.build-id | Bin 36 -> 0 bytes .../sys/module/bluetooth/parameters/disable_ertm | 1 - .../sys/module/bluetooth/parameters/disable_esco | 1 - .../sys/module/bluetooth/parameters/enable_hs | 1 - .../sys/module/bluetooth/parameters/enable_le | 1 - .../sys/module/bluetooth/parameters/enable_mgmt | 1 - .../show-depends/sys/module/bluetooth/refcnt | 1 - .../sys/module/bluetooth/sections/.bss | 1 - .../sys/module/bluetooth/sections/.data | 1 - .../sys/module/bluetooth/sections/.exit.text | 1 - .../bluetooth/sections/.gnu.linkonce.this_module | 1 - .../sys/module/bluetooth/sections/.init.text | 1 - .../module/bluetooth/sections/.note.gnu.build-id | 1 - .../sys/module/bluetooth/sections/.rodata | 1 - .../sys/module/bluetooth/sections/.rodata.str1.1 | 1 - .../sys/module/bluetooth/sections/.rodata.str1.8 | 1 - .../sys/module/bluetooth/sections/.smp_locks | 1 - .../sys/module/bluetooth/sections/.strtab | 1 - .../sys/module/bluetooth/sections/.symtab | 1 - .../sys/module/bluetooth/sections/.text | 1 - .../sys/module/bluetooth/sections/.text.unlikely | 1 - .../sys/module/bluetooth/sections/__bug_table | 1 - .../sys/module/bluetooth/sections/__jump_table | 1 - .../sys/module/bluetooth/sections/__kcrctab | 1 - .../sys/module/bluetooth/sections/__kcrctab_gpl | 1 - .../sys/module/bluetooth/sections/__ksymtab | 1 - .../sys/module/bluetooth/sections/__ksymtab_gpl | 1 - .../module/bluetooth/sections/__ksymtab_strings | 1 - .../sys/module/bluetooth/sections/__param | 1 - .../show-depends/sys/module/bluetooth/srcversion | 1 - .../show-depends/sys/module/bluetooth/taint | 1 - .../show-depends/sys/module/bluetooth/version | 1 - .../show-depends/sys/module/btusb/coresize | 1 - .../sys/module/btusb/drivers/usb:btusb | 1 - .../sys/module/btusb/holders/.gitignore | 0 .../show-depends/sys/module/btusb/initsize | 1 - .../show-depends/sys/module/btusb/initstate | 1 - .../sys/module/btusb/notes/.note.gnu.build-id | Bin 36 -> 0 bytes .../sys/module/btusb/parameters/disable_scofix | 1 - .../sys/module/btusb/parameters/force_scofix | 1 - .../sys/module/btusb/parameters/ignore_csr | 1 - .../sys/module/btusb/parameters/ignore_dga | 1 - .../sys/module/btusb/parameters/ignore_sniffer | 1 - .../show-depends/sys/module/btusb/parameters/reset | 1 - .../show-depends/sys/module/btusb/refcnt | 1 - .../show-depends/sys/module/btusb/sections/.bss | 1 - .../show-depends/sys/module/btusb/sections/.data | 1 - .../sys/module/btusb/sections/.exit.text | 1 - .../btusb/sections/.gnu.linkonce.this_module | 1 - .../sys/module/btusb/sections/.init.text | 1 - .../sys/module/btusb/sections/.note.gnu.build-id | 1 - .../show-depends/sys/module/btusb/sections/.rodata | 1 - .../sys/module/btusb/sections/.rodata.str1.1 | 1 - .../sys/module/btusb/sections/.rodata.str1.8 | 1 - .../sys/module/btusb/sections/.smp_locks | 1 - .../show-depends/sys/module/btusb/sections/.strtab | 1 - .../show-depends/sys/module/btusb/sections/.symtab | 1 - .../show-depends/sys/module/btusb/sections/.text | 1 - .../show-depends/sys/module/btusb/sections/__param | 1 - .../show-depends/sys/module/btusb/srcversion | 1 - .../show-depends/sys/module/btusb/taint | 1 - .../show-depends/sys/module/btusb/version | 1 - .../softdep-loop/etc/modprobe.d/dumb-softdep.conf | 1 - .../4.4.4/kernel/drivers/bluetooth/btusb.ko | Bin 28134 -> 0 bytes .../4.4.4/kernel/drivers/input/mouse/psmouse.ko | Bin 95649 -> 0 bytes .../4.4.4/kernel/net/bluetooth/bluetooth.ko | Bin 284834 -> 0 bytes .../softdep-loop/lib/modules/4.4.4/modules.alias | 21 - .../lib/modules/4.4.4/modules.alias.bin | Bin 1227 -> 0 bytes .../softdep-loop/lib/modules/4.4.4/modules.dep | 3 - .../softdep-loop/lib/modules/4.4.4/modules.dep.bin | Bin 298 -> 0 bytes .../softdep-loop/lib/modules/4.4.4/modules.devname | 1 - .../softdep-loop/lib/modules/4.4.4/modules.softdep | 2 - .../softdep-loop/lib/modules/4.4.4/modules.symbols | 45 - .../lib/modules/4.4.4/modules.symbols.bin | Bin 2390 -> 0 bytes .../test-new-module/from_alias/correct.txt | 2 - .../from_alias/etc/modprobe.d/modprobe.conf | 1 - .../test-new-module/from_name/correct.txt | 6 - testsuite/rootfs-pristine/test-remove/correct.txt | 28 - testsuite/rootfs-pristine/test-remove/ext4-i686.ko | Bin 437788 -> 0 bytes .../rootfs-pristine/test-remove/ext4-ppc64.ko | Bin 704776 -> 0 bytes .../rootfs-pristine/test-remove/ext4-s390x.ko | Bin 773856 -> 0 bytes .../rootfs-pristine/test-remove/ext4-x86_64.ko | Bin 627040 -> 0 bytes .../rootfs-pristine/test-rootfs/lib/modules/a | 1 - .../rootfs-pristine/test-rootfs/testdir/.gitignore | 0 testsuite/rootfs.tar.xz | Bin 0 -> 661752 bytes testsuite/stripped-module.h | 8 +- testsuite/test-alias.c | 19 +- testsuite/test-blacklist.c | 109 - testsuite/test-dependencies.c | 93 - testsuite/test-depmod.c | 63 - testsuite/test-init.c | 23 +- testsuite/test-loaded.c | 19 +- testsuite/test-modinfo.c | 22 +- testsuite/test-modprobe.c | 92 +- testsuite/test-new-module.c | 19 +- testsuite/test-testsuite.c | 19 +- testsuite/testsuite.c | 224 +- testsuite/testsuite.h | 38 +- testsuite/uname.c | 19 +- tools/depmod.c | 2700 ------------------- tools/insmod.c | 158 -- tools/kmod-depmod.c | 2774 ++++++++++++++++++++ tools/kmod-insmod.c | 171 ++ tools/kmod-lsmod.c | 109 + tools/kmod-modinfo.c | 486 ++++ tools/kmod-modprobe.c | 1036 ++++++++ tools/kmod-rmmod.c | 254 ++ tools/kmod.c | 6 +- tools/kmod.h | 9 +- tools/log.c | 143 - tools/log.h | 37 - tools/lsmod.c | 99 - tools/modinfo.c | 465 ---- tools/modprobe.c | 944 ------- tools/rmmod.c | 204 -- tools/static-nodes.c | 263 -- 287 files changed, 6495 insertions(+), 8656 deletions(-) delete mode 100644 .travis.yml delete mode 100644 libkmod/libkmod-signature.c delete mode 100644 libkmod/missing.h create mode 100644 test/WARNING create mode 100644 test/test-blacklist.c create mode 100644 test/test-elf.c create mode 100644 test/test-get-dependencies.c create mode 100644 test/test-invalidate-config.c create mode 100644 test/test-lookup.c create mode 100644 test/test-mod-double-ref.c create mode 100644 test/test-path-from-name.c create mode 100644 test/test-probe.c create mode 100644 test/test.conf delete mode 100644 testsuite/COPYING delete mode 100644 testsuite/mkdir.c delete mode 100644 testsuite/mkdir.h delete mode 100644 testsuite/rootfs-pristine/test-alias/correct.txt delete mode 100644 testsuite/rootfs-pristine/test-blacklist/etc/modprobe.d/modprobe.conf delete mode 100644 testsuite/rootfs-pristine/test-dependencies/lib/modules/4.0.20-kmod/kernel/fs/jbd2/jbd2.ko delete mode 100644 testsuite/rootfs-pristine/test-dependencies/lib/modules/4.0.20-kmod/kernel/fs/mbcache.ko delete mode 100644 testsuite/rootfs-pristine/test-dependencies/lib/modules/4.0.20-kmod/kernel/lib/crc16.ko delete mode 100644 testsuite/rootfs-pristine/test-dependencies/lib/modules/4.0.20-kmod/modules.alias delete mode 100644 testsuite/rootfs-pristine/test-dependencies/lib/modules/4.0.20-kmod/modules.alias.bin delete mode 100644 testsuite/rootfs-pristine/test-dependencies/lib/modules/4.0.20-kmod/modules.builtin delete mode 100644 testsuite/rootfs-pristine/test-dependencies/lib/modules/4.0.20-kmod/modules.builtin.bin delete mode 100644 testsuite/rootfs-pristine/test-dependencies/lib/modules/4.0.20-kmod/modules.dep delete mode 100644 testsuite/rootfs-pristine/test-dependencies/lib/modules/4.0.20-kmod/modules.dep.bin delete mode 100644 testsuite/rootfs-pristine/test-dependencies/lib/modules/4.0.20-kmod/modules.devname delete mode 100644 testsuite/rootfs-pristine/test-dependencies/lib/modules/4.0.20-kmod/modules.order delete mode 100644 testsuite/rootfs-pristine/test-dependencies/lib/modules/4.0.20-kmod/modules.softdep delete mode 100644 testsuite/rootfs-pristine/test-dependencies/lib/modules/4.0.20-kmod/modules.symbols delete mode 100644 testsuite/rootfs-pristine/test-dependencies/lib/modules/4.0.20-kmod/modules.symbols.bin delete mode 100644 testsuite/rootfs-pristine/test-depmod/modules-order-compressed/lib/modules/3.5.4-1-ARCH/correct-modules.alias delete mode 100644 testsuite/rootfs-pristine/test-depmod/modules-order-compressed/lib/modules/3.5.4-1-ARCH/kernel/drivers/block/cciss.ko.gz delete mode 100644 testsuite/rootfs-pristine/test-depmod/modules-order-compressed/lib/modules/3.5.4-1-ARCH/kernel/drivers/scsi/hpsa.ko.gz delete mode 100644 testsuite/rootfs-pristine/test-depmod/modules-order-compressed/lib/modules/3.5.4-1-ARCH/kernel/drivers/scsi/scsi_mod.ko.gz delete mode 100644 testsuite/rootfs-pristine/test-depmod/modules-order-compressed/lib/modules/3.5.4-1-ARCH/modules.builtin delete mode 100644 testsuite/rootfs-pristine/test-depmod/modules-order-compressed/lib/modules/3.5.4-1-ARCH/modules.order delete mode 100644 testsuite/rootfs-pristine/test-init/correct.txt delete mode 100644 testsuite/rootfs-pristine/test-init/ext4-i686.ko delete mode 100644 testsuite/rootfs-pristine/test-init/ext4-ppc64.ko delete mode 100644 testsuite/rootfs-pristine/test-init/ext4-s390x.ko delete mode 100644 testsuite/rootfs-pristine/test-init/ext4-x86_64.ko delete mode 100644 testsuite/rootfs-pristine/test-loaded/correct.txt delete mode 100644 testsuite/rootfs-pristine/test-loaded/proc/modules delete mode 120000 testsuite/rootfs-pristine/test-loaded/sys/module/btusb/drivers/usb:btusb delete mode 100644 testsuite/rootfs-pristine/test-loaded/sys/module/btusb/holders/.gitignore delete mode 100644 testsuite/rootfs-pristine/test-loaded/sys/module/btusb/initstate delete mode 100644 testsuite/rootfs-pristine/test-loaded/sys/module/btusb/notes/.note.gnu.build-id delete mode 100644 testsuite/rootfs-pristine/test-loaded/sys/module/btusb/parameters/disable_scofix delete mode 100644 testsuite/rootfs-pristine/test-loaded/sys/module/btusb/parameters/force_scofix delete mode 100644 testsuite/rootfs-pristine/test-loaded/sys/module/btusb/parameters/ignore_csr delete mode 100644 testsuite/rootfs-pristine/test-loaded/sys/module/btusb/parameters/ignore_dga delete mode 100644 testsuite/rootfs-pristine/test-loaded/sys/module/btusb/parameters/ignore_sniffer delete mode 100644 testsuite/rootfs-pristine/test-loaded/sys/module/btusb/parameters/reset delete mode 100644 testsuite/rootfs-pristine/test-loaded/sys/module/btusb/refcnt delete mode 100644 testsuite/rootfs-pristine/test-loaded/sys/module/btusb/sections/.bss delete mode 100644 testsuite/rootfs-pristine/test-loaded/sys/module/btusb/sections/.data delete mode 100644 testsuite/rootfs-pristine/test-loaded/sys/module/btusb/sections/.exit.text delete mode 100644 testsuite/rootfs-pristine/test-loaded/sys/module/btusb/sections/.gnu.linkonce.this_module delete mode 100644 testsuite/rootfs-pristine/test-loaded/sys/module/btusb/sections/.init.text delete mode 100644 testsuite/rootfs-pristine/test-loaded/sys/module/btusb/sections/.note.gnu.build-id delete mode 100644 testsuite/rootfs-pristine/test-loaded/sys/module/btusb/sections/.rodata delete mode 100644 testsuite/rootfs-pristine/test-loaded/sys/module/btusb/sections/.rodata.str1.1 delete mode 100644 testsuite/rootfs-pristine/test-loaded/sys/module/btusb/sections/.rodata.str1.8 delete mode 100644 testsuite/rootfs-pristine/test-loaded/sys/module/btusb/sections/.smp_locks delete mode 100644 testsuite/rootfs-pristine/test-loaded/sys/module/btusb/sections/.strtab delete mode 100644 testsuite/rootfs-pristine/test-loaded/sys/module/btusb/sections/.symtab delete mode 100644 testsuite/rootfs-pristine/test-loaded/sys/module/btusb/sections/.text delete mode 100644 testsuite/rootfs-pristine/test-loaded/sys/module/btusb/sections/__param delete mode 100644 testsuite/rootfs-pristine/test-loaded/sys/module/btusb/srcversion delete mode 100644 testsuite/rootfs-pristine/test-loaded/sys/module/btusb/version delete mode 100644 testsuite/rootfs-pristine/test-modinfo/correct.txt delete mode 100644 testsuite/rootfs-pristine/test-modinfo/ext4-i686.ko delete mode 100644 testsuite/rootfs-pristine/test-modinfo/ext4-ppc64.ko delete mode 100644 testsuite/rootfs-pristine/test-modinfo/ext4-s390x.ko delete mode 100644 testsuite/rootfs-pristine/test-modinfo/ext4-x86_64-sha1.ko delete mode 100644 testsuite/rootfs-pristine/test-modinfo/ext4-x86_64-sha256.ko delete mode 100644 testsuite/rootfs-pristine/test-modinfo/ext4-x86_64.ko delete mode 100644 testsuite/rootfs-pristine/test-modprobe/alias-to-none/correct-psmouse.txt delete mode 100644 testsuite/rootfs-pristine/test-modprobe/alias-to-none/etc/modprobe.d/bogus.conf delete mode 100644 testsuite/rootfs-pristine/test-modprobe/alias-to-none/lib/modules/4.4.4/kernel/drivers/input/mouse/psmouse.ko delete mode 100644 testsuite/rootfs-pristine/test-modprobe/alias-to-none/lib/modules/4.4.4/modules.alias delete mode 100644 testsuite/rootfs-pristine/test-modprobe/alias-to-none/lib/modules/4.4.4/modules.alias.bin delete mode 100644 testsuite/rootfs-pristine/test-modprobe/alias-to-none/lib/modules/4.4.4/modules.builtin.bin delete mode 100644 testsuite/rootfs-pristine/test-modprobe/alias-to-none/lib/modules/4.4.4/modules.dep delete mode 100644 testsuite/rootfs-pristine/test-modprobe/alias-to-none/lib/modules/4.4.4/modules.dep.bin delete mode 100644 testsuite/rootfs-pristine/test-modprobe/alias-to-none/lib/modules/4.4.4/modules.devname delete mode 100644 testsuite/rootfs-pristine/test-modprobe/alias-to-none/lib/modules/4.4.4/modules.softdep delete mode 100644 testsuite/rootfs-pristine/test-modprobe/alias-to-none/lib/modules/4.4.4/modules.symbols delete mode 100644 testsuite/rootfs-pristine/test-modprobe/alias-to-none/lib/modules/4.4.4/modules.symbols.bin delete mode 100644 testsuite/rootfs-pristine/test-modprobe/alias-to-none/proc/modules delete mode 100644 testsuite/rootfs-pristine/test-modprobe/builtin/lib/modules/4.4.4/modules.alias delete mode 100644 testsuite/rootfs-pristine/test-modprobe/builtin/lib/modules/4.4.4/modules.alias.bin delete mode 100644 testsuite/rootfs-pristine/test-modprobe/builtin/lib/modules/4.4.4/modules.builtin delete mode 100644 testsuite/rootfs-pristine/test-modprobe/builtin/lib/modules/4.4.4/modules.builtin.bin delete mode 100644 testsuite/rootfs-pristine/test-modprobe/builtin/lib/modules/4.4.4/modules.dep delete mode 100644 testsuite/rootfs-pristine/test-modprobe/builtin/lib/modules/4.4.4/modules.dep.bin delete mode 100644 testsuite/rootfs-pristine/test-modprobe/builtin/lib/modules/4.4.4/modules.devname delete mode 100644 testsuite/rootfs-pristine/test-modprobe/builtin/lib/modules/4.4.4/modules.softdep delete mode 100644 testsuite/rootfs-pristine/test-modprobe/builtin/lib/modules/4.4.4/modules.symbols delete mode 100644 testsuite/rootfs-pristine/test-modprobe/builtin/lib/modules/4.4.4/modules.symbols.bin delete mode 100644 testsuite/rootfs-pristine/test-modprobe/install-cmd-loop/etc/modprobe.d/dumb-instal-loop.conf delete mode 100644 testsuite/rootfs-pristine/test-modprobe/install-cmd-loop/lib/modules/4.4.4/kernel/sound/core/snd-pcm.ko.gz delete mode 100644 testsuite/rootfs-pristine/test-modprobe/install-cmd-loop/lib/modules/4.4.4/kernel/sound/core/snd.ko.gz delete mode 100644 testsuite/rootfs-pristine/test-modprobe/install-cmd-loop/lib/modules/4.4.4/modules.alias delete mode 100644 testsuite/rootfs-pristine/test-modprobe/install-cmd-loop/lib/modules/4.4.4/modules.alias.bin delete mode 100644 testsuite/rootfs-pristine/test-modprobe/install-cmd-loop/lib/modules/4.4.4/modules.dep delete mode 100644 testsuite/rootfs-pristine/test-modprobe/install-cmd-loop/lib/modules/4.4.4/modules.dep.bin delete mode 100644 testsuite/rootfs-pristine/test-modprobe/install-cmd-loop/lib/modules/4.4.4/modules.devname delete mode 100644 testsuite/rootfs-pristine/test-modprobe/install-cmd-loop/lib/modules/4.4.4/modules.softdep delete mode 100644 testsuite/rootfs-pristine/test-modprobe/install-cmd-loop/lib/modules/4.4.4/modules.symbols delete mode 100644 testsuite/rootfs-pristine/test-modprobe/install-cmd-loop/lib/modules/4.4.4/modules.symbols.bin delete mode 100644 testsuite/rootfs-pristine/test-modprobe/show-depends/correct-psmouse.txt delete mode 100644 testsuite/rootfs-pristine/test-modprobe/show-depends/correct.txt delete mode 100644 testsuite/rootfs-pristine/test-modprobe/show-depends/lib/modules/4.4.4/kernel/drivers/bluetooth/btusb.ko delete mode 100644 testsuite/rootfs-pristine/test-modprobe/show-depends/lib/modules/4.4.4/kernel/drivers/input/mouse/psmouse.ko delete mode 100644 testsuite/rootfs-pristine/test-modprobe/show-depends/lib/modules/4.4.4/kernel/net/bluetooth/bluetooth.ko delete mode 100644 testsuite/rootfs-pristine/test-modprobe/show-depends/lib/modules/4.4.4/modules.alias delete mode 100644 testsuite/rootfs-pristine/test-modprobe/show-depends/lib/modules/4.4.4/modules.alias.bin delete mode 100644 testsuite/rootfs-pristine/test-modprobe/show-depends/lib/modules/4.4.4/modules.dep delete mode 100644 testsuite/rootfs-pristine/test-modprobe/show-depends/lib/modules/4.4.4/modules.dep.bin delete mode 100644 testsuite/rootfs-pristine/test-modprobe/show-depends/lib/modules/4.4.4/modules.devname delete mode 100644 testsuite/rootfs-pristine/test-modprobe/show-depends/lib/modules/4.4.4/modules.softdep delete mode 100644 testsuite/rootfs-pristine/test-modprobe/show-depends/lib/modules/4.4.4/modules.symbols delete mode 100644 testsuite/rootfs-pristine/test-modprobe/show-depends/lib/modules/4.4.4/modules.symbols.bin delete mode 100644 testsuite/rootfs-pristine/test-modprobe/show-depends/proc/modules delete mode 100644 testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/bluetooth/coresize delete mode 120000 testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/bluetooth/holders/btusb delete mode 100644 testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/bluetooth/initsize delete mode 100644 testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/bluetooth/initstate delete mode 100644 testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/bluetooth/notes/.note.gnu.build-id delete mode 100644 testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/bluetooth/parameters/disable_ertm delete mode 100644 testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/bluetooth/parameters/disable_esco delete mode 100644 testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/bluetooth/parameters/enable_hs delete mode 100644 testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/bluetooth/parameters/enable_le delete mode 100644 testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/bluetooth/parameters/enable_mgmt delete mode 100644 testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/bluetooth/refcnt delete mode 100644 testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/bluetooth/sections/.bss delete mode 100644 testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/bluetooth/sections/.data delete mode 100644 testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/bluetooth/sections/.exit.text delete mode 100644 testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/bluetooth/sections/.gnu.linkonce.this_module delete mode 100644 testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/bluetooth/sections/.init.text delete mode 100644 testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/bluetooth/sections/.note.gnu.build-id delete mode 100644 testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/bluetooth/sections/.rodata delete mode 100644 testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/bluetooth/sections/.rodata.str1.1 delete mode 100644 testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/bluetooth/sections/.rodata.str1.8 delete mode 100644 testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/bluetooth/sections/.smp_locks delete mode 100644 testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/bluetooth/sections/.strtab delete mode 100644 testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/bluetooth/sections/.symtab delete mode 100644 testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/bluetooth/sections/.text delete mode 100644 testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/bluetooth/sections/.text.unlikely delete mode 100644 testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/bluetooth/sections/__bug_table delete mode 100644 testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/bluetooth/sections/__jump_table delete mode 100644 testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/bluetooth/sections/__kcrctab delete mode 100644 testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/bluetooth/sections/__kcrctab_gpl delete mode 100644 testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/bluetooth/sections/__ksymtab delete mode 100644 testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/bluetooth/sections/__ksymtab_gpl delete mode 100644 testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/bluetooth/sections/__ksymtab_strings delete mode 100644 testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/bluetooth/sections/__param delete mode 100644 testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/bluetooth/srcversion delete mode 100644 testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/bluetooth/taint delete mode 100644 testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/bluetooth/version delete mode 100644 testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/btusb/coresize delete mode 120000 testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/btusb/drivers/usb:btusb delete mode 100644 testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/btusb/holders/.gitignore delete mode 100644 testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/btusb/initsize delete mode 100644 testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/btusb/initstate delete mode 100644 testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/btusb/notes/.note.gnu.build-id delete mode 100644 testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/btusb/parameters/disable_scofix delete mode 100644 testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/btusb/parameters/force_scofix delete mode 100644 testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/btusb/parameters/ignore_csr delete mode 100644 testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/btusb/parameters/ignore_dga delete mode 100644 testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/btusb/parameters/ignore_sniffer delete mode 100644 testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/btusb/parameters/reset delete mode 100644 testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/btusb/refcnt delete mode 100644 testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/btusb/sections/.bss delete mode 100644 testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/btusb/sections/.data delete mode 100644 testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/btusb/sections/.exit.text delete mode 100644 testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/btusb/sections/.gnu.linkonce.this_module delete mode 100644 testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/btusb/sections/.init.text delete mode 100644 testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/btusb/sections/.note.gnu.build-id delete mode 100644 testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/btusb/sections/.rodata delete mode 100644 testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/btusb/sections/.rodata.str1.1 delete mode 100644 testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/btusb/sections/.rodata.str1.8 delete mode 100644 testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/btusb/sections/.smp_locks delete mode 100644 testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/btusb/sections/.strtab delete mode 100644 testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/btusb/sections/.symtab delete mode 100644 testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/btusb/sections/.text delete mode 100644 testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/btusb/sections/__param delete mode 100644 testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/btusb/srcversion delete mode 100644 testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/btusb/taint delete mode 100644 testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/btusb/version delete mode 100644 testsuite/rootfs-pristine/test-modprobe/softdep-loop/etc/modprobe.d/dumb-softdep.conf delete mode 100644 testsuite/rootfs-pristine/test-modprobe/softdep-loop/lib/modules/4.4.4/kernel/drivers/bluetooth/btusb.ko delete mode 100644 testsuite/rootfs-pristine/test-modprobe/softdep-loop/lib/modules/4.4.4/kernel/drivers/input/mouse/psmouse.ko delete mode 100644 testsuite/rootfs-pristine/test-modprobe/softdep-loop/lib/modules/4.4.4/kernel/net/bluetooth/bluetooth.ko delete mode 100644 testsuite/rootfs-pristine/test-modprobe/softdep-loop/lib/modules/4.4.4/modules.alias delete mode 100644 testsuite/rootfs-pristine/test-modprobe/softdep-loop/lib/modules/4.4.4/modules.alias.bin delete mode 100644 testsuite/rootfs-pristine/test-modprobe/softdep-loop/lib/modules/4.4.4/modules.dep delete mode 100644 testsuite/rootfs-pristine/test-modprobe/softdep-loop/lib/modules/4.4.4/modules.dep.bin delete mode 100644 testsuite/rootfs-pristine/test-modprobe/softdep-loop/lib/modules/4.4.4/modules.devname delete mode 100644 testsuite/rootfs-pristine/test-modprobe/softdep-loop/lib/modules/4.4.4/modules.softdep delete mode 100644 testsuite/rootfs-pristine/test-modprobe/softdep-loop/lib/modules/4.4.4/modules.symbols delete mode 100644 testsuite/rootfs-pristine/test-modprobe/softdep-loop/lib/modules/4.4.4/modules.symbols.bin delete mode 100644 testsuite/rootfs-pristine/test-new-module/from_alias/correct.txt delete mode 100644 testsuite/rootfs-pristine/test-new-module/from_alias/etc/modprobe.d/modprobe.conf delete mode 100644 testsuite/rootfs-pristine/test-new-module/from_name/correct.txt delete mode 100644 testsuite/rootfs-pristine/test-remove/correct.txt delete mode 100644 testsuite/rootfs-pristine/test-remove/ext4-i686.ko delete mode 100644 testsuite/rootfs-pristine/test-remove/ext4-ppc64.ko delete mode 100644 testsuite/rootfs-pristine/test-remove/ext4-s390x.ko delete mode 100644 testsuite/rootfs-pristine/test-remove/ext4-x86_64.ko delete mode 100644 testsuite/rootfs-pristine/test-rootfs/lib/modules/a delete mode 100644 testsuite/rootfs-pristine/test-rootfs/testdir/.gitignore create mode 100644 testsuite/rootfs.tar.xz delete mode 100644 testsuite/test-blacklist.c delete mode 100644 testsuite/test-dependencies.c delete mode 100644 testsuite/test-depmod.c delete mode 100644 tools/depmod.c delete mode 100644 tools/insmod.c create mode 100644 tools/kmod-depmod.c create mode 100644 tools/kmod-insmod.c create mode 100644 tools/kmod-lsmod.c create mode 100644 tools/kmod-modinfo.c create mode 100644 tools/kmod-modprobe.c create mode 100644 tools/kmod-rmmod.c delete mode 100644 tools/log.c delete mode 100644 tools/log.h delete mode 100644 tools/lsmod.c delete mode 100644 tools/modinfo.c delete mode 100644 tools/modprobe.c delete mode 100644 tools/rmmod.c delete mode 100644 tools/static-nodes.c diff --git a/.gitignore b/.gitignore index 5bfab9a..8d7c74a 100644 --- a/.gitignore +++ b/.gitignore @@ -16,7 +16,6 @@ Makefile.in /configure /libtool /stamp-h1 -/test-suite.log *~ .*.swp diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 262a1c5..0000000 --- a/.travis.yml +++ /dev/null @@ -1,17 +0,0 @@ -language: c -compiler: - - gcc - - clang -before_install: - - sudo apt-get update - - sudo apt-get install -qq liblzma-dev - - sudo apt-get install -qq zlib1g-dev - - sudo apt-get install -qq xsltproc docbook-xsl -# Change this to your needs -script: ./bootstrap-configure && make CFLAGS="-Wno-error" && make CFLAGS="-Wno-error" check -notifications: - irc: - channels: - - "irc.freenode.org#kmod" - template: - - "%{commit}: %{author} - %{message}" diff --git a/CODING-STYLE b/CODING-STYLE index 865252e..e60df9e 100644 --- a/CODING-STYLE +++ b/CODING-STYLE @@ -15,12 +15,10 @@ them is actually an error. In certain circumstances one can ignore the 80 character per line limit. This is generally only allowed if the alternative would make the code even less readable. -Besides the kernel coding style above, kmod coding style is heavily based on +Besides the kernel coding style above, kmod coding style is havily based on oFono's and BlueZ's. Below some basic rules: -1) Wrap line at 80 char limit. - -There are a few exceptions: +1) Wrap line at 80 char limit. There are a few exceptions: - Headers may or may not wrap - If it's a string that is hitting the limit, it's preferred not to break in order to be able to grep for that string. E.g: @@ -31,9 +29,6 @@ There are a few exceptions: - If there's only one argument to the function, don't put it alone in a new line. -Align the wrapped line either with tabs (BlueZ, oFono, etc) or tab + spaces -(kernel), at your discretion. Kernel's is preferred. - 2) It's better to return/exit early in a function than having a really long "if (...) { }". Example: diff --git a/Makefile.am b/Makefile.am index b1bfd59..6d0cbe4 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,8 +1,4 @@ -SUBDIRS = . libkmod/docs - -if BUILD_MANPAGES -SUBDIRS += man -endif +SUBDIRS = . libkmod/docs man DISTCLEAN_LOCAL_HOOKS = EXTRA_DIST = @@ -13,12 +9,19 @@ AM_MAKEFLAGS = --no-print-directory AM_CPPFLAGS = \ -include $(top_builddir)/config.h \ -I$(top_srcdir)/libkmod \ + -DROOTPREFIX=\""$(rootprefix)"\" \ -DSYSCONFDIR=\""$(sysconfdir)"\" \ -DLIBEXECDIR=\""$(libexecdir)"\" \ ${zlib_CFLAGS} -AM_CFLAGS = $(WARNINGFLAGS) -AM_LDFLAGS = $(GCLDFLAGS) +AM_CFLAGS = \ + -fvisibility=hidden \ + -ffunction-sections \ + -fdata-sections + +AM_LDFLAGS = \ + -Wl,--gc-sections \ + -Wl,--as-needed SED_PROCESS = \ $(AM_V_GEN)$(MKDIR_P) $(dir $@) && $(SED) \ @@ -36,9 +39,9 @@ SED_PROCESS = \ %.pc: %.pc.in Makefile $(SED_PROCESS) -LIBKMOD_CURRENT=4 -LIBKMOD_REVISION=3 -LIBKMOD_AGE=2 +LIBKMOD_CURRENT=2 +LIBKMOD_REVISION=0 +LIBKMOD_AGE=0 noinst_LTLIBRARIES = libkmod/libkmod-util.la libkmod_libkmod_util_la_SOURCES = libkmod/libkmod-hash.c \ @@ -55,7 +58,6 @@ libkmod_libkmod_la_SOURCES =\ libkmod/libkmod.h \ libkmod/libkmod-private.h \ libkmod/macro.h \ - libkmod/missing.h \ libkmod/libkmod.c \ libkmod/libkmod-list.c \ libkmod/libkmod-config.c \ @@ -63,11 +65,10 @@ libkmod_libkmod_la_SOURCES =\ libkmod/libkmod-index.h \ libkmod/libkmod-module.c \ libkmod/libkmod-file.c \ - libkmod/libkmod-elf.c \ - libkmod/libkmod-signature.c + libkmod/libkmod-elf.c EXTRA_DIST += libkmod/libkmod.sym -EXTRA_DIST += libkmod/README libkmod/COPYING testsuite/COPYING COPYING +EXTRA_DIST += libkmod/COPYING libkmod/README libkmod_libkmod_la_LDFLAGS = $(AM_LDFLAGS) \ -version-info $(LIBKMOD_CURRENT):$(LIBKMOD_REVISION):$(LIBKMOD_AGE) \ @@ -107,16 +108,19 @@ bin_PROGRAMS = tools/kmod noinst_SCRIPTS = tools/insmod tools/rmmod tools/lsmod \ tools/modprobe tools/modinfo tools/depmod -tools_kmod_SOURCES = tools/kmod.c tools/kmod.h tools/lsmod.c \ - tools/rmmod.c tools/insmod.c \ - tools/modinfo.c tools/modprobe.c \ - tools/depmod.c tools/log.h tools/log.c \ - tools/static-nodes.c +tools_kmod_SOURCES = tools/kmod.c tools/kmod.h tools/kmod-lsmod.c \ + tools/kmod-rmmod.c tools/kmod-insmod.c \ + tools/kmod-modinfo.c tools/kmod-modprobe.c \ + tools/kmod-depmod.c +tools_kmod_CPPFLAGS = $(AM_CPPFLAGS) -DKMOD_BUNDLE_TOOL=1 +tools_kmod_CFLAGS = $(AM_CFLAGS) tools_kmod_LDADD = libkmod/libkmod-util.la \ libkmod/libkmod.la noinst_PROGRAMS = tools/kmod-nolib tools_kmod_nolib_SOURCES = $(tools_kmod_SOURCES) +tools_kmod_nolib_CPPFLAGS = $(tools_kmod_CPPFLAGS) +tools_kmod_nolib_CFLAGS = $(tools_kmod_CFLAGS) tools_kmod_nolib_LDADD = libkmod/libkmod-util.la \ libkmod/libkmod-private.la @@ -129,19 +133,9 @@ endif # TESTSUITE # ------------------------------------------------------------------------------ -ROOTFS = testsuite/rootfs -ROOTFS_PRISTINE = $(top_srcdir)/testsuite/rootfs-pristine -CREATE_ROOTFS = $(AM_V_GEN) ( $(RM) -rf $(ROOTFS) && \ - cp -r $(ROOTFS_PRISTINE) $(ROOTFS) && \ - touch testsuite/stamp-rootfs && \ - find $(ROOTFS) -type d -exec chmod +w {} \; ) - -rootfs: - $(CREATE_ROOTFS) -.PHONY: rootfs - -$(ROOTFS): $(ROOTFS_PRISTINE) - $(CREATE_ROOTFS) +testsuite/rootfs: $(top_srcdir)/testsuite/rootfs.tar.xz + $(AM_V_GEN) tar -C testsuite/ \ + -xJf $(top_srcdir)/testsuite/rootfs.tar.xz TESTSUITE_OVERRIDE_LIBS = testsuite/uname.la testsuite/path.la \ testsuite/init_module.la \ @@ -149,8 +143,6 @@ TESTSUITE_OVERRIDE_LIBS = testsuite/uname.la testsuite/path.la \ TESTSUITE_OVERRIDE_LIBS_LDFLAGS = avoid-version -module -shared -export-dynamic \ -rpath /nowhere -ldl -check-am: rootfs - check_LTLIBRARIES = $(TESTSUITE_OVERRIDE_LIBS) testsuite_uname_la_LDFLAGS = $(TESTSUITE_OVERRIDE_LIBS_LDFLAGS) @@ -159,33 +151,39 @@ testsuite_path_la_LDFLAGS = $(TESTSUITE_OVERRIDE_LIBS_LDFLAGS) testsuite_delete_module_la_LDFLAGS = $(TESTSUITE_OVERRIDE_LIBS_LDFLAGS) testsuite_init_module_la_LDFLAGS = $(TESTSUITE_OVERRIDE_LIBS_LDFLAGS) testsuite_init_module_la_SOURCES = testsuite/init_module.c \ - testsuite/mkdir.c testsuite/mkdir.h \ testsuite/stripped-module.h testsuite_init_module_la_LIBADD = libkmod/libkmod-private.la +testsuite-distclean: + -rm -rf testsuite/rootfs + +testsuite-pack-rootfs: + $(AM_V_GEN) ( cd testsuite && tar -cJf \ + $(abs_top_srcdir)/testsuite/rootfs.tar.xz \ + rootfs ) + +DISTCLEAN_LOCAL_HOOKS += testsuite-distclean +EXTRA_DIST += testsuite/rootfs.tar.xz + TESTSUITE_CPPFLAGS = $(AM_CPPFLAGS) \ - -DTESTSUITE_ROOTFS=\"$(abs_top_builddir)/$(ROOTFS)/\" \ + -DTESTSUITE_ROOTFS=\"$(abs_top_builddir)/testsuite/rootfs/\" \ -DABS_TOP_BUILDDIR=\"$(abs_top_builddir)\" -TESTSUITE_LDADD = testsuite/libtestsuite.la libkmod/libkmod-private.la \ - libkmod/libkmod-util.la +TESTSUITE_LDADD = testsuite/libtestsuite.la libkmod/libkmod-private.la check_LTLIBRARIES += testsuite/libtestsuite.la testsuite_libtestsuite_la_SOURCES = testsuite/testsuite.c \ testsuite/testsuite.h -testsuite_libtestsuite_la_DEPENDENCIES = $(ROOTFS) \ - $(TESTSUITE_OVERRIDE_LIBS) +testsuite_libtestsuite_la_DEPENDENCIES = testsuite/rootfs \ + $(TESTSUITE_OVERRIDE_LIBS) testsuite_libtestsuite_la_CPPFLAGS = $(TESTSUITE_CPPFLAGS) -testsuite_libtestsuite_la_LIBADD = -lrt TESTSUITE = testsuite/test-init testsuite/test-testsuite testsuite/test-loaded \ testsuite/test-modinfo testsuite/test-alias testsuite/test-new-module \ - testsuite/test-modprobe testsuite/test-blacklist \ - testsuite/test-dependencies testsuite/test-depmod - + testsuite/test-modprobe check_PROGRAMS = $(TESTSUITE) TESTS = $(TESTSUITE) -testsuite_test_testsuite_LDADD = testsuite/libtestsuite.la libkmod/libkmod-util.la +testsuite_test_testsuite_LDADD = testsuite/libtestsuite.la testsuite_test_testsuite_CPPFLAGS = $(TESTSUITE_CPPFLAGS) testsuite_test_init_LDADD = $(TESTSUITE_LDADD) testsuite_test_init_CPPFLAGS = $(TESTSUITE_CPPFLAGS) @@ -199,21 +197,8 @@ testsuite_test_new_module_LDADD = $(TESTSUITE_LDADD) testsuite_test_new_module_CPPFLAGS = $(TESTSUITE_CPPFLAGS) testsuite_test_modprobe_LDADD = $(TESTSUITE_LDADD) testsuite_test_modprobe_CPPFLAGS = $(TESTSUITE_CPPFLAGS) -testsuite_test_blacklist_LDADD = $(TESTSUITE_LDADD) -testsuite_test_blacklist_CPPFLAGS = $(TESTSUITE_CPPFLAGS) -testsuite_test_dependencies_LDADD = $(TESTSUITE_LDADD) -testsuite_test_dependencies_CPPFLAGS = $(TESTSUITE_CPPFLAGS) -testsuite_test_depmod_LDADD = $(TESTSUITE_LDADD) -testsuite_test_depmod_CPPFLAGS = $(TESTSUITE_CPPFLAGS) - -testsuite-distclean: - $(RM) -r $(ROOTFS) - $(RM) testsuite/stamp-rootfs - -DISTCLEAN_LOCAL_HOOKS += testsuite-distclean -EXTRA_DIST += testsuite/rootfs-pristine -DISTCHECK_CONFIGURE_FLAGS=--enable-gtk-doc --sysconfdir=/etc --with-zlib +DISTCHECK_CONFIGURE_FLAGS=--enable-gtk-doc distclean-local: $(DISTCLEAN_LOCAL_HOOKS) diff --git a/NEWS b/NEWS index 5324934..4181097 100644 --- a/NEWS +++ b/NEWS @@ -1,151 +1,3 @@ -kmod 13 -======= - -- Bug fixes: - - Add the long option --symbol-prefix option to depmod (it was absent) - and fix its behavior - - Don't abort if there's a bogus line in configuration file like "alias - psmouse off". Some distros are carrying this since the days of - modutils - -- New features: - - Add support for finit_module(2). If the module is load straight from - the disk and without compression we use finit_module() syscall when - available, falling back to init_module() otherwise - - kmod_module_get_info() also returns the signature if the module is - signed and modinfo uses it - - Use secure_getenv if available - - rmmod understands builtin modules, just like modprobe does - - Improve compatibility with musl-libc - - Test cases exit with success when receiving a signal if they are - xfail tests - -kmod 12 -======= - -- Bug fixes: - - Fix removing vermagic from module when told to force load a module - - Fix removing __versions section when told to force load a module: we - need to mangle the section header, not the section. - - modinfo no longer fails while loading a module from file when path - contains ".ko" substring - -kmod 11 -======= - -- Improvements to testsuite: - - Fix testsuite defining symbols twice on 32 bit systems - - Allow to check generated files against correct ones - -- New features: - - libkmod now keeps a file opened after the first call to - kmod_module_get_{info,versions,symbols,dependency_symbols}. This - reduces signficantly the amount of time depmod tool takes to - execute. Particularly if compressed modules are used. - - Remove --with-rootprefix from build system. It was not a great idea - after all and should not be use since it causes more harm then - benefits. - - Hide --wait option on rmmod. This feature is being targeted for - removal from kernel. rmmod still accepts this option, but it's hidden - now: man page and usage() says nothing about it and if it's used, - user will get a 10s sleep. This way we can check and help if anyone - is using this feature. - - Refactor message logging on all tools, giving proper prefix, routing - everything to syslog when asked for, etc. - -- Bug fixes: - - Fix parsing of modules.order when using compressed modules - - Usage messages go to stdout instead of stderr - - Fix memory leak in hash implementation - -kmod 10 -======= - -- New features: - - Read coresize from /sys if supported - - - Add flag to kmod_module_probe_insert() to apply blacklisting during - probe only if mod is an alias. Now modprobe uses this flag by default. - This is needed to fix a change in behavior regarding module-init-tools - and ultimately makes us loading a blacklisted module. - -- Better formatting in man pages - -- Add option to disable building man pages at build time - -- Fixes in the testsuite and refactoring of LDPRELOAD'ed libraries - -- Re-licensing testsuite as LGPL - -kmod 9 -====== - -- Improvements to the testsuite: - - Check for correct handling of softdep loops - - Check for correct handling of install command loops - -- Bug fixes: - - Fix build with compilers that don't support --gc-sections - - Handle errors when dealing with gzipped modules - - depmod now handles errors while writing indices, so it doesn't end up - with a corrupted index without telling the user - -kmod 8 -====== - -- No new features, small bug fixes only. - - Fix a bug in "modprobe -c" output: be compatible with - module-init-tools - - - Give a useful error message when init_module fails due to bad - parameter or unknown symbols - - - Fix doc generation - -kmod 7 -====== - -- Re-order dirs for configuration files to match the change in systemd and - udev: now the priority is: - 1. /etc/modprobe.d - 2. /run/modprobe.d - 3. /lib/modprobe.d - -- Fix setting CFLAGS/LDFLAGS in build system. This prevented us from not - allowing the user to set his preferences. - -- Bug fixes: - - Return same error codes of module-init-tools when removing modules - with modprobe - - Fix builtin output in "--show-depends" when target kernel is not the - same of the running kernel - - 'modprobe -r' always look at all command line arguments - - Fix '-q' usage in modprobe - -kmod 6 -====== - -- New API in libkmod: - - kmod_module_apply_filter(): a generic function to apply filters in a - list of modules. This deprecates the use of - kmod_module_get_filtered_blacklist() - -- More tests in testsuite - -- Add compatibility with uClibc again - -- Lookup modules.builtin.bin to decide if a module is built in kernel - -- Downgrade some log messages so we don't annoy people with useless messages - -- Bug fixes: - - Flag --ignore-loaded was not being properly handled - - Infinite loop with softdeps - - Infinite loop with dumb user configuration with install commands - - Fix leak in index when there's a partial match - -- Move repository and tarballs to kernel.org - kmod 5 ====== diff --git a/README b/README index 65499cc..2ce8a2b 100644 --- a/README +++ b/README @@ -37,8 +37,7 @@ Hacking Run 'bootstrap' script before configure. If you want to accept the recommended flags, you just need to run 'bootstrap-configure'. -Make sure to read the CODING-STYLE file and the other READMEs: libkmod/README -and testsuite/README. +Make sure to read the CODING-STYLE file. Information =========== @@ -47,7 +46,7 @@ Signed packages: http://www.kernel.org/pub/linux/utils/kernel/kmod/ Mailing list: - linux-modules@vger.kernel.org (no subscription needed) + linux-modules@vger.kernel.org Git: git://git.kernel.org/pub/scm/utils/kernel/kmod/kmod.git diff --git a/TODO b/TODO index e3f81d1..f9e3b55 100644 --- a/TODO +++ b/TODO @@ -1,26 +1,21 @@ Features: ========= -* Add command for signing modules - - There is a script to sign modules in kernel tree, but we should be able to - sign modules by ourselves - -* Stop using NOFAIL() and fatal() - -* Protect index against OOM - -* Implement actions in kmod tool like 'insert', 'remove', 'info', etc - * testsuite: + - when fake init_module() succeeds, create an entry in /sys/module - when fake delete_module() succeeds, remove its entry from /sys/module - -* Stop using system() inside the library and use fork + exec instead - -* config: configs that do not need to be matched by fnmatch() could be using a - vector instead of a list. This way we could search in it by calling - bsearch(). - -* review API, maybe unify all of these getters: + - add test for dependency loop _with install commands_ relying on module + already been loaded in order to succeed. E.g.: alsa install rules on + debian: + + install snd /sbin/modprobe --ignore-install snd && { /sbin/modprobe --quiet snd-ioctl32 ; /sbin/modprobe --quiet snd-seq ; } + install snd_rawmidi /sbin/modprobe --ignore-install snd-rawmidi && { /sbin/modprobe --quiet snd-seq-midi ; : ; } + install snd_emu10k1 /sbin/modprobe --ignore-install snd-emu10k1 && { /sbin/modprobe --quiet snd-emu10k1-synth ; : ; } + install snd_pcm modprobe --ignore-install snd-pcm $CMDLINE_OPTS && { modprobe --quiet snd-pcm-oss ; : ; } + install snd_mixer modprobe --ignore-install snd-mixer $CMDLINE_OPTS && { modprobe --quiet snd-mixer-oss ; : ; } + install snd_seq modprobe --ignore-install snd-seq $CMDLINE_OPTS && { modprobe --quiet snd-seq-midi ; modprobe --quiet snd-seq-oss ; : ; } + +* review API, maybe unify all of these setters: - kmod_module_version_get_symbol() - kmod_module_version_get_crc() - kmod_module_symbol_get_symbol() @@ -31,12 +26,14 @@ Features: - kmod_module_symbols_free_list() - kmod_module_dependency_symbols_free_list() -* index: drop the "open(), seek(), read()" implementation and use another one - with mmap(). When lookup() is called and the file is not mmaped, mmap it. +* Stop using system() inside the library and use fork + exec instead -* Finish removal of "rmmod -w" when it's gone from kernel. +* config: configs that do not need to be matched by fnmatch() could be using a + vector instead of a list. This way we could search in it by calling + bsearch(). -* Deprecate not using KMOD_REMOVE_NOWAIT on libkmod. +* index: drop the "open(), seek(), read()" implementation and use another one + with mmap(). When lookup() is called and the file is not mmaped, mmap it. Things to be added/removed in kernel (check what is really needed): =================================================================== @@ -45,11 +42,12 @@ Things to be added/removed in kernel (check what is really needed): - readdir() in /sys/modules: dir without a 'initstate' file means the module is builtin. +* module's size should be available under /sys + - DONE in 3.3: http://git.kernel.org/?p=linux/kernel/git/torvalds/linux.git;a=commit;h=cca3e707301862ca9b9327e6a732463982f8cd1b + * kill /proc/modules ? - Unlikely, given other tools might depend on it - - Things that are different from module-init-tools on purpose (!TODO) =================================================================== diff --git a/bootstrap b/bootstrap index 5163aa0..6c73d4e 100755 --- a/bootstrap +++ b/bootstrap @@ -4,7 +4,7 @@ gtkdocize --docdir libkmod/docs || touch libkmod/docs/gtk-doc.make autoreconf --install --symlink libdir() { - (cd "$1/$(gcc -print-multi-os-directory)"; pwd) + echo $(cd $1/$(gcc -print-multi-os-directory); pwd) } args="--prefix=/usr \ diff --git a/bootstrap-configure b/bootstrap-configure index 857745e..2bcd788 100755 --- a/bootstrap-configure +++ b/bootstrap-configure @@ -1,4 +1,4 @@ #!/bin/sh . ./bootstrap && \ - exec ./configure CFLAGS="-g -O2 -Werror" $args $hackargs "$@" + exec ./configure CFLAGS="-g -O2 -Werror" $args $hackargs $* diff --git a/configure.ac b/configure.ac index 929eb7f..af70820 100644 --- a/configure.ac +++ b/configure.ac @@ -1,6 +1,6 @@ AC_PREREQ(2.60) AC_INIT([kmod], - [13], + [5], [linux-modules@vger.kernel.org], [kmod], [http://git.kernel.org/?p=utils/kernel/kmod/kmod.git]) @@ -8,7 +8,7 @@ AC_INIT([kmod], AC_CONFIG_SRCDIR([libkmod/libkmod.c]) AC_CONFIG_AUX_DIR([build-aux]) AM_INIT_AUTOMAKE([check-news foreign 1.11 silent-rules - tar-pax no-dist-gzip dist-xz subdir-objects color-tests parallel-tests]) + tar-pax no-dist-gzip dist-xz subdir-objects color-tests]) AC_PROG_CC_STDC AC_USE_SYSTEM_EXTENSIONS AC_SYS_LARGEFILE @@ -18,14 +18,6 @@ AM_SILENT_RULES([yes]) LT_INIT([disable-static pic-only]) AC_PREFIX_DEFAULT([/usr]) -AS_IF([test "x$enable_static" = "xyes"], - [AC_MSG_ERROR([--enable-static is not supported by kmod])]) - - -##################################################################### -# Program checks and configurations -##################################################################### - AC_PROG_CC AC_PROG_CC_C99 AC_C_TYPEOF @@ -35,33 +27,33 @@ AC_C_BIGENDIAN AC_PROG_SED AC_PROG_MKDIR_P +AC_PATH_PROG([XSLTPROC], [xsltproc]) PKG_PROG_PKG_CONFIG - -##################################################################### -# Function and structure checks -##################################################################### - AC_CHECK_FUNCS_ONCE(__xstat) -AC_CHECK_FUNCS_ONCE([__secure_getenv secure_getenv]) -AC_CHECK_FUNCS_ONCE([finit_module]) -# dietlibc doesn't have st.st_mtim struct member -AC_CHECK_MEMBERS([struct stat.st_mtim], [], [], [#include ]) - -# Check kernel headers -AC_CHECK_HEADERS_ONCE([linux/module.h]) - - -##################################################################### -# --with- -##################################################################### +AC_ARG_WITH([rootprefix], + AS_HELP_STRING([--with-rootprefix=DIR], [rootfs directory prefix for config files and kernel modules]), + [], [with_rootprefix=""]) +AC_SUBST([rootprefix], [$with_rootprefix]) AC_ARG_WITH([rootlibdir], AS_HELP_STRING([--with-rootlibdir=DIR], [rootfs directory to install shared libraries]), [], [with_rootlibdir=$libdir]) AC_SUBST([rootlibdir], [$with_rootlibdir]) +AC_ARG_ENABLE([tools], + AS_HELP_STRING([--disable-tools], [disable building tools that provide same functionality as module-init-tools @<:@default=enabled@:>@]), + [], enable_tools=yes) +AM_CONDITIONAL([BUILD_TOOLS], [test "x$enable_tools" = "xyes"]) + +AC_ARG_ENABLE([logging], + AS_HELP_STRING([--disable-logging], [disable system logging @<:@default=enabled@:>@]), + [], enable_logging=yes) +AS_IF([test "x$enable_logging" = "xyes"], [ + AC_DEFINE(ENABLE_LOGGING, [1], [System logging.]) +]) + AC_ARG_WITH([xz], AS_HELP_STRING([--with-xz], [handle Xz-compressed modules @<:@default=disabled@:>@]), [], [with_xz=no]) @@ -82,32 +74,6 @@ AS_IF([test "x$with_zlib" != "xno"], [ AC_MSG_NOTICE([zlib support not requested]) ]) - -##################################################################### -# --enable- -##################################################################### - -AC_ARG_ENABLE([tools], - AS_HELP_STRING([--disable-tools], [disable building tools that provide same functionality as module-init-tools @<:@default=enabled@:>@]), - [], enable_tools=yes) -AM_CONDITIONAL([BUILD_TOOLS], [test "x$enable_tools" = "xyes"]) - -AC_ARG_ENABLE([manpages], - AS_HELP_STRING([--disable-manpages], [disable manpages @<:@default=enabled@:>@]), - [], enable_manpages=yes) -AM_CONDITIONAL([BUILD_MANPAGES], [test "x$enable_manpages" = "xyes"]) -AC_PATH_PROG([XSLTPROC], [xsltproc], [no]) -AS_IF([test "x$XSLTPROC" = "xno" && test "x$enable_manpages" = "xyes"], [ - AC_MSG_ERROR([xsltproc command not found, try ./configure --disable-manpages]) -]) - -AC_ARG_ENABLE([logging], - AS_HELP_STRING([--disable-logging], [disable system logging @<:@default=enabled@:>@]), - [], enable_logging=yes) -AS_IF([test "x$enable_logging" = "xyes"], [ - AC_DEFINE(ENABLE_LOGGING, [1], [System logging.]) -]) - AC_ARG_ENABLE([debug], AS_HELP_STRING([--enable-debug], [enable debug messages @<:@default=disabled@:>@]), [], [enable_debug=no]) @@ -115,70 +81,54 @@ AS_IF([test "x$enable_debug" = "xyes"], [ AC_DEFINE(ENABLE_DEBUG, [1], [Debug messages.]) ]) -m4_ifdef([GTK_DOC_CHECK], [ -GTK_DOC_CHECK([1.14],[--flavour no-tmpl-flat]) -], [ -AM_CONDITIONAL([ENABLE_GTK_DOC], false)]) - +# dietlibc doesn't have st.st_mtim struct member +AC_CHECK_MEMBERS([struct stat.st_mtim], [], [], [#include ]) -##################################################################### -# Default CFLAGS and LDFLAGS -##################################################################### - -CC_CHECK_FLAGS_APPEND(with_cflags, [CFLAGS], [\ - -pipe \ - -DANOTHER_BRICK_IN_THE \ - -Wall \ - -W \ - -Wextra \ - -Wno-inline \ - -Wvla \ - -Wundef \ - -Wformat=2 \ - -Wlogical-op \ - -Wsign-compare \ - -Wformat-security \ - -Wmissing-include-dirs \ - -Wformat-nonliteral \ - -Wold-style-definition \ - -Wpointer-arith \ - -Winit-self \ - -Wdeclaration-after-statement \ - -Wfloat-equal \ - -Wmissing-prototypes \ - -Wstrict-prototypes \ - -Wredundant-decls \ - -Wmissing-declarations \ - -Wmissing-noreturn \ - -Wshadow \ - -Wendif-labels \ - -Wstrict-aliasing=2 \ - -Wwrite-strings \ - -Wno-long-long \ - -Wno-overlength-strings \ - -Wno-unused-parameter \ - -Wno-missing-field-initializers \ - -Wno-unused-result \ - -Wnested-externs \ - -Wchar-subscripts \ - -Wtype-limits \ - -Wuninitialized \ - -fno-common \ - -fdiagnostics-show-option \ - -fvisibility=hidden \ - -ffunction-sections \ - -fdata-sections]) -AC_SUBST([WARNINGFLAGS], $with_cflags) - - -CC_CHECK_FLAGS_APPEND([with_ldflags], [LDFLAGS], [ \ - -Wl,--as-needed \ - -Wl,--gc-sections]) -AC_SUBST([GCLDFLAGS], $with_ldflags) - -##################################################################### -# Generate files from *.in -##################################################################### +CC_CHECK_CFLAGS_APPEND([ \ + -pipe \ + -DANOTHER_BRICK_IN_THE \ + -Wall \ + -W \ + -Wextra \ + -Wno-inline \ + -Wvla \ + -Wundef \ + -Wformat=2 \ + -Wlogical-op \ + -Wsign-compare \ + -Wformat-security \ + -Wmissing-include-dirs \ + -Wformat-nonliteral \ + -Wold-style-definition \ + -Wpointer-arith \ + -Winit-self \ + -Wdeclaration-after-statement \ + -Wfloat-equal \ + -Wmissing-prototypes \ + -Wstrict-prototypes \ + -Wredundant-decls \ + -Wmissing-declarations \ + -Wmissing-noreturn \ + -Wshadow \ + -Wendif-labels \ + -Wstrict-aliasing=2 \ + -Wwrite-strings \ + -Wno-long-long \ + -Wno-overlength-strings \ + -Wno-unused-parameter \ + -Wno-missing-field-initializers \ + -Wno-unused-result \ + -Wnested-externs \ + -Wchar-subscripts \ + -Wtype-limits \ + -Wuninitialized \ + -fno-common \ + -fdiagnostics-show-option \ + -fvisibility=hidden \ + -ffunction-sections \ + -fdata-sections \ + -Wl,--as-needed \ + -Wl,--gc-sections]) AC_CONFIG_HEADERS(config.h) AC_CONFIG_FILES([ @@ -188,8 +138,10 @@ AC_CONFIG_FILES([ libkmod/docs/version.xml ]) - -##################################################################### +m4_ifdef([GTK_DOC_CHECK], [ +GTK_DOC_CHECK([1.14],[--flavour no-tmpl-flat]) +], [ +AM_CONDITIONAL([ENABLE_GTK_DOC], false)]) AC_OUTPUT AC_MSG_RESULT([ @@ -197,6 +149,7 @@ AC_MSG_RESULT([ ====== prefix: ${prefix} + rootprefix: ${rootprefix} sysconfdir: ${sysconfdir} libdir: ${libdir} rootlibdir: ${rootlibdir} @@ -204,13 +157,12 @@ AC_MSG_RESULT([ bindir: ${bindir} compiler: ${CC} - cflags: ${with_cflags} ${CFLAGS} - ldflags: ${with_ldflags} ${LDFLAGS} + cflags: ${CFLAGS} + ldflags: ${LDFLAGS} tools: ${enable_tools} logging: ${enable_logging} compression: xz=${with_xz} zlib=${with_zlib} debug: ${enable_debug} doc: ${enable_gtk_doc} - man: ${enable_manpages} ]) diff --git a/libkmod/docs/libkmod-docs.xml b/libkmod/docs/libkmod-docs.xml index fd17506..8a8f139 100644 --- a/libkmod/docs/libkmod-docs.xml +++ b/libkmod/docs/libkmod-docs.xml @@ -3,7 +3,6 @@ "http://www.oasis-open.org/docbook/xml/4.3/docbookx.dtd" [ - ]> @@ -18,10 +17,20 @@ - + + + Object Hierarchy + + API Index + + Index of deprecated API + + + + diff --git a/libkmod/docs/libkmod-sections.txt b/libkmod/docs/libkmod-sections.txt index e59ab7a..1a5a5fd 100644 --- a/libkmod/docs/libkmod-sections.txt +++ b/libkmod/docs/libkmod-sections.txt @@ -60,7 +60,6 @@ kmod_module_remove_module kmod_module_get_module kmod_module_get_dependencies kmod_module_get_softdeps -kmod_module_apply_filter kmod_module_get_filtered_blacklist kmod_module_get_install_commands kmod_module_get_remove_commands diff --git a/libkmod/libkmod-array.c b/libkmod/libkmod-array.c index 8417f9a..f9ca5cf 100644 --- a/libkmod/libkmod-array.c +++ b/libkmod/libkmod-array.c @@ -1,7 +1,7 @@ /* * libkmod - interface to kernel module operations * - * Copyright (C) 2011-2013 ProFUSION embedded systems + * Copyright (C) 2011-2012 ProFUSION embedded systems * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public diff --git a/libkmod/libkmod-array.h b/libkmod/libkmod-array.h index dd2ba55..6400993 100644 --- a/libkmod/libkmod-array.h +++ b/libkmod/libkmod-array.h @@ -1,4 +1,5 @@ -#pragma once +#ifndef _LIBKMOD_ARRAY_H_ +#define _LIBKMOD_ARRAY_H_ /* * Declaration of struct array is in header because we may want to embed the @@ -18,3 +19,5 @@ void array_pop(struct array *array); void array_free_array(struct array *array); void array_sort(struct array *array, int (*cmp)(const void *a, const void *b)); int array_remove_at(struct array *array, unsigned int pos); + +#endif diff --git a/libkmod/libkmod-config.c b/libkmod/libkmod-config.c index 11b1f3d..f2ad4b4 100644 --- a/libkmod/libkmod-config.c +++ b/libkmod/libkmod-config.c @@ -1,7 +1,7 @@ /* * libkmod - interface to kernel module operations * - * Copyright (C) 2011-2013 ProFUSION embedded systems + * Copyright (C) 2011-2012 ProFUSION embedded systems * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -108,37 +108,6 @@ const char * const *kmod_softdep_get_post(const struct kmod_list *l, unsigned in return dep->post; } -/* - * Replace dashes with underscores. - * Dashes inside character range patterns (e.g. [0-9]) are left unchanged. - */ -static char *underscores(struct kmod_ctx *ctx, char *s) -{ - unsigned int i; - - if (!s) - return NULL; - - for (i = 0; s[i]; i++) { - switch (s[i]) { - case '-': - s[i] = '_'; - break; - - case ']': - INFO(ctx, "Unmatched bracket in %s\n", s); - break; - - case '[': - i += strcspn(&s[i], "]"); - if (!s[i]) - INFO(ctx, "Unmatched bracket in %s\n", s); - break; - } - } - return s; -} - static int kmod_config_add_command(struct kmod_config *config, const char *modname, const char *command, @@ -567,10 +536,8 @@ static int kmod_config_parse_kcmdline(struct kmod_config *config) modname = p + 1; break; case '.': - if (param == NULL) { - *p = '\0'; - param = p + 1; - } + *p = '\0'; + param = p + 1; break; case '=': if (param != NULL) @@ -977,7 +944,6 @@ static struct kmod_config_iter *kmod_config_iter_new(const struct kmod_ctx* ctx, enum config_type type) { struct kmod_config_iter *iter = calloc(1, sizeof(*iter)); - const struct kmod_config *config = kmod_get_config(ctx); if (iter == NULL) return NULL; @@ -986,31 +952,31 @@ static struct kmod_config_iter *kmod_config_iter_new(const struct kmod_ctx* ctx, switch (type) { case CONFIG_TYPE_BLACKLIST: - iter->list = config->blacklists; + iter->list = kmod_get_blacklists(ctx); iter->get_key = kmod_blacklist_get_modname; break; case CONFIG_TYPE_INSTALL: - iter->list = config->install_commands; + iter->list = kmod_get_install_commands(ctx); iter->get_key = kmod_command_get_modname; iter->get_value = kmod_command_get_command; break; case CONFIG_TYPE_REMOVE: - iter->list = config->remove_commands; + iter->list = kmod_get_remove_commands(ctx); iter->get_key = kmod_command_get_modname; iter->get_value = kmod_command_get_command; break; case CONFIG_TYPE_ALIAS: - iter->list = config->aliases; + iter->list = kmod_get_aliases(ctx); iter->get_key = kmod_alias_get_name; iter->get_value = kmod_alias_get_modname; break; case CONFIG_TYPE_OPTION: - iter->list = config->options; + iter->list = kmod_get_options(ctx); iter->get_key = kmod_option_get_modname; iter->get_value = kmod_option_get_options; break; case CONFIG_TYPE_SOFTDEP: - iter->list = config->softdeps; + iter->list = kmod_get_softdeps(ctx); iter->get_key = kmod_softdep_get_name; iter->get_value = softdep_get_plain_softdep; iter->intermediate = true; @@ -1034,7 +1000,7 @@ static struct kmod_config_iter *kmod_config_iter_new(const struct kmod_ctx* ctx, * kmod_config_iter_next(). At least one call to kmod_config_iter_next() must * be made to initialize the iterator and check if it's valid. * - * Returns: a new iterator over the blacklists or NULL on failure. Free it + * Returns: a new iterator over the blacklists or %NULL on failure. Free it * with kmod_config_iter_free_iter(). */ KMOD_EXPORT struct kmod_config_iter *kmod_config_get_blacklists(const struct kmod_ctx *ctx) @@ -1054,7 +1020,7 @@ KMOD_EXPORT struct kmod_config_iter *kmod_config_get_blacklists(const struct kmo * kmod_config_iter_next(). At least one call to kmod_config_iter_next() must * be made to initialize the iterator and check if it's valid. * - * Returns: a new iterator over the install commands or NULL on failure. Free + * Returns: a new iterator over the install commands or %NULL on failure. Free * it with kmod_config_iter_free_iter(). */ KMOD_EXPORT struct kmod_config_iter *kmod_config_get_install_commands(const struct kmod_ctx *ctx) @@ -1074,7 +1040,7 @@ KMOD_EXPORT struct kmod_config_iter *kmod_config_get_install_commands(const stru * kmod_config_iter_next(). At least one call to kmod_config_iter_next() must * be made to initialize the iterator and check if it's valid. * - * Returns: a new iterator over the remove commands or NULL on failure. Free + * Returns: a new iterator over the remove commands or %NULL on failure. Free * it with kmod_config_iter_free_iter(). */ KMOD_EXPORT struct kmod_config_iter *kmod_config_get_remove_commands(const struct kmod_ctx *ctx) @@ -1094,7 +1060,7 @@ KMOD_EXPORT struct kmod_config_iter *kmod_config_get_remove_commands(const struc * kmod_config_iter_next(). At least one call to kmod_config_iter_next() must * be made to initialize the iterator and check if it's valid. * - * Returns: a new iterator over the aliases or NULL on failure. Free it with + * Returns: a new iterator over the aliases or %NULL on failure. Free it with * kmod_config_iter_free_iter(). */ KMOD_EXPORT struct kmod_config_iter *kmod_config_get_aliases(const struct kmod_ctx *ctx) @@ -1114,7 +1080,7 @@ KMOD_EXPORT struct kmod_config_iter *kmod_config_get_aliases(const struct kmod_c * kmod_config_iter_next(). At least one call to kmod_config_iter_next() must * be made to initialize the iterator and check if it's valid. * - * Returns: a new iterator over the options or NULL on failure. Free it with + * Returns: a new iterator over the options or %NULL on failure. Free it with * kmod_config_iter_free_iter(). */ KMOD_EXPORT struct kmod_config_iter *kmod_config_get_options(const struct kmod_ctx *ctx) @@ -1134,7 +1100,7 @@ KMOD_EXPORT struct kmod_config_iter *kmod_config_get_options(const struct kmod_c * kmod_config_iter_next(). At least one call to kmod_config_iter_next() must * be made to initialize the iterator and check if it's valid. * - * Returns: a new iterator over the softdeps or NULL on failure. Free it with + * Returns: a new iterator over the softdeps or %NULL on failure. Free it with * kmod_config_iter_free_iter(). */ KMOD_EXPORT struct kmod_config_iter *kmod_config_get_softdeps(const struct kmod_ctx *ctx) diff --git a/libkmod/libkmod-elf.c b/libkmod/libkmod-elf.c index 7207ac2..1f47e07 100644 --- a/libkmod/libkmod-elf.c +++ b/libkmod/libkmod-elf.c @@ -1,7 +1,7 @@ /* * libkmod - interface to kernel module operations * - * Copyright (C) 2011-2013 ProFUSION embedded systems + * Copyright (C) 2011-2012 ProFUSION embedded systems * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -243,12 +243,12 @@ static inline int elf_get_section_info(const struct kmod_elf *elf, uint16_t idx, elf_get_uint(elf, off + offsetof(typeof(*hdr), field), sizeof(hdr->field)) if (elf->class & KMOD_ELF_32) { - const Elf32_Shdr *hdr _unused_ = (const Elf32_Shdr *)p; + const Elf32_Shdr *hdr = (const Elf32_Shdr *)p; *size = READV(sh_size); *offset = READV(sh_offset); *nameoff = READV(sh_name); } else { - const Elf64_Shdr *hdr _unused_ = (const Elf64_Shdr *)p; + const Elf64_Shdr *hdr = (const Elf64_Shdr *)p; *size = READV(sh_size); *offset = READV(sh_offset); *nameoff = READV(sh_name); @@ -280,10 +280,10 @@ struct kmod_elf *kmod_elf_new(const void *memory, off_t size) size_t hdr_size, shdr_size, min_size; int class; - assert_cc(sizeof(uint16_t) == sizeof(Elf32_Half)); - assert_cc(sizeof(uint16_t) == sizeof(Elf64_Half)); - assert_cc(sizeof(uint32_t) == sizeof(Elf32_Word)); - assert_cc(sizeof(uint32_t) == sizeof(Elf64_Word)); + assert(sizeof(uint16_t) == sizeof(Elf32_Half)); + assert(sizeof(uint16_t) == sizeof(Elf64_Half)); + assert(sizeof(uint32_t) == sizeof(Elf32_Word)); + assert(sizeof(uint32_t) == sizeof(Elf64_Word)); class = elf_identify(memory, size); if (class < 0) { @@ -311,12 +311,12 @@ struct kmod_elf *kmod_elf_new(const void *memory, off_t size) elf->header.strings.section = READV(e_shstrndx); \ elf->header.machine = READV(e_machine) if (elf->class & KMOD_ELF_32) { - const Elf32_Ehdr *hdr _unused_ = elf_get_mem(elf, 0); + const Elf32_Ehdr *hdr = elf_get_mem(elf, 0); LOAD_HEADER; hdr_size = sizeof(Elf32_Ehdr); shdr_size = sizeof(Elf32_Shdr); } else { - const Elf64_Ehdr *hdr _unused_ = elf_get_mem(elf, 0); + const Elf64_Ehdr *hdr = elf_get_mem(elf, 0); LOAD_HEADER; hdr_size = sizeof(Elf64_Ehdr); shdr_size = sizeof(Elf64_Shdr); @@ -375,31 +375,6 @@ const void *kmod_elf_get_memory(const struct kmod_elf *elf) return elf->memory; } -static int elf_find_section(const struct kmod_elf *elf, const char *section) -{ - uint64_t nameslen; - const char *names = elf_get_strings_section(elf, &nameslen); - uint16_t i; - - for (i = 1; i < elf->header.section.count; i++) { - uint64_t off, size; - uint32_t nameoff; - const char *n; - int err = elf_get_section_info(elf, i, &off, &size, &nameoff); - if (err < 0) - continue; - if (nameoff >= nameslen) - continue; - n = names + nameoff; - if (!streq(section, n)) - continue; - - return i; - } - - return -ENOENT; -} - int kmod_elf_get_section(const struct kmod_elf *elf, const char *section, const void **buf, uint64_t *buf_size) { uint64_t nameslen; @@ -513,7 +488,7 @@ int kmod_elf_get_modversions(const struct kmod_elf *elf, struct kmod_modversion int i, count, err; #define MODVERSION_SEC_SIZE (sizeof(struct kmod_modversion64)) - assert_cc(sizeof(struct kmod_modversion64) == + assert(sizeof(struct kmod_modversion64) == sizeof(struct kmod_modversion32)); if (elf->class == KMOD_ELF_32) @@ -575,29 +550,26 @@ int kmod_elf_get_modversions(const struct kmod_elf *elf, struct kmod_modversion int kmod_elf_strip_section(struct kmod_elf *elf, const char *section) { - uint64_t off, size; + uint64_t size, off; const void *buf; - int idx = elf_find_section(elf, section); - uint64_t val; - - if (idx < 0) - return idx; + int err = kmod_elf_get_section(elf, section, &buf, &size); + if (err < 0) + return err; - buf = elf_get_section_header(elf, idx); off = (const uint8_t *)buf - elf->memory; +#define WRITEV(field, value) \ + elf_set_uint(elf, off + offsetof(typeof(*hdr), field), sizeof(hdr->field), value) if (elf->class & KMOD_ELF_32) { - off += offsetof(Elf32_Shdr, sh_flags); - size = sizeof(((Elf32_Shdr *)buf)->sh_flags); + const Elf32_Shdr *hdr = buf; + uint32_t val = ~(uint32_t)SHF_ALLOC; + return WRITEV(sh_flags, val); } else { - off += offsetof(Elf64_Shdr, sh_flags); - size = sizeof(((Elf64_Shdr *)buf)->sh_flags); + const Elf64_Shdr *hdr = buf; + uint64_t val = ~(uint64_t)SHF_ALLOC; + return WRITEV(sh_flags, val); } - - val = elf_get_uint(elf, off, size); - val &= ~(uint64_t)SHF_ALLOC; - - return elf_set_uint(elf, off, size, val); +#undef WRITEV } int kmod_elf_strip_vermagic(struct kmod_elf *elf) @@ -639,6 +611,7 @@ int kmod_elf_strip_vermagic(struct kmod_elf *elf) i += strlen(s); continue; } + s += len; off = (const uint8_t *)s - elf->memory; if (elf->changed == NULL) { @@ -732,6 +705,7 @@ static int kmod_elf_get_symbols_symtab(const struct kmod_elf *elf, struct kmod_m a[count].symbol = itr; memcpy(itr, strings + last, slen); itr[slen] = '\0'; + itr += slen + 1; count++; } diff --git a/libkmod/libkmod-file.c b/libkmod/libkmod-file.c index 5313796..46ad8d9 100644 --- a/libkmod/libkmod-file.c +++ b/libkmod/libkmod-file.c @@ -1,7 +1,7 @@ /* * libkmod - interface to kernel module operations * - * Copyright (C) 2011-2013 ProFUSION embedded systems + * Copyright (C) 2011-2012 ProFUSION embedded systems * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -52,12 +52,10 @@ struct kmod_file { gzFile gzf; #endif int fd; - bool direct; off_t size; void *memory; const struct file_ops *ops; const struct kmod_ctx *ctx; - struct kmod_elf *elf; }; #ifdef ENABLE_XZ @@ -201,13 +199,7 @@ static int load_zlib(struct kmod_file *file) if (r == 0) break; else if (r < 0) { - int gzerr; - const char *gz_errmsg = gzerror(file->gzf, &gzerr); - - ERR(file->ctx, "gzip: %s\n", gz_errmsg); - - /* gzip might not set errno here */ - err = gzerr == Z_ERRNO ? -errno : -EINVAL; + err = -errno; goto error; } did += r; @@ -255,11 +247,9 @@ static int load_reg(struct kmod_file *file) return -errno; file->size = st.st_size; - file->memory = mmap(NULL, file->size, PROT_READ, MAP_PRIVATE, - file->fd, 0); + file->memory = mmap(0, file->size, PROT_READ, MAP_PRIVATE, file->fd, 0); if (file->memory == MAP_FAILED) return -errno; - file->direct = true; return 0; } @@ -272,15 +262,6 @@ static const struct file_ops reg_ops = { load_reg, unload_reg }; -struct kmod_elf *kmod_file_get_elf(struct kmod_file *file) -{ - if (file->elf) - return file->elf; - - file->elf = kmod_elf_new(file->memory, file->size); - return file->elf; -} - struct kmod_file *kmod_file_open(const struct kmod_ctx *ctx, const char *filename) { @@ -303,7 +284,6 @@ struct kmod_file *kmod_file_open(const struct kmod_ctx *ctx, magic_size_max = itr->magic_size; } - file->direct = false; if (magic_size_max > 0) { char *buf = alloca(magic_size_max + 1); ssize_t sz; @@ -357,21 +337,8 @@ off_t kmod_file_get_size(const struct kmod_file *file) return file->size; } -bool kmod_file_get_direct(const struct kmod_file *file) -{ - return file->direct; -} - -int kmod_file_get_fd(const struct kmod_file *file) -{ - return file->fd; -} - void kmod_file_unref(struct kmod_file *file) { - if (file->elf) - kmod_elf_unref(file->elf); - file->ops->unload(file); if (file->fd >= 0) close(file->fd); diff --git a/libkmod/libkmod-hash.c b/libkmod/libkmod-hash.c index 57f475c..3a6c8bf 100644 --- a/libkmod/libkmod-hash.c +++ b/libkmod/libkmod-hash.c @@ -1,7 +1,7 @@ /* * libkmod - interface to kernel module operations * - * Copyright (C) 2011-2013 ProFUSION embedded systems + * Copyright (C) 2011-2012 ProFUSION embedded systems * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -21,7 +21,6 @@ #include "libkmod.h" #include "libkmod-hash.h" -#include "libkmod-util.h" #include #include #include @@ -84,6 +83,15 @@ void hash_free(struct hash *hash) free(hash); } +struct unaligned_short { + unsigned short v; +} __attribute__((packed)); + +static inline unsigned short get16bits(const char *ptr) +{ + return ((struct unaligned_short *)ptr)->v; +} + static inline unsigned int hash_superfast(const char *key, unsigned int len) { /* Paul Hsieh (http://www.azillionmonkeys.com/qed/hash.html) @@ -96,8 +104,8 @@ static inline unsigned int hash_superfast(const char *key, unsigned int len) /* Main loop */ for (; len > 0; len--) { - hash += get_unaligned((uint16_t *) key); - tmp = (get_unaligned((uint16_t *)(key + 2)) << 11) ^ hash; + hash += get16bits(key); + tmp = (get16bits(key + 2) << 11) ^ hash; hash = (hash << 16) ^ tmp; key += 4; hash += hash >> 11; @@ -106,14 +114,14 @@ static inline unsigned int hash_superfast(const char *key, unsigned int len) /* Handle end cases */ switch (rem) { case 3: - hash += get_unaligned((uint16_t *) key); + hash += get16bits(key); hash ^= hash << 16; hash ^= key[2] << 18; hash += hash >> 11; break; case 2: - hash += get_unaligned((uint16_t *) key); + hash += get16bits(key); hash ^= hash << 11; hash += hash >> 17; break; @@ -164,8 +172,7 @@ int hash_add(struct hash *hash, const char *key, const void *value) for (; entry < entry_end; entry++) { int c = strcmp(key, entry->key); if (c == 0) { - if (hash->free_value) - hash->free_value((void *)entry->value); + hash->free_value((void *)entry->value); entry->value = value; return 0; } else if (c < 0) { @@ -264,9 +271,6 @@ int hash_del(struct hash *hash, const char *key) if (entry == NULL) return -ENOENT; - if (hash->free_value) - hash->free_value((void *)entry->value); - entry_end = bucket->entries + bucket->used; memmove(entry, entry + 1, (entry_end - entry) * sizeof(struct hash_entry)); diff --git a/libkmod/libkmod-hash.h b/libkmod/libkmod-hash.h index ca0af05..8f20b8f 100644 --- a/libkmod/libkmod-hash.h +++ b/libkmod/libkmod-hash.h @@ -1,4 +1,5 @@ -#pragma once +#ifndef _LIBKMOD_HASH_H_ +#define _LIBKMOD_HASH_H_ #include @@ -20,3 +21,5 @@ unsigned int hash_get_count(const struct hash *hash); void hash_iter_init(const struct hash *hash, struct hash_iter *iter); bool hash_iter_next(struct hash_iter *iter, const char **key, const void **value); + +#endif diff --git a/libkmod/libkmod-index.c b/libkmod/libkmod-index.c index 0f94059..2a5a26e 100644 --- a/libkmod/libkmod-index.c +++ b/libkmod/libkmod-index.c @@ -1,7 +1,7 @@ /* * libkmod - interface to kernel module operations * - * Copyright (C) 2011-2013 ProFUSION embedded systems + * Copyright (C) 2011-2012 ProFUSION embedded systems * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -25,7 +25,6 @@ #include #include #include -#include #include "libkmod-private.h" #include "libkmod-index.h" @@ -432,12 +431,9 @@ void index_dump(struct index_file *in, int fd, const char *prefix) struct index_node_f *root; struct buffer buf; - root = index_readroot(in); - if (root == NULL) - return; - buf_init(&buf); buf_pushchars(&buf, prefix); + root = index_readroot(in); index_dump_node(root, &buf, fd); buf_release(&buf); } @@ -462,12 +458,13 @@ static char *index_search__node(struct index_node_f *node, const char *key, int i += j; if (key[i] == '\0') { - value = node->values != NULL - ? strdup(node->values[0].value) - : NULL; - - index_close(node); - return value; + if (node->values) { + value = strdup(node->values[0].value); + index_close(node); + return value; + } else { + return NULL; + } } child = index_readchild(node, key[i]); @@ -488,7 +485,6 @@ static char *index_search__node(struct index_node_f *node, const char *key, int */ char *index_search(struct index_file *in, const char *key) { -// FIXME: return value by reference instead of strdup struct index_node_f *root; char *value; @@ -678,7 +674,7 @@ static inline uint32_t read_long_mm(void **p) uint32_t v; /* addr may be unalined to uint32_t */ - v = get_unaligned((uint32_t *) addr); + memcpy(&v, addr, sizeof(uint32_t)); *p = addr + sizeof(uint32_t); return ntohl(v); @@ -775,9 +771,10 @@ static void index_mm_free_node(struct index_mm_node *node) } struct index_mm *index_mm_open(struct kmod_ctx *ctx, const char *filename, - unsigned long long *stamp) + bool populate, unsigned long long *stamp) { int fd; + int flags; struct stat st; struct index_mm *idx; struct { @@ -801,14 +798,15 @@ struct index_mm *index_mm_open(struct kmod_ctx *ctx, const char *filename, } fstat(fd, &st); - if ((size_t) st.st_size < sizeof(hdr)) - goto fail_nommap; + flags = MAP_PRIVATE; + if (populate) + flags |= MAP_POPULATE; - if ((idx->mm = mmap(NULL, st.st_size, PROT_READ, MAP_PRIVATE, fd, 0)) + if ((idx->mm = mmap(0, st.st_size, PROT_READ, flags, fd, 0)) == MAP_FAILED) { - ERR(ctx, "mmap(NULL, %"PRIu64", PROT_READ, %d, MAP_PRIVATE, 0): %m\n", - st.st_size, fd); - goto fail_nommap; + ERR(ctx, "mmap(0, %zd, PROT_READ, %d, %d, 0): %m\n", + (size_t)st.st_size, flags, fd); + goto fail; } p = idx->mm; @@ -838,9 +836,9 @@ struct index_mm *index_mm_open(struct kmod_ctx *ctx, const char *filename, return idx; fail: - munmap(idx->mm, st.st_size); -fail_nommap: close(fd); + if (idx->mm != MAP_FAILED) + munmap(idx->mm, st.st_size); fail_open: free(idx); return NULL; @@ -905,12 +903,9 @@ void index_mm_dump(struct index_mm *idx, int fd, const char *prefix) struct index_mm_node *root; struct buffer buf; - root = index_mm_readroot(idx); - if (root == NULL) - return; - buf_init(&buf); buf_pushchars(&buf, prefix); + root = index_mm_readroot(idx); index_mm_dump_node(root, &buf, fd); buf_release(&buf); } @@ -936,12 +931,13 @@ static char *index_mm_search_node(struct index_mm_node *node, const char *key, i += j; if (key[i] == '\0') { - value = node->values.len > 0 - ? strdup(node->values.values[0].value) - : NULL; - - index_mm_free_node(node); - return value; + if (node->values.len > 0) { + value = strdup(node->values.values[0].value); + index_mm_free_node(node); + return value; + } else { + return NULL; + } } child = index_mm_readchild(node, key[i]); @@ -962,7 +958,6 @@ static char *index_mm_search_node(struct index_mm_node *node, const char *key, */ char *index_mm_search(struct index_mm *idx, const char *key) { -// FIXME: return value by reference instead of strdup struct index_mm_node *root; char *value; diff --git a/libkmod/libkmod-index.h b/libkmod/libkmod-index.h index ad63e15..0134ac5 100644 --- a/libkmod/libkmod-index.h +++ b/libkmod/libkmod-index.h @@ -1,7 +1,7 @@ /* * libkmod - interface to kernel module operations * - * Copyright (C) 2011-2013 ProFUSION embedded systems + * Copyright (C) 2011-2012 ProFUSION embedded systems * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -18,7 +18,8 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ -#pragma once +#ifndef _LIBKMOD_INDEX_H +#define _LIBKMOD_INDEX_H #include @@ -121,8 +122,10 @@ void index_values_free(struct index_value *values); /* Implementation using mmap */ struct index_mm; struct index_mm *index_mm_open(struct kmod_ctx *ctx, const char *filename, - unsigned long long *stamp); + bool populate, unsigned long long *stamp); void index_mm_close(struct index_mm *index); char *index_mm_search(struct index_mm *idx, const char *key); struct index_value *index_mm_searchwild(struct index_mm *idx, const char *key); void index_mm_dump(struct index_mm *idx, int fd, const char *prefix); + +#endif diff --git a/libkmod/libkmod-list.c b/libkmod/libkmod-list.c index 54c994c..982c4ab 100644 --- a/libkmod/libkmod-list.c +++ b/libkmod/libkmod-list.c @@ -1,7 +1,7 @@ /* * libkmod - interface to kernel module operations * - * Copyright (C) 2011-2013 ProFUSION embedded systems + * Copyright (C) 2011-2012 ProFUSION embedded systems * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public diff --git a/libkmod/libkmod-module.c b/libkmod/libkmod-module.c index cc2c076..9f33531 100644 --- a/libkmod/libkmod-module.c +++ b/libkmod/libkmod-module.c @@ -1,7 +1,7 @@ /* * libkmod - interface to kernel module operations * - * Copyright (C) 2011-2013 ProFUSION embedded systems + * Copyright (C) 2011-2012 ProFUSION embedded systems * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -33,15 +33,10 @@ #include #include #include -#include #include #include #include -#ifdef HAVE_LINUX_MODULE_H -#include -#endif - #include "libkmod.h" #include "libkmod-private.h" @@ -65,7 +60,6 @@ struct kmod_module { const char *install_commands; /* owned by kmod_config */ const char *remove_commands; /* owned by kmod_config */ char *alias; /* only set if this module was created from an alias */ - struct kmod_file *file; int n_dep; int refcount; struct { @@ -442,10 +436,6 @@ KMOD_EXPORT struct kmod_module *kmod_module_unref(struct kmod_module *mod) kmod_pool_del_module(mod->ctx, mod, mod->hashkey); kmod_module_unref_list(mod->dep); - - if (mod->file) - kmod_file_unref(mod->file); - kmod_unref(mod->ctx); free(mod->options); free(mod->path); @@ -570,7 +560,8 @@ fail: * Drop a reference of each kmod module in @list and releases the resources * taken by the list itself. * - * Returns: 0 + * Returns: NULL if @mod is NULL or if the module was released. Otherwise it + * returns the passed @mod with its refcount decremented. */ KMOD_EXPORT int kmod_module_unref_list(struct kmod_list *list) { @@ -586,7 +577,7 @@ KMOD_EXPORT int kmod_module_unref_list(struct kmod_list *list) * @input: list of kmod_module to be filtered with blacklist * @output: where to save the new list * - * This function should not be used. Use kmod_module_apply_filter instead. + * Deprecated: use kmod_module_apply_filter instead. * * Given a list @input, this function filter it out with config's blacklist * and save it in @output. @@ -628,8 +619,9 @@ static const struct kmod_list *module_get_dependencies_noref(const struct kmod_m * The result is cached in @mod, so subsequent calls to this function will * return the already searched list of modules. * - * Returns: NULL on failure. Otherwise it returns a list of kmod modules - * that can be released by calling kmod_module_unref_list(). + * Returns: NULL on failure or if there are any dependencies. Otherwise it + * returns a list of kmod modules that can be released by calling + * kmod_module_unref_list(). */ KMOD_EXPORT struct kmod_list *kmod_module_get_dependencies(const struct kmod_module *mod) { @@ -738,15 +730,7 @@ extern long delete_module(const char *name, unsigned int flags); /** * kmod_module_remove_module: * @mod: kmod module - * @flags: flags to pass to Linux kernel when removing the module, valid flags are - * KMOD_REMOVE_FORCE: force remove module regardless if it's still in - * use by a kernel subsystem or other process; - * KMOD_REMOVE_NOWAIT: return immediately. It will fail if the module - * is in using and KMOD_REMOVE_FORCE is not specified. - * If this module is in use by any kernel subsystem or process, not using - * this flag will cause the call to block indefinitely, until the module - * is not in use anymore. Always use this flag, it's deprecated not using - * it and the default behavior might change in future to always set it. + * @flags: flags to pass to Linux kernel when removing the module * * Remove a module from Linux kernel. * @@ -778,9 +762,7 @@ extern long init_module(const void *mem, unsigned long len, const char *args); * kmod_module_insert_module: * @mod: kmod module * @flags: flags are not passed to Linux Kernel, but instead they dictate the - * behavior of this function, valid flags are - * KMOD_INSERT_FORCE_VERMAGIC: ignore kernel version magic; - * KMOD_INSERT_FORCE_MODVERSION: ignore symbol version hashes. + * behavior of this function. * @options: module's options to pass to Linux Kernel. * * Insert a module in Linux kernel. It opens the file pointed by @mod, @@ -816,19 +798,6 @@ KMOD_EXPORT int kmod_module_insert_module(struct kmod_module *mod, return err; } - if (kmod_file_get_direct(file)) { - unsigned int kernel_flags = 0; - - if (flags & KMOD_INSERT_FORCE_VERMAGIC) - kernel_flags |= MODULE_INIT_IGNORE_VERMAGIC; - if (flags & KMOD_INSERT_FORCE_MODVERSION) - kernel_flags |= MODULE_INIT_IGNORE_MODVERSIONS; - - err = finit_module(kmod_file_get_fd(file), args, kernel_flags); - if (err == 0 || errno != ENOSYS) - goto init_finished; - } - size = kmod_file_get_size(file); mem = kmod_file_get_contents(file); @@ -855,7 +824,6 @@ KMOD_EXPORT int kmod_module_insert_module(struct kmod_module *mod, } err = init_module(mem, size, args); -init_finished: if (err < 0) { err = -errno; INFO(mod->ctx, "Failed to insert module '%s': %m\n", path); @@ -872,8 +840,7 @@ elf_failed: static bool module_is_blacklisted(struct kmod_module *mod) { struct kmod_ctx *ctx = mod->ctx; - const struct kmod_config *config = kmod_get_config(ctx); - const struct kmod_list *bl = config->blacklists; + const struct kmod_list *bl = kmod_get_blacklists(ctx); const struct kmod_list *l; kmod_list_foreach(l, bl) { @@ -889,9 +856,7 @@ static bool module_is_blacklisted(struct kmod_module *mod) /** * kmod_module_apply_filter * @ctx: kmod library context - * @filter_type: bitmask to filter modules out, valid types are - * KMOD_FILTER_BLACKLIST: filter modules in blacklist out; - * KMOD_FILTER_BUILTIN: filter builtin modules out. + * @filter_type: bitmask to filter modules on * @input: list of kmod_module to be filtered * @output: where to save the new list * @@ -923,7 +888,8 @@ KMOD_EXPORT int kmod_module_apply_filter(const struct kmod_ctx *ctx, module_is_blacklisted(mod)) continue; - if ((filter_type & KMOD_FILTER_BUILTIN) && mod->builtin) + if ((filter_type & KMOD_FILTER_BUILTIN) && + kmod_module_get_initstate(mod) == KMOD_MODULE_BUILTIN) continue; node = kmod_list_append(*output, mod); @@ -1162,25 +1128,7 @@ static int kmod_module_get_probe_list(struct kmod_module *mod, * kmod_module_probe_insert_module: * @mod: kmod module * @flags: flags are not passed to Linux Kernel, but instead they dictate the - * behavior of this function, valid flags are - * KMOD_PROBE_FORCE_VERMAGIC: ignore kernel version magic; - * KMOD_PROBE_FORCE_MODVERSION: ignore symbol version hashes; - * KMOD_PROBE_IGNORE_COMMAND: whether the probe should ignore install - * commands and softdeps configured in the system; - * KMOD_PROBE_IGNORE_LOADED: do not check whether the module is already - * live in kernel or not; - * KMOD_PROBE_DRY_RUN: dry run, do not insert module, just call the - * associated callback function; - * KMOD_PROBE_FAIL_ON_LOADED: if KMOD_PROBE_IGNORE_LOADED is not specified - * and the module is already live in kernel, the function will fail if this - * flag is specified; - * KMOD_PROBE_APPLY_BLACKLIST_ALL: probe will apply KMOD_FILTER_BLACKLIST - * filter to this module and its dependencies. If any of the dependencies (or - * the module) is blacklisted, the probe will fail, unless the blacklisted - * module is already live in kernel; - * KMOD_PROBE_APPLY_BLACKLIST: probe will fail if the module is blacklisted; - * KMOD_PROBE_APPLY_BLACKLIST_ALIAS_ONLY: probe will fail if the module is an - * alias and is blacklisted. + * behavior of this function. * @extra_options: module's options to pass to Linux Kernel. It applies only * to @mod, not to its dependencies. * @run_install: function to run when @mod is backed by an install command. @@ -1224,15 +1172,9 @@ KMOD_EXPORT int kmod_module_probe_insert_module(struct kmod_module *mod, return 0; } - /* - * Ugly assignement + check. We need to check if we were told to check - * blacklist and also return the reason why we failed. - * KMOD_PROBE_APPLY_BLACKLIST_ALIAS_ONLY will take effect only if the - * module is an alias, so we also need to check it - */ - if ((mod->alias != NULL && ((err = flags & KMOD_PROBE_APPLY_BLACKLIST_ALIAS_ONLY))) - || (err = flags & KMOD_PROBE_APPLY_BLACKLIST_ALL) - || (err = flags & KMOD_PROBE_APPLY_BLACKLIST)) { + err = flags & (KMOD_PROBE_APPLY_BLACKLIST | + KMOD_PROBE_APPLY_BLACKLIST_ALL); + if (err != 0) { if (module_is_blacklisted(mod)) return err; } @@ -1339,14 +1281,13 @@ KMOD_EXPORT const char *kmod_module_get_options(const struct kmod_module *mod) if (!mod->init.options) { /* lazy init */ struct kmod_module *m = (struct kmod_module *)mod; - const struct kmod_list *l; - const struct kmod_config *config; + const struct kmod_list *l, *ctx_options; char *opts = NULL; size_t optslen = 0; - config = kmod_get_config(mod->ctx); + ctx_options = kmod_get_options(mod->ctx); - kmod_list_foreach(l, config->options) { + kmod_list_foreach(l, ctx_options) { const char *modname = kmod_option_get_modname(l); const char *str; size_t len; @@ -1414,12 +1355,11 @@ KMOD_EXPORT const char *kmod_module_get_install_commands(const struct kmod_modul if (!mod->init.install_commands) { /* lazy init */ struct kmod_module *m = (struct kmod_module *)mod; - const struct kmod_list *l; - const struct kmod_config *config; + const struct kmod_list *l, *ctx_install_commands; - config = kmod_get_config(mod->ctx); + ctx_install_commands = kmod_get_install_commands(mod->ctx); - kmod_list_foreach(l, config->install_commands) { + kmod_list_foreach(l, ctx_install_commands) { const char *modname = kmod_command_get_modname(l); if (fnmatch(modname, mod->name, 0) != 0) @@ -1487,8 +1427,7 @@ KMOD_EXPORT int kmod_module_get_softdeps(const struct kmod_module *mod, struct kmod_list **pre, struct kmod_list **post) { - const struct kmod_list *l; - const struct kmod_config *config; + const struct kmod_list *l, *ctx_softdeps; if (mod == NULL || pre == NULL || post == NULL) return -ENOENT; @@ -1496,9 +1435,9 @@ KMOD_EXPORT int kmod_module_get_softdeps(const struct kmod_module *mod, assert(*pre == NULL); assert(*post == NULL); - config = kmod_get_config(mod->ctx); + ctx_softdeps = kmod_get_softdeps(mod->ctx); - kmod_list_foreach(l, config->softdeps) { + kmod_list_foreach(l, ctx_softdeps) { const char *modname = kmod_softdep_get_name(l); const char * const *array; unsigned count; @@ -1543,12 +1482,11 @@ KMOD_EXPORT const char *kmod_module_get_remove_commands(const struct kmod_module if (!mod->init.remove_commands) { /* lazy init */ struct kmod_module *m = (struct kmod_module *)mod; - const struct kmod_list *l; - const struct kmod_config *config; + const struct kmod_list *l, *ctx_remove_commands; - config = kmod_get_config(mod->ctx); + ctx_remove_commands = kmod_get_remove_commands(mod->ctx); - kmod_list_foreach(l, config->remove_commands) { + kmod_list_foreach(l, ctx_remove_commands) { const char *modname = kmod_command_get_modname(l); if (fnmatch(modname, mod->name, 0) != 0) @@ -1592,7 +1530,7 @@ void kmod_module_set_remove_commands(struct kmod_module *mod, const char *cmd) * Create a new list of kmod modules with all modules currently loaded in * kernel. It uses /proc/modules to get the names of loaded modules and to * create kmod modules by calling kmod_module_new_from_name() in each of them. - * They are put in @list in no particular order. + * They are put are put in @list in no particular order. * * The initial refcount is 1, and needs to be decremented to release the * resources of the kmod_module. The returned @list must be released by @@ -1680,11 +1618,7 @@ KMOD_EXPORT const char *kmod_module_initstate_str(enum kmod_module_initstate sta * Get the initstate of this @mod, as returned by Linux Kernel, by reading * /sys filesystem. * - * Returns: < 0 on error or module state if module is found in kernel, valid states are - * KMOD_MODULE_BUILTIN: module is builtin; - * KMOD_MODULE_LIVE: module is live in kernel; - * KMOD_MODULE_COMING: module is being loaded; - * KMOD_MODULE_GOING: module is being unloaded. + * Returns: < 0 on error or enum kmod_initstate if module is found in kernel. */ KMOD_EXPORT int kmod_module_get_initstate(const struct kmod_module *mod) { @@ -1741,43 +1675,22 @@ KMOD_EXPORT int kmod_module_get_initstate(const struct kmod_module *mod) * kmod_module_get_size: * @mod: kmod module * - * Get the size of this kmod module as returned by Linux kernel. If supported, - * the size is read from the coresize attribute in /sys/module. For older - * kernels, this falls back on /proc/modules and searches for the specified - * module to get its size. + * Get the size of this kmod module as returned by Linux kernel. It reads the + * file /proc/modules to search for this module and get its size. * * Returns: the size of this kmod module. */ KMOD_EXPORT long kmod_module_get_size(const struct kmod_module *mod) { + // FIXME TODO: this should be available from /sys/module/foo FILE *fp; char line[4096]; int lineno = 0; long size = -ENOENT; - int dfd, cfd; if (mod == NULL) return -ENOENT; - /* try to open the module dir in /sys. If this fails, don't - * bother trying to find the size as we know the module isn't - * loaded. - */ - snprintf(line, sizeof(line), "/sys/module/%s", mod->name); - dfd = open(line, O_RDONLY); - if (dfd < 0) - return -errno; - - /* available as of linux 3.3.x */ - cfd = openat(dfd, "coresize", O_RDONLY|O_CLOEXEC); - if (cfd >= 0) { - if (read_str_long(cfd, &size, 10) < 0) - ERR(mod->ctx, "failed to read coresize from %s\n", line); - close(cfd); - goto done; - } - - /* fall back on parsing /proc/modules */ fp = fopen("/proc/modules", "re"); if (fp == NULL) { int err = -errno; @@ -1812,9 +1725,6 @@ KMOD_EXPORT long kmod_module_get_size(const struct kmod_module *mod) break; } fclose(fp); - -done: - close(dfd); return size; } @@ -1840,7 +1750,7 @@ KMOD_EXPORT int kmod_module_get_refcnt(const struct kmod_module *mod) fd = open(path, O_RDONLY|O_CLOEXEC); if (fd < 0) { err = -errno; - DBG(mod->ctx, "could not open '%s': %s\n", + ERR(mod->ctx, "could not open '%s': %s\n", path, strerror(errno)); return err; } @@ -1871,7 +1781,7 @@ KMOD_EXPORT struct kmod_list *kmod_module_get_holders(const struct kmod_module * struct kmod_list *list = NULL; DIR *d; - if (mod == NULL || mod->ctx == NULL) + if (mod == NULL) return NULL; snprintf(dname, sizeof(dname), "/sys/module/%s/holders", mod->name); @@ -2099,25 +2009,6 @@ KMOD_EXPORT void kmod_module_section_free_list(struct kmod_list *list) } } -static struct kmod_elf *kmod_module_get_elf(const struct kmod_module *mod) -{ - if (mod->file == NULL) { - const char *path = kmod_module_get_path(mod); - - if (path == NULL) { - errno = ENOENT; - return NULL; - } - - ((struct kmod_module *)mod)->file = kmod_file_open(mod->ctx, - path); - if (mod->file == NULL) - return NULL; - } - - return kmod_file_get_elf(mod->file); -} - struct kmod_module_info { char *key; char value[]; @@ -2132,7 +2023,7 @@ static struct kmod_module_info *kmod_module_info_new(const char *key, size_t key return NULL; info->key = (char *)info + sizeof(struct kmod_module_info) - + valuelen + 1; + + valuelen + 1; memcpy(info->key, key, keylen); info->key[keylen] = '\0'; memcpy(info->value, value, valuelen); @@ -2145,22 +2036,6 @@ static void kmod_module_info_free(struct kmod_module_info *info) free(info); } -static struct kmod_list *kmod_module_info_append(struct kmod_list **list, const char *key, size_t keylen, const char *value, size_t valuelen) -{ - struct kmod_module_info *info; - struct kmod_list *n; - - info = kmod_module_info_new(key, keylen, value, valuelen); - if (info == NULL) - return NULL; - n = kmod_list_append(*list, info); - if (n != NULL) - *list = n; - else - kmod_module_info_free(info); - return n; -} - /** * kmod_module_get_info: * @mod: kmod module @@ -2171,9 +2046,7 @@ static struct kmod_list *kmod_module_info_append(struct kmod_list **list, const * * Get a list of entries in ELF section ".modinfo", these contain * alias, license, depends, vermagic and other keys with respective - * values. If the module is signed (CONFIG_MODULE_SIG), information - * about the module signature is included as well: signer, - * sig_key and sig_hashalgo. + * values. * * After use, free the @list by calling kmod_module_info_free_list(). * @@ -2181,25 +2054,44 @@ static struct kmod_list *kmod_module_info_append(struct kmod_list **list, const */ KMOD_EXPORT int kmod_module_get_info(const struct kmod_module *mod, struct kmod_list **list) { + struct kmod_file *file; struct kmod_elf *elf; + const char *path; + const void *mem; char **strings; - int i, count, ret = -ENOMEM; - struct kmod_signature_info sig_info; + size_t size; + int i, count, ret = 0; if (mod == NULL || list == NULL) return -ENOENT; assert(*list == NULL); - elf = kmod_module_get_elf(mod); - if (elf == NULL) + path = kmod_module_get_path(mod); + if (path == NULL) + return -ENOENT; + + file = kmod_file_open(mod->ctx, path); + if (file == NULL) return -errno; + size = kmod_file_get_size(file); + mem = kmod_file_get_contents(file); + + elf = kmod_elf_new(mem, size); + if (elf == NULL) { + ret = -errno; + goto elf_open_error; + } + count = kmod_elf_get_strings(elf, ".modinfo", &strings); - if (count < 0) - return count; + if (count < 0) { + ret = count; + goto get_strings_error; + } for (i = 0; i < count; i++) { + struct kmod_module_info *info; struct kmod_list *n; const char *key, *value; size_t keylen, valuelen; @@ -2209,65 +2101,40 @@ KMOD_EXPORT int kmod_module_get_info(const struct kmod_module *mod, struct kmod_ if (value == NULL) { keylen = strlen(key); valuelen = 0; - value = key; } else { keylen = value - key; value++; valuelen = strlen(value); } - n = kmod_module_info_append(list, key, keylen, value, valuelen); - if (n == NULL) - goto list_error; - } - - if (kmod_module_signature_info(mod->file, &sig_info)) { - struct kmod_list *n; - char *key_hex; - - n = kmod_module_info_append(list, "signer", strlen("signer"), - sig_info.signer, sig_info.signer_len); - if (n == NULL) - goto list_error; - count++; - - /* Display the key id as 01:12:DE:AD:BE:EF:... */ - key_hex = malloc(sig_info.key_id_len * 3); - if (key_hex == NULL) + info = kmod_module_info_new(key, keylen, value, valuelen); + if (info == NULL) { + ret = -errno; + kmod_module_info_free_list(*list); + *list = NULL; goto list_error; - for (i = 0; i < (int)sig_info.key_id_len; i++) { - sprintf(key_hex + i * 3, "%02X", - (unsigned char)sig_info.key_id[i]); - if (i < (int)sig_info.key_id_len - 1) - key_hex[i * 3 + 2] = ':'; } - n = kmod_module_info_append(list, "sig_key", strlen("sig_key"), - key_hex, sig_info.key_id_len * 3 - 1); - free(key_hex); - if (n == NULL) - goto list_error; - count++; - n = kmod_module_info_append(list, - "sig_hashalgo", strlen("sig_hashalgo"), - sig_info.hash_algo, strlen(sig_info.hash_algo)); - if (n == NULL) + n = kmod_list_append(*list, info); + if (n != NULL) + *list = n; + else { + kmod_module_info_free(info); + kmod_module_info_free_list(*list); + *list = NULL; + ret = -ENOMEM; goto list_error; - count++; - - /* - * Omit sig_info.id_type and sig_info.algo for now, as these - * are currently constant. - */ + } } ret = count; list_error: - if (ret < 0) { - kmod_module_info_free_list(*list); - *list = NULL; - } free(strings); +get_strings_error: + kmod_elf_unref(elf); +elf_open_error: + kmod_file_unref(file); + return ret; } @@ -2365,8 +2232,12 @@ static void kmod_module_version_free(struct kmod_module_version *version) */ KMOD_EXPORT int kmod_module_get_versions(const struct kmod_module *mod, struct kmod_list **list) { + struct kmod_file *file; struct kmod_elf *elf; + const char *path; + const void *mem; struct kmod_modversion *versions; + size_t size; int i, count, ret = 0; if (mod == NULL || list == NULL) @@ -2374,13 +2245,28 @@ KMOD_EXPORT int kmod_module_get_versions(const struct kmod_module *mod, struct k assert(*list == NULL); - elf = kmod_module_get_elf(mod); - if (elf == NULL) + path = kmod_module_get_path(mod); + if (path == NULL) + return -ENOENT; + + file = kmod_file_open(mod->ctx, path); + if (file == NULL) return -errno; + size = kmod_file_get_size(file); + mem = kmod_file_get_contents(file); + + elf = kmod_elf_new(mem, size); + if (elf == NULL) { + ret = -errno; + goto elf_open_error; + } + count = kmod_elf_get_modversions(elf, &versions); - if (count < 0) - return count; + if (count < 0) { + ret = count; + goto get_strings_error; + } for (i = 0; i < count; i++) { struct kmod_module_version *mv; @@ -2409,11 +2295,16 @@ KMOD_EXPORT int kmod_module_get_versions(const struct kmod_module *mod, struct k list_error: free(versions); +get_strings_error: + kmod_elf_unref(elf); +elf_open_error: + kmod_file_unref(file); + return ret; } /** - * kmod_module_version_get_symbol: + * kmod_module_versions_get_symbol: * @entry: a list entry representing a kmod module versions * * Get the symbol of a kmod module versions. @@ -2506,8 +2397,12 @@ static void kmod_module_symbol_free(struct kmod_module_symbol *symbol) */ KMOD_EXPORT int kmod_module_get_symbols(const struct kmod_module *mod, struct kmod_list **list) { + struct kmod_file *file; struct kmod_elf *elf; + const char *path; + const void *mem; struct kmod_modversion *symbols; + size_t size; int i, count, ret = 0; if (mod == NULL || list == NULL) @@ -2515,13 +2410,28 @@ KMOD_EXPORT int kmod_module_get_symbols(const struct kmod_module *mod, struct km assert(*list == NULL); - elf = kmod_module_get_elf(mod); - if (elf == NULL) + path = kmod_module_get_path(mod); + if (path == NULL) + return -ENOENT; + + file = kmod_file_open(mod->ctx, path); + if (file == NULL) return -errno; + size = kmod_file_get_size(file); + mem = kmod_file_get_contents(file); + + elf = kmod_elf_new(mem, size); + if (elf == NULL) { + ret = -errno; + goto elf_open_error; + } + count = kmod_elf_get_symbols(elf, &symbols); - if (count < 0) - return count; + if (count < 0) { + ret = count; + goto get_strings_error; + } for (i = 0; i < count; i++) { struct kmod_module_symbol *mv; @@ -2550,6 +2460,11 @@ KMOD_EXPORT int kmod_module_get_symbols(const struct kmod_module *mod, struct km list_error: free(symbols); +get_strings_error: + kmod_elf_unref(elf); +elf_open_error: + kmod_file_unref(file); + return ret; } @@ -2650,8 +2565,12 @@ static void kmod_module_dependency_symbol_free(struct kmod_module_dependency_sym */ KMOD_EXPORT int kmod_module_get_dependency_symbols(const struct kmod_module *mod, struct kmod_list **list) { + struct kmod_file *file; struct kmod_elf *elf; + const char *path; + const void *mem; struct kmod_modversion *symbols; + size_t size; int i, count, ret = 0; if (mod == NULL || list == NULL) @@ -2659,13 +2578,28 @@ KMOD_EXPORT int kmod_module_get_dependency_symbols(const struct kmod_module *mod assert(*list == NULL); - elf = kmod_module_get_elf(mod); - if (elf == NULL) + path = kmod_module_get_path(mod); + if (path == NULL) + return -ENOENT; + + file = kmod_file_open(mod->ctx, path); + if (file == NULL) return -errno; + size = kmod_file_get_size(file); + mem = kmod_file_get_contents(file); + + elf = kmod_elf_new(mem, size); + if (elf == NULL) { + ret = -errno; + goto elf_open_error; + } + count = kmod_elf_get_dependency_symbols(elf, &symbols); - if (count < 0) - return count; + if (count < 0) { + ret = count; + goto get_strings_error; + } for (i = 0; i < count; i++) { struct kmod_module_dependency_symbol *mv; @@ -2696,6 +2630,11 @@ KMOD_EXPORT int kmod_module_get_dependency_symbols(const struct kmod_module *mod list_error: free(symbols); +get_strings_error: + kmod_elf_unref(elf); +elf_open_error: + kmod_file_unref(file); + return ret; } diff --git a/libkmod/libkmod-private.h b/libkmod/libkmod-private.h index 0180124..ebda945 100644 --- a/libkmod/libkmod-private.h +++ b/libkmod/libkmod-private.h @@ -1,15 +1,15 @@ -#pragma once +#ifndef _LIBKMOD_PRIVATE_H_ +#define _LIBKMOD_PRIVATE_H_ #include #include #include #include -#include "missing.h" #include "macro.h" #include "libkmod.h" -static _always_inline_ _printf_format_(2, 3) void +static __always_inline __printf_format(2, 3) void kmod_log_null(struct kmod_ctx *ctx, const char *format, ...) {} #define kmod_log_cond(ctx, prio, arg...) \ @@ -36,15 +36,6 @@ static _always_inline_ _printf_format_(2, 3) void #define KCMD_LINE_SIZE 4096 -#ifndef HAVE_SECURE_GETENV -# ifdef HAVE___SECURE_GETENV -# define secure_getenv __secure_getenv -# else -# warning neither secure_getenv nor __secure_getenv is available -# define secure_getenv getenv -# endif -#endif - void kmod_log(const struct kmod_ctx *ctx, int priority, const char *file, int line, const char *fn, const char *format, ...) __attribute__((format(printf, 6, 7))) __attribute__((nonnull(1, 3, 5))); @@ -58,16 +49,16 @@ struct kmod_list { void *data; }; -struct kmod_list *kmod_list_append(struct kmod_list *list, const void *data) _must_check_ __attribute__((nonnull(2))); -struct kmod_list *kmod_list_prepend(struct kmod_list *list, const void *data) _must_check_ __attribute__((nonnull(2))); -struct kmod_list *kmod_list_remove(struct kmod_list *list) _must_check_; +struct kmod_list *kmod_list_append(struct kmod_list *list, const void *data) __must_check __attribute__((nonnull(2))); +struct kmod_list *kmod_list_prepend(struct kmod_list *list, const void *data) __must_check __attribute__((nonnull(2))); +struct kmod_list *kmod_list_remove(struct kmod_list *list) __must_check; struct kmod_list *kmod_list_remove_data(struct kmod_list *list, - const void *data) _must_check_ __attribute__((nonnull(2))); + const void *data) __must_check __attribute__((nonnull(2))); struct kmod_list *kmod_list_remove_n_latest(struct kmod_list *list, - unsigned int n) _must_check_; + unsigned int n) __must_check; struct kmod_list *kmod_list_insert_after(struct kmod_list *list, const void *data) __attribute__((nonnull(2))); struct kmod_list *kmod_list_insert_before(struct kmod_list *list, const void *data) __attribute__((nonnull(2))); -struct kmod_list *kmod_list_append_list(struct kmod_list *list1, struct kmod_list *list2) _must_check_; +struct kmod_list *kmod_list_append_list(struct kmod_list *list1, struct kmod_list *list2) __must_check; #undef kmod_list_foreach #define kmod_list_foreach(list_entry, first_entry) \ @@ -97,10 +88,16 @@ void kmod_set_modules_visited(struct kmod_ctx *ctx, bool visited) __attribute__( char *kmod_search_moddep(struct kmod_ctx *ctx, const char *name) __attribute__((nonnull(1,2))); struct kmod_module *kmod_pool_get_module(struct kmod_ctx *ctx, const char *key) __attribute__((nonnull(1,2))); -void kmod_pool_add_module(struct kmod_ctx *ctx, struct kmod_module *mod, const char *key) __attribute__((nonnull(1, 2, 3))); -void kmod_pool_del_module(struct kmod_ctx *ctx, struct kmod_module *mod, const char *key) __attribute__((nonnull(1, 2, 3))); +void kmod_pool_add_module(struct kmod_ctx *ctx, struct kmod_module *mod, const char *key) __attribute__((nonnull(1,2, 3))); +void kmod_pool_del_module(struct kmod_ctx *ctx, struct kmod_module *mod, const char *key) __attribute__((nonnull(1,2, 3))); + +const struct kmod_list *kmod_get_blacklists(const struct kmod_ctx *ctx) __must_check __attribute__((nonnull(1))); +const struct kmod_list *kmod_get_options(const struct kmod_ctx *ctx) __must_check __attribute__((nonnull(1))); +const struct kmod_list *kmod_get_install_commands(const struct kmod_ctx *ctx) __must_check __attribute__((nonnull(1))); +const struct kmod_list *kmod_get_remove_commands(const struct kmod_ctx *ctx) __must_check __attribute__((nonnull(1))); +const struct kmod_list *kmod_get_softdeps(const struct kmod_ctx *ctx) __must_check __attribute__((nonnull(1))); +const struct kmod_list *kmod_get_aliases(const struct kmod_ctx *ctx) __must_check __attribute__((nonnull(1))); -const struct kmod_config *kmod_get_config(const struct kmod_ctx *ctx) __attribute__((nonnull(1))); /* libkmod-config.c */ struct kmod_config_path { @@ -148,12 +145,9 @@ void kmod_module_set_builtin(struct kmod_module *mod, bool builtin) __attribute_ #include "libkmod-hash.h" /* libkmod-file.c */ -struct kmod_file *kmod_file_open(const struct kmod_ctx *ctx, const char *filename) _must_check_ __attribute__((nonnull(1,2))); -struct kmod_elf *kmod_file_get_elf(struct kmod_file *file) __attribute__((nonnull(1))); -void *kmod_file_get_contents(const struct kmod_file *file) _must_check_ __attribute__((nonnull(1))); -off_t kmod_file_get_size(const struct kmod_file *file) _must_check_ __attribute__((nonnull(1))); -bool kmod_file_get_direct(const struct kmod_file *file) _must_check_ __attribute__((nonnull(1))); -int kmod_file_get_fd(const struct kmod_file *file) _must_check_ __attribute__((nonnull(1))); +struct kmod_file *kmod_file_open(const struct kmod_ctx *ctx, const char *filename) __must_check __attribute__((nonnull(1,2))); +void *kmod_file_get_contents(const struct kmod_file *file) __must_check __attribute__((nonnull(1))); +off_t kmod_file_get_size(const struct kmod_file *file) __must_check __attribute__((nonnull(1))); void kmod_file_unref(struct kmod_file *file) __attribute__((nonnull(1))); /* libkmod-elf.c */ @@ -164,30 +158,23 @@ struct kmod_modversion { char *symbol; }; -struct kmod_elf *kmod_elf_new(const void *memory, off_t size) _must_check_ __attribute__((nonnull(1))); +struct kmod_elf *kmod_elf_new(const void *memory, off_t size) __must_check __attribute__((nonnull(1))); void kmod_elf_unref(struct kmod_elf *elf) __attribute__((nonnull(1))); -const void *kmod_elf_get_memory(const struct kmod_elf *elf) _must_check_ __attribute__((nonnull(1))); -int kmod_elf_get_strings(const struct kmod_elf *elf, const char *section, char ***array) _must_check_ __attribute__((nonnull(1,2,3))); -int kmod_elf_get_modversions(const struct kmod_elf *elf, struct kmod_modversion **array) _must_check_ __attribute__((nonnull(1,2))); -int kmod_elf_get_symbols(const struct kmod_elf *elf, struct kmod_modversion **array) _must_check_ __attribute__((nonnull(1,2))); -int kmod_elf_get_dependency_symbols(const struct kmod_elf *elf, struct kmod_modversion **array) _must_check_ __attribute__((nonnull(1,2))); -int kmod_elf_strip_section(struct kmod_elf *elf, const char *section) _must_check_ __attribute__((nonnull(1,2))); -int kmod_elf_strip_vermagic(struct kmod_elf *elf) _must_check_ __attribute__((nonnull(1))); +const void *kmod_elf_get_memory(const struct kmod_elf *elf) __must_check __attribute__((nonnull(1))); +int kmod_elf_get_strings(const struct kmod_elf *elf, const char *section, char ***array) __must_check __attribute__((nonnull(1,2,3))); +int kmod_elf_get_modversions(const struct kmod_elf *elf, struct kmod_modversion **array) __must_check __attribute__((nonnull(1,2))); +int kmod_elf_get_symbols(const struct kmod_elf *elf, struct kmod_modversion **array) __must_check __attribute__((nonnull(1,2))); +int kmod_elf_get_dependency_symbols(const struct kmod_elf *elf, struct kmod_modversion **array) __must_check __attribute__((nonnull(1,2))); +int kmod_elf_strip_section(struct kmod_elf *elf, const char *section) __must_check __attribute__((nonnull(1,2))); +int kmod_elf_strip_vermagic(struct kmod_elf *elf) __must_check __attribute__((nonnull(1))); /* * Debug mock lib need to find section ".gnu.linkonce.this_module" in order to * get modname */ -int kmod_elf_get_section(const struct kmod_elf *elf, const char *section, const void **buf, uint64_t *buf_size) _must_check_ __attribute__((nonnull(1,2,3,4))); - -/* libkmod-signature.c */ -struct kmod_signature_info { - const char *signer; - size_t signer_len; - const char *key_id; - size_t key_id_len; - const char *algo, *hash_algo, *id_type; -}; -bool kmod_module_signature_info(const struct kmod_file *file, struct kmod_signature_info *sig_info) _must_check_ __attribute__((nonnull(1, 2))); +int kmod_elf_get_section(const struct kmod_elf *elf, const char *section, const void **buf, uint64_t *buf_size) __must_check __attribute__((nonnull(1,2,3,4))); + /* util functions */ #include "libkmod-util.h" + +#endif diff --git a/libkmod/libkmod-signature.c b/libkmod/libkmod-signature.c deleted file mode 100644 index 6b80caa..0000000 --- a/libkmod/libkmod-signature.c +++ /dev/null @@ -1,141 +0,0 @@ -/* - * libkmod - module signature display - * - * Copyright (C) 2013 Michal Marek, SUSE - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include -#include -#include -#include -#include - -#include "libkmod-private.h" - -/* These types and tables were copied from the 3.7 kernel sources. - * As this is just description of the signature format, it should not be - * considered derived work (so libkmod can use the LGPL license). - */ -enum pkey_algo { - PKEY_ALGO_DSA, - PKEY_ALGO_RSA, - PKEY_ALGO__LAST -}; - -static const char *const pkey_algo[PKEY_ALGO__LAST] = { - [PKEY_ALGO_DSA] = "DSA", - [PKEY_ALGO_RSA] = "RSA", -}; - -enum pkey_hash_algo { - PKEY_HASH_MD4, - PKEY_HASH_MD5, - PKEY_HASH_SHA1, - PKEY_HASH_RIPE_MD_160, - PKEY_HASH_SHA256, - PKEY_HASH_SHA384, - PKEY_HASH_SHA512, - PKEY_HASH_SHA224, - PKEY_HASH__LAST -}; - -const char *const pkey_hash_algo[PKEY_HASH__LAST] = { - [PKEY_HASH_MD4] = "md4", - [PKEY_HASH_MD5] = "md5", - [PKEY_HASH_SHA1] = "sha1", - [PKEY_HASH_RIPE_MD_160] = "rmd160", - [PKEY_HASH_SHA256] = "sha256", - [PKEY_HASH_SHA384] = "sha384", - [PKEY_HASH_SHA512] = "sha512", - [PKEY_HASH_SHA224] = "sha224", -}; - -enum pkey_id_type { - PKEY_ID_PGP, /* OpenPGP generated key ID */ - PKEY_ID_X509, /* X.509 arbitrary subjectKeyIdentifier */ - PKEY_ID_TYPE__LAST -}; - -const char *const pkey_id_type[PKEY_ID_TYPE__LAST] = { - [PKEY_ID_PGP] = "PGP", - [PKEY_ID_X509] = "X509", -}; - -/* - * Module signature information block. - * - * The constituents of the signature section are, in order: - * - * - Signer's name - * - Key identifier - * - Signature data - * - Information block - */ -struct module_signature { - uint8_t algo; /* Public-key crypto algorithm [enum pkey_algo] */ - uint8_t hash; /* Digest algorithm [enum pkey_hash_algo] */ - uint8_t id_type; /* Key identifier type [enum pkey_id_type] */ - uint8_t signer_len; /* Length of signer's name */ - uint8_t key_id_len; /* Length of key identifier */ - uint8_t __pad[3]; - uint32_t sig_len; /* Length of signature data (big endian) */ -}; - -#define SIG_MAGIC "~Module signature appended~\n" - -bool kmod_module_signature_info(const struct kmod_file *file, struct kmod_signature_info *sig_info) -{ - const char *mem; - off_t size; - const struct module_signature *modsig; - size_t sig_len; - - - size = kmod_file_get_size(file); - mem = kmod_file_get_contents(file); - if (size < (off_t)strlen(SIG_MAGIC)) - return false; - size -= strlen(SIG_MAGIC); - if (memcmp(SIG_MAGIC, mem + size, strlen(SIG_MAGIC)) != 0) - return false; - - if (size < (off_t)sizeof(struct module_signature)) - return false; - size -= sizeof(struct module_signature); - modsig = (struct module_signature *)(mem + size); - if (modsig->algo >= PKEY_ALGO__LAST || - modsig->hash >= PKEY_HASH__LAST || - modsig->id_type >= PKEY_ID_TYPE__LAST) - return false; - sig_len = be32toh(modsig->sig_len); - if (size < (off_t)(modsig->signer_len + modsig->key_id_len + sig_len)) - return false; - - size -= modsig->key_id_len + sig_len; - sig_info->key_id = mem + size; - sig_info->key_id_len = modsig->key_id_len; - - size -= modsig->signer_len; - sig_info->signer = mem + size; - sig_info->signer_len = modsig->signer_len; - - sig_info->algo = pkey_algo[modsig->algo]; - sig_info->hash_algo = pkey_hash_algo[modsig->hash]; - sig_info->id_type = pkey_id_type[modsig->id_type]; - - return true; -} diff --git a/libkmod/libkmod-util.c b/libkmod/libkmod-util.c index d1475e7..f499578 100644 --- a/libkmod/libkmod-util.c +++ b/libkmod/libkmod-util.c @@ -1,7 +1,7 @@ /* * libkmod - interface to kernel module operations * - * Copyright (C) 2011-2013 ProFUSION embedded systems + * Copyright (C) 2011-2012 ProFUSION embedded systems * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -90,6 +90,37 @@ char *getline_wrapped(FILE *fp, unsigned int *linenum) } } +/* + * Replace dashes with underscores. + * Dashes inside character range patterns (e.g. [0-9]) are left unchanged. + */ +char *underscores(struct kmod_ctx *ctx, char *s) +{ + unsigned int i; + + if (!s) + return NULL; + + for (i = 0; s[i]; i++) { + switch (s[i]) { + case '-': + s[i] = '_'; + break; + + case ']': + INFO(ctx, "Unmatched bracket in %s\n", s); + break; + + case '[': + i += strcspn(&s[i], "]"); + if (!s[i]) + INFO(ctx, "Unmatched bracket in %s\n", s); + break; + } + } + return s; +} + inline int alias_normalize(const char *alias, char buf[PATH_MAX], size_t *len) { size_t s; @@ -308,43 +339,13 @@ char *path_make_absolute_cwd(const char *p) return r; } -const struct kmod_ext kmod_exts[] = { - {".ko", sizeof(".ko") - 1}, -#ifdef ENABLE_ZLIB - {".ko.gz", sizeof(".ko.gz") - 1}, -#endif -#ifdef ENABLE_XZ - {".ko.xz", sizeof(".ko.xz") - 1}, -#endif - { } -}; - -bool path_ends_with_kmod_ext(const char *path, size_t len) -{ - const struct kmod_ext *eitr; - - for (eitr = kmod_exts; eitr->ext != NULL; eitr++) { - if (len <= eitr->len) - continue; - if (streq(path + len - eitr->len, eitr->ext)) - return true; - } - - return false; -} - #define USEC_PER_SEC 1000000ULL #define NSEC_PER_USEC 1000ULL -unsigned long long ts_usec(const struct timespec *ts) -{ - return (unsigned long long) ts->tv_sec * USEC_PER_SEC + - (unsigned long long) ts->tv_nsec / NSEC_PER_USEC; -} - unsigned long long stat_mstamp(const struct stat *st) { #ifdef HAVE_STRUCT_STAT_ST_MTIM - return ts_usec(&st->st_mtim); + return (unsigned long long) st->st_mtim.tv_sec * USEC_PER_SEC + + (unsigned long long) st->st_mtim.tv_nsec / NSEC_PER_USEC; #else return (unsigned long long) st->st_mtime; #endif diff --git a/libkmod/libkmod-util.h b/libkmod/libkmod-util.h index 17f8801..317b2f7 100644 --- a/libkmod/libkmod-util.h +++ b/libkmod/libkmod-util.h @@ -1,51 +1,29 @@ -#pragma once +#ifndef _LIBKMOD_UTIL_H_ +#define _LIBKMOD_UTIL_H_ + #include "macro.h" #include -#include #include #include -#include char *getline_wrapped(FILE *fp, unsigned int *linenum) __attribute__((nonnull(1))); +char *underscores(struct kmod_ctx *ctx, char *s) __attribute__((nonnull(1, 2))); #define streq(a, b) (strcmp((a), (b)) == 0) #define strstartswith(a, b) (strncmp(a, b, strlen(b)) == 0) void *memdup(const void *p, size_t n) __attribute__((nonnull(1))); -ssize_t read_str_safe(int fd, char *buf, size_t buflen) _must_check_ __attribute__((nonnull(2))); +ssize_t read_str_safe(int fd, char *buf, size_t buflen) __must_check __attribute__((nonnull(2))); ssize_t write_str_safe(int fd, const char *buf, size_t buflen) __attribute__((nonnull(2))); -int read_str_long(int fd, long *value, int base) _must_check_ __attribute__((nonnull(2))); -int read_str_ulong(int fd, unsigned long *value, int base) _must_check_ __attribute__((nonnull(2))); +int read_str_long(int fd, long *value, int base) __must_check __attribute__((nonnull(2))); +int read_str_ulong(int fd, unsigned long *value, int base) __must_check __attribute__((nonnull(2))); char *strchr_replace(char *s, int c, char r); -bool path_is_absolute(const char *p) _must_check_ __attribute__((nonnull(1))); -char *path_make_absolute_cwd(const char *p) _must_check_ __attribute__((nonnull(1))); -int alias_normalize(const char *alias, char buf[PATH_MAX], size_t *len) _must_check_ __attribute__((nonnull(1,2))); +bool path_is_absolute(const char *p) __must_check __attribute__((nonnull(1))); +char *path_make_absolute_cwd(const char *p) __must_check __attribute__((nonnull(1))); +int alias_normalize(const char *alias, char buf[PATH_MAX], size_t *len) __must_check __attribute__((nonnull(1,2))); char *modname_normalize(const char *modname, char buf[PATH_MAX], size_t *len) __attribute__((nonnull(1, 2))); char *path_to_modname(const char *path, char buf[PATH_MAX], size_t *len) __attribute__((nonnull(2))); - -extern const struct kmod_ext { - const char *ext; - size_t len; -} kmod_exts[]; -#define KMOD_EXT_UNC 0 -bool path_ends_with_kmod_ext(const char *path, size_t len) __attribute__((nonnull(1))); - unsigned long long stat_mstamp(const struct stat *st); -unsigned long long ts_usec(const struct timespec *ts); - -#define get_unaligned(ptr) \ -({ \ - struct __attribute__((packed)) { \ - typeof(*(ptr)) __v; \ - } *__p = (typeof(__p)) (ptr); \ - __p->__v; \ -}) -#define put_unaligned(val, ptr) \ -do { \ - struct __attribute__((packed)) { \ - typeof(*(ptr)) __v; \ - } *__p = (typeof(__p)) (ptr); \ - __p->__v = (val); \ -} while(0) +#endif diff --git a/libkmod/libkmod.c b/libkmod/libkmod.c index 788676c..8c91a7c 100644 --- a/libkmod/libkmod.c +++ b/libkmod/libkmod.c @@ -1,7 +1,7 @@ /* * libkmod - interface to kernel module operations * - * Copyright (C) 2011-2013 ProFUSION embedded systems + * Copyright (C) 2011-2012 ProFUSION embedded systems * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -18,7 +18,6 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ -#include #include #include #include @@ -59,9 +58,9 @@ static struct _index_files { }; static const char *default_config_paths[] = { - SYSCONFDIR "/modprobe.d", "/run/modprobe.d", - "/lib/modprobe.d", + SYSCONFDIR "/modprobe.d", + ROOTPREFIX "/lib/modprobe.d", NULL }; @@ -99,7 +98,6 @@ void kmod_log(const struct kmod_ctx *ctx, va_end(args); } -_printf_format_(6, 0) static void log_filep(void *data, int priority, const char *file, int line, const char *fn, const char *format, va_list args) @@ -196,7 +194,7 @@ static int log_priority(const char *priority) return 0; } -static const char *dirname_default_prefix = "/lib/modules"; +static const char *dirname_default_prefix = ROOTPREFIX "/lib/modules"; static char *get_kernel_release(const char *dirname) { @@ -218,15 +216,16 @@ static char *get_kernel_release(const char *dirname) /** * kmod_new: * @dirname: what to consider as linux module's directory, if NULL - * defaults to /lib/modules/`uname -r`. If it's relative, - * it's treated as relative to the current working directory. - * Otherwise, give an absolute dirname. + * defaults to $rootprefix/lib/modules/`uname -r`. If it's relative, + * it's treated as relative to current 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 /run/modprobe.d, /etc/modprobe.d and - * /lib/modprobe.d. Give an empty vector if configuration should - * not be read. This array must be null terminated. + * $rootprefix/lib/modprobe.d. Give an empty vector if + * configuration should not be read. This array must be null + * terminated. * * Create kmod library context. This reads the kmod configuration * and fills in the default values. @@ -255,7 +254,7 @@ KMOD_EXPORT struct kmod_ctx *kmod_new(const char *dirname, ctx->dirname = get_kernel_release(dirname); /* environment overwrites config */ - env = secure_getenv("KMOD_LOG"); + env = getenv("KMOD_LOG"); if (env != NULL) kmod_set_log_priority(ctx, log_priority(env)); @@ -307,8 +306,6 @@ KMOD_EXPORT struct kmod_ctx *kmod_ref(struct kmod_ctx *ctx) * * Drop a reference of the kmod library context. If the refcount * reaches zero, the resources of the context will be released. - * - * Returns: the passed kmod library context or NULL if it's freed */ KMOD_EXPORT struct kmod_ctx *kmod_unref(struct kmod_ctx *ctx) { @@ -483,53 +480,18 @@ int kmod_lookup_alias_from_aliases_file(struct kmod_ctx *ctx, const char *name, int kmod_lookup_alias_from_builtin_file(struct kmod_ctx *ctx, const char *name, struct kmod_list **list) { - char *line = NULL; - int err = 0; - - assert(*list == NULL); - - if (ctx->indexes[KMOD_INDEX_MODULES_BUILTIN]) { - DBG(ctx, "use mmaped index '%s' modname=%s\n", - index_files[KMOD_INDEX_MODULES_BUILTIN].fn, - name); - line = index_mm_search(ctx->indexes[KMOD_INDEX_MODULES_BUILTIN], - name); - } else { - struct index_file *idx; - char fn[PATH_MAX]; - - snprintf(fn, sizeof(fn), "%s/%s.bin", ctx->dirname, - index_files[KMOD_INDEX_MODULES_BUILTIN].fn); - DBG(ctx, "file=%s modname=%s\n", fn, name); - - idx = index_file_open(fn); - if (idx == NULL) { - DBG(ctx, "could not open builtin file '%s'\n", fn); - goto finish; - } - - line = index_search(idx, name); - index_file_close(idx); - } - - if (line != NULL) { - struct kmod_module *mod; + const struct kmod_list *l; - err = kmod_module_new_from_name(ctx, name, &mod); - if (err < 0) { - ERR(ctx, "Could not create module from name %s: %s\n", - name, strerror(-err)); - goto finish; - } + int err = kmod_lookup_alias_from_alias_bin(ctx, + KMOD_INDEX_MODULES_BUILTIN, name, list); + if (err < 0) + return err; - kmod_module_set_builtin(mod, true); - *list = kmod_list_append(*list, mod); - if (*list == NULL) - err = -ENOMEM; + kmod_list_foreach(l, *list) { + struct kmod_module *m = l->data; + kmod_module_set_builtin(m, true); } -finish: - free(line); return err; } @@ -809,7 +771,7 @@ KMOD_EXPORT int kmod_load_resources(struct kmod_ctx *ctx) snprintf(path, sizeof(path), "%s/%s.bin", ctx->dirname, index_files[i].fn); - ctx->indexes[i] = index_mm_open(ctx, path, + ctx->indexes[i] = index_mm_open(ctx, path, true, &ctx->indexes_stamp[i]); if (ctx->indexes[i] == NULL) goto fail; @@ -856,11 +818,7 @@ KMOD_EXPORT void kmod_unload_resources(struct kmod_ctx *ctx) /** * kmod_dump_index: * @ctx: kmod library context - * @type: index to dump, valid indexes are - * KMOD_INDEX_MODULES_DEP: index of module dependencies; - * KMOD_INDEX_MODULES_ALIAS: index of module aliases; - * KMOD_INDEX_MODULES_SYMBOL: index of symbol aliases; - * KMOD_INDEX_MODULES_BUILTIN: index of builtin module. + * @type: index to dump * @fd: file descriptor to dump index to * * Dump index to file descriptor. Note that this function doesn't use stdio.h @@ -902,7 +860,32 @@ KMOD_EXPORT int kmod_dump_index(struct kmod_ctx *ctx, enum kmod_index type, return 0; } -const struct kmod_config *kmod_get_config(const struct kmod_ctx *ctx) +const struct kmod_list *kmod_get_blacklists(const struct kmod_ctx *ctx) +{ + return ctx->config->blacklists; +} + +const struct kmod_list *kmod_get_options(const struct kmod_ctx *ctx) +{ + return ctx->config->options; +} + +const struct kmod_list *kmod_get_install_commands(const struct kmod_ctx *ctx) +{ + return ctx->config->install_commands; +} + +const struct kmod_list *kmod_get_remove_commands(const struct kmod_ctx *ctx) +{ + return ctx->config->remove_commands; +} + +const struct kmod_list *kmod_get_softdeps(const struct kmod_ctx *ctx) +{ + return ctx->config->softdeps; +} + +const struct kmod_list *kmod_get_aliases(const struct kmod_ctx *ctx) { - return ctx->config; + return ctx->config->aliases; } diff --git a/libkmod/libkmod.h b/libkmod/libkmod.h index 3397f87..f907e1d 100644 --- a/libkmod/libkmod.h +++ b/libkmod/libkmod.h @@ -1,7 +1,7 @@ /* * libkmod - interface to kernel module operations * - * Copyright (C) 2011-2013 ProFUSION embedded systems + * Copyright (C) 2011-2012 ProFUSION embedded systems * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -18,7 +18,6 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ -#pragma once #ifndef _LIBKMOD_H_ #define _LIBKMOD_H_ @@ -161,7 +160,6 @@ enum kmod_probe { /* codes below can be used in return value, too */ KMOD_PROBE_APPLY_BLACKLIST_ALL = 0x10000, KMOD_PROBE_APPLY_BLACKLIST = 0x20000, - KMOD_PROBE_APPLY_BLACKLIST_ALIAS_ONLY = 0x40000, }; /* Flags to kmod_module_apply_filter() */ diff --git a/libkmod/libkmod.sym b/libkmod/libkmod.sym index 854d257..cebb8d2 100644 --- a/libkmod/libkmod.sym +++ b/libkmod/libkmod.sym @@ -2,6 +2,7 @@ LIBKMOD_5 { global: kmod_get_log_priority; kmod_get_userdata; + kmod_log; kmod_new; kmod_ref; kmod_set_log_fn; diff --git a/libkmod/macro.h b/libkmod/macro.h index c6ba855..06300df 100644 --- a/libkmod/macro.h +++ b/libkmod/macro.h @@ -1,7 +1,7 @@ /* * libkmod - interface to kernel module operations * - * Copyright (C) 2011-2013 ProFUSION embedded systems + * Copyright (C) 2011-2012 ProFUSION embedded systems * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -17,20 +17,31 @@ * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ -#pragma once + +#ifndef _LIBKMOD_MACRO_H_ +#define _LIBKMOD_MACRO_H_ #include -#define assert_cc(expr) \ - _Static_assert((expr), #expr) +#define BUILD_ASSERT(cond) \ + do { (void) sizeof(char [1 - 2*!(cond)]); } while(0) + +#define EXPR_BUILD_ASSERT(cond) \ + (sizeof(char [1 - 2*!(cond)]) - 1) #if HAVE_TYPEOF +#define check_type(expr, type) \ + ((typeof(expr) *)0 != (type *)0) + #define check_types_match(expr1, expr2) \ ((typeof(expr1) *)0 != (typeof(expr2) *)0) #else /* Without typeof, we can only test the sizes. */ +#define check_type(expr, type) \ + EXPR_BUILD_ASSERT(sizeof(expr) == sizeof(type)) + #define check_types_match(expr1, expr2) \ - assert_cc(sizeof(expr1) == sizeof(expr2)) + EXPR_BUILD_ASSERT(sizeof(expr1) == sizeof(expr2)) #endif /* HAVE_TYPEOF */ #define container_of(member_ptr, containing_type, member) \ @@ -38,13 +49,26 @@ ((char *)(member_ptr) - offsetof(containing_type, member)) \ - check_types_match(*(member_ptr), ((containing_type *)0)->member)) +/* + * BUILD_ASSERT_OR_ZERO - assert a build-time dependency, as an expression. + * @cond: the compile-time condition which must be true. + * + * Your compile will fail if the condition isn't true, or can't be evaluated + * by the compiler. This can be used in an expression: its value is "0". + * + * Example: + * #define foo_to_char(foo) \ + * ((char *)(foo) \ + * + BUILD_ASSERT_OR_ZERO(offsetof(struct foo, string) == 0)) + */ +#define BUILD_ASSERT_OR_ZERO(cond) \ + (sizeof(char [1 - 2*!(cond)]) - 1) /* Two gcc extensions. * &a[0] degrades to a pointer: a different type from an array */ -#define _array_size_chk(arr) ({ \ - assert_cc(!__builtin_types_compatible_p(typeof(arr), typeof(&(arr)[0]))); \ - 0; \ - }) +#define _array_size_chk(arr) \ + BUILD_ASSERT_OR_ZERO(!__builtin_types_compatible_p(typeof(arr), \ + typeof(&(arr)[0]))) #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]) + _array_size_chk(arr)) @@ -54,7 +78,10 @@ /* Attributes */ -#define _must_check_ __attribute__((warn_unused_result)) -#define _printf_format_(a,b) __attribute__((format (printf, a, b))) -#define _unused_ __attribute__((unused)) -#define _always_inline_ __inline__ __attribute__((always_inline)) +#define __must_check __attribute__((warn_unused_result)) +#define __printf_format(a,b) __attribute__((format (printf, a, b))) +#if !defined(__always_inline) +#define __always_inline __inline__ __attribute__((always_inline)) +#endif + +#endif diff --git a/libkmod/missing.h b/libkmod/missing.h deleted file mode 100644 index b45bbe2..0000000 --- a/libkmod/missing.h +++ /dev/null @@ -1,34 +0,0 @@ -#pragma once - -#include -#include - -#ifdef HAVE_LINUX_MODULE_H -#include -#endif - -#ifndef MODULE_INIT_IGNORE_MODVERSIONS -# define MODULE_INIT_IGNORE_MODVERSIONS 1 -#endif - -#ifndef MODULE_INIT_IGNORE_VERMAGIC -# define MODULE_INIT_IGNORE_VERMAGIC 2 -#endif - -#ifndef __NR_finit_module -# define __NR_finit_module -1 -#endif - -#ifndef HAVE_FINIT_MODULE -#include - -static inline int finit_module(int fd, const char *uargs, int flags) -{ - if (__NR_finit_module == -1) { - errno = ENOSYS; - return -1; - } - - return syscall(__NR_finit_module, fd, uargs, flags); -} -#endif diff --git a/m4/attributes.m4 b/m4/attributes.m4 index e822197..9d561c2 100644 --- a/m4/attributes.m4 +++ b/m4/attributes.m4 @@ -1,7 +1,6 @@ dnl Macros to check the presence of generic (non-typed) symbols. dnl Copyright (c) 2006-2008 Diego Pettenò dnl Copyright (c) 2006-2008 xine project -dnl Copyright (c) 2012 Lucas De Marchi dnl dnl This program is free software; you can redistribute it and/or modify dnl it under the terms of the GNU General Public License as published by @@ -33,56 +32,68 @@ dnl distribute a modified version of the Autoconf Macro, you may extend dnl this special exception to the GPL to apply to your modified version as dnl well. -dnl Check if flag in a envvar is supported by compiler and append -dnl "backup" variable -dnl CC_CHECK_FLAG_APPEND([WHERE-TO-APPEND], [ENV-VAR], [FLAG]) -AC_DEFUN([CC_CHECK_FLAG_APPEND], [ - AC_CACHE_CHECK([if $CC supports flag $3 in envvar $2], - AS_TR_SH([cc_cv_$2_$3]), - [eval "AS_TR_SH([cc_save_$2])='${$2}'" - eval "AS_TR_SH([$2])='-Werror $3'" - AC_COMPILE_IFELSE([AC_LANG_SOURCE([int a = 0; int main(void) { return a; } ])], - [eval "AS_TR_SH([cc_cv_$2_$3])='yes'"], - [eval "AS_TR_SH([cc_cv_$2_$3])='no'"]) - eval "AS_TR_SH([$2])='$cc_save_$2'"]) - - AS_IF([eval test x$]AS_TR_SH([cc_cv_$2_$3])[ = xyes], - [eval "$1='${$1} $3'"]) -]) +dnl Check if the flag is supported by compiler +dnl CC_CHECK_CFLAGS_SILENT([FLAG], [ACTION-IF-FOUND],[ACTION-IF-NOT-FOUND]) -dnl CC_CHECK_FLAGS_APPEND([WHERE-TO-APPEND], [ENV-VAR], [FLAG1 FLAG2]) -AC_DEFUN([CC_CHECK_FLAGS_APPEND], [ - for flag in $3; do - CC_CHECK_FLAG_APPEND($1, $2, $flag) - done -]) +AC_DEFUN([CC_CHECK_CFLAGS_SILENT], [ + AC_CACHE_VAL(AS_TR_SH([cc_cv_cflags_$1]), + [ac_save_CFLAGS="$CFLAGS" + CFLAGS="$CFLAGS $1" + AC_COMPILE_IFELSE([AC_LANG_SOURCE([int a;])], + [eval "AS_TR_SH([cc_cv_cflags_$1])='yes'"], + [eval "AS_TR_SH([cc_cv_cflags_$1])='no'"]) + CFLAGS="$ac_save_CFLAGS" + ]) + AS_IF([eval test x$]AS_TR_SH([cc_cv_cflags_$1])[ = xyes], + [$2], [$3]) +]) +dnl Check if the flag is supported by compiler (cacheable) +dnl CC_CHECK_CFLAGS([FLAG], [ACTION-IF-FOUND],[ACTION-IF-NOT-FOUND]) -dnl Check if the flag is supported by linker -dnl CC_CHECK_LDFLAGS_SILENT([FLAG], [ACTION-IF-FOUND],[ACTION-IF-NOT-FOUND]) -AC_DEFUN([CC_CHECK_LDFLAGS_SILENT], [ - AC_CACHE_VAL(AS_TR_SH([cc_cv_ldflags_$1]), - [ac_save_LDFLAGS="$LDFLAGS" - LDFLAGS="$LDFLAGS $1" - AC_LINK_IFELSE([AC_LANG_SOURCE([int main() { return 1; }])], - [eval "AS_TR_SH([cc_cv_ldflags_$1])='yes'"], - [eval "AS_TR_SH([cc_cv_ldflags_$1])="]) - LDFLAGS="$ac_save_LDFLAGS" - ]) +AC_DEFUN([CC_CHECK_CFLAGS], [ + AC_CACHE_CHECK([if $CC supports $1 flag], + AS_TR_SH([cc_cv_cflags_$1]), + CC_CHECK_CFLAGS_SILENT([$1]) dnl Don't execute actions here! + ) - AS_IF([eval test x$]AS_TR_SH([cc_cv_ldflags_$1])[ = xyes], + AS_IF([eval test x$]AS_TR_SH([cc_cv_cflags_$1])[ = xyes], [$2], [$3]) ]) +dnl CC_CHECK_CFLAG_APPEND(FLAG, [action-if-found], [action-if-not-found]) +dnl Check for CFLAG and appends them to CFLAGS if supported +AC_DEFUN([CC_CHECK_CFLAG_APPEND], [ + AC_CACHE_CHECK([if $CC supports $1 flag], + AS_TR_SH([cc_cv_cflags_$1]), + CC_CHECK_CFLAGS_SILENT([$1]) dnl Don't execute actions here! + ) + + AS_IF([eval test x$]AS_TR_SH([cc_cv_cflags_$1])[ = xyes], + [CFLAGS="$CFLAGS $1"; DEBUG_CFLAGS="$DEBUG_CFLAGS $1"; $2], [$3]) +]) + +dnl CC_CHECK_CFLAGS_APPEND([FLAG1 FLAG2], [action-if-found], [action-if-not]) +AC_DEFUN([CC_CHECK_CFLAGS_APPEND], [ + for flag in $1; do + CC_CHECK_CFLAG_APPEND($flag, [$2], [$3]) + done +]) + dnl Check if the flag is supported by linker (cacheable) dnl CC_CHECK_LDFLAGS([FLAG], [ACTION-IF-FOUND],[ACTION-IF-NOT-FOUND]) AC_DEFUN([CC_CHECK_LDFLAGS], [ AC_CACHE_CHECK([if $CC supports $1 flag], AS_TR_SH([cc_cv_ldflags_$1]), - CC_CHECK_LDFLAGS_SILENT([$1]) dnl Don't execute actions here! - ) + [ac_save_LDFLAGS="$LDFLAGS" + LDFLAGS="$LDFLAGS $1" + AC_LINK_IFELSE([int main() { return 1; }], + [eval "AS_TR_SH([cc_cv_ldflags_$1])='yes'"], + [eval "AS_TR_SH([cc_cv_ldflags_$1])="]) + LDFLAGS="$ac_save_LDFLAGS" + ]) AS_IF([eval test x$]AS_TR_SH([cc_cv_ldflags_$1])[ = xyes], [$2], [$3]) diff --git a/man/Makefile.am b/man/Makefile.am index 12870bd..772ff7f 100644 --- a/man/Makefile.am +++ b/man/Makefile.am @@ -2,10 +2,6 @@ MAN5 = depmod.d.5 modprobe.d.5 modules.dep.5 MAN8 = depmod.8 insmod.8 lsmod.8 rmmod.8 modprobe.8 modinfo.8 MAN_STUB = modules.dep.bin.5 -AM_V_XSLT = $(AM_V_XSLT_$(V)) -AM_V_XSLT_ = $(AM_V_XSLT_$(AM_DEFAULT_VERBOSITY)) -AM_V_XSLT_0 = @echo " XSLT " $@; - if BUILD_TOOLS dist_man_MANS = $(MAN5) $(MAN8) $(MAN_STUB) modules.dep.bin.5: modules.dep.5 @@ -15,11 +11,10 @@ EXTRA_DIST = $(MAN5:%.5=%.xml) $(MAN8:%.8=%.xml) XSLTPROC_FLAGS = \ --nonet \ - --stringparam man.output.quietly 1 \ --param funcsynopsis.style "'ansi'" CLEANFILES = $(dist_man_MANS) %.5 %.8: %.xml - $(AM_V_XSLT)$(XSLTPROC) $(XSLTPROC_FLAGS) \ + $(AM_V_GEN)$(XSLTPROC) $(XSLTPROC_FLAGS) \ http://docbook.sourceforge.net/release/xsl/current/manpages/docbook.xsl $< diff --git a/man/depmod.xml b/man/depmod.xml index 5f71802..789f40d 100644 --- a/man/depmod.xml +++ b/man/depmod.xml @@ -101,11 +101,7 @@ OPTIONS - - - - - + @@ -115,11 +111,7 @@ - - - - - + @@ -132,8 +124,6 @@ - - @@ -151,11 +141,7 @@ - - - - - + @@ -165,11 +151,7 @@ - - - - - + @@ -184,11 +166,7 @@ - - - - - + @@ -201,11 +179,7 @@ - - - - - + @@ -217,11 +191,7 @@ - - - - - + @@ -230,11 +200,7 @@ - - - - - + @@ -244,8 +210,7 @@ - - + @@ -255,11 +220,7 @@ - - - - - + @@ -270,11 +231,7 @@ - - - - - + @@ -284,8 +241,7 @@ - - + diff --git a/man/modinfo.xml b/man/modinfo.xml index 2a37852..f444e42 100644 --- a/man/modinfo.xml +++ b/man/modinfo.xml @@ -76,8 +76,6 @@ - - @@ -89,8 +87,6 @@ - - @@ -107,19 +103,6 @@ - - - - - - - - - - Root directory for modules, / by default. - - - @@ -138,8 +121,6 @@ - - @@ -153,31 +134,18 @@ - - - - - - - - - - - - - - These are shortcuts for the flag's - author, description, - license, parm and - filename arguments, to ease the transition - from the old modutils modinfo. + These are shortcuts for author, + description, license. + parm and filename + respectively, to ease the transition from the old modutils + modinfo. diff --git a/man/modprobe.d.xml b/man/modprobe.d.xml index 7b0c298..dc19b23 100644 --- a/man/modprobe.d.xml +++ b/man/modprobe.d.xml @@ -40,7 +40,7 @@ - /lib/modprobe.d/*.conf + /usr/lib/modprobe.d/*.conf /etc/modprobe.d/*.conf /run/modprobe.d/*.conf diff --git a/man/modprobe.xml b/man/modprobe.xml index 5abb948..0b3b01d 100644 --- a/man/modprobe.xml +++ b/man/modprobe.xml @@ -80,14 +80,13 @@ modprobe looks in the module directory /lib/modules/`uname -r` for all the modules and other files, except for the optional - configuration files in the + /etc/modprobe.conf configuration file and /etc/modprobe.d directory (see - modprobe.d5 + modprobe.conf5 ). modprobe will also use module options specified on the kernel command line in the form of - <module>.<option> and blacklists in the form of - modprobe.blacklist=<module>. + <module>.<option>. Note that unlike in 2.4 series Linux kernels (which are not supported @@ -121,23 +120,13 @@ OPTIONS - - - - - - + Insert all module names on the command line. - - - - - - + This option causes modprobe to apply the @@ -150,12 +139,7 @@ - - - - - - + This option overrides the default configuration directory (/etc/modprobe.d). @@ -169,12 +153,7 @@ - - - - - - + Dump out the effective configuration from the config directory and @@ -183,8 +162,7 @@ - - + @@ -195,22 +173,17 @@ - - - - - - + - Root directory for modules, / by default. + Directory where modules can be found, + /lib/modules/RELEASE + by default. - - - + Normally, modprobe will succeed (and do @@ -224,9 +197,7 @@ - - - + Every module contains a small string containing important @@ -243,9 +214,7 @@ - - - + When modules are compiled with CONFIG_MODVERSIONS set, a section @@ -264,12 +233,7 @@ - - - - - - + Try to strip any versioning information from the module which might @@ -288,11 +252,7 @@ - - - - @@ -315,11 +275,7 @@ - - - - @@ -336,8 +292,6 @@ - - @@ -355,8 +309,6 @@ - - @@ -369,8 +321,6 @@ - - @@ -392,8 +342,6 @@ - - @@ -427,8 +375,6 @@ - - @@ -449,8 +395,6 @@ - - @@ -460,8 +404,6 @@ - - diff --git a/man/rmmod.xml b/man/rmmod.xml index 3605068..2dfe971 100644 --- a/man/rmmod.xml +++ b/man/rmmod.xml @@ -60,11 +60,7 @@ OPTIONS - - - - - + @@ -75,11 +71,7 @@ - - - - - + @@ -110,11 +102,7 @@ - - - - - + diff --git a/test/WARNING b/test/WARNING new file mode 100644 index 0000000..c5cfece --- /dev/null +++ b/test/WARNING @@ -0,0 +1,3 @@ +Don't add new tests here. They are not built anymore on purpose and are being +slowly migrated to testsuite dir. See testsuite/README in order to add new test +cases. diff --git a/test/test-blacklist.c b/test/test-blacklist.c new file mode 100644 index 0000000..a53c902 --- /dev/null +++ b/test/test-blacklist.c @@ -0,0 +1,76 @@ +#include +#include +#include +#include +#include +#include +#include +#include + + +int main(int argc, char *argv[]) +{ + const char *alias; + struct kmod_ctx *ctx; + struct kmod_list *list = NULL, *l; + int err; + + printf("libkmod version %s\n", VERSION); + + if (argc < 2) { + fprintf(stderr, "ERR: Provide an alias name\n"); + return EXIT_FAILURE; + } + + alias = argv[1]; + + ctx = kmod_new(NULL, NULL); + if (ctx == NULL) + exit(EXIT_FAILURE); + + err = kmod_module_new_from_lookup(ctx, alias, &list); + if (err < 0) + goto fail_lookup; + + if (list == NULL) + printf("No module matches '%s'\n", alias); + else + printf("Alias: '%s'\nModules matching:\n", alias); + + kmod_list_foreach(l, list) { + struct kmod_module *mod = kmod_module_get_module(l); + printf("\t%s\n", kmod_module_get_name(mod)); + kmod_module_unref(mod); + } + + if (list != NULL) { + struct kmod_list *filtered; + err = kmod_module_get_filtered_blacklist(ctx, list, &filtered); + if (err < 0) { + printf("Could not filter: %s\n", strerror(-err)); + goto fail; + } + if (filtered == NULL) + printf("All modules were filtered out!\n"); + else + printf("Modules remaining after filter:\n"); + + kmod_list_foreach(l, filtered) { + struct kmod_module *mod = kmod_module_get_module(l); + printf("\t%s\n", kmod_module_get_name(mod)); + kmod_module_unref(mod); + } + kmod_module_unref_list(filtered); + } + + kmod_module_unref_list(list); + kmod_unref(ctx); + + return EXIT_SUCCESS; + +fail: + kmod_module_unref_list(list); +fail_lookup: + kmod_unref(ctx); + return EXIT_FAILURE; +} diff --git a/test/test-elf.c b/test/test-elf.c new file mode 100644 index 0000000..23dd1fd --- /dev/null +++ b/test/test-elf.c @@ -0,0 +1,106 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include + +int main(int argc, char *argv[]) +{ + struct kmod_ctx *ctx; + struct kmod_module *mod; + struct kmod_list *list, *l; + int err; + + printf("libkmod version %s\n", VERSION); + + if (argc != 2) { + fprintf(stderr, "Usage:\n\t%s \n", argv[0]); + return EXIT_FAILURE; + } + + ctx = kmod_new(NULL, NULL); + if (ctx == NULL) + return EXIT_FAILURE; + + err = kmod_module_new_from_path(ctx, argv[1], &mod); + if (err < 0) { + fprintf(stderr, "ERROR: could not load %s: %s\n", + argv[1], strerror(-errno)); + goto module_error; + } + + list = NULL; + err = kmod_module_get_info(mod, &list); + if (err <= 0) + printf("no information! (%s)\n", strerror(-err)); + else { + puts("info:"); + kmod_list_foreach(l, list) { + const char *key, *val; + key = kmod_module_info_get_key(l); + val = kmod_module_info_get_value(l); + printf("\t%s: %s\n", key, val ? val : ""); + } + kmod_module_info_free_list(list); + } + + list = NULL; + err = kmod_module_get_versions(mod, &list); + if (err <= 0) + printf("no modversions! (%s)\n", strerror(-err)); + else { + puts("modversions:"); + kmod_list_foreach(l, list) { + const char *symbol; + uint64_t crc; + symbol = kmod_module_version_get_symbol(l); + crc = kmod_module_version_get_crc(l); + printf("\t%s: %#"PRIx64"\n", symbol, crc); + } + kmod_module_versions_free_list(list); + } + + list = NULL; + err = kmod_module_get_symbols(mod, &list); + if (err <= 0) + printf("no symbols! (%s)\n", strerror(-err)); + else { + puts("symbols:"); + kmod_list_foreach(l, list) { + const char *symbol; + uint64_t crc; + symbol = kmod_module_symbol_get_symbol(l); + crc = kmod_module_symbol_get_crc(l); + printf("\t%s: %#"PRIx64"\n", symbol, crc); + } + kmod_module_symbols_free_list(list); + } + + list = NULL; + err = kmod_module_get_dependency_symbols(mod, &list); + if (err <= 0) + printf("no dependency symbols! (%s)\n", strerror(-err)); + else { + puts("dependency symbols:"); + kmod_list_foreach(l, list) { + const char *symbol; + uint8_t bind; + uint64_t crc; + symbol = kmod_module_dependency_symbol_get_symbol(l); + bind = kmod_module_dependency_symbol_get_bind(l); + crc = kmod_module_dependency_symbol_get_crc(l); + printf("\t%s %c: %#"PRIx64"\n", symbol, bind, crc); + } + kmod_module_dependency_symbols_free_list(list); + } + + kmod_module_unref(mod); +module_error: + kmod_unref(ctx); + + return (err < 0) ? EXIT_FAILURE : EXIT_SUCCESS; +} diff --git a/test/test-get-dependencies.c b/test/test-get-dependencies.c new file mode 100644 index 0000000..3a7bbf2 --- /dev/null +++ b/test/test-get-dependencies.c @@ -0,0 +1,52 @@ +#include +#include +#include +#include +#include +#include +#include +#include + + +int main(int argc, char *argv[]) +{ + const char *name; + struct kmod_ctx *ctx; + struct kmod_module *mod; + struct kmod_list *list, *l; + int err; + + printf("libkmod version %s\n", VERSION); + + if (argc < 2) { + fprintf(stderr, "ERR: Provide a module name\n"); + return EXIT_FAILURE; + } + + name = argv[1]; + + ctx = kmod_new(NULL, NULL); + if (ctx == NULL) + exit(EXIT_FAILURE); + + err = kmod_module_new_from_name(ctx, name, &mod); + if (err < 0) { + kmod_unref(ctx); + exit(EXIT_FAILURE); + } + + list = kmod_module_get_dependencies(mod); + printf("Module: %s\nDependency list:\n", name); + + kmod_list_foreach(l, list) { + struct kmod_module *m = kmod_module_get_module(l); + printf("\t%s\n", kmod_module_get_name(m)); + kmod_module_unref(m); + } + + kmod_module_unref_list(list); + kmod_module_unref(mod); + kmod_unref(ctx); + + return EXIT_SUCCESS; +} diff --git a/test/test-invalidate-config.c b/test/test-invalidate-config.c new file mode 100644 index 0000000..52370c8 --- /dev/null +++ b/test/test-invalidate-config.c @@ -0,0 +1,49 @@ +#include +#include +#include +#include +#include +#include +#include +#include + +static const char *config[] = { + NULL, + NULL, +}; + +int main(int argc, char *argv[]) +{ + struct kmod_ctx *ctx; + int r; + char cmd[4096]; + + if (argc < 2) { + fprintf(stderr, "Provide a path to config\n"); + return EXIT_FAILURE; + } + + config[0] = argv[1]; + + ctx = kmod_new(NULL, config); + if (ctx == NULL) + exit(EXIT_FAILURE); + + r = kmod_validate_resources(ctx); + if (r != KMOD_RESOURCES_OK) { + fprintf(stderr, "ERR: return should be 'resources ok'\n"); + return EXIT_FAILURE; + } + + snprintf(cmd, sizeof(cmd), "touch %s", config[0]); + system(cmd); + r = kmod_validate_resources(ctx); + if (r != KMOD_RESOURCES_MUST_RECREATE) { + fprintf(stderr, "ERR: return should be 'must recreate'\n"); + return EXIT_FAILURE; + } + + kmod_unref(ctx); + + return EXIT_SUCCESS; +} diff --git a/test/test-lookup.c b/test/test-lookup.c new file mode 100644 index 0000000..70cdb5c --- /dev/null +++ b/test/test-lookup.c @@ -0,0 +1,184 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include + +static const char cmdoptions_short[] = "lh"; +static const struct option cmdoptions[] = { + {"load-resources", no_argument, 0, 'l'}, + {"help", no_argument, 0, 'h'}, + {NULL, 0, 0, 0} +}; + +static void help(const char *progname) +{ + const struct option *itr_opt; + const char *itr_short; + printf("Usage:\n" + "\t%s [options] \n" + "Options:\n", + progname); + for (itr_opt = cmdoptions, itr_short = cmdoptions_short; + itr_opt->name != NULL; itr_opt++, itr_short++) + printf("\t-%c, --%s\n", *itr_short, itr_opt->name); +} + +int main(int argc, char *argv[]) +{ + const char *alias = NULL; + struct kmod_ctx *ctx; + struct kmod_list *list = NULL, *l; + int load_resources = 0; + int err; + + printf("libkmod version %s\n", VERSION); + + for (;;) { + int c, idx = 0; + c = getopt_long(argc, argv, cmdoptions_short, cmdoptions, &idx); + if (c == -1) + break; + switch (c) { + case 'l': + load_resources = 1; + break; + case 'h': + help(argv[0]); + return 0; + case '?': + return -1; + default: + fprintf(stderr, + "ERR: unexpected getopt_long() value %c\n", c); + return -1; + } + } + + if (optind >= argc) { + fprintf(stderr, "ERR: Provide an alias name\n"); + return EXIT_FAILURE; + } + + alias = argv[optind]; + + ctx = kmod_new(NULL, NULL); + if (ctx == NULL) { + kmod_unref(ctx); + exit(EXIT_FAILURE); + } + + if (load_resources) { + err = kmod_load_resources(ctx); + if (err < 0) { + printf("Could not load resources: %s\n", + strerror(-err)); + kmod_unref(ctx); + exit(EXIT_FAILURE); + } + } + + err = kmod_module_new_from_lookup(ctx, alias, &list); + if (err < 0) + exit(EXIT_FAILURE); + + if (list == NULL) + printf("No module matches '%s'\n", alias); + else + printf("Alias: '%s'\nModules matching:\n", alias); + + kmod_list_foreach(l, list) { + struct kmod_list *d, *pre = NULL, *post = NULL; + struct kmod_module *mod = kmod_module_get_module(l); + const char *str; + + printf("\t%s\n", kmod_module_get_name(mod)); + str = kmod_module_get_options(mod); + if (str) + printf("\t\toptions: '%s'\n", str); + str = kmod_module_get_install_commands(mod); + if (str) + printf("\t\tinstall commands: '%s'\n", str); + str = kmod_module_get_remove_commands(mod); + if (str) + printf("\t\tremove commands: '%s'\n", str); + + err = kmod_module_get_softdeps(mod, &pre, &post); + if (err == 0) { + if (pre != NULL || post != NULL) + puts("\t\tsoft dependencies:"); + if (pre != NULL) { + fputs("\t\t\tpre:", stdout); + kmod_list_foreach(d, pre) { + struct kmod_module *dm = kmod_module_get_module(d); + printf(" %s", kmod_module_get_name(dm)); + kmod_module_unref(dm); + } + putchar('\n'); + kmod_module_unref_list(pre); + } + if (post != NULL) { + fputs("\t\t\tpost:", stdout); + kmod_list_foreach(d, post) { + struct kmod_module *dm = kmod_module_get_module(d); + printf(" %s", kmod_module_get_name(dm)); + kmod_module_unref(dm); + } + putchar('\n'); + kmod_module_unref_list(post); + } + } + + pre = NULL; + err = kmod_module_get_info(mod, &pre); + if (err > 0) { + puts("\t\tmodinfo:"); + kmod_list_foreach(d, pre) { + const char *key, *val; + key = kmod_module_info_get_key(d); + val = kmod_module_info_get_value(d); + printf("\t\t\t%s: %s\n", key, val ? val : ""); + } + kmod_module_info_free_list(pre); + } + + pre = NULL; + err = kmod_module_get_versions(mod, &pre); + if (err > 0) { + puts("\t\tmodversions:"); + kmod_list_foreach(d, pre) { + const char *symbol; + uint64_t crc; + symbol = kmod_module_version_get_symbol(d); + crc = kmod_module_version_get_crc(d); + printf("\t\t\t%s: %#"PRIx64"\n", symbol, crc); + } + kmod_module_versions_free_list(pre); + } + + pre = NULL; + err = kmod_module_get_symbols(mod, &pre); + if (err > 0) { + puts("\t\tsymbols:"); + kmod_list_foreach(d, pre) { + const char *symbol; + uint64_t crc; + symbol = kmod_module_symbol_get_symbol(d); + crc = kmod_module_symbol_get_crc(d); + printf("\t\t\t%s: %#"PRIx64"\n", symbol, crc); + } + kmod_module_symbols_free_list(pre); + } + + kmod_module_unref(mod); + } + + kmod_module_unref_list(list); + kmod_unref(ctx); + + return EXIT_SUCCESS; +} diff --git a/test/test-mod-double-ref.c b/test/test-mod-double-ref.c new file mode 100644 index 0000000..9033247 --- /dev/null +++ b/test/test-mod-double-ref.c @@ -0,0 +1,78 @@ +#include +#include +#include +#include +#include +#include +#include +#include + + +int main(int argc, char *argv[]) +{ + struct kmod_ctx *ctx; + struct kmod_module *mod1, *mod2; + const char *modname; + int err; + + if (argc < 2) { + fprintf(stderr, "ERR: Provide an alias name\n"); + return EXIT_FAILURE; + } + + modname = argv[1]; + + ctx = kmod_new(NULL, NULL); + if (ctx == NULL) + exit(EXIT_FAILURE); + + printf("libkmod version %s\n", VERSION); + + err = kmod_module_new_from_name(ctx, modname, &mod1); + if (err < 0) { + fprintf(stderr, "error creating module: '%s'\n", strerror(-err)); + goto fail; + } + + printf("modname='%s' obj=%p\n", modname, mod1); + + err = kmod_module_new_from_name(ctx, modname, &mod2); + if (err < 0) { + fprintf(stderr, "error creating module: '%s'\n", strerror(-err)); + goto fail; + } + + printf("modname='%s' obj=%p\n", modname, mod2); + + kmod_module_unref(mod1); + kmod_module_unref(mod2); + + /* same thing, but now unref the first module */ + + err = kmod_module_new_from_name(ctx, modname, &mod1); + if (err < 0) { + fprintf(stderr, "error creating module: '%s'\n", strerror(-err)); + goto fail; + } + + printf("modname='%s' obj=%p\n", modname, mod1); + + kmod_module_unref(mod1); + + err = kmod_module_new_from_name(ctx, modname, &mod2); + if (err < 0) { + fprintf(stderr, "error creating module: '%s'\n", strerror(-err)); + goto fail; + } + + printf("modname='%s' obj=%p\n", modname, mod2); + + kmod_module_unref(mod2); + kmod_unref(ctx); + + return EXIT_SUCCESS; + +fail: + kmod_unref(ctx); + return EXIT_FAILURE; +} diff --git a/test/test-path-from-name.c b/test/test-path-from-name.c new file mode 100644 index 0000000..3f3d568 --- /dev/null +++ b/test/test-path-from-name.c @@ -0,0 +1,48 @@ +#include +#include +#include +#include +#include +#include +#include +#include + + +int main(int argc, char *argv[]) +{ + struct kmod_ctx *ctx; + struct kmod_module *mod; + const char *path, *modname; + int err; + + if (argc < 2) { + fprintf(stderr, "ERR: Provide an alias name\n"); + return EXIT_FAILURE; + } + + modname = argv[1]; + + ctx = kmod_new(NULL, NULL); + if (ctx == NULL) + exit(EXIT_FAILURE); + + printf("libkmod version %s\n", VERSION); + + err = kmod_module_new_from_name(ctx, modname, &mod); + if (err < 0) { + fprintf(stderr, "error creating module: '%s'\n", strerror(-err)); + goto fail; + } + + path = kmod_module_get_path(mod); + + printf("modname: '%s' path: '%s'\n", modname, path); + kmod_module_unref(mod); + kmod_unref(ctx); + + return EXIT_SUCCESS; + +fail: + kmod_unref(ctx); + return EXIT_FAILURE; +} diff --git a/test/test-probe.c b/test/test-probe.c new file mode 100644 index 0000000..c68a783 --- /dev/null +++ b/test/test-probe.c @@ -0,0 +1,118 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include + +static const char cmdoptions_short[] = "lh"; +static const struct option cmdoptions[] = { + {"load-resources", no_argument, 0, 'l'}, + {"help", no_argument, 0, 'h'}, + {NULL, 0, 0, 0} +}; + +static void help(const char *progname) +{ + const struct option *itr_opt; + const char *itr_short; + printf("Usage:\n" + "\t%s [options] [ module_options ]\n" + "Options:\n", + progname); + for (itr_opt = cmdoptions, itr_short = cmdoptions_short; + itr_opt->name != NULL; itr_opt++, itr_short++) + printf("\t-%c, --%s\n", *itr_short, itr_opt->name); +} + +int main(int argc, char *argv[]) +{ + const char *alias; + const char *opt; + struct kmod_ctx *ctx; + struct kmod_list *list = NULL, *l; + int load_resources = 0; + int err; + + printf("libkmod version %s\n", VERSION); + + for (;;) { + int c, idx = 0; + c = getopt_long(argc, argv, cmdoptions_short, cmdoptions, &idx); + if (c == -1) + break; + switch (c) { + case 'l': + load_resources = 1; + break; + case 'h': + help(argv[0]); + return 0; + case '?': + return -1; + default: + fprintf(stderr, + "ERR: unexpected getopt_long() value %c\n", c); + return -1; + } + } + + if (optind >= argc) { + fprintf(stderr, "ERR: Provide an alias name\n"); + return EXIT_FAILURE; + } + + alias = argv[optind++]; + + if (optind < argc) + opt = argv[optind]; + else + opt = NULL; + + ctx = kmod_new(NULL, NULL); + if (ctx == NULL) { + kmod_unref(ctx); + exit(EXIT_FAILURE); + } + + if (load_resources) { + err = kmod_load_resources(ctx); + if (err < 0) { + printf("Could not load resources: %s\n", + strerror(-err)); + kmod_unref(ctx); + exit(EXIT_FAILURE); + } + } + + err = kmod_module_new_from_lookup(ctx, alias, &list); + if (err < 0) + exit(EXIT_FAILURE); + + if (list == NULL) + printf("No module matches '%s'\n", alias); + else + printf("Alias: '%s'\nModules matching:\n", alias); + + kmod_list_foreach(l, list) { + struct kmod_module *mod = kmod_module_get_module(l); + + printf("\t%s", kmod_module_get_name(mod)); + + err = kmod_module_probe_insert_module(mod, 0, opt, NULL, NULL); + if (err >=0 ) + printf(": inserted ok\n"); + else + printf(": failed to insert\n"); + + kmod_module_unref(mod); + } + + kmod_module_unref_list(list); + kmod_unref(ctx); + + return EXIT_SUCCESS; +} diff --git a/test/test.conf b/test/test.conf new file mode 100644 index 0000000..e69de29 diff --git a/testsuite/.gitignore b/testsuite/.gitignore index 71f34cc..7b71048 100644 --- a/testsuite/.gitignore +++ b/testsuite/.gitignore @@ -2,35 +2,11 @@ *.la *.so /.dirstamp +/rootfs/ /test-alias -/test-blacklist -/test-dependencies -/test-depmod /test-init /test-loaded /test-modinfo /test-new-module /test-testsuite /test-modprobe -/rootfs -/stamp-rootfs -/test-alias.log -/test-alias.trs -/test-blacklist.log -/test-blacklist.trs -/test-dependencies.log -/test-dependencies.trs -/test-depmod.log -/test-depmod.trs -/test-init.log -/test-init.trs -/test-loaded.log -/test-loaded.trs -/test-modinfo.log -/test-modinfo.trs -/test-modprobe.log -/test-modprobe.trs -/test-new-module.log -/test-new-module.trs -/test-testsuite.log -/test-testsuite.trs diff --git a/testsuite/COPYING b/testsuite/COPYING deleted file mode 100644 index 8add30a..0000000 --- a/testsuite/COPYING +++ /dev/null @@ -1,504 +0,0 @@ - GNU LESSER GENERAL PUBLIC LICENSE - Version 2.1, February 1999 - - Copyright (C) 1991, 1999 Free Software Foundation, Inc. - 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - -[This is the first released version of the Lesser GPL. It also counts - as the successor of the GNU Library Public License, version 2, hence - the version number 2.1.] - - Preamble - - The licenses for most software are designed to take away your -freedom to share and change it. By contrast, the GNU General Public -Licenses are intended to guarantee your freedom to share and change -free software--to make sure the software is free for all its users. - - This license, the Lesser General Public License, applies to some -specially designated software packages--typically libraries--of the -Free Software Foundation and other authors who decide to use it. You -can use it too, but we suggest you first think carefully about whether -this license or the ordinary General Public License is the better -strategy to use in any particular case, based on the explanations below. - - When we speak of free software, we are referring to freedom of use, -not price. Our General Public Licenses are designed to make sure that -you have the freedom to distribute copies of free software (and charge -for this service if you wish); that you receive source code or can get -it if you want it; that you can change the software and use pieces of -it in new free programs; and that you are informed that you can do -these things. - - To protect your rights, we need to make restrictions that forbid -distributors to deny you these rights or to ask you to surrender these -rights. These restrictions translate to certain responsibilities for -you if you distribute copies of the library or if you modify it. - - For example, if you distribute copies of the library, whether gratis -or for a fee, you must give the recipients all the rights that we gave -you. You must make sure that they, too, receive or can get the source -code. If you link other code with the library, you must provide -complete object files to the recipients, so that they can relink them -with the library after making changes to the library and recompiling -it. And you must show them these terms so they know their rights. - - We protect your rights with a two-step method: (1) we copyright the -library, and (2) we offer you this license, which gives you legal -permission to copy, distribute and/or modify the library. - - To protect each distributor, we want to make it very clear that -there is no warranty for the free library. Also, if the library is -modified by someone else and passed on, the recipients should know -that what they have is not the original version, so that the original -author's reputation will not be affected by problems that might be -introduced by others. - - Finally, software patents pose a constant threat to the existence of -any free program. We wish to make sure that a company cannot -effectively restrict the users of a free program by obtaining a -restrictive license from a patent holder. Therefore, we insist that -any patent license obtained for a version of the library must be -consistent with the full freedom of use specified in this license. - - Most GNU software, including some libraries, is covered by the -ordinary GNU General Public License. This license, the GNU Lesser -General Public License, applies to certain designated libraries, and -is quite different from the ordinary General Public License. We use -this license for certain libraries in order to permit linking those -libraries into non-free programs. - - When a program is linked with a library, whether statically or using -a shared library, the combination of the two is legally speaking a -combined work, a derivative of the original library. The ordinary -General Public License therefore permits such linking only if the -entire combination fits its criteria of freedom. The Lesser General -Public License permits more lax criteria for linking other code with -the library. - - We call this license the "Lesser" General Public License because it -does Less to protect the user's freedom than the ordinary General -Public License. It also provides other free software developers Less -of an advantage over competing non-free programs. These disadvantages -are the reason we use the ordinary General Public License for many -libraries. However, the Lesser license provides advantages in certain -special circumstances. - - For example, on rare occasions, there may be a special need to -encourage the widest possible use of a certain library, so that it becomes -a de-facto standard. To achieve this, non-free programs must be -allowed to use the library. A more frequent case is that a free -library does the same job as widely used non-free libraries. In this -case, there is little to gain by limiting the free library to free -software only, so we use the Lesser General Public License. - - In other cases, permission to use a particular library in non-free -programs enables a greater number of people to use a large body of -free software. For example, permission to use the GNU C Library in -non-free programs enables many more people to use the whole GNU -operating system, as well as its variant, the GNU/Linux operating -system. - - Although the Lesser General Public License is Less protective of the -users' freedom, it does ensure that the user of a program that is -linked with the Library has the freedom and the wherewithal to run -that program using a modified version of the Library. - - The precise terms and conditions for copying, distribution and -modification follow. Pay close attention to the difference between a -"work based on the library" and a "work that uses the library". The -former contains code derived from the library, whereas the latter must -be combined with the library in order to run. - - GNU LESSER GENERAL PUBLIC LICENSE - TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION - - 0. This License Agreement applies to any software library or other -program which contains a notice placed by the copyright holder or -other authorized party saying it may be distributed under the terms of -this Lesser General Public License (also called "this License"). -Each licensee is addressed as "you". - - A "library" means a collection of software functions and/or data -prepared so as to be conveniently linked with application programs -(which use some of those functions and data) to form executables. - - The "Library", below, refers to any such software library or work -which has been distributed under these terms. A "work based on the -Library" means either the Library or any derivative work under -copyright law: that is to say, a work containing the Library or a -portion of it, either verbatim or with modifications and/or translated -straightforwardly into another language. (Hereinafter, translation is -included without limitation in the term "modification".) - - "Source code" for a work means the preferred form of the work for -making modifications to it. For a library, complete source code means -all the source code for all modules it contains, plus any associated -interface definition files, plus the scripts used to control compilation -and installation of the library. - - Activities other than copying, distribution and modification are not -covered by this License; they are outside its scope. The act of -running a program using the Library is not restricted, and output from -such a program is covered only if its contents constitute a work based -on the Library (independent of the use of the Library in a tool for -writing it). Whether that is true depends on what the Library does -and what the program that uses the Library does. - - 1. You may copy and distribute verbatim copies of the Library's -complete source code as you receive it, in any medium, provided that -you conspicuously and appropriately publish on each copy an -appropriate copyright notice and disclaimer of warranty; keep intact -all the notices that refer to this License and to the absence of any -warranty; and distribute a copy of this License along with the -Library. - - You may charge a fee for the physical act of transferring a copy, -and you may at your option offer warranty protection in exchange for a -fee. - - 2. You may modify your copy or copies of the Library or any portion -of it, thus forming a work based on the Library, and copy and -distribute such modifications or work under the terms of Section 1 -above, provided that you also meet all of these conditions: - - a) The modified work must itself be a software library. - - b) You must cause the files modified to carry prominent notices - stating that you changed the files and the date of any change. - - c) You must cause the whole of the work to be licensed at no - charge to all third parties under the terms of this License. - - d) If a facility in the modified Library refers to a function or a - table of data to be supplied by an application program that uses - the facility, other than as an argument passed when the facility - is invoked, then you must make a good faith effort to ensure that, - in the event an application does not supply such function or - table, the facility still operates, and performs whatever part of - its purpose remains meaningful. - - (For example, a function in a library to compute square roots has - a purpose that is entirely well-defined independent of the - application. Therefore, Subsection 2d requires that any - application-supplied function or table used by this function must - be optional: if the application does not supply it, the square - root function must still compute square roots.) - -These requirements apply to the modified work as a whole. If -identifiable sections of that work are not derived from the Library, -and can be reasonably considered independent and separate works in -themselves, then this License, and its terms, do not apply to those -sections when you distribute them as separate works. But when you -distribute the same sections as part of a whole which is a work based -on the Library, the distribution of the whole must be on the terms of -this License, whose permissions for other licensees extend to the -entire whole, and thus to each and every part regardless of who wrote -it. - -Thus, it is not the intent of this section to claim rights or contest -your rights to work written entirely by you; rather, the intent is to -exercise the right to control the distribution of derivative or -collective works based on the Library. - -In addition, mere aggregation of another work not based on the Library -with the Library (or with a work based on the Library) on a volume of -a storage or distribution medium does not bring the other work under -the scope of this License. - - 3. You may opt to apply the terms of the ordinary GNU General Public -License instead of this License to a given copy of the Library. To do -this, you must alter all the notices that refer to this License, so -that they refer to the ordinary GNU General Public License, version 2, -instead of to this License. (If a newer version than version 2 of the -ordinary GNU General Public License has appeared, then you can specify -that version instead if you wish.) Do not make any other change in -these notices. - - Once this change is made in a given copy, it is irreversible for -that copy, so the ordinary GNU General Public License applies to all -subsequent copies and derivative works made from that copy. - - This option is useful when you wish to copy part of the code of -the Library into a program that is not a library. - - 4. You may copy and distribute the Library (or a portion or -derivative of it, under Section 2) in object code or executable form -under the terms of Sections 1 and 2 above provided that you accompany -it with the complete corresponding machine-readable source code, which -must be distributed under the terms of Sections 1 and 2 above on a -medium customarily used for software interchange. - - If distribution of object code is made by offering access to copy -from a designated place, then offering equivalent access to copy the -source code from the same place satisfies the requirement to -distribute the source code, even though third parties are not -compelled to copy the source along with the object code. - - 5. A program that contains no derivative of any portion of the -Library, but is designed to work with the Library by being compiled or -linked with it, is called a "work that uses the Library". Such a -work, in isolation, is not a derivative work of the Library, and -therefore falls outside the scope of this License. - - However, linking a "work that uses the Library" with the Library -creates an executable that is a derivative of the Library (because it -contains portions of the Library), rather than a "work that uses the -library". The executable is therefore covered by this License. -Section 6 states terms for distribution of such executables. - - When a "work that uses the Library" uses material from a header file -that is part of the Library, the object code for the work may be a -derivative work of the Library even though the source code is not. -Whether this is true is especially significant if the work can be -linked without the Library, or if the work is itself a library. The -threshold for this to be true is not precisely defined by law. - - If such an object file uses only numerical parameters, data -structure layouts and accessors, and small macros and small inline -functions (ten lines or less in length), then the use of the object -file is unrestricted, regardless of whether it is legally a derivative -work. (Executables containing this object code plus portions of the -Library will still fall under Section 6.) - - Otherwise, if the work is a derivative of the Library, you may -distribute the object code for the work under the terms of Section 6. -Any executables containing that work also fall under Section 6, -whether or not they are linked directly with the Library itself. - - 6. As an exception to the Sections above, you may also combine or -link a "work that uses the Library" with the Library to produce a -work containing portions of the Library, and distribute that work -under terms of your choice, provided that the terms permit -modification of the work for the customer's own use and reverse -engineering for debugging such modifications. - - You must give prominent notice with each copy of the work that the -Library is used in it and that the Library and its use are covered by -this License. You must supply a copy of this License. If the work -during execution displays copyright notices, you must include the -copyright notice for the Library among them, as well as a reference -directing the user to the copy of this License. Also, you must do one -of these things: - - a) Accompany the work with the complete corresponding - machine-readable source code for the Library including whatever - changes were used in the work (which must be distributed under - Sections 1 and 2 above); and, if the work is an executable linked - with the Library, with the complete machine-readable "work that - uses the Library", as object code and/or source code, so that the - user can modify the Library and then relink to produce a modified - executable containing the modified Library. (It is understood - that the user who changes the contents of definitions files in the - Library will not necessarily be able to recompile the application - to use the modified definitions.) - - b) Use a suitable shared library mechanism for linking with the - Library. A suitable mechanism is one that (1) uses at run time a - copy of the library already present on the user's computer system, - rather than copying library functions into the executable, and (2) - will operate properly with a modified version of the library, if - the user installs one, as long as the modified version is - interface-compatible with the version that the work was made with. - - c) Accompany the work with a written offer, valid for at - least three years, to give the same user the materials - specified in Subsection 6a, above, for a charge no more - than the cost of performing this distribution. - - d) If distribution of the work is made by offering access to copy - from a designated place, offer equivalent access to copy the above - specified materials from the same place. - - e) Verify that the user has already received a copy of these - materials or that you have already sent this user a copy. - - For an executable, the required form of the "work that uses the -Library" must include any data and utility programs needed for -reproducing the executable from it. However, as a special exception, -the materials to be distributed need not include anything that is -normally distributed (in either source or binary form) with the major -components (compiler, kernel, and so on) of the operating system on -which the executable runs, unless that component itself accompanies -the executable. - - It may happen that this requirement contradicts the license -restrictions of other proprietary libraries that do not normally -accompany the operating system. Such a contradiction means you cannot -use both them and the Library together in an executable that you -distribute. - - 7. You may place library facilities that are a work based on the -Library side-by-side in a single library together with other library -facilities not covered by this License, and distribute such a combined -library, provided that the separate distribution of the work based on -the Library and of the other library facilities is otherwise -permitted, and provided that you do these two things: - - a) Accompany the combined library with a copy of the same work - based on the Library, uncombined with any other library - facilities. This must be distributed under the terms of the - Sections above. - - b) Give prominent notice with the combined library of the fact - that part of it is a work based on the Library, and explaining - where to find the accompanying uncombined form of the same work. - - 8. You may not copy, modify, sublicense, link with, or distribute -the Library except as expressly provided under this License. Any -attempt otherwise to copy, modify, sublicense, link with, or -distribute the Library is void, and will automatically terminate your -rights under this License. However, parties who have received copies, -or rights, from you under this License will not have their licenses -terminated so long as such parties remain in full compliance. - - 9. You are not required to accept this License, since you have not -signed it. However, nothing else grants you permission to modify or -distribute the Library or its derivative works. These actions are -prohibited by law if you do not accept this License. Therefore, by -modifying or distributing the Library (or any work based on the -Library), you indicate your acceptance of this License to do so, and -all its terms and conditions for copying, distributing or modifying -the Library or works based on it. - - 10. Each time you redistribute the Library (or any work based on the -Library), the recipient automatically receives a license from the -original licensor to copy, distribute, link with or modify the Library -subject to these terms and conditions. You may not impose any further -restrictions on the recipients' exercise of the rights granted herein. -You are not responsible for enforcing compliance by third parties with -this License. - - 11. If, as a consequence of a court judgment or allegation of patent -infringement or for any other reason (not limited to patent issues), -conditions are imposed on you (whether by court order, agreement or -otherwise) that contradict the conditions of this License, they do not -excuse you from the conditions of this License. If you cannot -distribute so as to satisfy simultaneously your obligations under this -License and any other pertinent obligations, then as a consequence you -may not distribute the Library at all. For example, if a patent -license would not permit royalty-free redistribution of the Library by -all those who receive copies directly or indirectly through you, then -the only way you could satisfy both it and this License would be to -refrain entirely from distribution of the Library. - -If any portion of this section is held invalid or unenforceable under any -particular circumstance, the balance of the section is intended to apply, -and the section as a whole is intended to apply in other circumstances. - -It is not the purpose of this section to induce you to infringe any -patents or other property right claims or to contest validity of any -such claims; this section has the sole purpose of protecting the -integrity of the free software distribution system which is -implemented by public license practices. Many people have made -generous contributions to the wide range of software distributed -through that system in reliance on consistent application of that -system; it is up to the author/donor to decide if he or she is willing -to distribute software through any other system and a licensee cannot -impose that choice. - -This section is intended to make thoroughly clear what is believed to -be a consequence of the rest of this License. - - 12. If the distribution and/or use of the Library is restricted in -certain countries either by patents or by copyrighted interfaces, the -original copyright holder who places the Library under this License may add -an explicit geographical distribution limitation excluding those countries, -so that distribution is permitted only in or among countries not thus -excluded. In such case, this License incorporates the limitation as if -written in the body of this License. - - 13. The Free Software Foundation may publish revised and/or new -versions of the Lesser General Public License from time to time. -Such new versions will be similar in spirit to the present version, -but may differ in detail to address new problems or concerns. - -Each version is given a distinguishing version number. If the Library -specifies a version number of this License which applies to it and -"any later version", you have the option of following the terms and -conditions either of that version or of any later version published by -the Free Software Foundation. If the Library does not specify a -license version number, you may choose any version ever published by -the Free Software Foundation. - - 14. If you wish to incorporate parts of the Library into other free -programs whose distribution conditions are incompatible with these, -write to the author to ask for permission. For software which is -copyrighted by the Free Software Foundation, write to the Free -Software Foundation; we sometimes make exceptions for this. Our -decision will be guided by the two goals of preserving the free status -of all derivatives of our free software and of promoting the sharing -and reuse of software generally. - - NO WARRANTY - - 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO -WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. -EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR -OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY -KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE -LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME -THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. - - 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN -WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY -AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU -FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR -CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE -LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING -RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A -FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF -SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH -DAMAGES. - - END OF TERMS AND CONDITIONS - - How to Apply These Terms to Your New Libraries - - If you develop a new library, and you want it to be of the greatest -possible use to the public, we recommend making it free software that -everyone can redistribute and change. You can do so by permitting -redistribution under these terms (or, alternatively, under the terms of the -ordinary General Public License). - - To apply these terms, attach the following notices to the library. It is -safest to attach them to the start of each source file to most effectively -convey the exclusion of warranty; and each file should have at least the -"copyright" line and a pointer to where the full notice is found. - - - Copyright (C) - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - -Also add information on how to contact you by electronic and paper mail. - -You should also get your employer (if you work as a programmer) or your -school, if any, to sign a "copyright disclaimer" for the library, if -necessary. Here is a sample; alter the names: - - Yoyodyne, Inc., hereby disclaims all copyright interest in the - library `Frob' (a library for tweaking knobs) written by James Random Hacker. - - , 1 April 1990 - Ty Coon, President of Vice - -That's all there is to it! - - diff --git a/testsuite/delete_module.c b/testsuite/delete_module.c index 9718894..9e4fba4 100644 --- a/testsuite/delete_module.c +++ b/testsuite/delete_module.c @@ -1,19 +1,18 @@ /* - * Copyright (C) 2012-2013 ProFUSION embedded systems + * Copyright (C) 2012 ProFUSION embedded systems * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ #include diff --git a/testsuite/init_module.c b/testsuite/init_module.c index dad66e5..7141566 100644 --- a/testsuite/init_module.c +++ b/testsuite/init_module.c @@ -1,28 +1,21 @@ /* - * Copyright (C) 2012-2013 ProFUSION embedded systems - * Copyright (C) 2012-2013 Lucas De Marchi + * Copyright (C) 2012 ProFUSION embedded systems * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ -#ifndef HAVE_FINIT_MODULE -#define HAVE_FINIT_MODULE 1 -#endif - #include -#include #include #include #include @@ -33,10 +26,8 @@ #include #include #include -#include #include #include -#include #include /* kmod_elf_get_section() is not exported, we need the private header */ @@ -44,7 +35,6 @@ /* FIXME: hack, change name so we don't clash */ #undef ERR -#include "mkdir.h" #include "testsuite.h" #include "stripped-module.h" @@ -57,7 +47,6 @@ struct mod { static struct mod *modules; static bool need_init = true; -static struct kmod_ctx *ctx; static void parse_retcodes(struct mod *_modules, const char *s) { @@ -113,61 +102,12 @@ static void parse_retcodes(struct mod *_modules, const char *s) } } -static int write_one_line_file(const char *fn, const char *line, int len) -{ - FILE *f; - int r; - - assert(fn); - assert(line); - - f = fopen(fn, "we"); - if (!f) - return -errno; - - errno = 0; - if (fputs(line, f) < 0) { - r = -errno; - goto finish; - } - - fflush(f); - - if (ferror(f)) { - if (errno != 0) - r = -errno; - else - r = -EIO; - } else - r = 0; - -finish: - fclose(f); - return r; -} - -static int create_sysfs_files(const char *modname) -{ - char buf[PATH_MAX]; - const char *sysfsmod = "/sys/module/"; - int len = strlen(sysfsmod); - - memcpy(buf, sysfsmod, len); - strcpy(buf + len, modname); - len += strlen(modname); - - assert(mkdir_p(buf, 0755) >= 0); - - strcpy(buf + len, "/initstate"); - return write_one_line_file(buf, "live\n", strlen("live\n")); -} - static struct mod *find_module(struct mod *_modules, const char *modname) { struct mod *mod; for (mod = _modules; mod != NULL; mod = mod->next) { - if (strcmp(mod->name, modname) == 0) + if (strcmp(mod->name, modname)) return mod; } @@ -188,49 +128,16 @@ static void init_retcodes(void) S_TC_INIT_MODULE_RETCODES); } - ctx = kmod_new(NULL, NULL); - parse_retcodes(modules, s); } -static inline bool module_is_inkernel(const char *modname) -{ - struct kmod_module *mod; - int state; - bool ret; - - if (kmod_module_new_from_name(ctx, modname, &mod) < 0) - return false; - - state = kmod_module_get_initstate(mod); - - if (state == KMOD_MODULE_LIVE || - state == KMOD_MODULE_BUILTIN) - ret = true; - else - ret = false; - - kmod_module_unref(mod); - - return ret; -} - -static uint8_t elf_identify(void *mem) -{ - uint8_t *p = mem; - return p[EI_CLASS]; -} - TS_EXPORT long init_module(void *mem, unsigned long len, const char *args); /* - * Default behavior is to try to mimic init_module behavior inside the kernel. - * If it is a simple test that you know the error code, set the return code - * in TESTSUITE_INIT_MODULE_RETCODES env var instead. + * FIXME: change /sys/module/ to fake-insert a module * - * The exception is when the module name is not find in the memory passed. - * This is because we want to be able to pass dummy modules (and not real - * ones) and it still work. + * Default behavior is to exit successfully. If this is not the intended + * behavior, set TESTSUITE_INIT_MODULE_RETCODES env var. */ long init_module(void *mem, unsigned long len, const char *args) { @@ -240,8 +147,6 @@ long init_module(void *mem, unsigned long len, const char *args) const void *buf; uint64_t bufsize; int err; - uint8_t class; - off_t offset; init_retcodes(); @@ -253,89 +158,20 @@ long init_module(void *mem, unsigned long len, const char *args) &bufsize); kmod_elf_unref(elf); - /* We couldn't parse the ELF file. Just exit as if it was successful */ + /* + * We couldn't find the module's name inside the ELF file. Just exit + * as if it was successful + */ if (err < 0) return 0; - /* We need to open both 32 and 64 bits module - hack! */ - class = elf_identify(mem); - if (class == ELFCLASS64) - offset = MODULE_NAME_OFFSET_64; - else - offset = MODULE_NAME_OFFSET_32; - - modname = (char *)buf + offset; + modname = (char *)buf + offsetof(struct module, name); mod = find_module(modules, modname); - if (mod != NULL) { - errno = mod->errcode; - err = mod->ret; - } else if (module_is_inkernel(modname)) { - err = -1; - errno = EEXIST; - } else - err = 0; - - if (err == 0) - create_sysfs_files(modname); - - return err; -} - -TS_EXPORT int finit_module(const int fd, const char *args, const int flags); - -int finit_module(const int fd, const char *args, const int flags) -{ - int err; - void *mem; - unsigned long len; - struct stat st; - - if (fstat(fd, &st) < 0) - return -1; - - len = st.st_size; - mem = mmap(NULL, len, PROT_READ, MAP_PRIVATE, fd, 0); - if (mem == MAP_FAILED) - return -1; - - err = init_module(mem, len, args); - munmap(mem, len); - - return err; -} - -TS_EXPORT long int syscall(long int __sysno, ...) -{ - va_list ap; - long ret; - - if (__sysno == -1) { - errno = ENOSYS; - return -1; - } - - if (__sysno == __NR_finit_module) { - const char *args; - int flags; - int fd; - - va_start(ap, __sysno); - - fd = va_arg(ap, int); - args = va_arg(ap, const char *); - flags = va_arg(ap, int); - - ret = finit_module(fd, args, flags); - - va_end(ap); - return ret; - } + if (mod == NULL) + return 0; - /* - * FIXME: no way to call the libc function - let's hope there are no - * other users. - */ - abort(); + errno = mod->errcode; + return mod->ret; } /* the test is going away anyway, but lets keep valgrind happy */ @@ -347,7 +183,4 @@ void free_resources(void) free(modules); modules = mod; } - - if (ctx) - kmod_unref(ctx); } diff --git a/testsuite/mkdir.c b/testsuite/mkdir.c deleted file mode 100644 index 0a7de69..0000000 --- a/testsuite/mkdir.c +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright (C) 2012 Lucas De Marchi -#include -#include -#include - -#include "mkdir.h" -#include "testsuite.h" - -TS_EXPORT int mkdir_p(const char *path, mode_t mode) -{ - char *start = strdupa(path); - int len = strlen(path); - char *end = start + len; - struct stat st; - - /* - * scan backwards, replacing '/' with '\0' while the component doesn't - * exist - */ - for (;;) { - if (stat(start, &st) >= 0) { - if (S_ISDIR(st.st_mode)) - break; - return -ENOTDIR; - } - - /* Find the next component, backwards, discarding extra '/'*/ - for (; end != start && *end != '/'; end--) - ; - - for (; end != start - 1 && *end == '/'; end--) - ; - - end++; - if (end == start) - break; - - *end = '\0'; - } - - if (end == start + len) - return 0; - - for (; end < start + len;) { - *end = '/'; - end += strlen(end); - - if (mkdir(start, mode) < 0) - return -errno; - } - - return 0; -} diff --git a/testsuite/mkdir.h b/testsuite/mkdir.h deleted file mode 100644 index 35f6a1d..0000000 --- a/testsuite/mkdir.h +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright (C) 2012 Lucas De Marchi - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#pragma once - -#include -#include - -int mkdir_p(const char *path, mode_t mode); diff --git a/testsuite/path.c b/testsuite/path.c index f87f5c5..60df4a0 100644 --- a/testsuite/path.c +++ b/testsuite/path.c @@ -1,19 +1,18 @@ /* - * Copyright (C) 2012-2013 ProFUSION embedded systems + * Copyright (C) 2012 ProFUSION embedded systems * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ #include @@ -95,109 +94,122 @@ static void *get_libc_func(const char *f) return fp; } -/* wrapper template for a function with one "const char* path" argument */ -#define WRAP_1ARG(rettype, failret, name) \ -TS_EXPORT rettype name(const char *path) \ -{ \ - const char *p; \ - char buf[PATH_MAX * 2]; \ - static rettype (*_fn)(const char*); \ - \ - if (!get_rootpath(__func__)) \ - return failret; \ - _fn = get_libc_func(#name); \ - p = trap_path(path, buf); \ - if (p == NULL) \ - return failret; \ - return (*_fn)(p); \ -} +TS_EXPORT FILE *fopen(const char *path, const char *mode) +{ + const char *p; + char buf[PATH_MAX * 2]; + static FILE* (*_fopen)(const char *path, const char *mode); -/* wrapper template for a function with "const char* path" and another argument */ -#define WRAP_2ARGS(rettype, failret, name, arg2t) \ -TS_EXPORT rettype name(const char *path, arg2t arg2) \ -{ \ - const char *p; \ - char buf[PATH_MAX * 2]; \ - static rettype (*_fn)(const char*, arg2t arg2); \ - \ - if (!get_rootpath(__func__)) \ - return failret; \ - _fn = get_libc_func(#name); \ - p = trap_path(path, buf); \ - if (p == NULL) \ - return failret; \ - return (*_fn)(p, arg2); \ -} + if (!get_rootpath(__func__)) + return NULL; + + _fopen = get_libc_func("fopen"); -/* wrapper template for open family */ -#define WRAP_OPEN(suffix) \ -TS_EXPORT int open ## suffix (const char *path, int flags, ...) \ -{ \ - const char *p; \ - char buf[PATH_MAX * 2]; \ - static int (*_fn)(const char *path, int flags, ...); \ - \ - if (!get_rootpath(__func__)) \ - return -1; \ - _fn = get_libc_func("open" #suffix); \ - p = trap_path(path, buf); \ - if (p == NULL) \ - return -1; \ - \ - if (flags & O_CREAT) { \ - mode_t mode; \ - va_list ap; \ - \ - va_start(ap, flags); \ - mode = va_arg(ap, mode_t); \ - va_end(ap); \ - return _fn(p, flags, mode); \ - } \ - \ - return _fn(p, flags); \ + p = trap_path(path, buf); + if (p == NULL) + return NULL; + + return (*_fopen)(p, mode); } -/* wrapper template for __xstat family */ -#define WRAP_VERSTAT(prefix, suffix) \ -TS_EXPORT int prefix ## stat ## suffix (int ver, \ - const char *path, \ - struct stat ## suffix *st) \ -{ \ - const char *p; \ - char buf[PATH_MAX * 2]; \ - static int (*_fn)(int ver, const char *path, \ - struct stat ## suffix *); \ - _fn = get_libc_func(#prefix "stat" #suffix); \ - \ - if (!get_rootpath(__func__)) \ - return -1; \ - p = trap_path(path, buf); \ - if (p == NULL) \ - return -1; \ - \ - return _fn(ver, p, st); \ +TS_EXPORT int open(const char *path, int flags, ...) +{ + const char *p; + char buf[PATH_MAX * 2]; + static int (*_open)(const char *path, int flags, ...); + + if (!get_rootpath(__func__)) + return -1; + + _open = get_libc_func("open"); + p = trap_path(path, buf); + if (p == NULL) + return -1; + + if (flags & O_CREAT) { + mode_t mode; + va_list ap; + + va_start(ap, flags); + mode = va_arg(ap, mode_t); + va_end(ap); + _open(p, flags, mode); + } + + return _open(p, flags); } -WRAP_1ARG(DIR*, NULL, opendir); - -WRAP_2ARGS(FILE*, NULL, fopen, const char*); -WRAP_2ARGS(int, -1, mkdir, mode_t); -WRAP_2ARGS(int, -1, access, int); -WRAP_2ARGS(int, -1, stat, struct stat*); -WRAP_2ARGS(int, -1, lstat, struct stat*); -#ifndef _FILE_OFFSET_BITS -WRAP_2ARGS(int, -1, stat64, struct stat64*); -WRAP_2ARGS(int, -1, lstat64, struct stat64*); -WRAP_OPEN(64); -#endif +TS_EXPORT int stat(const char *path, struct stat *st) +{ + const char *p; + char buf[PATH_MAX * 2]; + static int (*_stat)(const char *path, struct stat *buf); + + if (!get_rootpath(__func__)) + return -1; + + _stat = get_libc_func("stat"); + + p = trap_path(path, buf); + if (p == NULL) + return -1; -WRAP_OPEN(); + return _stat(p, st); +} #ifdef HAVE___XSTAT -WRAP_VERSTAT(__x,); -WRAP_VERSTAT(__lx,); -#ifndef _FILE_OFFSET_BITS -WRAP_VERSTAT(__x,64); -WRAP_VERSTAT(__lx,64); -#endif +TS_EXPORT int __xstat(int ver, const char *path, struct stat *st) +{ + const char *p; + char buf[PATH_MAX * 2]; + static int (*_xstat)(int __ver, const char *__filename, + struct stat *__stat_buf); + + if (!get_rootpath(__func__)) + return -1; + + _xstat = get_libc_func("__xstat"); + + p = trap_path(path, buf); + if (p == NULL) + return -1; + + return _xstat(ver, p, st); +} #endif + +TS_EXPORT int access(const char *path, int mode) +{ + const char *p; + char buf[PATH_MAX * 2]; + static int (*_access)(const char *path, int mode); + + if (!get_rootpath(__func__)) + return -1; + + _access = get_libc_func("access"); + + p = trap_path(path, buf); + if (p == NULL) + return -1; + + return _access(p, mode); +} + +TS_EXPORT DIR *opendir(const char *path) +{ + const char *p; + char buf[PATH_MAX * 2]; + static DIR* (*_opendir)(const char *path); + + if (!get_rootpath(__func__)) + return NULL; + + _opendir = get_libc_func("opendir"); + + p = trap_path(path, buf); + if (p == NULL) + return NULL; + + return (*_opendir)(p); +} diff --git a/testsuite/rootfs-pristine/test-alias/correct.txt b/testsuite/rootfs-pristine/test-alias/correct.txt deleted file mode 100644 index 86d0304..0000000 --- a/testsuite/rootfs-pristine/test-alias/correct.txt +++ /dev/null @@ -1,25 +0,0 @@ -input test1234 -return 0 -len 8 -output test1234 - -input test[abcfoobar]2211 -return 0 -len 19 -output test[abcfoobar]2211 - -input bar[aaa][bbbb]sss -return 0 -len 17 -output bar[aaa][bbbb]sss - -input kmod[p.b]lib -return 0 -len 12 -output kmod[p.b]lib - -input [az]1234[AZ] -return 0 -len 12 -output [az]1234[AZ] - diff --git a/testsuite/rootfs-pristine/test-blacklist/etc/modprobe.d/modprobe.conf b/testsuite/rootfs-pristine/test-blacklist/etc/modprobe.d/modprobe.conf deleted file mode 100644 index 126612f..0000000 --- a/testsuite/rootfs-pristine/test-blacklist/etc/modprobe.d/modprobe.conf +++ /dev/null @@ -1,2 +0,0 @@ -blacklist floppy -blacklist pcspkr diff --git a/testsuite/rootfs-pristine/test-dependencies/lib/modules/4.0.20-kmod/kernel/fs/jbd2/jbd2.ko b/testsuite/rootfs-pristine/test-dependencies/lib/modules/4.0.20-kmod/kernel/fs/jbd2/jbd2.ko deleted file mode 100644 index 521c214..0000000 Binary files a/testsuite/rootfs-pristine/test-dependencies/lib/modules/4.0.20-kmod/kernel/fs/jbd2/jbd2.ko and /dev/null differ diff --git a/testsuite/rootfs-pristine/test-dependencies/lib/modules/4.0.20-kmod/kernel/fs/mbcache.ko b/testsuite/rootfs-pristine/test-dependencies/lib/modules/4.0.20-kmod/kernel/fs/mbcache.ko deleted file mode 100644 index 5849fa7..0000000 Binary files a/testsuite/rootfs-pristine/test-dependencies/lib/modules/4.0.20-kmod/kernel/fs/mbcache.ko and /dev/null differ diff --git a/testsuite/rootfs-pristine/test-dependencies/lib/modules/4.0.20-kmod/kernel/lib/crc16.ko b/testsuite/rootfs-pristine/test-dependencies/lib/modules/4.0.20-kmod/kernel/lib/crc16.ko deleted file mode 100644 index 2fffdb7..0000000 Binary files a/testsuite/rootfs-pristine/test-dependencies/lib/modules/4.0.20-kmod/kernel/lib/crc16.ko and /dev/null differ diff --git a/testsuite/rootfs-pristine/test-dependencies/lib/modules/4.0.20-kmod/modules.alias b/testsuite/rootfs-pristine/test-dependencies/lib/modules/4.0.20-kmod/modules.alias deleted file mode 100644 index ba76e18..0000000 --- a/testsuite/rootfs-pristine/test-dependencies/lib/modules/4.0.20-kmod/modules.alias +++ /dev/null @@ -1 +0,0 @@ -# Aliases extracted from modules themselves. diff --git a/testsuite/rootfs-pristine/test-dependencies/lib/modules/4.0.20-kmod/modules.alias.bin b/testsuite/rootfs-pristine/test-dependencies/lib/modules/4.0.20-kmod/modules.alias.bin deleted file mode 100644 index 7075435..0000000 Binary files a/testsuite/rootfs-pristine/test-dependencies/lib/modules/4.0.20-kmod/modules.alias.bin and /dev/null differ diff --git a/testsuite/rootfs-pristine/test-dependencies/lib/modules/4.0.20-kmod/modules.builtin b/testsuite/rootfs-pristine/test-dependencies/lib/modules/4.0.20-kmod/modules.builtin deleted file mode 100644 index e69de29..0000000 diff --git a/testsuite/rootfs-pristine/test-dependencies/lib/modules/4.0.20-kmod/modules.builtin.bin b/testsuite/rootfs-pristine/test-dependencies/lib/modules/4.0.20-kmod/modules.builtin.bin deleted file mode 100644 index 7075435..0000000 Binary files a/testsuite/rootfs-pristine/test-dependencies/lib/modules/4.0.20-kmod/modules.builtin.bin and /dev/null differ diff --git a/testsuite/rootfs-pristine/test-dependencies/lib/modules/4.0.20-kmod/modules.dep b/testsuite/rootfs-pristine/test-dependencies/lib/modules/4.0.20-kmod/modules.dep deleted file mode 100644 index c4e2516..0000000 --- a/testsuite/rootfs-pristine/test-dependencies/lib/modules/4.0.20-kmod/modules.dep +++ /dev/null @@ -1,4 +0,0 @@ -kernel/fs/mbcache.ko: -kernel/fs/ext4/ext4.ko: kernel/lib/crc16.ko kernel/fs/jbd2/jbd2.ko kernel/fs/mbcache.ko -kernel/fs/jbd2/jbd2.ko: -kernel/lib/crc16.ko: diff --git a/testsuite/rootfs-pristine/test-dependencies/lib/modules/4.0.20-kmod/modules.dep.bin b/testsuite/rootfs-pristine/test-dependencies/lib/modules/4.0.20-kmod/modules.dep.bin deleted file mode 100644 index 2e89d91..0000000 Binary files a/testsuite/rootfs-pristine/test-dependencies/lib/modules/4.0.20-kmod/modules.dep.bin and /dev/null differ diff --git a/testsuite/rootfs-pristine/test-dependencies/lib/modules/4.0.20-kmod/modules.devname b/testsuite/rootfs-pristine/test-dependencies/lib/modules/4.0.20-kmod/modules.devname deleted file mode 100644 index 58f6d6d..0000000 --- a/testsuite/rootfs-pristine/test-dependencies/lib/modules/4.0.20-kmod/modules.devname +++ /dev/null @@ -1 +0,0 @@ -# Device nodes to trigger on-demand module loading. diff --git a/testsuite/rootfs-pristine/test-dependencies/lib/modules/4.0.20-kmod/modules.order b/testsuite/rootfs-pristine/test-dependencies/lib/modules/4.0.20-kmod/modules.order deleted file mode 100644 index 85f2778..0000000 --- a/testsuite/rootfs-pristine/test-dependencies/lib/modules/4.0.20-kmod/modules.order +++ /dev/null @@ -1,7 +0,0 @@ -kernel/fs/mbcache.ko -kernel/fs/ext3/ext3.ko -kernel/fs/ext2/ext2.ko -kernel/fs/ext4/ext4.ko -kernel/fs/jbd/jbd.ko -kernel/fs/jbd2/jbd2.ko -kernel/lib/crc16.ko diff --git a/testsuite/rootfs-pristine/test-dependencies/lib/modules/4.0.20-kmod/modules.softdep b/testsuite/rootfs-pristine/test-dependencies/lib/modules/4.0.20-kmod/modules.softdep deleted file mode 100644 index 3cc0512..0000000 --- a/testsuite/rootfs-pristine/test-dependencies/lib/modules/4.0.20-kmod/modules.softdep +++ /dev/null @@ -1,2 +0,0 @@ -# Soft dependencies extracted from modules themselves. -# Copy, with a .conf extension, to /etc/modprobe.d to use it with modprobe. diff --git a/testsuite/rootfs-pristine/test-dependencies/lib/modules/4.0.20-kmod/modules.symbols b/testsuite/rootfs-pristine/test-dependencies/lib/modules/4.0.20-kmod/modules.symbols deleted file mode 100644 index 0f0d88c..0000000 --- a/testsuite/rootfs-pristine/test-dependencies/lib/modules/4.0.20-kmod/modules.symbols +++ /dev/null @@ -1,58 +0,0 @@ -# Aliases for symbols, used by symbol_request(). -alias symbol:jbd2_journal_invalidatepage jbd2 -alias symbol:jbd2_journal_release_buffer jbd2 -alias symbol:jbd2_journal_init_inode jbd2 -alias symbol:jbd2__journal_restart jbd2 -alias symbol:mb_cache_entry_find_next mbcache -alias symbol:crc16 crc16 -alias symbol:mb_cache_entry_insert mbcache -alias symbol:jbd2_journal_destroy jbd2 -alias symbol:jbd2_journal_lock_updates jbd2 -alias symbol:mb_cache_entry_free mbcache -alias symbol:jbd2_log_start_commit jbd2 -alias symbol:mb_cache_entry_find_first mbcache -alias symbol:mb_cache_destroy mbcache -alias symbol:jbd2_journal_extend jbd2 -alias symbol:jbd2_journal_begin_ordered_truncate jbd2 -alias symbol:jbd2_journal_revoke jbd2 -alias symbol:jbd2_journal_get_write_access jbd2 -alias symbol:jbd2_inode_cache jbd2 -alias symbol:jbd2_journal_ack_err jbd2 -alias symbol:mb_cache_create mbcache -alias symbol:jbd2_journal_flush jbd2 -alias symbol:jbd2_journal_init_jbd_inode jbd2 -alias symbol:mb_cache_entry_alloc mbcache -alias symbol:jbd2_journal_get_undo_access jbd2 -alias symbol:jbd2_journal_get_create_access jbd2 -alias symbol:jbd2_journal_update_format jbd2 -alias symbol:crc16_table crc16 -alias symbol:jbd2_journal_wipe jbd2 -alias symbol:jbd2_journal_check_used_features jbd2 -alias symbol:mb_cache_entry_get mbcache -alias symbol:jbd2_journal_force_commit_nested jbd2 -alias symbol:jbd2_log_wait_commit jbd2 -alias symbol:jbd2_journal_stop jbd2 -alias symbol:jbd2_journal_set_triggers jbd2 -alias symbol:jbd2_journal_release_jbd_inode jbd2 -alias symbol:jbd2_journal_unlock_updates jbd2 -alias symbol:jbd2_journal_start_commit jbd2 -alias symbol:jbd2_journal_dirty_metadata jbd2 -alias symbol:jbd2_journal_force_commit jbd2 -alias symbol:mb_cache_entry_release mbcache -alias symbol:jbd2_journal_init_dev jbd2 -alias symbol:jbd2_journal_forget jbd2 -alias symbol:jbd2_journal_set_features jbd2 -alias symbol:jbd2_journal_start jbd2 -alias symbol:jbd2_journal_clear_features jbd2 -alias symbol:jbd2__journal_start jbd2 -alias symbol:mb_cache_shrink mbcache -alias symbol:jbd2_journal_clear_err jbd2 -alias symbol:jbd2_journal_file_inode jbd2 -alias symbol:jbd2_journal_restart jbd2 -alias symbol:jbd2_journal_load jbd2 -alias symbol:jbd2_journal_check_available_features jbd2 -alias symbol:jbd2_journal_abort jbd2 -alias symbol:jbd2_journal_blocks_per_page jbd2 -alias symbol:jbd2_journal_try_to_free_buffers jbd2 -alias symbol:jbd2_trans_will_send_data_barrier jbd2 -alias symbol:jbd2_journal_errno jbd2 diff --git a/testsuite/rootfs-pristine/test-dependencies/lib/modules/4.0.20-kmod/modules.symbols.bin b/testsuite/rootfs-pristine/test-dependencies/lib/modules/4.0.20-kmod/modules.symbols.bin deleted file mode 100644 index aa8cfc8..0000000 Binary files a/testsuite/rootfs-pristine/test-dependencies/lib/modules/4.0.20-kmod/modules.symbols.bin and /dev/null differ diff --git a/testsuite/rootfs-pristine/test-depmod/modules-order-compressed/lib/modules/3.5.4-1-ARCH/correct-modules.alias b/testsuite/rootfs-pristine/test-depmod/modules-order-compressed/lib/modules/3.5.4-1-ARCH/correct-modules.alias deleted file mode 100644 index 5675329..0000000 --- a/testsuite/rootfs-pristine/test-depmod/modules-order-compressed/lib/modules/3.5.4-1-ARCH/correct-modules.alias +++ /dev/null @@ -1,37 +0,0 @@ -# Aliases extracted from modules themselves. -alias pci:v0000103Cd00003230sv0000103Csd0000323Dbc*sc*i* cciss -alias pci:v0000103Cd00003230sv0000103Csd00003237bc*sc*i* cciss -alias pci:v0000103Cd00003238sv0000103Csd00003215bc*sc*i* cciss -alias pci:v0000103Cd00003238sv0000103Csd00003214bc*sc*i* cciss -alias pci:v0000103Cd00003238sv0000103Csd00003213bc*sc*i* cciss -alias pci:v0000103Cd00003238sv0000103Csd00003212bc*sc*i* cciss -alias pci:v0000103Cd00003238sv0000103Csd00003211bc*sc*i* cciss -alias pci:v0000103Cd00003230sv0000103Csd00003235bc*sc*i* cciss -alias pci:v0000103Cd00003230sv0000103Csd00003234bc*sc*i* cciss -alias pci:v0000103Cd00003230sv0000103Csd00003223bc*sc*i* cciss -alias pci:v0000103Cd00003220sv0000103Csd00003225bc*sc*i* cciss -alias pci:v00000E11d00000046sv00000E11sd0000409Dbc*sc*i* cciss -alias pci:v00000E11d00000046sv00000E11sd0000409Cbc*sc*i* cciss -alias pci:v00000E11d00000046sv00000E11sd0000409Bbc*sc*i* cciss -alias pci:v00000E11d00000046sv00000E11sd0000409Abc*sc*i* cciss -alias pci:v00000E11d00000046sv00000E11sd00004091bc*sc*i* cciss -alias pci:v00000E11d0000B178sv00000E11sd00004083bc*sc*i* cciss -alias pci:v00000E11d0000B178sv00000E11sd00004082bc*sc*i* cciss -alias pci:v00000E11d0000B178sv00000E11sd00004080bc*sc*i* cciss -alias pci:v00000E11d0000B060sv00000E11sd00004070bc*sc*i* cciss -alias pci:v0000103Cd*sv*sd*bc01sc04i* hpsa -alias pci:v0000103Cd0000323Bsv0000103Csd00003356bc*sc*i* hpsa -alias pci:v0000103Cd0000323Bsv0000103Csd00003355bc*sc*i* hpsa -alias pci:v0000103Cd0000323Bsv0000103Csd00003354bc*sc*i* hpsa -alias pci:v0000103Cd0000323Bsv0000103Csd00003353bc*sc*i* hpsa -alias pci:v0000103Cd0000323Bsv0000103Csd00003352bc*sc*i* hpsa -alias pci:v0000103Cd0000323Bsv0000103Csd00003351bc*sc*i* hpsa -alias pci:v0000103Cd0000323Bsv0000103Csd00003350bc*sc*i* hpsa -alias pci:v0000103Cd0000323Asv0000103Csd00003233bc*sc*i* hpsa -alias pci:v0000103Cd0000323Asv0000103Csd0000324Bbc*sc*i* hpsa -alias pci:v0000103Cd0000323Asv0000103Csd0000324Abc*sc*i* hpsa -alias pci:v0000103Cd0000323Asv0000103Csd00003249bc*sc*i* hpsa -alias pci:v0000103Cd0000323Asv0000103Csd00003247bc*sc*i* hpsa -alias pci:v0000103Cd0000323Asv0000103Csd00003245bc*sc*i* hpsa -alias pci:v0000103Cd0000323Asv0000103Csd00003243bc*sc*i* hpsa -alias pci:v0000103Cd0000323Asv0000103Csd00003241bc*sc*i* hpsa diff --git a/testsuite/rootfs-pristine/test-depmod/modules-order-compressed/lib/modules/3.5.4-1-ARCH/kernel/drivers/block/cciss.ko.gz b/testsuite/rootfs-pristine/test-depmod/modules-order-compressed/lib/modules/3.5.4-1-ARCH/kernel/drivers/block/cciss.ko.gz deleted file mode 100644 index 0684dc1..0000000 Binary files a/testsuite/rootfs-pristine/test-depmod/modules-order-compressed/lib/modules/3.5.4-1-ARCH/kernel/drivers/block/cciss.ko.gz and /dev/null differ diff --git a/testsuite/rootfs-pristine/test-depmod/modules-order-compressed/lib/modules/3.5.4-1-ARCH/kernel/drivers/scsi/hpsa.ko.gz b/testsuite/rootfs-pristine/test-depmod/modules-order-compressed/lib/modules/3.5.4-1-ARCH/kernel/drivers/scsi/hpsa.ko.gz deleted file mode 100644 index 403d6fb..0000000 Binary files a/testsuite/rootfs-pristine/test-depmod/modules-order-compressed/lib/modules/3.5.4-1-ARCH/kernel/drivers/scsi/hpsa.ko.gz and /dev/null differ diff --git a/testsuite/rootfs-pristine/test-depmod/modules-order-compressed/lib/modules/3.5.4-1-ARCH/kernel/drivers/scsi/scsi_mod.ko.gz b/testsuite/rootfs-pristine/test-depmod/modules-order-compressed/lib/modules/3.5.4-1-ARCH/kernel/drivers/scsi/scsi_mod.ko.gz deleted file mode 100644 index 2306bb1..0000000 Binary files a/testsuite/rootfs-pristine/test-depmod/modules-order-compressed/lib/modules/3.5.4-1-ARCH/kernel/drivers/scsi/scsi_mod.ko.gz and /dev/null differ diff --git a/testsuite/rootfs-pristine/test-depmod/modules-order-compressed/lib/modules/3.5.4-1-ARCH/modules.builtin b/testsuite/rootfs-pristine/test-depmod/modules-order-compressed/lib/modules/3.5.4-1-ARCH/modules.builtin deleted file mode 100644 index e69de29..0000000 diff --git a/testsuite/rootfs-pristine/test-depmod/modules-order-compressed/lib/modules/3.5.4-1-ARCH/modules.order b/testsuite/rootfs-pristine/test-depmod/modules-order-compressed/lib/modules/3.5.4-1-ARCH/modules.order deleted file mode 100644 index 4b64309..0000000 --- a/testsuite/rootfs-pristine/test-depmod/modules-order-compressed/lib/modules/3.5.4-1-ARCH/modules.order +++ /dev/null @@ -1,7 +0,0 @@ -#336 -kernel/drivers/block/cciss.ko -#2094 -kernel/drivers/scsi/scsi_mod.ko -#2137 -kernel/drivers/scsi/hpsa.ko - diff --git a/testsuite/rootfs-pristine/test-init/correct.txt b/testsuite/rootfs-pristine/test-init/correct.txt deleted file mode 100644 index 1682154..0000000 --- a/testsuite/rootfs-pristine/test-init/correct.txt +++ /dev/null @@ -1,28 +0,0 @@ -filename: /ext4-i686.ko -license: GPL -description: Fourth Extended Filesystem -author: Remy Card, Stephen Tweedie, Andrew Morton, Andreas Dilger, Theodore Ts'o and others -srcversion: A80608676B83D55514B450E -depends: mbcache,jbd2 -vermagic: 2.6.32-220.el6.i686 SMP mod_unload modversions 686 -filename: /ext4-ppc64.ko -license: GPL -description: Fourth Extended Filesystem -author: Remy Card, Stephen Tweedie, Andrew Morton, Andreas Dilger, Theodore Ts'o and others -srcversion: 670806A855D5836BE150B41 -depends: jbd2,mbcache -vermagic: 2.6.32-220.el6.ppc64 SMP mod_unload modversions -filename: /ext4-s390x.ko -license: GPL -description: Fourth Extended Filesystem -author: Remy Card, Stephen Tweedie, Andrew Morton, Andreas Dilger, Theodore Ts'o and others -srcversion: 670806A855D5836BE150B41 -depends: mbcache,jbd2 -vermagic: 2.6.32-220.el6.s390x SMP mod_unload modversions -filename: /ext4-x86_64.ko -license: GPL -description: Fourth Extended Filesystem -author: Remy Card, Stephen Tweedie, Andrew Morton, Andreas Dilger, Theodore Ts'o and others -srcversion: A80608676B83D55514B450E -depends: mbcache,jbd2 -vermagic: 2.6.32-220.el6.x86_64 SMP mod_unload modversions diff --git a/testsuite/rootfs-pristine/test-init/ext4-i686.ko b/testsuite/rootfs-pristine/test-init/ext4-i686.ko deleted file mode 100644 index e5d2fb7..0000000 Binary files a/testsuite/rootfs-pristine/test-init/ext4-i686.ko and /dev/null differ diff --git a/testsuite/rootfs-pristine/test-init/ext4-ppc64.ko b/testsuite/rootfs-pristine/test-init/ext4-ppc64.ko deleted file mode 100644 index cb02ed4..0000000 Binary files a/testsuite/rootfs-pristine/test-init/ext4-ppc64.ko and /dev/null differ diff --git a/testsuite/rootfs-pristine/test-init/ext4-s390x.ko b/testsuite/rootfs-pristine/test-init/ext4-s390x.ko deleted file mode 100644 index 74c3799..0000000 Binary files a/testsuite/rootfs-pristine/test-init/ext4-s390x.ko and /dev/null differ diff --git a/testsuite/rootfs-pristine/test-init/ext4-x86_64.ko b/testsuite/rootfs-pristine/test-init/ext4-x86_64.ko deleted file mode 100644 index ae96eef..0000000 Binary files a/testsuite/rootfs-pristine/test-init/ext4-x86_64.ko and /dev/null differ diff --git a/testsuite/rootfs-pristine/test-loaded/correct.txt b/testsuite/rootfs-pristine/test-loaded/correct.txt deleted file mode 100644 index 71c5f7f..0000000 --- a/testsuite/rootfs-pristine/test-loaded/correct.txt +++ /dev/null @@ -1,2 +0,0 @@ -Module Size Used by -btusb 11216 0 diff --git a/testsuite/rootfs-pristine/test-loaded/proc/modules b/testsuite/rootfs-pristine/test-loaded/proc/modules deleted file mode 100644 index ce468c0..0000000 --- a/testsuite/rootfs-pristine/test-loaded/proc/modules +++ /dev/null @@ -1 +0,0 @@ -btusb 11216 0 - Live 0xffffffffa014a000 diff --git a/testsuite/rootfs-pristine/test-loaded/sys/module/btusb/drivers/usb:btusb b/testsuite/rootfs-pristine/test-loaded/sys/module/btusb/drivers/usb:btusb deleted file mode 120000 index c173837..0000000 --- a/testsuite/rootfs-pristine/test-loaded/sys/module/btusb/drivers/usb:btusb +++ /dev/null @@ -1 +0,0 @@ -../../../bus/usb/drivers/btusb \ No newline at end of file diff --git a/testsuite/rootfs-pristine/test-loaded/sys/module/btusb/holders/.gitignore b/testsuite/rootfs-pristine/test-loaded/sys/module/btusb/holders/.gitignore deleted file mode 100644 index e69de29..0000000 diff --git a/testsuite/rootfs-pristine/test-loaded/sys/module/btusb/initstate b/testsuite/rootfs-pristine/test-loaded/sys/module/btusb/initstate deleted file mode 100644 index e23fe64..0000000 --- a/testsuite/rootfs-pristine/test-loaded/sys/module/btusb/initstate +++ /dev/null @@ -1 +0,0 @@ -live diff --git a/testsuite/rootfs-pristine/test-loaded/sys/module/btusb/notes/.note.gnu.build-id b/testsuite/rootfs-pristine/test-loaded/sys/module/btusb/notes/.note.gnu.build-id deleted file mode 100644 index 0758558..0000000 Binary files a/testsuite/rootfs-pristine/test-loaded/sys/module/btusb/notes/.note.gnu.build-id and /dev/null differ diff --git a/testsuite/rootfs-pristine/test-loaded/sys/module/btusb/parameters/disable_scofix b/testsuite/rootfs-pristine/test-loaded/sys/module/btusb/parameters/disable_scofix deleted file mode 100644 index d52e798..0000000 --- a/testsuite/rootfs-pristine/test-loaded/sys/module/btusb/parameters/disable_scofix +++ /dev/null @@ -1 +0,0 @@ -N diff --git a/testsuite/rootfs-pristine/test-loaded/sys/module/btusb/parameters/force_scofix b/testsuite/rootfs-pristine/test-loaded/sys/module/btusb/parameters/force_scofix deleted file mode 100644 index d52e798..0000000 --- a/testsuite/rootfs-pristine/test-loaded/sys/module/btusb/parameters/force_scofix +++ /dev/null @@ -1 +0,0 @@ -N diff --git a/testsuite/rootfs-pristine/test-loaded/sys/module/btusb/parameters/ignore_csr b/testsuite/rootfs-pristine/test-loaded/sys/module/btusb/parameters/ignore_csr deleted file mode 100644 index d52e798..0000000 --- a/testsuite/rootfs-pristine/test-loaded/sys/module/btusb/parameters/ignore_csr +++ /dev/null @@ -1 +0,0 @@ -N diff --git a/testsuite/rootfs-pristine/test-loaded/sys/module/btusb/parameters/ignore_dga b/testsuite/rootfs-pristine/test-loaded/sys/module/btusb/parameters/ignore_dga deleted file mode 100644 index d52e798..0000000 --- a/testsuite/rootfs-pristine/test-loaded/sys/module/btusb/parameters/ignore_dga +++ /dev/null @@ -1 +0,0 @@ -N diff --git a/testsuite/rootfs-pristine/test-loaded/sys/module/btusb/parameters/ignore_sniffer b/testsuite/rootfs-pristine/test-loaded/sys/module/btusb/parameters/ignore_sniffer deleted file mode 100644 index d52e798..0000000 --- a/testsuite/rootfs-pristine/test-loaded/sys/module/btusb/parameters/ignore_sniffer +++ /dev/null @@ -1 +0,0 @@ -N diff --git a/testsuite/rootfs-pristine/test-loaded/sys/module/btusb/parameters/reset b/testsuite/rootfs-pristine/test-loaded/sys/module/btusb/parameters/reset deleted file mode 100644 index 9bda8c3..0000000 --- a/testsuite/rootfs-pristine/test-loaded/sys/module/btusb/parameters/reset +++ /dev/null @@ -1 +0,0 @@ -Y diff --git a/testsuite/rootfs-pristine/test-loaded/sys/module/btusb/refcnt b/testsuite/rootfs-pristine/test-loaded/sys/module/btusb/refcnt deleted file mode 100644 index 573541a..0000000 --- a/testsuite/rootfs-pristine/test-loaded/sys/module/btusb/refcnt +++ /dev/null @@ -1 +0,0 @@ -0 diff --git a/testsuite/rootfs-pristine/test-loaded/sys/module/btusb/sections/.bss b/testsuite/rootfs-pristine/test-loaded/sys/module/btusb/sections/.bss deleted file mode 100644 index e971686..0000000 --- a/testsuite/rootfs-pristine/test-loaded/sys/module/btusb/sections/.bss +++ /dev/null @@ -1 +0,0 @@ -0xffffffffa014c828 diff --git a/testsuite/rootfs-pristine/test-loaded/sys/module/btusb/sections/.data b/testsuite/rootfs-pristine/test-loaded/sys/module/btusb/sections/.data deleted file mode 100644 index 5ccfa09..0000000 --- a/testsuite/rootfs-pristine/test-loaded/sys/module/btusb/sections/.data +++ /dev/null @@ -1 +0,0 @@ -0xffffffffa014c040 diff --git a/testsuite/rootfs-pristine/test-loaded/sys/module/btusb/sections/.exit.text b/testsuite/rootfs-pristine/test-loaded/sys/module/btusb/sections/.exit.text deleted file mode 100644 index 446df03..0000000 --- a/testsuite/rootfs-pristine/test-loaded/sys/module/btusb/sections/.exit.text +++ /dev/null @@ -1 +0,0 @@ -0xffffffffa014bd7c diff --git a/testsuite/rootfs-pristine/test-loaded/sys/module/btusb/sections/.gnu.linkonce.this_module b/testsuite/rootfs-pristine/test-loaded/sys/module/btusb/sections/.gnu.linkonce.this_module deleted file mode 100644 index f91a8fd..0000000 --- a/testsuite/rootfs-pristine/test-loaded/sys/module/btusb/sections/.gnu.linkonce.this_module +++ /dev/null @@ -1 +0,0 @@ -0xffffffffa014c600 diff --git a/testsuite/rootfs-pristine/test-loaded/sys/module/btusb/sections/.init.text b/testsuite/rootfs-pristine/test-loaded/sys/module/btusb/sections/.init.text deleted file mode 100644 index 1179bf2..0000000 --- a/testsuite/rootfs-pristine/test-loaded/sys/module/btusb/sections/.init.text +++ /dev/null @@ -1 +0,0 @@ -0xffffffffa014e000 diff --git a/testsuite/rootfs-pristine/test-loaded/sys/module/btusb/sections/.note.gnu.build-id b/testsuite/rootfs-pristine/test-loaded/sys/module/btusb/sections/.note.gnu.build-id deleted file mode 100644 index e08ddab..0000000 --- a/testsuite/rootfs-pristine/test-loaded/sys/module/btusb/sections/.note.gnu.build-id +++ /dev/null @@ -1 +0,0 @@ -0xffffffffa014bd90 diff --git a/testsuite/rootfs-pristine/test-loaded/sys/module/btusb/sections/.rodata b/testsuite/rootfs-pristine/test-loaded/sys/module/btusb/sections/.rodata deleted file mode 100644 index 327441b..0000000 --- a/testsuite/rootfs-pristine/test-loaded/sys/module/btusb/sections/.rodata +++ /dev/null @@ -1 +0,0 @@ -0xffffffffa014bfe0 diff --git a/testsuite/rootfs-pristine/test-loaded/sys/module/btusb/sections/.rodata.str1.1 b/testsuite/rootfs-pristine/test-loaded/sys/module/btusb/sections/.rodata.str1.1 deleted file mode 100644 index e96b658..0000000 --- a/testsuite/rootfs-pristine/test-loaded/sys/module/btusb/sections/.rodata.str1.1 +++ /dev/null @@ -1 +0,0 @@ -0xffffffffa014be29 diff --git a/testsuite/rootfs-pristine/test-loaded/sys/module/btusb/sections/.rodata.str1.8 b/testsuite/rootfs-pristine/test-loaded/sys/module/btusb/sections/.rodata.str1.8 deleted file mode 100644 index d437cbe..0000000 --- a/testsuite/rootfs-pristine/test-loaded/sys/module/btusb/sections/.rodata.str1.8 +++ /dev/null @@ -1 +0,0 @@ -0xffffffffa014bdb8 diff --git a/testsuite/rootfs-pristine/test-loaded/sys/module/btusb/sections/.smp_locks b/testsuite/rootfs-pristine/test-loaded/sys/module/btusb/sections/.smp_locks deleted file mode 100644 index 955e243..0000000 --- a/testsuite/rootfs-pristine/test-loaded/sys/module/btusb/sections/.smp_locks +++ /dev/null @@ -1 +0,0 @@ -0xffffffffa014bea8 diff --git a/testsuite/rootfs-pristine/test-loaded/sys/module/btusb/sections/.strtab b/testsuite/rootfs-pristine/test-loaded/sys/module/btusb/sections/.strtab deleted file mode 100644 index a874fed..0000000 --- a/testsuite/rootfs-pristine/test-loaded/sys/module/btusb/sections/.strtab +++ /dev/null @@ -1 +0,0 @@ -0xffffffffa014ede8 diff --git a/testsuite/rootfs-pristine/test-loaded/sys/module/btusb/sections/.symtab b/testsuite/rootfs-pristine/test-loaded/sys/module/btusb/sections/.symtab deleted file mode 100644 index fafe019..0000000 --- a/testsuite/rootfs-pristine/test-loaded/sys/module/btusb/sections/.symtab +++ /dev/null @@ -1 +0,0 @@ -0xffffffffa014e020 diff --git a/testsuite/rootfs-pristine/test-loaded/sys/module/btusb/sections/.text b/testsuite/rootfs-pristine/test-loaded/sys/module/btusb/sections/.text deleted file mode 100644 index 0a967df..0000000 --- a/testsuite/rootfs-pristine/test-loaded/sys/module/btusb/sections/.text +++ /dev/null @@ -1 +0,0 @@ -0xffffffffa014a000 diff --git a/testsuite/rootfs-pristine/test-loaded/sys/module/btusb/sections/__param b/testsuite/rootfs-pristine/test-loaded/sys/module/btusb/sections/__param deleted file mode 100644 index 9f6710a..0000000 --- a/testsuite/rootfs-pristine/test-loaded/sys/module/btusb/sections/__param +++ /dev/null @@ -1 +0,0 @@ -0xffffffffa014bf20 diff --git a/testsuite/rootfs-pristine/test-loaded/sys/module/btusb/srcversion b/testsuite/rootfs-pristine/test-loaded/sys/module/btusb/srcversion deleted file mode 100644 index a688adf..0000000 --- a/testsuite/rootfs-pristine/test-loaded/sys/module/btusb/srcversion +++ /dev/null @@ -1 +0,0 @@ -8EEAC35838CCA1118F97F5F diff --git a/testsuite/rootfs-pristine/test-loaded/sys/module/btusb/version b/testsuite/rootfs-pristine/test-loaded/sys/module/btusb/version deleted file mode 100644 index 5a2a580..0000000 --- a/testsuite/rootfs-pristine/test-loaded/sys/module/btusb/version +++ /dev/null @@ -1 +0,0 @@ -0.6 diff --git a/testsuite/rootfs-pristine/test-modinfo/correct.txt b/testsuite/rootfs-pristine/test-modinfo/correct.txt deleted file mode 100644 index 4a7a4ac..0000000 --- a/testsuite/rootfs-pristine/test-modinfo/correct.txt +++ /dev/null @@ -1,52 +0,0 @@ -filename: /ext4-i686.ko -license: GPL -description: Fourth Extended Filesystem -author: Remy Card, Stephen Tweedie, Andrew Morton, Andreas Dilger, Theodore Ts'o and others -srcversion: A80608676B83D55514B450E -depends: mbcache,jbd2 -vermagic: 2.6.32-220.el6.i686 SMP mod_unload modversions 686 -filename: /ext4-ppc64.ko -license: GPL -description: Fourth Extended Filesystem -author: Remy Card, Stephen Tweedie, Andrew Morton, Andreas Dilger, Theodore Ts'o and others -srcversion: 670806A855D5836BE150B41 -depends: jbd2,mbcache -vermagic: 2.6.32-220.el6.ppc64 SMP mod_unload modversions -filename: /ext4-s390x.ko -license: GPL -description: Fourth Extended Filesystem -author: Remy Card, Stephen Tweedie, Andrew Morton, Andreas Dilger, Theodore Ts'o and others -srcversion: 670806A855D5836BE150B41 -depends: mbcache,jbd2 -vermagic: 2.6.32-220.el6.s390x SMP mod_unload modversions -filename: /ext4-x86_64.ko -license: GPL -description: Fourth Extended Filesystem -author: Remy Card, Stephen Tweedie, Andrew Morton, Andreas Dilger, Theodore Ts'o and others -srcversion: A80608676B83D55514B450E -depends: mbcache,jbd2 -vermagic: 2.6.32-220.el6.x86_64 SMP mod_unload modversions -filename: /ext4-x86_64-sha1.ko -license: GPL -description: Fourth Extended Filesystem -author: Remy Card, Stephen Tweedie, Andrew Morton, Andreas Dilger, Theodore Ts'o and others -alias: ext3 -alias: ext2 -depends: mbcache,jbd2 -intree: Y -vermagic: 3.7.0 SMP mod_unload -signer: Magrathea: Glacier signing key -sig_key: E3:C8:FC:A7:3F:B3:1D:DE:84:81:EF:38:E3:4C:DE:4B:0C:FD:1B:F9 -sig_hashalgo: sha1 -filename: /ext4-x86_64-sha256.ko -license: GPL -description: Fourth Extended Filesystem -author: Remy Card, Stephen Tweedie, Andrew Morton, Andreas Dilger, Theodore Ts'o and others -alias: ext3 -alias: ext2 -depends: mbcache,jbd2 -intree: Y -vermagic: 3.7.0 SMP mod_unload -signer: Magrathea: Glacier signing key -sig_key: E3:C8:FC:A7:3F:B3:1D:DE:84:81:EF:38:E3:4C:DE:4B:0C:FD:1B:F9 -sig_hashalgo: sha256 diff --git a/testsuite/rootfs-pristine/test-modinfo/ext4-i686.ko b/testsuite/rootfs-pristine/test-modinfo/ext4-i686.ko deleted file mode 100644 index e5d2fb7..0000000 Binary files a/testsuite/rootfs-pristine/test-modinfo/ext4-i686.ko and /dev/null differ diff --git a/testsuite/rootfs-pristine/test-modinfo/ext4-ppc64.ko b/testsuite/rootfs-pristine/test-modinfo/ext4-ppc64.ko deleted file mode 100644 index cb02ed4..0000000 Binary files a/testsuite/rootfs-pristine/test-modinfo/ext4-ppc64.ko and /dev/null differ diff --git a/testsuite/rootfs-pristine/test-modinfo/ext4-s390x.ko b/testsuite/rootfs-pristine/test-modinfo/ext4-s390x.ko deleted file mode 100644 index 74c3799..0000000 Binary files a/testsuite/rootfs-pristine/test-modinfo/ext4-s390x.ko and /dev/null differ diff --git a/testsuite/rootfs-pristine/test-modinfo/ext4-x86_64-sha1.ko b/testsuite/rootfs-pristine/test-modinfo/ext4-x86_64-sha1.ko deleted file mode 100644 index 6e894f9..0000000 Binary files a/testsuite/rootfs-pristine/test-modinfo/ext4-x86_64-sha1.ko and /dev/null differ diff --git a/testsuite/rootfs-pristine/test-modinfo/ext4-x86_64-sha256.ko b/testsuite/rootfs-pristine/test-modinfo/ext4-x86_64-sha256.ko deleted file mode 100644 index bf72008..0000000 Binary files a/testsuite/rootfs-pristine/test-modinfo/ext4-x86_64-sha256.ko and /dev/null differ diff --git a/testsuite/rootfs-pristine/test-modinfo/ext4-x86_64.ko b/testsuite/rootfs-pristine/test-modinfo/ext4-x86_64.ko deleted file mode 100644 index ae96eef..0000000 Binary files a/testsuite/rootfs-pristine/test-modinfo/ext4-x86_64.ko and /dev/null differ diff --git a/testsuite/rootfs-pristine/test-modprobe/alias-to-none/correct-psmouse.txt b/testsuite/rootfs-pristine/test-modprobe/alias-to-none/correct-psmouse.txt deleted file mode 100644 index e69de29..0000000 diff --git a/testsuite/rootfs-pristine/test-modprobe/alias-to-none/etc/modprobe.d/bogus.conf b/testsuite/rootfs-pristine/test-modprobe/alias-to-none/etc/modprobe.d/bogus.conf deleted file mode 100644 index 14bed0b..0000000 --- a/testsuite/rootfs-pristine/test-modprobe/alias-to-none/etc/modprobe.d/bogus.conf +++ /dev/null @@ -1 +0,0 @@ -alias psmouse deaddood diff --git a/testsuite/rootfs-pristine/test-modprobe/alias-to-none/lib/modules/4.4.4/kernel/drivers/input/mouse/psmouse.ko b/testsuite/rootfs-pristine/test-modprobe/alias-to-none/lib/modules/4.4.4/kernel/drivers/input/mouse/psmouse.ko deleted file mode 100644 index 4eac2a3..0000000 Binary files a/testsuite/rootfs-pristine/test-modprobe/alias-to-none/lib/modules/4.4.4/kernel/drivers/input/mouse/psmouse.ko and /dev/null differ diff --git a/testsuite/rootfs-pristine/test-modprobe/alias-to-none/lib/modules/4.4.4/modules.alias b/testsuite/rootfs-pristine/test-modprobe/alias-to-none/lib/modules/4.4.4/modules.alias deleted file mode 100644 index a4e7677..0000000 --- a/testsuite/rootfs-pristine/test-modprobe/alias-to-none/lib/modules/4.4.4/modules.alias +++ /dev/null @@ -1,3 +0,0 @@ -# Aliases extracted from modules themselves. -alias serio:ty05pr*id*ex* psmouse -alias serio:ty01pr*id*ex* psmouse diff --git a/testsuite/rootfs-pristine/test-modprobe/alias-to-none/lib/modules/4.4.4/modules.alias.bin b/testsuite/rootfs-pristine/test-modprobe/alias-to-none/lib/modules/4.4.4/modules.alias.bin deleted file mode 100644 index 0b13537..0000000 Binary files a/testsuite/rootfs-pristine/test-modprobe/alias-to-none/lib/modules/4.4.4/modules.alias.bin and /dev/null differ diff --git a/testsuite/rootfs-pristine/test-modprobe/alias-to-none/lib/modules/4.4.4/modules.builtin.bin b/testsuite/rootfs-pristine/test-modprobe/alias-to-none/lib/modules/4.4.4/modules.builtin.bin deleted file mode 100644 index e69de29..0000000 diff --git a/testsuite/rootfs-pristine/test-modprobe/alias-to-none/lib/modules/4.4.4/modules.dep b/testsuite/rootfs-pristine/test-modprobe/alias-to-none/lib/modules/4.4.4/modules.dep deleted file mode 100644 index 7ba5711..0000000 --- a/testsuite/rootfs-pristine/test-modprobe/alias-to-none/lib/modules/4.4.4/modules.dep +++ /dev/null @@ -1 +0,0 @@ -kernel/drivers/input/mouse/psmouse.ko: diff --git a/testsuite/rootfs-pristine/test-modprobe/alias-to-none/lib/modules/4.4.4/modules.dep.bin b/testsuite/rootfs-pristine/test-modprobe/alias-to-none/lib/modules/4.4.4/modules.dep.bin deleted file mode 100644 index bdd0eb5..0000000 Binary files a/testsuite/rootfs-pristine/test-modprobe/alias-to-none/lib/modules/4.4.4/modules.dep.bin and /dev/null differ diff --git a/testsuite/rootfs-pristine/test-modprobe/alias-to-none/lib/modules/4.4.4/modules.devname b/testsuite/rootfs-pristine/test-modprobe/alias-to-none/lib/modules/4.4.4/modules.devname deleted file mode 100644 index 58f6d6d..0000000 --- a/testsuite/rootfs-pristine/test-modprobe/alias-to-none/lib/modules/4.4.4/modules.devname +++ /dev/null @@ -1 +0,0 @@ -# Device nodes to trigger on-demand module loading. diff --git a/testsuite/rootfs-pristine/test-modprobe/alias-to-none/lib/modules/4.4.4/modules.softdep b/testsuite/rootfs-pristine/test-modprobe/alias-to-none/lib/modules/4.4.4/modules.softdep deleted file mode 100644 index 3cc0512..0000000 --- a/testsuite/rootfs-pristine/test-modprobe/alias-to-none/lib/modules/4.4.4/modules.softdep +++ /dev/null @@ -1,2 +0,0 @@ -# Soft dependencies extracted from modules themselves. -# Copy, with a .conf extension, to /etc/modprobe.d to use it with modprobe. diff --git a/testsuite/rootfs-pristine/test-modprobe/alias-to-none/lib/modules/4.4.4/modules.symbols b/testsuite/rootfs-pristine/test-modprobe/alias-to-none/lib/modules/4.4.4/modules.symbols deleted file mode 100644 index 618c345..0000000 --- a/testsuite/rootfs-pristine/test-modprobe/alias-to-none/lib/modules/4.4.4/modules.symbols +++ /dev/null @@ -1 +0,0 @@ -# Aliases for symbols, used by symbol_request(). diff --git a/testsuite/rootfs-pristine/test-modprobe/alias-to-none/lib/modules/4.4.4/modules.symbols.bin b/testsuite/rootfs-pristine/test-modprobe/alias-to-none/lib/modules/4.4.4/modules.symbols.bin deleted file mode 100644 index 7075435..0000000 Binary files a/testsuite/rootfs-pristine/test-modprobe/alias-to-none/lib/modules/4.4.4/modules.symbols.bin and /dev/null differ diff --git a/testsuite/rootfs-pristine/test-modprobe/alias-to-none/proc/modules b/testsuite/rootfs-pristine/test-modprobe/alias-to-none/proc/modules deleted file mode 100644 index e69de29..0000000 diff --git a/testsuite/rootfs-pristine/test-modprobe/builtin/lib/modules/4.4.4/modules.alias b/testsuite/rootfs-pristine/test-modprobe/builtin/lib/modules/4.4.4/modules.alias deleted file mode 100644 index ba76e18..0000000 --- a/testsuite/rootfs-pristine/test-modprobe/builtin/lib/modules/4.4.4/modules.alias +++ /dev/null @@ -1 +0,0 @@ -# Aliases extracted from modules themselves. diff --git a/testsuite/rootfs-pristine/test-modprobe/builtin/lib/modules/4.4.4/modules.alias.bin b/testsuite/rootfs-pristine/test-modprobe/builtin/lib/modules/4.4.4/modules.alias.bin deleted file mode 100644 index 7075435..0000000 Binary files a/testsuite/rootfs-pristine/test-modprobe/builtin/lib/modules/4.4.4/modules.alias.bin and /dev/null differ diff --git a/testsuite/rootfs-pristine/test-modprobe/builtin/lib/modules/4.4.4/modules.builtin b/testsuite/rootfs-pristine/test-modprobe/builtin/lib/modules/4.4.4/modules.builtin deleted file mode 100644 index 3c4ef2c..0000000 --- a/testsuite/rootfs-pristine/test-modprobe/builtin/lib/modules/4.4.4/modules.builtin +++ /dev/null @@ -1 +0,0 @@ -kernel/net/unix/unix.ko diff --git a/testsuite/rootfs-pristine/test-modprobe/builtin/lib/modules/4.4.4/modules.builtin.bin b/testsuite/rootfs-pristine/test-modprobe/builtin/lib/modules/4.4.4/modules.builtin.bin deleted file mode 100644 index 41af3ee..0000000 Binary files a/testsuite/rootfs-pristine/test-modprobe/builtin/lib/modules/4.4.4/modules.builtin.bin and /dev/null differ diff --git a/testsuite/rootfs-pristine/test-modprobe/builtin/lib/modules/4.4.4/modules.dep b/testsuite/rootfs-pristine/test-modprobe/builtin/lib/modules/4.4.4/modules.dep deleted file mode 100644 index e69de29..0000000 diff --git a/testsuite/rootfs-pristine/test-modprobe/builtin/lib/modules/4.4.4/modules.dep.bin b/testsuite/rootfs-pristine/test-modprobe/builtin/lib/modules/4.4.4/modules.dep.bin deleted file mode 100644 index 7075435..0000000 Binary files a/testsuite/rootfs-pristine/test-modprobe/builtin/lib/modules/4.4.4/modules.dep.bin and /dev/null differ diff --git a/testsuite/rootfs-pristine/test-modprobe/builtin/lib/modules/4.4.4/modules.devname b/testsuite/rootfs-pristine/test-modprobe/builtin/lib/modules/4.4.4/modules.devname deleted file mode 100644 index 58f6d6d..0000000 --- a/testsuite/rootfs-pristine/test-modprobe/builtin/lib/modules/4.4.4/modules.devname +++ /dev/null @@ -1 +0,0 @@ -# Device nodes to trigger on-demand module loading. diff --git a/testsuite/rootfs-pristine/test-modprobe/builtin/lib/modules/4.4.4/modules.softdep b/testsuite/rootfs-pristine/test-modprobe/builtin/lib/modules/4.4.4/modules.softdep deleted file mode 100644 index 3cc0512..0000000 --- a/testsuite/rootfs-pristine/test-modprobe/builtin/lib/modules/4.4.4/modules.softdep +++ /dev/null @@ -1,2 +0,0 @@ -# Soft dependencies extracted from modules themselves. -# Copy, with a .conf extension, to /etc/modprobe.d to use it with modprobe. diff --git a/testsuite/rootfs-pristine/test-modprobe/builtin/lib/modules/4.4.4/modules.symbols b/testsuite/rootfs-pristine/test-modprobe/builtin/lib/modules/4.4.4/modules.symbols deleted file mode 100644 index 618c345..0000000 --- a/testsuite/rootfs-pristine/test-modprobe/builtin/lib/modules/4.4.4/modules.symbols +++ /dev/null @@ -1 +0,0 @@ -# Aliases for symbols, used by symbol_request(). diff --git a/testsuite/rootfs-pristine/test-modprobe/builtin/lib/modules/4.4.4/modules.symbols.bin b/testsuite/rootfs-pristine/test-modprobe/builtin/lib/modules/4.4.4/modules.symbols.bin deleted file mode 100644 index 7075435..0000000 Binary files a/testsuite/rootfs-pristine/test-modprobe/builtin/lib/modules/4.4.4/modules.symbols.bin and /dev/null differ diff --git a/testsuite/rootfs-pristine/test-modprobe/install-cmd-loop/etc/modprobe.d/dumb-instal-loop.conf b/testsuite/rootfs-pristine/test-modprobe/install-cmd-loop/etc/modprobe.d/dumb-instal-loop.conf deleted file mode 100644 index 8014af3..0000000 --- a/testsuite/rootfs-pristine/test-modprobe/install-cmd-loop/etc/modprobe.d/dumb-instal-loop.conf +++ /dev/null @@ -1 +0,0 @@ -install snd $MODPROBE --ignore-install snd && { $MODPROBE --quiet snd-ioctl32 ; $MODPROBE --quiet snd-pcm ; } diff --git a/testsuite/rootfs-pristine/test-modprobe/install-cmd-loop/lib/modules/4.4.4/kernel/sound/core/snd-pcm.ko.gz b/testsuite/rootfs-pristine/test-modprobe/install-cmd-loop/lib/modules/4.4.4/kernel/sound/core/snd-pcm.ko.gz deleted file mode 100644 index b149c6a..0000000 Binary files a/testsuite/rootfs-pristine/test-modprobe/install-cmd-loop/lib/modules/4.4.4/kernel/sound/core/snd-pcm.ko.gz and /dev/null differ diff --git a/testsuite/rootfs-pristine/test-modprobe/install-cmd-loop/lib/modules/4.4.4/kernel/sound/core/snd.ko.gz b/testsuite/rootfs-pristine/test-modprobe/install-cmd-loop/lib/modules/4.4.4/kernel/sound/core/snd.ko.gz deleted file mode 100644 index c7c671d..0000000 Binary files a/testsuite/rootfs-pristine/test-modprobe/install-cmd-loop/lib/modules/4.4.4/kernel/sound/core/snd.ko.gz and /dev/null differ diff --git a/testsuite/rootfs-pristine/test-modprobe/install-cmd-loop/lib/modules/4.4.4/modules.alias b/testsuite/rootfs-pristine/test-modprobe/install-cmd-loop/lib/modules/4.4.4/modules.alias deleted file mode 100644 index 8631be6..0000000 --- a/testsuite/rootfs-pristine/test-modprobe/install-cmd-loop/lib/modules/4.4.4/modules.alias +++ /dev/null @@ -1,2 +0,0 @@ -# Aliases extracted from modules themselves. -alias char-major-116-* snd diff --git a/testsuite/rootfs-pristine/test-modprobe/install-cmd-loop/lib/modules/4.4.4/modules.alias.bin b/testsuite/rootfs-pristine/test-modprobe/install-cmd-loop/lib/modules/4.4.4/modules.alias.bin deleted file mode 100644 index e9d2680..0000000 Binary files a/testsuite/rootfs-pristine/test-modprobe/install-cmd-loop/lib/modules/4.4.4/modules.alias.bin and /dev/null differ diff --git a/testsuite/rootfs-pristine/test-modprobe/install-cmd-loop/lib/modules/4.4.4/modules.dep b/testsuite/rootfs-pristine/test-modprobe/install-cmd-loop/lib/modules/4.4.4/modules.dep deleted file mode 100644 index 518aa59..0000000 --- a/testsuite/rootfs-pristine/test-modprobe/install-cmd-loop/lib/modules/4.4.4/modules.dep +++ /dev/null @@ -1,2 +0,0 @@ -kernel/sound/core/snd.ko.gz: -kernel/sound/core/snd-pcm.ko.gz: kernel/sound/core/snd.ko.gz diff --git a/testsuite/rootfs-pristine/test-modprobe/install-cmd-loop/lib/modules/4.4.4/modules.dep.bin b/testsuite/rootfs-pristine/test-modprobe/install-cmd-loop/lib/modules/4.4.4/modules.dep.bin deleted file mode 100644 index 877ae7b..0000000 Binary files a/testsuite/rootfs-pristine/test-modprobe/install-cmd-loop/lib/modules/4.4.4/modules.dep.bin and /dev/null differ diff --git a/testsuite/rootfs-pristine/test-modprobe/install-cmd-loop/lib/modules/4.4.4/modules.devname b/testsuite/rootfs-pristine/test-modprobe/install-cmd-loop/lib/modules/4.4.4/modules.devname deleted file mode 100644 index 58f6d6d..0000000 --- a/testsuite/rootfs-pristine/test-modprobe/install-cmd-loop/lib/modules/4.4.4/modules.devname +++ /dev/null @@ -1 +0,0 @@ -# Device nodes to trigger on-demand module loading. diff --git a/testsuite/rootfs-pristine/test-modprobe/install-cmd-loop/lib/modules/4.4.4/modules.softdep b/testsuite/rootfs-pristine/test-modprobe/install-cmd-loop/lib/modules/4.4.4/modules.softdep deleted file mode 100644 index 3cc0512..0000000 --- a/testsuite/rootfs-pristine/test-modprobe/install-cmd-loop/lib/modules/4.4.4/modules.softdep +++ /dev/null @@ -1,2 +0,0 @@ -# Soft dependencies extracted from modules themselves. -# Copy, with a .conf extension, to /etc/modprobe.d to use it with modprobe. diff --git a/testsuite/rootfs-pristine/test-modprobe/install-cmd-loop/lib/modules/4.4.4/modules.symbols b/testsuite/rootfs-pristine/test-modprobe/install-cmd-loop/lib/modules/4.4.4/modules.symbols deleted file mode 100644 index 300cdc2..0000000 --- a/testsuite/rootfs-pristine/test-modprobe/install-cmd-loop/lib/modules/4.4.4/modules.symbols +++ /dev/null @@ -1,133 +0,0 @@ -# Aliases for symbols, used by symbol_request(). -alias symbol:copy_from_user_toio snd -alias symbol:snd_kctl_jack_new snd -alias symbol:snd_pcm_hw_constraint_minmax snd_pcm -alias symbol:snd_ctl_register_ioctl_compat snd -alias symbol:snd_pcm_period_elapsed snd_pcm -alias symbol:snd_pcm_format_linear snd_pcm -alias symbol:snd_pcm_format_big_endian snd_pcm -alias symbol:snd_request_card snd -alias symbol:snd_pcm_lib_ioctl snd_pcm -alias symbol:snd_add_device_sysfs_file snd -alias symbol:snd_card_proc_new snd -alias symbol:snd_ctl_boolean_stereo_info snd -alias symbol:snd_unregister_oss_device snd -alias symbol:snd_card_free snd -alias symbol:snd_pcm_sgbuf_ops_page snd_pcm -alias symbol:snd_pcm_new_stream snd_pcm -alias symbol:snd_card_create snd -alias symbol:snd_card_register snd -alias symbol:snd_ctl_free_one snd -alias symbol:snd_register_device_for_dev snd -alias symbol:snd_lookup_oss_minor_data snd -alias symbol:snd_pcm_hw_constraint_step snd_pcm -alias symbol:snd_seq_root snd -alias symbol:snd_pcm_new snd_pcm -alias symbol:snd_card_set_id snd -alias symbol:snd_info_register snd -alias symbol:snd_pcm_lib_preallocate_pages snd_pcm -alias symbol:snd_pcm_hw_rule_noresample snd_pcm -alias symbol:snd_ctl_remove snd -alias symbol:snd_pcm_lib_read snd_pcm -alias symbol:snd_pcm_mmap_data snd_pcm -alias symbol:snd_pcm_hw_constraint_list snd_pcm -alias symbol:snd_oss_info_register snd -alias symbol:snd_dma_pointer snd -alias symbol:snd_ctl_new1 snd -alias symbol:snd_interval_ratnum snd_pcm -alias symbol:snd_pcm_release_substream snd_pcm -alias symbol:snd_pcm_suspend_all snd_pcm -alias symbol:snd_ctl_register_ioctl snd -alias symbol:snd_ctl_rename_id snd -alias symbol:snd_card_file_add snd -alias symbol:snd_pcm_limit_hw_rates snd_pcm -alias symbol:snd_jack_set_parent snd -alias symbol:snd_pcm_format_width snd_pcm -alias symbol:snd_jack_new snd -alias symbol:snd_ctl_make_virtual_master snd -alias symbol:snd_jack_report snd -alias symbol:snd_pcm_format_little_endian snd_pcm -alias symbol:snd_ctl_notify snd -alias symbol:snd_pcm_set_sync snd_pcm -alias symbol:snd_component_add snd -alias symbol:_snd_ctl_add_slave snd -alias symbol:snd_device_register snd -alias symbol:snd_iprintf snd -alias symbol:snd_pcm_lib_default_mmap snd_pcm -alias symbol:_snd_pcm_hw_params_any snd_pcm -alias symbol:snd_card_file_remove snd -alias symbol:snd_ctl_replace snd -alias symbol:snd_pcm_link_rwlock snd_pcm -alias symbol:snd_info_get_line snd -alias symbol:snd_ctl_activate_id snd -alias symbol:snd_pcm_format_signed snd_pcm -alias symbol:snd_pcm_open_substream snd_pcm -alias symbol:snd_dma_disable snd -alias symbol:snd_pcm_set_ops snd_pcm -alias symbol:release_and_free_resource snd -alias symbol:snd_ecards_limit snd -alias symbol:snd_pcm_hw_param_value snd_pcm -alias symbol:snd_cards snd -alias symbol:snd_device_free snd -alias symbol:snd_dma_program snd -alias symbol:snd_interval_refine snd_pcm -alias symbol:snd_pcm_lib_preallocate_free_for_all snd_pcm -alias symbol:snd_pcm_hw_constraint_msbits snd_pcm -alias symbol:snd_pcm_lib_mmap_iomem snd_pcm -alias symbol:snd_pcm_lib_get_vmalloc_page snd_pcm -alias symbol:snd_pcm_suspend snd_pcm -alias symbol:snd_pcm_format_unsigned snd_pcm -alias symbol:snd_card_free_when_closed snd -alias symbol:snd_ctl_unregister_ioctl_compat snd -alias symbol:snd_interval_list snd_pcm -alias symbol:snd_pcm_lib_malloc_pages snd_pcm -alias symbol:snd_unregister_device snd -alias symbol:snd_pcm_lib_readv snd_pcm -alias symbol:snd_pcm_hw_constraint_ratnums snd_pcm -alias symbol:snd_pcm_hw_constraint_ratdens snd_pcm -alias symbol:snd_major snd -alias symbol:copy_to_user_fromio snd -alias symbol:snd_pcm_format_name snd_pcm -alias symbol:snd_pcm_lib_preallocate_pages_for_all snd_pcm -alias symbol:snd_ctl_add snd -alias symbol:snd_info_create_card_entry snd -alias symbol:snd_pcm_hw_rule_add snd_pcm -alias symbol:snd_pcm_lib_writev snd_pcm -alias symbol:snd_pcm_format_set_silence snd_pcm -alias symbol:snd_pcm_hw_param_last snd_pcm -alias symbol:snd_card_disconnect snd -alias symbol:snd_info_get_str snd -alias symbol:snd_lookup_minor_data snd -alias symbol:snd_pci_quirk_lookup_id snd -alias symbol:snd_pcm_rate_to_rate_bit snd_pcm -alias symbol:snd_pcm_lib_free_vmalloc_buffer snd_pcm -alias symbol:snd_pcm_format_silence_64 snd_pcm -alias symbol:snd_pcm_sgbuf_get_chunk_size snd_pcm -alias symbol:snd_pci_quirk_lookup snd -alias symbol:snd_pcm_notify snd_pcm -alias symbol:_snd_pcm_hw_param_setempty snd_pcm -alias symbol:snd_power_wait snd -alias symbol:snd_pcm_hw_constraint_pow2 snd_pcm -alias symbol:snd_register_oss_device snd -alias symbol:snd_ctl_find_numid snd -alias symbol:snd_pcm_kernel_ioctl snd_pcm -alias symbol:snd_pcm_hw_constraint_integer snd_pcm -alias symbol:snd_pcm_lib_write snd_pcm -alias symbol:snd_kctl_jack_report snd -alias symbol:snd_pcm_lib_free_pages snd_pcm -alias symbol:snd_pcm_hw_param_first snd_pcm -alias symbol:snd_ctl_enum_info snd -alias symbol:snd_jack_set_key snd -alias symbol:snd_device_new snd -alias symbol:snd_ctl_find_id snd -alias symbol:snd_pcm_hw_refine snd_pcm -alias symbol:snd_ctl_boolean_mono_info snd -alias symbol:snd_mixer_oss_notify_callback snd -alias symbol:snd_pcm_format_size snd_pcm -alias symbol:snd_pcm_format_physical_width snd_pcm -alias symbol:snd_info_free_entry snd -alias symbol:snd_ctl_remove_id snd -alias symbol:_snd_pcm_lib_alloc_vmalloc_buffer snd_pcm -alias symbol:snd_pcm_stop snd_pcm -alias symbol:snd_ctl_unregister_ioctl snd -alias symbol:snd_info_create_module_entry snd diff --git a/testsuite/rootfs-pristine/test-modprobe/install-cmd-loop/lib/modules/4.4.4/modules.symbols.bin b/testsuite/rootfs-pristine/test-modprobe/install-cmd-loop/lib/modules/4.4.4/modules.symbols.bin deleted file mode 100644 index 03366e3..0000000 Binary files a/testsuite/rootfs-pristine/test-modprobe/install-cmd-loop/lib/modules/4.4.4/modules.symbols.bin and /dev/null differ diff --git a/testsuite/rootfs-pristine/test-modprobe/show-depends/correct-psmouse.txt b/testsuite/rootfs-pristine/test-modprobe/show-depends/correct-psmouse.txt deleted file mode 100644 index 1e773d7..0000000 --- a/testsuite/rootfs-pristine/test-modprobe/show-depends/correct-psmouse.txt +++ /dev/null @@ -1 +0,0 @@ -insmod /lib/modules/4.4.4/kernel/drivers/input/mouse/psmouse.ko diff --git a/testsuite/rootfs-pristine/test-modprobe/show-depends/correct.txt b/testsuite/rootfs-pristine/test-modprobe/show-depends/correct.txt deleted file mode 100644 index 52fddba..0000000 --- a/testsuite/rootfs-pristine/test-modprobe/show-depends/correct.txt +++ /dev/null @@ -1,2 +0,0 @@ -insmod /lib/modules/4.4.4/kernel/net/bluetooth/bluetooth.ko -insmod /lib/modules/4.4.4/kernel/drivers/bluetooth/btusb.ko diff --git a/testsuite/rootfs-pristine/test-modprobe/show-depends/lib/modules/4.4.4/kernel/drivers/bluetooth/btusb.ko b/testsuite/rootfs-pristine/test-modprobe/show-depends/lib/modules/4.4.4/kernel/drivers/bluetooth/btusb.ko deleted file mode 100644 index f4e21e0..0000000 Binary files a/testsuite/rootfs-pristine/test-modprobe/show-depends/lib/modules/4.4.4/kernel/drivers/bluetooth/btusb.ko and /dev/null differ diff --git a/testsuite/rootfs-pristine/test-modprobe/show-depends/lib/modules/4.4.4/kernel/drivers/input/mouse/psmouse.ko b/testsuite/rootfs-pristine/test-modprobe/show-depends/lib/modules/4.4.4/kernel/drivers/input/mouse/psmouse.ko deleted file mode 100644 index 4eac2a3..0000000 Binary files a/testsuite/rootfs-pristine/test-modprobe/show-depends/lib/modules/4.4.4/kernel/drivers/input/mouse/psmouse.ko and /dev/null differ diff --git a/testsuite/rootfs-pristine/test-modprobe/show-depends/lib/modules/4.4.4/kernel/net/bluetooth/bluetooth.ko b/testsuite/rootfs-pristine/test-modprobe/show-depends/lib/modules/4.4.4/kernel/net/bluetooth/bluetooth.ko deleted file mode 100644 index a8949a6..0000000 Binary files a/testsuite/rootfs-pristine/test-modprobe/show-depends/lib/modules/4.4.4/kernel/net/bluetooth/bluetooth.ko and /dev/null differ diff --git a/testsuite/rootfs-pristine/test-modprobe/show-depends/lib/modules/4.4.4/modules.alias b/testsuite/rootfs-pristine/test-modprobe/show-depends/lib/modules/4.4.4/modules.alias deleted file mode 100644 index 94804f1..0000000 --- a/testsuite/rootfs-pristine/test-modprobe/show-depends/lib/modules/4.4.4/modules.alias +++ /dev/null @@ -1,21 +0,0 @@ -# Aliases extracted from modules themselves. -alias usb:v413Cp8197d*dc*dsc*dp*ic*isc*ip* btusb -alias usb:v0A5Cp21E3d*dc*dsc*dp*ic*isc*ip* btusb -alias usb:v0C10p0000d*dc*dsc*dp*ic*isc*ip* btusb -alias usb:v0BDBp1002d*dc*dsc*dp*ic*isc*ip* btusb -alias usb:v044Ep3002d*dc*dsc*dp*ic*isc*ip* btusb -alias usb:v044Ep3001d*dc*dsc*dp*ic*isc*ip* btusb -alias usb:v04BFp030Ad*dc*dsc*dp*ic*isc*ip* btusb -alias usb:v057Cp3800d*dc*dsc*dp*ic*isc*ip* btusb -alias usb:v05ACp8281d*dc*dsc*dp*ic*isc*ip* btusb -alias usb:v05ACp821Ad*dc*dsc*dp*ic*isc*ip* btusb -alias usb:v05ACp821Fd*dc*dsc*dp*ic*isc*ip* btusb -alias usb:v05ACp821Bd*dc*dsc*dp*ic*isc*ip* btusb -alias usb:v05ACp8218d*dc*dsc*dp*ic*isc*ip* btusb -alias usb:v05ACp8215d*dc*dsc*dp*ic*isc*ip* btusb -alias usb:v05ACp8213d*dc*dsc*dp*ic*isc*ip* btusb -alias usb:v05ACp21E1d*dc*dsc*dp*ic*isc*ip* btusb -alias usb:v*p*d*dcE0dsc01dp01ic*isc*ip* btusb -alias serio:ty05pr*id*ex* psmouse -alias serio:ty01pr*id*ex* psmouse -alias net-pf-31 bluetooth diff --git a/testsuite/rootfs-pristine/test-modprobe/show-depends/lib/modules/4.4.4/modules.alias.bin b/testsuite/rootfs-pristine/test-modprobe/show-depends/lib/modules/4.4.4/modules.alias.bin deleted file mode 100644 index 86481a4..0000000 Binary files a/testsuite/rootfs-pristine/test-modprobe/show-depends/lib/modules/4.4.4/modules.alias.bin and /dev/null differ diff --git a/testsuite/rootfs-pristine/test-modprobe/show-depends/lib/modules/4.4.4/modules.dep b/testsuite/rootfs-pristine/test-modprobe/show-depends/lib/modules/4.4.4/modules.dep deleted file mode 100644 index a34af87..0000000 --- a/testsuite/rootfs-pristine/test-modprobe/show-depends/lib/modules/4.4.4/modules.dep +++ /dev/null @@ -1,3 +0,0 @@ -kernel/drivers/bluetooth/btusb.ko: kernel/net/bluetooth/bluetooth.ko -kernel/drivers/input/mouse/psmouse.ko: -kernel/net/bluetooth/bluetooth.ko: diff --git a/testsuite/rootfs-pristine/test-modprobe/show-depends/lib/modules/4.4.4/modules.dep.bin b/testsuite/rootfs-pristine/test-modprobe/show-depends/lib/modules/4.4.4/modules.dep.bin deleted file mode 100644 index 3382706..0000000 Binary files a/testsuite/rootfs-pristine/test-modprobe/show-depends/lib/modules/4.4.4/modules.dep.bin and /dev/null differ diff --git a/testsuite/rootfs-pristine/test-modprobe/show-depends/lib/modules/4.4.4/modules.devname b/testsuite/rootfs-pristine/test-modprobe/show-depends/lib/modules/4.4.4/modules.devname deleted file mode 100644 index 58f6d6d..0000000 --- a/testsuite/rootfs-pristine/test-modprobe/show-depends/lib/modules/4.4.4/modules.devname +++ /dev/null @@ -1 +0,0 @@ -# Device nodes to trigger on-demand module loading. diff --git a/testsuite/rootfs-pristine/test-modprobe/show-depends/lib/modules/4.4.4/modules.softdep b/testsuite/rootfs-pristine/test-modprobe/show-depends/lib/modules/4.4.4/modules.softdep deleted file mode 100644 index 3cc0512..0000000 --- a/testsuite/rootfs-pristine/test-modprobe/show-depends/lib/modules/4.4.4/modules.softdep +++ /dev/null @@ -1,2 +0,0 @@ -# Soft dependencies extracted from modules themselves. -# Copy, with a .conf extension, to /etc/modprobe.d to use it with modprobe. diff --git a/testsuite/rootfs-pristine/test-modprobe/show-depends/lib/modules/4.4.4/modules.symbols b/testsuite/rootfs-pristine/test-modprobe/show-depends/lib/modules/4.4.4/modules.symbols deleted file mode 100644 index b970b60..0000000 --- a/testsuite/rootfs-pristine/test-modprobe/show-depends/lib/modules/4.4.4/modules.symbols +++ /dev/null @@ -1,45 +0,0 @@ -# Aliases for symbols, used by symbol_request(). -alias symbol:hci_conn_check_secure bluetooth -alias symbol:hci_send_acl bluetooth -alias symbol:hci_recv_fragment bluetooth -alias symbol:hci_recv_frame bluetooth -alias symbol:hci_le_ltk_reply bluetooth -alias symbol:hci_send_sco bluetooth -alias symbol:bt_debugfs bluetooth -alias symbol:bt_accept_unlink bluetooth -alias symbol:bt_sock_recvmsg bluetooth -alias symbol:bt_sock_ioctl bluetooth -alias symbol:hci_le_conn_update bluetooth -alias symbol:hci_unregister_cb bluetooth -alias symbol:hci_connect bluetooth -alias symbol:hci_le_start_enc bluetooth -alias symbol:bt_sock_link bluetooth -alias symbol:bt_printk bluetooth -alias symbol:hci_alloc_dev bluetooth -alias symbol:baswap bluetooth -alias symbol:hci_conn_switch_role bluetooth -alias symbol:hci_resume_dev bluetooth -alias symbol:bt_sock_stream_recvmsg bluetooth -alias symbol:hci_conn_check_link_mode bluetooth -alias symbol:hci_conn_hold_device bluetooth -alias symbol:hci_conn_change_link_key bluetooth -alias symbol:hci_conn_put_device bluetooth -alias symbol:batostr bluetooth -alias symbol:bt_to_errno bluetooth -alias symbol:bt_accept_dequeue bluetooth -alias symbol:hci_free_dev bluetooth -alias symbol:bt_accept_enqueue bluetooth -alias symbol:hci_find_link_key_type bluetooth -alias symbol:hci_find_ltk bluetooth -alias symbol:hci_recv_stream_fragment bluetooth -alias symbol:bt_sock_register bluetooth -alias symbol:hci_get_route bluetooth -alias symbol:hci_register_dev bluetooth -alias symbol:hci_unregister_dev bluetooth -alias symbol:bt_sock_poll bluetooth -alias symbol:bt_sock_wait_state bluetooth -alias symbol:bt_sock_unlink bluetooth -alias symbol:bt_sock_unregister bluetooth -alias symbol:hci_register_cb bluetooth -alias symbol:hci_suspend_dev bluetooth -alias symbol:hci_conn_security bluetooth diff --git a/testsuite/rootfs-pristine/test-modprobe/show-depends/lib/modules/4.4.4/modules.symbols.bin b/testsuite/rootfs-pristine/test-modprobe/show-depends/lib/modules/4.4.4/modules.symbols.bin deleted file mode 100644 index 156a61f..0000000 Binary files a/testsuite/rootfs-pristine/test-modprobe/show-depends/lib/modules/4.4.4/modules.symbols.bin and /dev/null differ diff --git a/testsuite/rootfs-pristine/test-modprobe/show-depends/proc/modules b/testsuite/rootfs-pristine/test-modprobe/show-depends/proc/modules deleted file mode 100644 index aab95dd..0000000 --- a/testsuite/rootfs-pristine/test-modprobe/show-depends/proc/modules +++ /dev/null @@ -1,2 +0,0 @@ -btusb 11911 0 - Live 0xffffffffa00ec000 -bluetooth 173424 1 btusb, Live 0xffffffffa0040000 diff --git a/testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/bluetooth/coresize b/testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/bluetooth/coresize deleted file mode 100644 index 8bc1425..0000000 --- a/testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/bluetooth/coresize +++ /dev/null @@ -1 +0,0 @@ -173424 diff --git a/testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/bluetooth/holders/btusb b/testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/bluetooth/holders/btusb deleted file mode 120000 index 8fe6aa9..0000000 --- a/testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/bluetooth/holders/btusb +++ /dev/null @@ -1 +0,0 @@ -../../btusb \ No newline at end of file diff --git a/testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/bluetooth/initsize b/testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/bluetooth/initsize deleted file mode 100644 index 573541a..0000000 --- a/testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/bluetooth/initsize +++ /dev/null @@ -1 +0,0 @@ -0 diff --git a/testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/bluetooth/initstate b/testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/bluetooth/initstate deleted file mode 100644 index e23fe64..0000000 --- a/testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/bluetooth/initstate +++ /dev/null @@ -1 +0,0 @@ -live diff --git a/testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/bluetooth/notes/.note.gnu.build-id b/testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/bluetooth/notes/.note.gnu.build-id deleted file mode 100644 index e917247..0000000 Binary files a/testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/bluetooth/notes/.note.gnu.build-id and /dev/null differ diff --git a/testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/bluetooth/parameters/disable_ertm b/testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/bluetooth/parameters/disable_ertm deleted file mode 100644 index d52e798..0000000 --- a/testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/bluetooth/parameters/disable_ertm +++ /dev/null @@ -1 +0,0 @@ -N diff --git a/testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/bluetooth/parameters/disable_esco b/testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/bluetooth/parameters/disable_esco deleted file mode 100644 index d52e798..0000000 --- a/testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/bluetooth/parameters/disable_esco +++ /dev/null @@ -1 +0,0 @@ -N diff --git a/testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/bluetooth/parameters/enable_hs b/testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/bluetooth/parameters/enable_hs deleted file mode 100644 index d52e798..0000000 --- a/testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/bluetooth/parameters/enable_hs +++ /dev/null @@ -1 +0,0 @@ -N diff --git a/testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/bluetooth/parameters/enable_le b/testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/bluetooth/parameters/enable_le deleted file mode 100644 index d52e798..0000000 --- a/testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/bluetooth/parameters/enable_le +++ /dev/null @@ -1 +0,0 @@ -N diff --git a/testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/bluetooth/parameters/enable_mgmt b/testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/bluetooth/parameters/enable_mgmt deleted file mode 100644 index d52e798..0000000 --- a/testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/bluetooth/parameters/enable_mgmt +++ /dev/null @@ -1 +0,0 @@ -N diff --git a/testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/bluetooth/refcnt b/testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/bluetooth/refcnt deleted file mode 100644 index d00491f..0000000 --- a/testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/bluetooth/refcnt +++ /dev/null @@ -1 +0,0 @@ -1 diff --git a/testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/bluetooth/sections/.bss b/testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/bluetooth/sections/.bss deleted file mode 100644 index ea8c54e..0000000 --- a/testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/bluetooth/sections/.bss +++ /dev/null @@ -1 +0,0 @@ -0xffffffffa0063fe0 diff --git a/testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/bluetooth/sections/.data b/testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/bluetooth/sections/.data deleted file mode 100644 index a6f2254..0000000 --- a/testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/bluetooth/sections/.data +++ /dev/null @@ -1 +0,0 @@ -0xffffffffa0063360 diff --git a/testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/bluetooth/sections/.exit.text b/testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/bluetooth/sections/.exit.text deleted file mode 100644 index 86d3cd1..0000000 --- a/testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/bluetooth/sections/.exit.text +++ /dev/null @@ -1 +0,0 @@ -0xffffffffa0060c32 diff --git a/testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/bluetooth/sections/.gnu.linkonce.this_module b/testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/bluetooth/sections/.gnu.linkonce.this_module deleted file mode 100644 index 50a1575..0000000 --- a/testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/bluetooth/sections/.gnu.linkonce.this_module +++ /dev/null @@ -1 +0,0 @@ -0xffffffffa0063da0 diff --git a/testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/bluetooth/sections/.init.text b/testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/bluetooth/sections/.init.text deleted file mode 100644 index 921b9d9..0000000 --- a/testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/bluetooth/sections/.init.text +++ /dev/null @@ -1 +0,0 @@ -0xffffffffa0076000 diff --git a/testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/bluetooth/sections/.note.gnu.build-id b/testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/bluetooth/sections/.note.gnu.build-id deleted file mode 100644 index 8a4d2ce..0000000 --- a/testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/bluetooth/sections/.note.gnu.build-id +++ /dev/null @@ -1 +0,0 @@ -0xffffffffa0060c98 diff --git a/testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/bluetooth/sections/.rodata b/testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/bluetooth/sections/.rodata deleted file mode 100644 index 24af87e..0000000 --- a/testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/bluetooth/sections/.rodata +++ /dev/null @@ -1 +0,0 @@ -0xffffffffa00610e0 diff --git a/testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/bluetooth/sections/.rodata.str1.1 b/testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/bluetooth/sections/.rodata.str1.1 deleted file mode 100644 index 0da8d6d..0000000 --- a/testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/bluetooth/sections/.rodata.str1.1 +++ /dev/null @@ -1 +0,0 @@ -0xffffffffa0062674 diff --git a/testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/bluetooth/sections/.rodata.str1.8 b/testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/bluetooth/sections/.rodata.str1.8 deleted file mode 100644 index 3c0aeba..0000000 --- a/testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/bluetooth/sections/.rodata.str1.8 +++ /dev/null @@ -1 +0,0 @@ -0xffffffffa0062af0 diff --git a/testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/bluetooth/sections/.smp_locks b/testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/bluetooth/sections/.smp_locks deleted file mode 100644 index d1da04c..0000000 --- a/testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/bluetooth/sections/.smp_locks +++ /dev/null @@ -1 +0,0 @@ -0xffffffffa00620cc diff --git a/testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/bluetooth/sections/.strtab b/testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/bluetooth/sections/.strtab deleted file mode 100644 index 3e03a95..0000000 --- a/testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/bluetooth/sections/.strtab +++ /dev/null @@ -1 +0,0 @@ -0xffffffffa007b280 diff --git a/testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/bluetooth/sections/.symtab b/testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/bluetooth/sections/.symtab deleted file mode 100644 index 9875bb4..0000000 --- a/testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/bluetooth/sections/.symtab +++ /dev/null @@ -1 +0,0 @@ -0xffffffffa0076300 diff --git a/testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/bluetooth/sections/.text b/testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/bluetooth/sections/.text deleted file mode 100644 index db229db..0000000 --- a/testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/bluetooth/sections/.text +++ /dev/null @@ -1 +0,0 @@ -0xffffffffa0040000 diff --git a/testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/bluetooth/sections/.text.unlikely b/testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/bluetooth/sections/.text.unlikely deleted file mode 100644 index 4d8920f..0000000 --- a/testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/bluetooth/sections/.text.unlikely +++ /dev/null @@ -1 +0,0 @@ -0xffffffffa0060c2c diff --git a/testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/bluetooth/sections/__bug_table b/testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/bluetooth/sections/__bug_table deleted file mode 100644 index 07fd388..0000000 --- a/testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/bluetooth/sections/__bug_table +++ /dev/null @@ -1 +0,0 @@ -0xffffffffa0062ac6 diff --git a/testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/bluetooth/sections/__jump_table b/testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/bluetooth/sections/__jump_table deleted file mode 100644 index ff0edf6..0000000 --- a/testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/bluetooth/sections/__jump_table +++ /dev/null @@ -1 +0,0 @@ -0xffffffffa0063d10 diff --git a/testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/bluetooth/sections/__kcrctab b/testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/bluetooth/sections/__kcrctab deleted file mode 100644 index 8542e00..0000000 --- a/testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/bluetooth/sections/__kcrctab +++ /dev/null @@ -1 +0,0 @@ -0xffffffffa0060f80 diff --git a/testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/bluetooth/sections/__kcrctab_gpl b/testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/bluetooth/sections/__kcrctab_gpl deleted file mode 100644 index aaa4573..0000000 --- a/testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/bluetooth/sections/__kcrctab_gpl +++ /dev/null @@ -1 +0,0 @@ -0xffffffffa00610d8 diff --git a/testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/bluetooth/sections/__ksymtab b/testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/bluetooth/sections/__ksymtab deleted file mode 100644 index a81db94..0000000 --- a/testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/bluetooth/sections/__ksymtab +++ /dev/null @@ -1 +0,0 @@ -0xffffffffa0060cc0 diff --git a/testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/bluetooth/sections/__ksymtab_gpl b/testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/bluetooth/sections/__ksymtab_gpl deleted file mode 100644 index 4d4c450..0000000 --- a/testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/bluetooth/sections/__ksymtab_gpl +++ /dev/null @@ -1 +0,0 @@ -0xffffffffa0060f70 diff --git a/testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/bluetooth/sections/__ksymtab_strings b/testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/bluetooth/sections/__ksymtab_strings deleted file mode 100644 index 5290e4c..0000000 --- a/testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/bluetooth/sections/__ksymtab_strings +++ /dev/null @@ -1 +0,0 @@ -0xffffffffa0062fe4 diff --git a/testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/bluetooth/sections/__param b/testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/bluetooth/sections/__param deleted file mode 100644 index 5d4be39..0000000 --- a/testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/bluetooth/sections/__param +++ /dev/null @@ -1 +0,0 @@ -0xffffffffa00632c0 diff --git a/testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/bluetooth/srcversion b/testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/bluetooth/srcversion deleted file mode 100644 index 64bc12e..0000000 --- a/testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/bluetooth/srcversion +++ /dev/null @@ -1 +0,0 @@ -72F6D42DC4BD163E7718A31 diff --git a/testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/bluetooth/taint b/testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/bluetooth/taint deleted file mode 100644 index 8b13789..0000000 --- a/testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/bluetooth/taint +++ /dev/null @@ -1 +0,0 @@ - diff --git a/testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/bluetooth/version b/testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/bluetooth/version deleted file mode 100644 index 6d28a11..0000000 --- a/testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/bluetooth/version +++ /dev/null @@ -1 +0,0 @@ -2.16 diff --git a/testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/btusb/coresize b/testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/btusb/coresize deleted file mode 100644 index 4b104f9..0000000 --- a/testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/btusb/coresize +++ /dev/null @@ -1 +0,0 @@ -11911 diff --git a/testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/btusb/drivers/usb:btusb b/testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/btusb/drivers/usb:btusb deleted file mode 120000 index c173837..0000000 --- a/testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/btusb/drivers/usb:btusb +++ /dev/null @@ -1 +0,0 @@ -../../../bus/usb/drivers/btusb \ No newline at end of file diff --git a/testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/btusb/holders/.gitignore b/testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/btusb/holders/.gitignore deleted file mode 100644 index e69de29..0000000 diff --git a/testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/btusb/initsize b/testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/btusb/initsize deleted file mode 100644 index 573541a..0000000 --- a/testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/btusb/initsize +++ /dev/null @@ -1 +0,0 @@ -0 diff --git a/testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/btusb/initstate b/testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/btusb/initstate deleted file mode 100644 index e23fe64..0000000 --- a/testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/btusb/initstate +++ /dev/null @@ -1 +0,0 @@ -live diff --git a/testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/btusb/notes/.note.gnu.build-id b/testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/btusb/notes/.note.gnu.build-id deleted file mode 100644 index 0afeca4..0000000 Binary files a/testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/btusb/notes/.note.gnu.build-id and /dev/null differ diff --git a/testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/btusb/parameters/disable_scofix b/testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/btusb/parameters/disable_scofix deleted file mode 100644 index d52e798..0000000 --- a/testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/btusb/parameters/disable_scofix +++ /dev/null @@ -1 +0,0 @@ -N diff --git a/testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/btusb/parameters/force_scofix b/testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/btusb/parameters/force_scofix deleted file mode 100644 index d52e798..0000000 --- a/testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/btusb/parameters/force_scofix +++ /dev/null @@ -1 +0,0 @@ -N diff --git a/testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/btusb/parameters/ignore_csr b/testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/btusb/parameters/ignore_csr deleted file mode 100644 index d52e798..0000000 --- a/testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/btusb/parameters/ignore_csr +++ /dev/null @@ -1 +0,0 @@ -N diff --git a/testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/btusb/parameters/ignore_dga b/testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/btusb/parameters/ignore_dga deleted file mode 100644 index d52e798..0000000 --- a/testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/btusb/parameters/ignore_dga +++ /dev/null @@ -1 +0,0 @@ -N diff --git a/testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/btusb/parameters/ignore_sniffer b/testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/btusb/parameters/ignore_sniffer deleted file mode 100644 index d52e798..0000000 --- a/testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/btusb/parameters/ignore_sniffer +++ /dev/null @@ -1 +0,0 @@ -N diff --git a/testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/btusb/parameters/reset b/testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/btusb/parameters/reset deleted file mode 100644 index 9bda8c3..0000000 --- a/testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/btusb/parameters/reset +++ /dev/null @@ -1 +0,0 @@ -Y diff --git a/testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/btusb/refcnt b/testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/btusb/refcnt deleted file mode 100644 index 573541a..0000000 --- a/testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/btusb/refcnt +++ /dev/null @@ -1 +0,0 @@ -0 diff --git a/testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/btusb/sections/.bss b/testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/btusb/sections/.bss deleted file mode 100644 index 44785c0..0000000 --- a/testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/btusb/sections/.bss +++ /dev/null @@ -1 +0,0 @@ -0xffffffffa00ee708 diff --git a/testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/btusb/sections/.data b/testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/btusb/sections/.data deleted file mode 100644 index bfdb603..0000000 --- a/testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/btusb/sections/.data +++ /dev/null @@ -1 +0,0 @@ -0xffffffffa00edf20 diff --git a/testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/btusb/sections/.exit.text b/testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/btusb/sections/.exit.text deleted file mode 100644 index a504729..0000000 --- a/testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/btusb/sections/.exit.text +++ /dev/null @@ -1 +0,0 @@ -0xffffffffa00edc68 diff --git a/testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/btusb/sections/.gnu.linkonce.this_module b/testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/btusb/sections/.gnu.linkonce.this_module deleted file mode 100644 index 2b18edc..0000000 --- a/testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/btusb/sections/.gnu.linkonce.this_module +++ /dev/null @@ -1 +0,0 @@ -0xffffffffa00ee4e0 diff --git a/testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/btusb/sections/.init.text b/testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/btusb/sections/.init.text deleted file mode 100644 index 017c50e..0000000 --- a/testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/btusb/sections/.init.text +++ /dev/null @@ -1 +0,0 @@ -0xffffffffa00f0000 diff --git a/testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/btusb/sections/.note.gnu.build-id b/testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/btusb/sections/.note.gnu.build-id deleted file mode 100644 index 982e7c1..0000000 --- a/testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/btusb/sections/.note.gnu.build-id +++ /dev/null @@ -1 +0,0 @@ -0xffffffffa00edc7c diff --git a/testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/btusb/sections/.rodata b/testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/btusb/sections/.rodata deleted file mode 100644 index 4988b02..0000000 --- a/testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/btusb/sections/.rodata +++ /dev/null @@ -1 +0,0 @@ -0xffffffffa00edec0 diff --git a/testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/btusb/sections/.rodata.str1.1 b/testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/btusb/sections/.rodata.str1.1 deleted file mode 100644 index 52bcaf7..0000000 --- a/testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/btusb/sections/.rodata.str1.1 +++ /dev/null @@ -1 +0,0 @@ -0xffffffffa00edd11 diff --git a/testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/btusb/sections/.rodata.str1.8 b/testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/btusb/sections/.rodata.str1.8 deleted file mode 100644 index 68be4ed..0000000 --- a/testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/btusb/sections/.rodata.str1.8 +++ /dev/null @@ -1 +0,0 @@ -0xffffffffa00edca0 diff --git a/testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/btusb/sections/.smp_locks b/testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/btusb/sections/.smp_locks deleted file mode 100644 index 9978310..0000000 --- a/testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/btusb/sections/.smp_locks +++ /dev/null @@ -1 +0,0 @@ -0xffffffffa00edd90 diff --git a/testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/btusb/sections/.strtab b/testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/btusb/sections/.strtab deleted file mode 100644 index e4fdf8e..0000000 --- a/testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/btusb/sections/.strtab +++ /dev/null @@ -1 +0,0 @@ -0xffffffffa00f0dd0 diff --git a/testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/btusb/sections/.symtab b/testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/btusb/sections/.symtab deleted file mode 100644 index 73f8cee..0000000 --- a/testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/btusb/sections/.symtab +++ /dev/null @@ -1 +0,0 @@ -0xffffffffa00f0020 diff --git a/testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/btusb/sections/.text b/testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/btusb/sections/.text deleted file mode 100644 index d39dfe6..0000000 --- a/testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/btusb/sections/.text +++ /dev/null @@ -1 +0,0 @@ -0xffffffffa00ec000 diff --git a/testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/btusb/sections/__param b/testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/btusb/sections/__param deleted file mode 100644 index 76e34cd..0000000 --- a/testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/btusb/sections/__param +++ /dev/null @@ -1 +0,0 @@ -0xffffffffa00ede00 diff --git a/testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/btusb/srcversion b/testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/btusb/srcversion deleted file mode 100644 index 2d4bd99..0000000 --- a/testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/btusb/srcversion +++ /dev/null @@ -1 +0,0 @@ -1FC03999655A6ECD28DC794 diff --git a/testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/btusb/taint b/testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/btusb/taint deleted file mode 100644 index 8b13789..0000000 --- a/testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/btusb/taint +++ /dev/null @@ -1 +0,0 @@ - diff --git a/testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/btusb/version b/testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/btusb/version deleted file mode 100644 index 5a2a580..0000000 --- a/testsuite/rootfs-pristine/test-modprobe/show-depends/sys/module/btusb/version +++ /dev/null @@ -1 +0,0 @@ -0.6 diff --git a/testsuite/rootfs-pristine/test-modprobe/softdep-loop/etc/modprobe.d/dumb-softdep.conf b/testsuite/rootfs-pristine/test-modprobe/softdep-loop/etc/modprobe.d/dumb-softdep.conf deleted file mode 100644 index fa41143..0000000 --- a/testsuite/rootfs-pristine/test-modprobe/softdep-loop/etc/modprobe.d/dumb-softdep.conf +++ /dev/null @@ -1 +0,0 @@ -softdep bluetooth post: btusb diff --git a/testsuite/rootfs-pristine/test-modprobe/softdep-loop/lib/modules/4.4.4/kernel/drivers/bluetooth/btusb.ko b/testsuite/rootfs-pristine/test-modprobe/softdep-loop/lib/modules/4.4.4/kernel/drivers/bluetooth/btusb.ko deleted file mode 100644 index f4e21e0..0000000 Binary files a/testsuite/rootfs-pristine/test-modprobe/softdep-loop/lib/modules/4.4.4/kernel/drivers/bluetooth/btusb.ko and /dev/null differ diff --git a/testsuite/rootfs-pristine/test-modprobe/softdep-loop/lib/modules/4.4.4/kernel/drivers/input/mouse/psmouse.ko b/testsuite/rootfs-pristine/test-modprobe/softdep-loop/lib/modules/4.4.4/kernel/drivers/input/mouse/psmouse.ko deleted file mode 100644 index 4eac2a3..0000000 Binary files a/testsuite/rootfs-pristine/test-modprobe/softdep-loop/lib/modules/4.4.4/kernel/drivers/input/mouse/psmouse.ko and /dev/null differ diff --git a/testsuite/rootfs-pristine/test-modprobe/softdep-loop/lib/modules/4.4.4/kernel/net/bluetooth/bluetooth.ko b/testsuite/rootfs-pristine/test-modprobe/softdep-loop/lib/modules/4.4.4/kernel/net/bluetooth/bluetooth.ko deleted file mode 100644 index a8949a6..0000000 Binary files a/testsuite/rootfs-pristine/test-modprobe/softdep-loop/lib/modules/4.4.4/kernel/net/bluetooth/bluetooth.ko and /dev/null differ diff --git a/testsuite/rootfs-pristine/test-modprobe/softdep-loop/lib/modules/4.4.4/modules.alias b/testsuite/rootfs-pristine/test-modprobe/softdep-loop/lib/modules/4.4.4/modules.alias deleted file mode 100644 index 94804f1..0000000 --- a/testsuite/rootfs-pristine/test-modprobe/softdep-loop/lib/modules/4.4.4/modules.alias +++ /dev/null @@ -1,21 +0,0 @@ -# Aliases extracted from modules themselves. -alias usb:v413Cp8197d*dc*dsc*dp*ic*isc*ip* btusb -alias usb:v0A5Cp21E3d*dc*dsc*dp*ic*isc*ip* btusb -alias usb:v0C10p0000d*dc*dsc*dp*ic*isc*ip* btusb -alias usb:v0BDBp1002d*dc*dsc*dp*ic*isc*ip* btusb -alias usb:v044Ep3002d*dc*dsc*dp*ic*isc*ip* btusb -alias usb:v044Ep3001d*dc*dsc*dp*ic*isc*ip* btusb -alias usb:v04BFp030Ad*dc*dsc*dp*ic*isc*ip* btusb -alias usb:v057Cp3800d*dc*dsc*dp*ic*isc*ip* btusb -alias usb:v05ACp8281d*dc*dsc*dp*ic*isc*ip* btusb -alias usb:v05ACp821Ad*dc*dsc*dp*ic*isc*ip* btusb -alias usb:v05ACp821Fd*dc*dsc*dp*ic*isc*ip* btusb -alias usb:v05ACp821Bd*dc*dsc*dp*ic*isc*ip* btusb -alias usb:v05ACp8218d*dc*dsc*dp*ic*isc*ip* btusb -alias usb:v05ACp8215d*dc*dsc*dp*ic*isc*ip* btusb -alias usb:v05ACp8213d*dc*dsc*dp*ic*isc*ip* btusb -alias usb:v05ACp21E1d*dc*dsc*dp*ic*isc*ip* btusb -alias usb:v*p*d*dcE0dsc01dp01ic*isc*ip* btusb -alias serio:ty05pr*id*ex* psmouse -alias serio:ty01pr*id*ex* psmouse -alias net-pf-31 bluetooth diff --git a/testsuite/rootfs-pristine/test-modprobe/softdep-loop/lib/modules/4.4.4/modules.alias.bin b/testsuite/rootfs-pristine/test-modprobe/softdep-loop/lib/modules/4.4.4/modules.alias.bin deleted file mode 100644 index 86481a4..0000000 Binary files a/testsuite/rootfs-pristine/test-modprobe/softdep-loop/lib/modules/4.4.4/modules.alias.bin and /dev/null differ diff --git a/testsuite/rootfs-pristine/test-modprobe/softdep-loop/lib/modules/4.4.4/modules.dep b/testsuite/rootfs-pristine/test-modprobe/softdep-loop/lib/modules/4.4.4/modules.dep deleted file mode 100644 index a34af87..0000000 --- a/testsuite/rootfs-pristine/test-modprobe/softdep-loop/lib/modules/4.4.4/modules.dep +++ /dev/null @@ -1,3 +0,0 @@ -kernel/drivers/bluetooth/btusb.ko: kernel/net/bluetooth/bluetooth.ko -kernel/drivers/input/mouse/psmouse.ko: -kernel/net/bluetooth/bluetooth.ko: diff --git a/testsuite/rootfs-pristine/test-modprobe/softdep-loop/lib/modules/4.4.4/modules.dep.bin b/testsuite/rootfs-pristine/test-modprobe/softdep-loop/lib/modules/4.4.4/modules.dep.bin deleted file mode 100644 index 3382706..0000000 Binary files a/testsuite/rootfs-pristine/test-modprobe/softdep-loop/lib/modules/4.4.4/modules.dep.bin and /dev/null differ diff --git a/testsuite/rootfs-pristine/test-modprobe/softdep-loop/lib/modules/4.4.4/modules.devname b/testsuite/rootfs-pristine/test-modprobe/softdep-loop/lib/modules/4.4.4/modules.devname deleted file mode 100644 index 58f6d6d..0000000 --- a/testsuite/rootfs-pristine/test-modprobe/softdep-loop/lib/modules/4.4.4/modules.devname +++ /dev/null @@ -1 +0,0 @@ -# Device nodes to trigger on-demand module loading. diff --git a/testsuite/rootfs-pristine/test-modprobe/softdep-loop/lib/modules/4.4.4/modules.softdep b/testsuite/rootfs-pristine/test-modprobe/softdep-loop/lib/modules/4.4.4/modules.softdep deleted file mode 100644 index 3cc0512..0000000 --- a/testsuite/rootfs-pristine/test-modprobe/softdep-loop/lib/modules/4.4.4/modules.softdep +++ /dev/null @@ -1,2 +0,0 @@ -# Soft dependencies extracted from modules themselves. -# Copy, with a .conf extension, to /etc/modprobe.d to use it with modprobe. diff --git a/testsuite/rootfs-pristine/test-modprobe/softdep-loop/lib/modules/4.4.4/modules.symbols b/testsuite/rootfs-pristine/test-modprobe/softdep-loop/lib/modules/4.4.4/modules.symbols deleted file mode 100644 index b970b60..0000000 --- a/testsuite/rootfs-pristine/test-modprobe/softdep-loop/lib/modules/4.4.4/modules.symbols +++ /dev/null @@ -1,45 +0,0 @@ -# Aliases for symbols, used by symbol_request(). -alias symbol:hci_conn_check_secure bluetooth -alias symbol:hci_send_acl bluetooth -alias symbol:hci_recv_fragment bluetooth -alias symbol:hci_recv_frame bluetooth -alias symbol:hci_le_ltk_reply bluetooth -alias symbol:hci_send_sco bluetooth -alias symbol:bt_debugfs bluetooth -alias symbol:bt_accept_unlink bluetooth -alias symbol:bt_sock_recvmsg bluetooth -alias symbol:bt_sock_ioctl bluetooth -alias symbol:hci_le_conn_update bluetooth -alias symbol:hci_unregister_cb bluetooth -alias symbol:hci_connect bluetooth -alias symbol:hci_le_start_enc bluetooth -alias symbol:bt_sock_link bluetooth -alias symbol:bt_printk bluetooth -alias symbol:hci_alloc_dev bluetooth -alias symbol:baswap bluetooth -alias symbol:hci_conn_switch_role bluetooth -alias symbol:hci_resume_dev bluetooth -alias symbol:bt_sock_stream_recvmsg bluetooth -alias symbol:hci_conn_check_link_mode bluetooth -alias symbol:hci_conn_hold_device bluetooth -alias symbol:hci_conn_change_link_key bluetooth -alias symbol:hci_conn_put_device bluetooth -alias symbol:batostr bluetooth -alias symbol:bt_to_errno bluetooth -alias symbol:bt_accept_dequeue bluetooth -alias symbol:hci_free_dev bluetooth -alias symbol:bt_accept_enqueue bluetooth -alias symbol:hci_find_link_key_type bluetooth -alias symbol:hci_find_ltk bluetooth -alias symbol:hci_recv_stream_fragment bluetooth -alias symbol:bt_sock_register bluetooth -alias symbol:hci_get_route bluetooth -alias symbol:hci_register_dev bluetooth -alias symbol:hci_unregister_dev bluetooth -alias symbol:bt_sock_poll bluetooth -alias symbol:bt_sock_wait_state bluetooth -alias symbol:bt_sock_unlink bluetooth -alias symbol:bt_sock_unregister bluetooth -alias symbol:hci_register_cb bluetooth -alias symbol:hci_suspend_dev bluetooth -alias symbol:hci_conn_security bluetooth diff --git a/testsuite/rootfs-pristine/test-modprobe/softdep-loop/lib/modules/4.4.4/modules.symbols.bin b/testsuite/rootfs-pristine/test-modprobe/softdep-loop/lib/modules/4.4.4/modules.symbols.bin deleted file mode 100644 index 156a61f..0000000 Binary files a/testsuite/rootfs-pristine/test-modprobe/softdep-loop/lib/modules/4.4.4/modules.symbols.bin and /dev/null differ diff --git a/testsuite/rootfs-pristine/test-new-module/from_alias/correct.txt b/testsuite/rootfs-pristine/test-new-module/from_alias/correct.txt deleted file mode 100644 index 6ed98ea..0000000 --- a/testsuite/rootfs-pristine/test-new-module/from_alias/correct.txt +++ /dev/null @@ -1,2 +0,0 @@ -modname: ext4 - diff --git a/testsuite/rootfs-pristine/test-new-module/from_alias/etc/modprobe.d/modprobe.conf b/testsuite/rootfs-pristine/test-new-module/from_alias/etc/modprobe.d/modprobe.conf deleted file mode 100644 index f9629a0..0000000 --- a/testsuite/rootfs-pristine/test-new-module/from_alias/etc/modprobe.d/modprobe.conf +++ /dev/null @@ -1 +0,0 @@ -alias ext4.* ext4 diff --git a/testsuite/rootfs-pristine/test-new-module/from_name/correct.txt b/testsuite/rootfs-pristine/test-new-module/from_name/correct.txt deleted file mode 100644 index a75cd3b..0000000 --- a/testsuite/rootfs-pristine/test-new-module/from_name/correct.txt +++ /dev/null @@ -1,6 +0,0 @@ -modname: ext4 -modname: balbalbalbbalbalbalbalbalbalbal -modname: snd_hda_intel -modname: snd_timer -modname: iTCO_wdt - diff --git a/testsuite/rootfs-pristine/test-remove/correct.txt b/testsuite/rootfs-pristine/test-remove/correct.txt deleted file mode 100644 index 1682154..0000000 --- a/testsuite/rootfs-pristine/test-remove/correct.txt +++ /dev/null @@ -1,28 +0,0 @@ -filename: /ext4-i686.ko -license: GPL -description: Fourth Extended Filesystem -author: Remy Card, Stephen Tweedie, Andrew Morton, Andreas Dilger, Theodore Ts'o and others -srcversion: A80608676B83D55514B450E -depends: mbcache,jbd2 -vermagic: 2.6.32-220.el6.i686 SMP mod_unload modversions 686 -filename: /ext4-ppc64.ko -license: GPL -description: Fourth Extended Filesystem -author: Remy Card, Stephen Tweedie, Andrew Morton, Andreas Dilger, Theodore Ts'o and others -srcversion: 670806A855D5836BE150B41 -depends: jbd2,mbcache -vermagic: 2.6.32-220.el6.ppc64 SMP mod_unload modversions -filename: /ext4-s390x.ko -license: GPL -description: Fourth Extended Filesystem -author: Remy Card, Stephen Tweedie, Andrew Morton, Andreas Dilger, Theodore Ts'o and others -srcversion: 670806A855D5836BE150B41 -depends: mbcache,jbd2 -vermagic: 2.6.32-220.el6.s390x SMP mod_unload modversions -filename: /ext4-x86_64.ko -license: GPL -description: Fourth Extended Filesystem -author: Remy Card, Stephen Tweedie, Andrew Morton, Andreas Dilger, Theodore Ts'o and others -srcversion: A80608676B83D55514B450E -depends: mbcache,jbd2 -vermagic: 2.6.32-220.el6.x86_64 SMP mod_unload modversions diff --git a/testsuite/rootfs-pristine/test-remove/ext4-i686.ko b/testsuite/rootfs-pristine/test-remove/ext4-i686.ko deleted file mode 100644 index e5d2fb7..0000000 Binary files a/testsuite/rootfs-pristine/test-remove/ext4-i686.ko and /dev/null differ diff --git a/testsuite/rootfs-pristine/test-remove/ext4-ppc64.ko b/testsuite/rootfs-pristine/test-remove/ext4-ppc64.ko deleted file mode 100644 index cb02ed4..0000000 Binary files a/testsuite/rootfs-pristine/test-remove/ext4-ppc64.ko and /dev/null differ diff --git a/testsuite/rootfs-pristine/test-remove/ext4-s390x.ko b/testsuite/rootfs-pristine/test-remove/ext4-s390x.ko deleted file mode 100644 index 74c3799..0000000 Binary files a/testsuite/rootfs-pristine/test-remove/ext4-s390x.ko and /dev/null differ diff --git a/testsuite/rootfs-pristine/test-remove/ext4-x86_64.ko b/testsuite/rootfs-pristine/test-remove/ext4-x86_64.ko deleted file mode 100644 index ae96eef..0000000 Binary files a/testsuite/rootfs-pristine/test-remove/ext4-x86_64.ko and /dev/null differ diff --git a/testsuite/rootfs-pristine/test-rootfs/lib/modules/a b/testsuite/rootfs-pristine/test-rootfs/lib/modules/a deleted file mode 100644 index 837c960..0000000 --- a/testsuite/rootfs-pristine/test-rootfs/lib/modules/a +++ /dev/null @@ -1 +0,0 @@ -kmod-test-chroot-works diff --git a/testsuite/rootfs-pristine/test-rootfs/testdir/.gitignore b/testsuite/rootfs-pristine/test-rootfs/testdir/.gitignore deleted file mode 100644 index e69de29..0000000 diff --git a/testsuite/rootfs.tar.xz b/testsuite/rootfs.tar.xz new file mode 100644 index 0000000..1ed83da Binary files /dev/null and b/testsuite/rootfs.tar.xz differ diff --git a/testsuite/stripped-module.h b/testsuite/stripped-module.h index 83986b2..9f97dae 100644 --- a/testsuite/stripped-module.h +++ b/testsuite/stripped-module.h @@ -1,4 +1,5 @@ -#pragma once +#ifndef _TESTSUITE_STRIPPED_MODULE_H +#define _TESTSUITE_STRIPPED_MODULE_H enum module_state { @@ -12,7 +13,6 @@ struct list_head { }; #define MODULE_NAME_LEN (64 - sizeof(unsigned long)) - struct module { enum module_state state; @@ -24,6 +24,4 @@ struct module char name[MODULE_NAME_LEN]; }; -/* padding */ -#define MODULE_NAME_OFFSET_64 4 + 4 + 2 * 8 -#define MODULE_NAME_OFFSET_32 4 + 2 * 4 +#endif diff --git a/testsuite/test-alias.c b/testsuite/test-alias.c index 5e21573..567d676 100644 --- a/testsuite/test-alias.c +++ b/testsuite/test-alias.c @@ -1,20 +1,19 @@ /* - * Copyright (C) 2012-2013 ProFUSION embedded systems + * Copyright (C) 2012 ProFUSION embedded systems * Copyright (C) 2012 Pedro Pedruzzi * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ #include diff --git a/testsuite/test-blacklist.c b/testsuite/test-blacklist.c deleted file mode 100644 index a018392..0000000 --- a/testsuite/test-blacklist.c +++ /dev/null @@ -1,109 +0,0 @@ -/* - * Copyright (C) 2011-2013 ProFUSION embedded systems - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include -#include -#include -#include -#include -#include -#include -#include - -/* good luck bulding a kmod_list outside of the library... makes this blacklist - * function rather pointless */ -#include - -/* FIXME: hack, change name so we don't clash */ -#undef ERR -#include "testsuite.h" - -static int blacklist_1(const struct test *t) -{ - struct kmod_ctx *ctx; - struct kmod_list *list = NULL, *l, *filtered; - struct kmod_module *mod; - int err; - size_t len = 0; - - const char *names[] = { "pcspkr", "pcspkr2", "floppy", "ext4", NULL }; - const char **name; - - ctx = kmod_new(NULL, NULL); - if (ctx == NULL) - exit(EXIT_FAILURE); - - for(name = names; *name; name++) { - err = kmod_module_new_from_name(ctx, *name, &mod); - if (err < 0) - goto fail_lookup; - list = kmod_list_append(list, mod); - } - - err = kmod_module_apply_filter(ctx, KMOD_FILTER_BLACKLIST, list, - &filtered); - if (err < 0) { - ERR("Could not filter: %s\n", strerror(-err)); - goto fail; - } - if (filtered == NULL) { - ERR("All modules were filtered out!\n"); - goto fail; - } - - kmod_list_foreach(l, filtered) { - const char *modname; - mod = kmod_module_get_module(l); - modname = kmod_module_get_name(mod); - if (strcmp("pcspkr", modname) == 0 || strcmp("floppy", modname) == 0) - goto fail; - len++; - kmod_module_unref(mod); - } - - if (len != 2) - goto fail; - - kmod_module_unref_list(filtered); - kmod_module_unref_list(list); - kmod_unref(ctx); - - return EXIT_SUCCESS; - -fail: - kmod_module_unref_list(list); -fail_lookup: - kmod_unref(ctx); - return EXIT_FAILURE; -} -static const struct test sblacklist_1 = { - .name = "blacklist_1", - .description = "check if modules are correctly blacklisted", - .func = blacklist_1, - .config = { - [TC_ROOTFS] = TESTSUITE_ROOTFS "test-blacklist/", - }, - .need_spawn = true, -}; - -static const struct test *tests[] = { - &sblacklist_1, - NULL, -}; - -TESTSUITE_MAIN(tests); diff --git a/testsuite/test-dependencies.c b/testsuite/test-dependencies.c deleted file mode 100644 index cdd8066..0000000 --- a/testsuite/test-dependencies.c +++ /dev/null @@ -1,93 +0,0 @@ -/* - * Copyright (C) 2011-2013 ProFUSION embedded systems - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include -#include -#include -#include -#include -#include -#include -#include - -#include "testsuite.h" -#define TEST_UNAME "4.0.20-kmod" - -static int test_dependencies(const struct test *t) -{ - struct kmod_ctx *ctx; - struct kmod_module *mod; - struct kmod_list *list, *l; - int err; - size_t len = 0; - int crc16 = 0, mbcache = 0, jbd2 = 0; - - ctx = kmod_new(NULL, NULL); - if (ctx == NULL) - return EXIT_FAILURE; - - err = kmod_module_new_from_name(ctx, "ext4", &mod); - if (err < 0) { - kmod_unref(ctx); - return EXIT_FAILURE; - } - - list = kmod_module_get_dependencies(mod); - - kmod_list_foreach(l, list) { - struct kmod_module *m = kmod_module_get_module(l); - const char *name = kmod_module_get_name(m); - - if (strcmp(name, "crc16") == 0) - crc16 = 1; - if (strcmp(name, "mbcache") == 0) - mbcache = 1; - else if (strcmp(name, "jbd2") == 0) - jbd2 = 1; - - kmod_module_unref(m); - len++; - } - - /* crc16, mbcache, jbd2 */ - if (len != 3 || !crc16 || !mbcache || !jbd2) - return EXIT_FAILURE; - - kmod_module_unref_list(list); - kmod_module_unref(mod); - kmod_unref(ctx); - - return EXIT_SUCCESS; -} -static const struct test stest_dependencies = { - .name = "test_dependencies", - .description = "test if kmod_module_get_dependencies works", - .func = test_dependencies, - .config = { - [TC_ROOTFS] = TESTSUITE_ROOTFS "test-dependencies/", - [TC_UNAME_R] = TEST_UNAME, - }, - .need_spawn = true, -}; - -static const struct test *tests[] = { - &stest_dependencies, - NULL, -}; - -TESTSUITE_MAIN(tests); diff --git a/testsuite/test-depmod.c b/testsuite/test-depmod.c deleted file mode 100644 index 0ea8982..0000000 --- a/testsuite/test-depmod.c +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright (C) 2012-2013 ProFUSION embedded systems - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include -#include -#include -#include -#include -#include -#include - -#include "testsuite.h" - -#define MODULES_ORDER_UNAME "3.5.4-1-ARCH" -#define MODULES_ORDER_ROOTFS TESTSUITE_ROOTFS "test-depmod/modules-order-compressed" -#define MODULES_ORDER_LIB_MODULES MODULES_ORDER_ROOTFS "/lib/modules/" MODULES_ORDER_UNAME -static __noreturn int depmod_modules_order_for_compressed(const struct test *t) -{ - const char *progname = ABS_TOP_BUILDDIR "/tools/depmod"; - const char *const args[] = { - progname, - NULL, - }; - - test_spawn_prog(progname, args); - exit(EXIT_FAILURE); -} -static DEFINE_TEST(depmod_modules_order_for_compressed, - .description = "check if depmod let aliases in right order when using compressed modules", - .config = { - [TC_UNAME_R] = MODULES_ORDER_UNAME, - [TC_ROOTFS] = MODULES_ORDER_ROOTFS, - }, - .output = { - .files = (const struct keyval[]) { - { MODULES_ORDER_LIB_MODULES "/correct-modules.alias", - MODULES_ORDER_LIB_MODULES "/modules.alias" }, - { } - }, - }); - - -static const struct test *tests[] = { - &sdepmod_modules_order_for_compressed, - NULL, -}; - -TESTSUITE_MAIN(tests); diff --git a/testsuite/test-init.c b/testsuite/test-init.c index 47a6512..f09c4d2 100644 --- a/testsuite/test-init.c +++ b/testsuite/test-init.c @@ -1,19 +1,18 @@ /* - * Copyright (C) 2012-2013 ProFUSION embedded systems + * Copyright (C) 2012 ProFUSION embedded systems * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ #include @@ -71,7 +70,7 @@ static __noreturn int test_insert(const struct test *t) static DEFINE_TEST(test_insert, .description = "test if libkmod's insert_module returns ok", .config = { - [TC_ROOTFS] = TESTSUITE_ROOTFS "test-init/", + [TC_ROOTFS] = TESTSUITE_ROOTFS "test-modinfo/", [TC_INIT_MODULE_RETCODES] = "bla:1:20", }, .need_spawn = true); @@ -105,7 +104,7 @@ static __noreturn int test_remove(const struct test *t) static DEFINE_TEST(test_remove, .description = "test if libkmod's remove_module returns ok", .config = { - [TC_ROOTFS] = TESTSUITE_ROOTFS "test-remove/", + [TC_ROOTFS] = TESTSUITE_ROOTFS "test-modinfo/", [TC_DELETE_MODULE_RETCODES] = "bla:1:20", }, .need_spawn = true); diff --git a/testsuite/test-loaded.c b/testsuite/test-loaded.c index 33865cb..81c9e5a 100644 --- a/testsuite/test-loaded.c +++ b/testsuite/test-loaded.c @@ -1,19 +1,18 @@ /* - * Copyright (C) 2012-2013 ProFUSION embedded systems + * Copyright (C) 2012 ProFUSION embedded systems * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ #include diff --git a/testsuite/test-modinfo.c b/testsuite/test-modinfo.c index c5934ea..0ff6998 100644 --- a/testsuite/test-modinfo.c +++ b/testsuite/test-modinfo.c @@ -1,19 +1,18 @@ /* - * Copyright (C) 2012-2013 ProFUSION embedded systems + * Copyright (C) 2012 ProFUSION embedded systems * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ #include @@ -32,8 +31,7 @@ static __noreturn int modinfo_jonsmodules(const struct test *t) const char *const args[] = { progname, "/ext4-i686.ko", "/ext4-ppc64.ko", "/ext4-s390x.ko", - "/ext4-x86_64.ko", "/ext4-x86_64-sha1.ko", - "/ext4-x86_64-sha256.ko", + "/ext4-x86_64.ko", NULL, }; diff --git a/testsuite/test-modprobe.c b/testsuite/test-modprobe.c index cc90dae..3aebcae 100644 --- a/testsuite/test-modprobe.c +++ b/testsuite/test-modprobe.c @@ -1,19 +1,18 @@ /* - * Copyright (C) 2012-2013 ProFUSION embedded systems + * Copyright (C) 2012 ProFUSION embedded systems * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ #include @@ -70,30 +69,6 @@ static DEFINE_TEST(modprobe_show_depends2, .stdout = TESTSUITE_ROOTFS "test-modprobe/show-depends/correct-psmouse.txt", }); - -static __noreturn int modprobe_show_alias_to_none(const struct test *t) -{ - const char *progname = ABS_TOP_BUILDDIR "/tools/modprobe"; - const char *const args[] = { - progname, - "--show-depends", "--ignore-install", "--quiet", "psmouse", - NULL, - }; - - test_spawn_prog(progname, args); - exit(EXIT_FAILURE); -} -static DEFINE_TEST(modprobe_show_alias_to_none, - .description = "check if modprobe --show-depends doesn't explode with an alias to nothing", - .config = { - [TC_UNAME_R] = "4.4.4", - [TC_ROOTFS] = TESTSUITE_ROOTFS "test-modprobe/alias-to-none", - }, - .output = { - .stdout = TESTSUITE_ROOTFS "test-modprobe/show-depends/correct-psmouse.txt", - }); - - static __noreturn int modprobe_builtin(const struct test *t) { const char *progname = ABS_TOP_BUILDDIR "/tools/modprobe"; @@ -113,59 +88,10 @@ static DEFINE_TEST(modprobe_builtin, [TC_ROOTFS] = TESTSUITE_ROOTFS "test-modprobe/builtin", }); -static __noreturn int modprobe_softdep_loop(const struct test *t) -{ - const char *progname = ABS_TOP_BUILDDIR "/tools/modprobe"; - const char *const args[] = { - progname, - "bluetooth", - NULL, - }; - - test_spawn_prog(progname, args); - exit(EXIT_FAILURE); -} -static DEFINE_TEST(modprobe_softdep_loop, - .description = "check if modprobe breaks softdep loop", - .config = { - [TC_UNAME_R] = "4.4.4", - [TC_ROOTFS] = TESTSUITE_ROOTFS "test-modprobe/softdep-loop", - [TC_INIT_MODULE_RETCODES] = "", - }); - -static __noreturn int modprobe_install_cmd_loop(const struct test *t) -{ - const char *progname = ABS_TOP_BUILDDIR "/tools/modprobe"; - const char *const args[] = { - progname, - "snd-pcm", - NULL, - }; - - test_spawn_prog(progname, args); - exit(EXIT_FAILURE); -} -static DEFINE_TEST(modprobe_install_cmd_loop, - .description = "check if modprobe breaks install-commands loop", - .config = { - [TC_UNAME_R] = "4.4.4", - [TC_ROOTFS] = TESTSUITE_ROOTFS "test-modprobe/install-cmd-loop", - [TC_INIT_MODULE_RETCODES] = "", - }, - .env_vars = (const struct keyval[]) { - { "MODPROBE", ABS_TOP_BUILDDIR "/tools/modprobe" }, - { } - }, - ); - - static const struct test *tests[] = { &smodprobe_show_depends, &smodprobe_show_depends2, - &smodprobe_show_alias_to_none, &smodprobe_builtin, - &smodprobe_softdep_loop, - &smodprobe_install_cmd_loop, NULL, }; diff --git a/testsuite/test-new-module.c b/testsuite/test-new-module.c index 240480e..9a0cc37 100644 --- a/testsuite/test-new-module.c +++ b/testsuite/test-new-module.c @@ -1,19 +1,18 @@ /* - * Copyright (C) 2012-2013 ProFUSION embedded systems + * Copyright (C) 2012 ProFUSION embedded systems * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ #include diff --git a/testsuite/test-testsuite.c b/testsuite/test-testsuite.c index f52dd1f..043e09d 100644 --- a/testsuite/test-testsuite.c +++ b/testsuite/test-testsuite.c @@ -1,19 +1,18 @@ /* - * Copyright (C) 2012-2013 ProFUSION embedded systems + * Copyright (C) 2012 ProFUSION embedded systems * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ #include diff --git a/testsuite/testsuite.c b/testsuite/testsuite.c index 6d85d7f..9efe8de 100644 --- a/testsuite/testsuite.c +++ b/testsuite/testsuite.c @@ -1,19 +1,18 @@ /* - * Copyright (C) 2012-2013 ProFUSION embedded systems + * Copyright (C) 2012 ProFUSION embedded systems * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ #include @@ -24,14 +23,11 @@ #include #include #include -#include #include #include #include -#include #include -#include "libkmod-util.h" #include "testsuite.h" static const char *ANSI_HIGHLIGHT_GREEN_ON = "\x1B[1;32m"; @@ -59,19 +55,6 @@ struct _env_config { [TC_DELETE_MODULE_RETCODES] = { S_TC_DELETE_MODULE_RETCODES, OVERRIDE_LIBDIR "delete_module.so" }, }; -#define USEC_PER_SEC 1000000ULL -#define USEC_PER_MSEC 1000ULL -#define TEST_TIMEOUT_USEC 2 * USEC_PER_SEC -static unsigned long long now_usec(void) -{ - struct timespec ts; - - if (clock_gettime(CLOCK_MONOTONIC, &ts) != 0) - return 0; - - return ts_usec(&ts); -} - static void help(void) { const struct option *itr; @@ -175,7 +158,6 @@ static void test_export_environ(const struct test *t) char *preload = NULL; size_t preloadlen = 0; size_t i; - const struct keyval *env; unsetenv("LD_PRELOAD"); @@ -209,13 +191,10 @@ static void test_export_environ(const struct test *t) setenv("LD_PRELOAD", preload, 1); free(preload); - - for (env = t->env_vars; env && env->key; env++) - setenv(env->key, env->val, 1); } static inline int test_run_child(const struct test *t, int fdout[2], - int fderr[2], int fdmonitor[2]) + int fderr[2]) { /* kill child if parent dies */ prctl(PR_SET_PDEATHSIG, SIGTERM); @@ -239,30 +218,6 @@ static inline int test_run_child(const struct test *t, int fdout[2], } } - close(fdmonitor[0]); - - if (t->config[TC_ROOTFS] != NULL) { - const char *stamp = TESTSUITE_ROOTFS "../stamp-rootfs"; - const char *rootfs = t->config[TC_ROOTFS]; - struct stat rootfsst, stampst; - - if (stat(stamp, &stampst) != 0) { - ERR("could not stat %s\n - %m", stamp); - exit(EXIT_FAILURE); - } - - if (stat(rootfs, &rootfsst) != 0) { - ERR("could not stat %s\n - %m", rootfs); - exit(EXIT_FAILURE); - } - - if (stat_mstamp(&rootfsst) > stat_mstamp(&stampst)) { - ERR("rootfs %s is dirty, please run 'make rootfs' before runnning this test\n", - rootfs); - exit(EXIT_FAILURE); - } - } - if (t->need_spawn) return test_spawn_test(t); else @@ -270,11 +225,13 @@ static inline int test_run_child(const struct test *t, int fdout[2], } static inline bool test_run_parent_check_outputs(const struct test *t, - int fdout, int fderr, int fdmonitor, pid_t child) + int fdout, int fderr) { - struct epoll_event ep_outpipe, ep_errpipe, ep_monitor; + struct epoll_event ep_outpipe, ep_errpipe; int err, fd_ep, fd_matchout = -1, fd_matcherr = -1; - unsigned long long end_usec, start_usec; + + if (t->output.stdout == NULL && t->output.stderr == NULL) + return true; fd_ep = epoll_create1(EPOLL_CLOEXEC); if (fd_ep < 0) { @@ -321,28 +278,11 @@ static inline bool test_run_parent_check_outputs(const struct test *t, } else fderr = -1; - memset(&ep_monitor, 0, sizeof(struct epoll_event)); - ep_monitor.events = EPOLLHUP; - ep_monitor.data.ptr = &fdmonitor; - if (epoll_ctl(fd_ep, EPOLL_CTL_ADD, fdmonitor, &ep_monitor) < 0) { - err = -errno; - ERR("could not add monitor fd to epoll: %m\n"); - goto out; - } - - start_usec = now_usec(); - end_usec = start_usec + TEST_TIMEOUT_USEC; - - for (err = 0; fdmonitor >= 0 || fdout >= 0 || fderr >= 0;) { - int fdcount, i, timeout; + for (err = 0; fdout >= 0 || fderr >= 0;) { + int fdcount, i; struct epoll_event ev[4]; - unsigned long long curr_usec = now_usec(); - if (curr_usec > end_usec) - break; - - timeout = (end_usec - curr_usec) / USEC_PER_MSEC; - fdcount = epoll_wait(fd_ep, ev, 4, timeout); + fdcount = epoll_wait(fd_ep, ev, 4, -1); if (fdcount < 0) { if (errno == EINTR) continue; @@ -371,13 +311,8 @@ static inline bool test_run_parent_check_outputs(const struct test *t, if (*fd == fdout) fd_match = fd_matchout; - else if (*fd == fderr) + else fd_match = fd_matcherr; - else { - ERR("Unexpected activity on monitor pipe\n"); - err = -EINVAL; - goto out; - } for (;;) { int rmatch = read(fd_match, @@ -416,14 +351,8 @@ static inline bool test_run_parent_check_outputs(const struct test *t, *fd = -1; } } - } - if (err == 0 && fdmonitor >= 0) { - err = -EINVAL; - ERR("Test '%s' timed out, killing %d\n", t->name, child); - kill(child, SIGKILL); } - out: if (fd_matchout >= 0) close(fd_matchout); @@ -434,102 +363,8 @@ out: return err == 0; } -static inline int safe_read(int fd, void *buf, size_t count) -{ - int r; - - while (1) { - r = read(fd, buf, count); - if (r == -1 && errno == EINTR) - continue; - break; - } - - return r; -} - -static bool check_generated_files(const struct test *t) -{ - const struct keyval *k; - - /* This is not meant to be a diff replacement, just stupidly check if - * the files match. Bear in mind they can be binary files */ - for (k = t->output.files; k && k->key; k++) { - struct stat sta, stb; - int fda = -1, fdb = -1; - char bufa[4096]; - char bufb[4096]; - - fda = open(k->key, O_RDONLY); - if (fda < 0) { - ERR("could not open %s\n - %m\n", k->key); - goto fail; - } - - fdb = open(k->val, O_RDONLY); - if (fdb < 0) { - ERR("could not open %s\n - %m\n", k->val); - goto fail; - } - - if (fstat(fda, &sta) != 0) { - ERR("could not fstat %d %s\n - %m\n", fda, k->key); - goto fail; - } - - if (fstat(fdb, &stb) != 0) { - ERR("could not fstat %d %s\n - %m\n", fdb, k->key); - goto fail; - } - - if (sta.st_size != stb.st_size) { - ERR("sizes do not match %s %s\n", k->key, k->val); - goto fail; - } - - for (;;) { - int r, done; - - r = safe_read(fda, bufa, sizeof(bufa)); - if (r < 0) - goto fail; - - if (r == 0) - /* size is already checked, go to next file */ - goto next; - - for (done = 0; done < r;) { - int r2 = safe_read(fdb, bufb + done, r - done); - - if (r2 <= 0) - goto fail; - - done += r2; - } - - if (memcmp(bufa, bufb, r) != 0) - goto fail; - } - -next: - close(fda); - close(fdb); - continue; - -fail: - if (fda >= 0) - close(fda); - if (fdb >= 0) - close(fdb); - - return false; - } - - return true; -} - static inline int test_run_parent(const struct test *t, int fdout[2], - int fderr[2], int fdmonitor[2], pid_t child) + int fderr[2]) { pid_t pid; int err; @@ -540,10 +375,8 @@ static inline int test_run_parent(const struct test *t, int fdout[2], close(fdout[1]); if (t->output.stderr != NULL) close(fderr[1]); - close(fdmonitor[1]); - matchout = test_run_parent_check_outputs(t, fdout[0], fderr[0], - fdmonitor[0], child); + matchout = test_run_parent_check_outputs(t, fdout[0], fderr[0]); /* * break pipe on the other end: either child already closed or we want @@ -553,7 +386,6 @@ static inline int test_run_parent(const struct test *t, int fdout[2], close(fdout[0]); if (t->output.stderr != NULL) close(fderr[0]); - close(fdmonitor[0]); do { pid = wait(&err); @@ -573,12 +405,8 @@ static inline int test_run_parent(const struct test *t, int fdout[2], } else if (WIFSIGNALED(err)) { ERR("'%s' [%u] terminated by signal %d (%s)\n", t->name, pid, WTERMSIG(err), strsignal(WTERMSIG(err))); - return t->expected_fail ? EXIT_SUCCESS : EXIT_FAILURE; } - if (matchout) - matchout = check_generated_files(t); - if (t->expected_fail == false) { if (err == 0) { if (matchout) @@ -645,7 +473,6 @@ int test_run(const struct test *t) pid_t pid; int fdout[2]; int fderr[2]; - int fdmonitor[2]; if (t->need_spawn && oneshot) test_run_spawned(t); @@ -664,11 +491,6 @@ int test_run(const struct test *t) } } - if (pipe(fdmonitor) != 0) { - ERR("could not create monitor pipe for %s\n", t->name); - return EXIT_FAILURE; - } - if (prepend_path(t->path) < 0) { ERR("failed to prepend '%s' to PATH\n", t->path); return EXIT_FAILURE; @@ -684,7 +506,7 @@ int test_run(const struct test *t) } if (pid > 0) - return test_run_parent(t, fdout, fderr, fdmonitor, pid); + return test_run_parent(t, fdout, fderr); - return test_run_child(t, fdout, fderr, fdmonitor); + return test_run_child(t, fdout, fderr); } diff --git a/testsuite/testsuite.h b/testsuite/testsuite.h index 329d4a1..be3bfb8 100644 --- a/testsuite/testsuite.h +++ b/testsuite/testsuite.h @@ -1,22 +1,22 @@ /* - * Copyright (C) 2012-2013 ProFUSION embedded systems + * Copyright (C) 2012 ProFUSION embedded systems * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ -#pragma once +#ifndef _LIBKMOD_TESTSUITE_ +#define _LIBKMOD_TESTSUITE_ #include #include @@ -72,31 +72,17 @@ enum test_config { #define S_TC_INIT_MODULE_RETCODES "TESTSUITE_INIT_MODULE_RETCODES" #define S_TC_DELETE_MODULE_RETCODES "TESTSUITE_DELETE_MODULE_RETCODES" -struct keyval { - const char *key; - const char *val; -}; struct test { const char *name; const char *description; struct { - /* File with correct stdout */ const char *stdout; - /* File with correct stderr */ const char *stderr; - - /* - * Vector with pair of files - * key = correct file - * val = file to check - */ - const struct keyval *files; } output; testfunc func; const char *config[_TC_LAST]; const char *path; - const struct keyval *env_vars; bool need_spawn; bool expected_fail; }; @@ -152,4 +138,6 @@ int test_run(const struct test *t); exit(EXIT_SUCCESS); \ } \ +#endif + #define __noreturn __attribute__((noreturn)) diff --git a/testsuite/uname.c b/testsuite/uname.c index 2ada200..8e5bdbb 100644 --- a/testsuite/uname.c +++ b/testsuite/uname.c @@ -1,19 +1,18 @@ /* - * Copyright (C) 2012-2013 ProFUSION embedded systems + * Copyright (C) 2012 ProFUSION embedded systems * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ #include diff --git a/tools/depmod.c b/tools/depmod.c deleted file mode 100644 index 4a02631..0000000 --- a/tools/depmod.c +++ /dev/null @@ -1,2700 +0,0 @@ -/* - * kmod-depmod - calculate modules.dep using libkmod. - * - * Copyright (C) 2011-2013 ProFUSION embedded systems - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -#include "libkmod.h" -#include "libkmod-array.h" -#include "libkmod-hash.h" -#include "libkmod-util.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "kmod.h" - -#define DEFAULT_VERBOSE LOG_WARNING -static int verbose = DEFAULT_VERBOSE; - -static const char CFG_BUILTIN_KEY[] = "built-in"; -static const char *default_cfg_paths[] = { - "/run/depmod.d", - SYSCONFDIR "/depmod.d", - "/lib/depmod.d", - NULL -}; - -static const char cmdopts_s[] = "aAb:C:E:F:euqrvnP:wmVh"; -static const struct option cmdopts[] = { - { "all", no_argument, 0, 'a' }, - { "quick", no_argument, 0, 'A' }, - { "basedir", required_argument, 0, 'b' }, - { "config", required_argument, 0, 'C' }, - { "symvers", required_argument, 0, 'E' }, - { "filesyms", required_argument, 0, 'F' }, - { "errsyms", no_argument, 0, 'e' }, - { "unresolved-error", no_argument, 0, 'u' }, /* deprecated */ - { "quiet", no_argument, 0, 'q' }, /* deprecated */ - { "root", no_argument, 0, 'r' }, /* deprecated */ - { "verbose", no_argument, 0, 'v' }, - { "show", no_argument, 0, 'n' }, - { "dry-run", no_argument, 0, 'n' }, - { "symbol-prefix", required_argument, 0, 'P' }, - { "warn", no_argument, 0, 'w' }, - { "map", no_argument, 0, 'm' }, /* deprecated */ - { "version", no_argument, 0, 'V' }, - { "help", no_argument, 0, 'h' }, - { } -}; - -static void help(void) -{ - printf("Usage:\n" - "\t%s -[aA] [options] [forced_version]\n" - "\n" - "If no arguments (except options) are given, \"depmod -a\" is assumed\n" - "\n" - "depmod will output a dependency list suitable for the modprobe utility.\n" - "\n" - "Options:\n" - "\t-a, --all Probe all modules\n" - "\t-A, --quick Only does the work if there's a new module\n" - "\t-e, --errsyms Report not supplied symbols\n" - "\t-n, --show Write the dependency file on stdout only\n" - "\t-P, --symbol-prefix Architecture symbol prefix\n" - "\t-C, --config=PATH Read configuration from PATH\n" - "\t-v, --verbose Enable verbose mode\n" - "\t-w, --warn Warn on duplicates\n" - "\t-V, --version show version\n" - "\t-h, --help show this help\n" - "\n" - "The following options are useful for people managing distributions:\n" - "\t-b, --basedir=DIR Use an image of a module tree.\n" - "\t-F, --filesyms=FILE Use the file instead of the\n" - "\t current kernel symbols.\n" - "\t-E, --symvers=FILE Use Module.symvers file to check\n" - "\t symbol versions.\n", - program_invocation_short_name); -} - -_printf_format_(1, 2) -static inline void _show(const char *fmt, ...) -{ - va_list args; - - if (verbose <= DEFAULT_VERBOSE) - return; - - va_start(args, fmt); - vfprintf(stdout, fmt, args); - fflush(stdout); - va_end(args); -} -#define SHOW(...) _show(__VA_ARGS__) - - -/* binary index write *************************************************/ -#include -#include "macro.h" -/* BEGIN: code from module-init-tools/index.c just modified to compile here. - * - * Original copyright: - * index.c: module index file shared functions for modprobe and depmod - * Copyright (C) 2008 Alan Jenkins . - * - * These programs are free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with these programs. If not, see . - */ - -/* Integers are stored as 32 bit unsigned in "network" order, i.e. MSB first. - All files start with a magic number. - - Magic spells "BOOTFAST". Second one used on newer versioned binary files. - */ -/* #define INDEX_MAGIC_OLD 0xB007FA57 */ -#define INDEX_MAGIC 0xB007F457 - -/* We use a version string to keep track of changes to the binary format - * This is stored in the form: INDEX_MAJOR (hi) INDEX_MINOR (lo) just in - * case we ever decide to have minor changes that are not incompatible. - */ - -#define INDEX_VERSION_MAJOR 0x0002 -#define INDEX_VERSION_MINOR 0x0001 -#define INDEX_VERSION ((INDEX_VERSION_MAJOR<<16)|INDEX_VERSION_MINOR) - -/* The index file maps keys to values. Both keys and values are ASCII strings. - Each key can have multiple values. Values are sorted by an integer priority. - - The reader also implements a wildcard search (including range expressions) - where the keys in the index are treated as patterns. - This feature is required for module aliases. -*/ - -/* Implementation is based on a radix tree, or "trie". - Each arc from parent to child is labelled with a character. - Each path from the root represents a string. - - == Example strings == - - ask - ate - on - once - one - - == Key == - + Normal node - * Marked node, representing a key and it's values. - - + - |-a-+-s-+-k-* - | | - | `-t-+-e-* - | - `-o-+-n-*-c-+-e-* - | - `-e-* - - Naive implementations tend to be very space inefficient; child pointers - are stored in arrays indexed by character, but most child pointers are null. - - Our implementation uses a scheme described by Wikipedia as a Patrica trie, - - "easiest to understand as a space-optimized trie where - each node with only one child is merged with its child" - - + - |-a-+-sk-* - | | - | `-te-* - | - `-on-*-ce-* - | - `-e-* - - We still use arrays of child pointers indexed by a single character; - the remaining characters of the label are stored as a "prefix" in the child. - - The paper describing the original Patrica trie works on individiual bits - - each node has a maximum of two children, which increases space efficiency. - However for this application it is simpler to use the ASCII character set. - Since the index file is read-only, it can be compressed by omitting null - child pointers at the start and end of arrays. -*/ - -#define INDEX_PRIORITY_MIN UINT32_MAX - -struct index_value { - struct index_value *next; - unsigned int priority; - char value[0]; -}; - -/* In-memory index (depmod only) */ - -#define INDEX_CHILDMAX 128 -struct index_node { - char *prefix; /* path compression */ - struct index_value *values; - unsigned char first; /* range of child nodes */ - unsigned char last; - struct index_node *children[INDEX_CHILDMAX]; /* indexed by character */ -}; - -/* Disk format: - - uint32_t magic = INDEX_MAGIC; - uint32_t version = INDEX_VERSION; - uint32_t root_offset; - - (node_offset & INDEX_NODE_MASK) specifies the file offset of nodes: - - char[] prefix; // nul terminated - - char first; - char last; - uint32_t children[last - first + 1]; - - uint32_t value_count; - struct { - uint32_t priority; - char[] value; // nul terminated - } values[value_count]; - - (node_offset & INDEX_NODE_FLAGS) indicates which fields are present. - Empty prefixes are omitted, leaf nodes omit the three child-related fields. - - This could be optimised further by adding a sparse child format - (indicated using a new flag). - */ - -/* Format of node offsets within index file */ -enum node_offset { - INDEX_NODE_FLAGS = 0xF0000000, /* Flags in high nibble */ - INDEX_NODE_PREFIX = 0x80000000, - INDEX_NODE_VALUES = 0x40000000, - INDEX_NODE_CHILDS = 0x20000000, - - INDEX_NODE_MASK = 0x0FFFFFFF, /* Offset value */ -}; - -static struct index_node *index_create(void) -{ - struct index_node *node; - - node = NOFAIL(calloc(sizeof(struct index_node), 1)); - node->prefix = NOFAIL(strdup("")); - node->first = INDEX_CHILDMAX; - - return node; -} - -static void index_values_free(struct index_value *values) -{ - while (values) { - struct index_value *value = values; - - values = value->next; - free(value); - } -} - -static void index_destroy(struct index_node *node) -{ - int c; - - for (c = node->first; c <= node->last; c++) { - struct index_node *child = node->children[c]; - - if (child) - index_destroy(child); - } - index_values_free(node->values); - free(node->prefix); - free(node); -} - -static void index__checkstring(const char *str) -{ - int i; - - for (i = 0; str[i]; i++) { - int ch = str[i]; - - if (ch >= INDEX_CHILDMAX) - CRIT("Module index: bad character '%c'=0x%x - only 7-bit ASCII is supported:" - "\n%s\n", (char) ch, (int) ch, str); - } -} - -static int index_add_value(struct index_value **values, - const char *value, unsigned int priority) -{ - struct index_value *v; - int duplicate = 0; - int len; - - /* report the presence of duplicate values */ - for (v = *values; v; v = v->next) { - if (streq(v->value, value)) - duplicate = 1; - } - - /* find position to insert value */ - while (*values && (*values)->priority < priority) - values = &(*values)->next; - - len = strlen(value); - v = NOFAIL(calloc(sizeof(struct index_value) + len + 1, 1)); - v->next = *values; - v->priority = priority; - memcpy(v->value, value, len + 1); - *values = v; - - return duplicate; -} - -static int index_insert(struct index_node *node, const char *key, - const char *value, unsigned int priority) -{ - int i = 0; /* index within str */ - int ch; - - index__checkstring(key); - index__checkstring(value); - - while(1) { - int j; /* index within node->prefix */ - - /* Ensure node->prefix is a prefix of &str[i]. - If it is not already, then we must split node. */ - for (j = 0; node->prefix[j]; j++) { - ch = node->prefix[j]; - - if (ch != key[i+j]) { - char *prefix = node->prefix; - struct index_node *n; - - /* New child is copy of node with prefix[j+1..N] */ - n = NOFAIL(calloc(sizeof(struct index_node), 1)); - memcpy(n, node, sizeof(struct index_node)); - n->prefix = NOFAIL(strdup(&prefix[j+1])); - - /* Parent has prefix[0..j], child at prefix[j] */ - memset(node, 0, sizeof(struct index_node)); - prefix[j] = '\0'; - node->prefix = prefix; - node->first = ch; - node->last = ch; - node->children[ch] = n; - - break; - } - } - /* j is now length of node->prefix */ - i += j; - - ch = key[i]; - if(ch == '\0') - return index_add_value(&node->values, value, priority); - - if (!node->children[ch]) { - struct index_node *child; - - if (ch < node->first) - node->first = ch; - if (ch > node->last) - node->last = ch; - node->children[ch] = NOFAIL(calloc(sizeof(struct index_node), 1)); - - child = node->children[ch]; - child->prefix = NOFAIL(strdup(&key[i+1])); - child->first = INDEX_CHILDMAX; - index_add_value(&child->values, value, priority); - - return 0; - } - - /* Descend into child node and continue */ - node = node->children[ch]; - i++; - } -} - -static int index__haschildren(const struct index_node *node) -{ - return node->first < INDEX_CHILDMAX; -} - -/* Recursive post-order traversal - - Pre-order would make for better read-side buffering / readahead / caching. - (post-order means you go backwards in the file as you descend the tree). - However, index reading is already fast enough. - Pre-order is simpler for writing, and depmod is already slow. - */ -static uint32_t index_write__node(const struct index_node *node, FILE *out) -{ - uint32_t *child_offs = NULL; - int child_count = 0; - long offset; - - if (!node) - return 0; - - /* Write children and save their offsets */ - if (index__haschildren(node)) { - const struct index_node *child; - int i; - - child_count = node->last - node->first + 1; - child_offs = NOFAIL(malloc(child_count * sizeof(uint32_t))); - - for (i = 0; i < child_count; i++) { - child = node->children[node->first + i]; - child_offs[i] = htonl(index_write__node(child, out)); - } - } - - /* Now write this node */ - offset = ftell(out); - - if (node->prefix[0]) { - fputs(node->prefix, out); - fputc('\0', out); - offset |= INDEX_NODE_PREFIX; - } - - if (child_count) { - fputc(node->first, out); - fputc(node->last, out); - fwrite(child_offs, sizeof(uint32_t), child_count, out); - free(child_offs); - offset |= INDEX_NODE_CHILDS; - } - - if (node->values) { - const struct index_value *v; - unsigned int value_count; - uint32_t u; - - value_count = 0; - for (v = node->values; v != NULL; v = v->next) - value_count++; - u = htonl(value_count); - fwrite(&u, sizeof(u), 1, out); - - for (v = node->values; v != NULL; v = v->next) { - u = htonl(v->priority); - fwrite(&u, sizeof(u), 1, out); - fputs(v->value, out); - fputc('\0', out); - } - offset |= INDEX_NODE_VALUES; - } - - return offset; -} - -static void index_write(const struct index_node *node, FILE *out) -{ - long initial_offset, final_offset; - uint32_t u; - - u = htonl(INDEX_MAGIC); - fwrite(&u, sizeof(u), 1, out); - u = htonl(INDEX_VERSION); - fwrite(&u, sizeof(u), 1, out); - - /* Second word is reserved for the offset of the root node */ - initial_offset = ftell(out); - u = 0; - fwrite(&u, sizeof(uint32_t), 1, out); - - /* Dump trie */ - u = htonl(index_write__node(node, out)); - - /* Update first word */ - final_offset = ftell(out); - fseek(out, initial_offset, SEEK_SET); - fwrite(&u, sizeof(uint32_t), 1, out); - fseek(out, final_offset, SEEK_SET); -} - -/* END: code from module-init-tools/index.c just modified to compile here. - */ - -/* utils (variants of libkmod-utils.c) *********************************/ -static const char *underscores2(const char *input, char *output, size_t outputlen) -{ - size_t i; - - for (i = 0; input[i] != '\0' && i < outputlen - 1; i++) { - switch (input[i]) { - case '-': - output[i] = '_'; - break; - - case ']': - WRN("Unmatched bracket in %s\n", input); - return NULL; - - case '[': { - size_t off = strcspn(input + i, "]"); - if (input[i + off] == '\0') { - WRN("Unmatched bracket in %s\n", input); - return NULL; - } - memcpy(output + i, input + i, off + 1); - i += off; - break; - } - - default: - output[i] = input[i]; - } - } - output[i] = '\0'; - - return output; -} - -/* configuration parsing **********************************************/ -struct cfg_override { - struct cfg_override *next; - size_t len; - char path[]; -}; - -struct cfg_search { - struct cfg_search *next; - uint8_t builtin; - size_t len; - char path[]; -}; - -struct cfg { - const char *kversion; - char dirname[PATH_MAX]; - size_t dirnamelen; - char sym_prefix; - uint8_t check_symvers; - uint8_t print_unknown; - uint8_t warn_dups; - struct cfg_override *overrides; - struct cfg_search *searches; -}; - -static int cfg_search_add(struct cfg *cfg, const char *path, uint8_t builtin) -{ - struct cfg_search *s; - size_t len; - - if (builtin) - len = 0; - else - len = strlen(path) + 1; - - s = malloc(sizeof(struct cfg_search) + len); - if (s == NULL) { - ERR("search add: out of memory\n"); - return -ENOMEM; - } - s->builtin = builtin; - if (builtin) - s->len = 0; - else { - s->len = len - 1; - memcpy(s->path, path, len); - } - - DBG("search add: %s, builtin=%hhu\n", path, builtin); - - s->next = cfg->searches; - cfg->searches = s; - return 0; -} - -static void cfg_search_free(struct cfg_search *s) -{ - free(s); -} - -static int cfg_override_add(struct cfg *cfg, const char *modname, const char *subdir) -{ - struct cfg_override *o; - size_t modnamelen = strlen(modname); - size_t subdirlen = strlen(subdir); - size_t i; - - o = malloc(sizeof(struct cfg_override) + subdirlen + 1 - + modnamelen + 1); - if (o == NULL) { - ERR("override add: out of memory\n"); - return -ENOMEM; - } - memcpy(o->path, subdir, subdirlen); - i = subdirlen; - o->path[i] = '/'; - i++; - - memcpy(o->path + i, modname, modnamelen); - i += modnamelen; - o->path[i] = '\0'; /* no extension, so we can match .ko/.ko.gz */ - - o->len = i; - - DBG("override add: %s\n", o->path); - - o->next = cfg->overrides; - cfg->overrides = o; - return 0; -} - -static void cfg_override_free(struct cfg_override *o) -{ - free(o); -} - -static int cfg_kernel_matches(const struct cfg *cfg, const char *pattern) -{ - regex_t re; - int status; - - /* old style */ - if (streq(pattern, "*")) - return 1; - - if (regcomp(&re, pattern, REG_EXTENDED|REG_NOSUB) != 0) - return 0; - - status = regexec(&re, cfg->kversion, 0, NULL, 0); - regfree(&re); - - return status == 0; -} - -static int cfg_file_parse(struct cfg *cfg, const char *filename) -{ - char *line; - FILE *fp; - unsigned int linenum = 0; - int err; - - fp = fopen(filename, "r"); - if (fp == NULL) { - err = -errno; - ERR("file parse %s: %m\n", filename); - return err; - } - - while ((line = getline_wrapped(fp, &linenum)) != NULL) { - char *cmd, *saveptr; - - if (line[0] == '\0' || line[0] == '#') - goto done_next; - - cmd = strtok_r(line, "\t ", &saveptr); - if (cmd == NULL) - goto done_next; - - if (streq(cmd, "search")) { - const char *sp; - while ((sp = strtok_r(NULL, "\t ", &saveptr)) != NULL) { - uint8_t builtin = streq(sp, CFG_BUILTIN_KEY); - cfg_search_add(cfg, sp, builtin); - } - } else if (streq(cmd, "override")) { - const char *modname = strtok_r(NULL, "\t ", &saveptr); - const char *version = strtok_r(NULL, "\t ", &saveptr); - const char *subdir = strtok_r(NULL, "\t ", &saveptr); - - if (modname == NULL || version == NULL || - subdir == NULL) - goto syntax_error; - - if (!cfg_kernel_matches(cfg, version)) { - INF("%s:%u: override kernel did not match %s\n", - filename, linenum, version); - goto done_next; - } - - cfg_override_add(cfg, modname, subdir); - } else if (streq(cmd, "include") - || streq(cmd, "make_map_files")) { - INF("%s:%u: command %s not implemented yet\n", - filename, linenum, cmd); - } else { -syntax_error: - ERR("%s:%u: ignoring bad line starting with '%s'\n", - filename, linenum, cmd); - } - -done_next: - free(line); - } - - fclose(fp); - - return 0; -} - -static int cfg_files_filter_out(DIR *d, const char *dir, const char *name) -{ - size_t len = strlen(name); - struct stat st; - - if (name[0] == '.') - return 1; - - if (len < 6 || !streq(name + len - 5, ".conf")) { - INF("All cfg files need .conf: %s/%s\n", dir, name); - return 1; - } - - fstatat(dirfd(d), name, &st, 0); - if (S_ISDIR(st.st_mode)) { - ERR("Directories inside directories are not supported: %s/%s\n", - dir, name); - return 1; - } - - return 0; -} - -struct cfg_file { - size_t dirlen; - size_t namelen; - const char *name; - char path[]; -}; - -static void cfg_file_free(struct cfg_file *f) -{ - free(f); -} - -static int cfg_files_insert_sorted(struct cfg_file ***p_files, size_t *p_n_files, - const char *dir, const char *name) -{ - struct cfg_file **files, *f; - size_t i, n_files, namelen, dirlen; - void *tmp; - - dirlen = strlen(dir); - if (name != NULL) - namelen = strlen(name); - else { - name = basename(dir); - namelen = strlen(name); - dirlen -= namelen + 1; - } - - n_files = *p_n_files; - files = *p_files; - for (i = 0; i < n_files; i++) { - int cmp = strcmp(name, files[i]->name); - if (cmp == 0) { - DBG("Ignoring duplicate config file: %.*s/%s\n", - (int)dirlen, dir, name); - return -EEXIST; - } else if (cmp < 0) - break; - } - - f = malloc(sizeof(struct cfg_file) + dirlen + namelen + 2); - if (f == NULL) { - ERR("files insert sorted: out of memory\n"); - return -ENOMEM; - } - - tmp = realloc(files, sizeof(struct cfg_file *) * (n_files + 1)); - if (tmp == NULL) { - ERR("files insert sorted: out of memory\n"); - free(f); - return -ENOMEM; - } - *p_files = files = tmp; - - if (i < n_files) { - memmove(files + i + 1, files + i, - sizeof(struct cfg_file *) * (n_files - i)); - } - files[i] = f; - - f->dirlen = dirlen; - f->namelen = namelen; - f->name = f->path + dirlen + 1; - memcpy(f->path, dir, dirlen); - f->path[dirlen] = '/'; - memcpy(f->path + dirlen + 1, name, namelen); - f->path[dirlen + 1 + namelen] = '\0'; - - *p_n_files = n_files + 1; - return 0; -} - -/* - * Insert configuration files ignoring duplicates - */ -static int cfg_files_list(struct cfg_file ***p_files, size_t *p_n_files, - const char *path) -{ - DIR *d; - int err = 0; - struct stat st; - - if (stat(path, &st) != 0) { - err = -errno; - DBG("could not stat '%s': %m\n", path); - return err; - } - - if (S_ISREG(st.st_mode)) { - cfg_files_insert_sorted(p_files, p_n_files, path, NULL); - return 0; - } if (!S_ISDIR(st.st_mode)) { - ERR("unsupported file mode %s: %#x\n", path, st.st_mode); - return -EINVAL; - } - - d = opendir(path); - if (d == NULL) { - ERR("files list %s: %m\n", path); - return -EINVAL; - } - - for (;;) { - struct dirent ent, *entp; - - err = readdir_r(d, &ent, &entp); - if (err != 0) { - ERR("reading entry %s\n", strerror(-err)); - break; - } - if (entp == NULL) - break; - if (cfg_files_filter_out(d, path, entp->d_name)) - continue; - - cfg_files_insert_sorted(p_files, p_n_files, path, entp->d_name); - } - - closedir(d); - DBG("parsed configuration files from %s\n", path); - return err; -} - -static int cfg_load(struct cfg *cfg, const char * const *cfg_paths) -{ - size_t i, n_files = 0; - struct cfg_file **files = NULL; - - if (cfg_paths == NULL) - cfg_paths = default_cfg_paths; - - for (i = 0; cfg_paths[i] != NULL; i++) - cfg_files_list(&files, &n_files, cfg_paths[i]); - - for (i = 0; i < n_files; i++) { - struct cfg_file *f = files[i]; - cfg_file_parse(cfg, f->path); - cfg_file_free(f); - } - free(files); - - /* For backward compatibility add "updates" to the head of the search - * list here. But only if there was no "search" option specified. - */ - if (cfg->searches == NULL) - cfg_search_add(cfg, "updates", 0); - - return 0; -} - -static void cfg_free(struct cfg *cfg) -{ - while (cfg->overrides) { - struct cfg_override *tmp = cfg->overrides; - cfg->overrides = cfg->overrides->next; - cfg_override_free(tmp); - } - - while (cfg->searches) { - struct cfg_search *tmp = cfg->searches; - cfg->searches = cfg->searches->next; - cfg_search_free(tmp); - } -} - - -/* depmod calculations ***********************************************/ -struct mod { - struct kmod_module *kmod; - char *path; - const char *relpath; /* path relative to '$ROOT/lib/modules/$VER/' */ - char *uncrelpath; /* same as relpath but ending in .ko */ - struct kmod_list *info_list; - struct kmod_list *dep_sym_list; - struct array deps; /* struct symbol */ - size_t baselen; /* points to start of basename/filename */ - size_t modnamelen; - int sort_idx; /* sort index using modules.order */ - int dep_sort_idx; /* topological sort index */ - uint16_t idx; /* index in depmod->modules.array */ - uint16_t users; /* how many modules depend on this one */ - uint8_t dep_loop : 1; - char modname[]; -}; - -struct symbol { - struct mod *owner; - uint64_t crc; - char name[]; -}; - -struct depmod { - const struct cfg *cfg; - struct kmod_ctx *ctx; - struct array modules; - struct hash *modules_by_uncrelpath; - struct hash *modules_by_name; - struct hash *symbols; - unsigned int dep_loops; -}; - -static void mod_free(struct mod *mod) -{ - DBG("free %p kmod=%p, path=%s\n", mod, mod->kmod, mod->path); - array_free_array(&mod->deps); - kmod_module_unref(mod->kmod); - kmod_module_info_free_list(mod->info_list); - kmod_module_dependency_symbols_free_list(mod->dep_sym_list); - free(mod->uncrelpath); - free(mod->path); - free(mod); -} - -static int mod_add_dependency(struct mod *mod, struct symbol *sym) -{ - int err; - - DBG("%s depends on %s %s\n", mod->path, sym->name, - sym->owner != NULL ? sym->owner->path : "(unknown)"); - - if (sym->owner == NULL) - return 0; - - err = array_append_unique(&mod->deps, sym->owner); - if (err == -EEXIST) - return 0; - if (err < 0) - return err; - - sym->owner->users++; - SHOW("%s needs \"%s\": %s\n", mod->path, sym->name, sym->owner->path); - return 0; -} - -static void symbol_free(struct symbol *sym) -{ - DBG("free %p sym=%s, owner=%p %s\n", sym, sym->name, sym->owner, - sym->owner != NULL ? sym->owner->path : ""); - free(sym); -} - -static int depmod_init(struct depmod *depmod, struct cfg *cfg, - struct kmod_ctx *ctx) -{ - int err = 0; - - depmod->cfg = cfg; - depmod->ctx = ctx; - - array_init(&depmod->modules, 128); - - depmod->modules_by_uncrelpath = hash_new(512, NULL); - if (depmod->modules_by_uncrelpath == NULL) { - err = -errno; - goto modules_by_uncrelpath_failed; - } - - depmod->modules_by_name = hash_new(512, NULL); - if (depmod->modules_by_name == NULL) { - err = -errno; - goto modules_by_name_failed; - } - - depmod->symbols = hash_new(2048, (void (*)(void *))symbol_free); - if (depmod->symbols == NULL) { - err = -errno; - goto symbols_failed; - } - - return 0; - -symbols_failed: - hash_free(depmod->modules_by_name); -modules_by_name_failed: - hash_free(depmod->modules_by_uncrelpath); -modules_by_uncrelpath_failed: - return err; -} - -static void depmod_shutdown(struct depmod *depmod) -{ - size_t i; - - hash_free(depmod->symbols); - - hash_free(depmod->modules_by_uncrelpath); - - hash_free(depmod->modules_by_name); - - for (i = 0; i < depmod->modules.count; i++) - mod_free(depmod->modules.array[i]); - array_free_array(&depmod->modules); - - kmod_unref(depmod->ctx); -} - -static int depmod_module_add(struct depmod *depmod, struct kmod_module *kmod) -{ - const struct cfg *cfg = depmod->cfg; - const char *modname, *lastslash; - size_t modnamelen; - struct mod *mod; - int err; - - modname = kmod_module_get_name(kmod); - modnamelen = strlen(modname) + 1; - - mod = calloc(1, sizeof(struct mod) + modnamelen); - if (mod == NULL) - return -ENOMEM; - mod->kmod = kmod; - mod->sort_idx = depmod->modules.count + 1; - mod->dep_sort_idx = INT32_MAX; - memcpy(mod->modname, modname, modnamelen); - mod->modnamelen = modnamelen; - - array_init(&mod->deps, 4); - - mod->path = strdup(kmod_module_get_path(kmod)); - lastslash = strrchr(mod->path, '/'); - mod->baselen = lastslash - mod->path; - if (strncmp(mod->path, cfg->dirname, cfg->dirnamelen) == 0 && - mod->path[cfg->dirnamelen] == '/') - mod->relpath = mod->path + cfg->dirnamelen + 1; - else - mod->relpath = NULL; - - err = hash_add_unique(depmod->modules_by_name, mod->modname, mod); - if (err < 0) { - ERR("hash_add_unique %s: %s\n", mod->modname, strerror(-err)); - goto fail; - } - - if (mod->relpath != NULL) { - size_t uncrelpathlen = lastslash - mod->relpath + modnamelen - + kmod_exts[KMOD_EXT_UNC].len; - mod->uncrelpath = memdup(mod->relpath, uncrelpathlen + 1); - mod->uncrelpath[uncrelpathlen] = '\0'; - err = hash_add_unique(depmod->modules_by_uncrelpath, - mod->uncrelpath, mod); - if (err < 0) { - ERR("hash_add_unique %s: %s\n", - mod->uncrelpath, strerror(-err)); - hash_del(depmod->modules_by_name, mod->modname); - goto fail; - } - } - - DBG("add %p kmod=%p, path=%s\n", mod, kmod, mod->path); - - return 0; - -fail: - free(mod->uncrelpath); - free(mod); - return err; -} - -static int depmod_module_del(struct depmod *depmod, struct mod *mod) -{ - DBG("del %p kmod=%p, path=%s\n", mod, mod->kmod, mod->path); - - if (mod->uncrelpath != NULL) - hash_del(depmod->modules_by_uncrelpath, mod->uncrelpath); - - hash_del(depmod->modules_by_name, mod->modname); - - mod_free(mod); - return 0; -} - -/* returns if existing module @mod is higher priority than newpath. - * note this is the inverse of module-init-tools is_higher_priority() - */ -static int depmod_module_is_higher_priority(const struct depmod *depmod, const struct mod *mod, size_t baselen, size_t namelen, size_t modnamelen, const char *newpath) -{ - const struct cfg *cfg = depmod->cfg; - const struct cfg_override *ov; - const struct cfg_search *se; - size_t newlen = baselen + modnamelen; - size_t oldlen = mod->baselen + mod->modnamelen; - const char *oldpath = mod->path; - int i, bprio = -1, oldprio = -1, newprio = -1; - - assert(strncmp(newpath, cfg->dirname, cfg->dirnamelen) == 0); - assert(strncmp(oldpath, cfg->dirname, cfg->dirnamelen) == 0); - - newpath += cfg->dirnamelen + 1; - newlen -= cfg->dirnamelen + 1; - oldpath += cfg->dirnamelen + 1; - oldlen -= cfg->dirnamelen + 1; - - DBG("comparing priorities of %s and %s\n", - oldpath, newpath); - - for (ov = cfg->overrides; ov != NULL; ov = ov->next) { - DBG("override %s\n", ov->path); - if (newlen == ov->len && memcmp(ov->path, newpath, newlen) == 0) - return 0; - if (oldlen == ov->len && memcmp(ov->path, oldpath, oldlen) == 0) - return 1; - } - - for (i = 0, se = cfg->searches; se != NULL; se = se->next, i++) { - DBG("search %s\n", se->builtin ? "built-in" : se->path); - if (se->builtin) - bprio = i; - else if (newlen >= se->len && - memcmp(se->path, newpath, se->len) == 0) - newprio = i; - else if (oldlen >= se->len && - memcmp(se->path, oldpath, se->len) == 0) - oldprio = i; - } - - if (newprio < 0) - newprio = bprio; - if (oldprio < 0) - oldprio = bprio; - - DBG("priorities: built-in: %d, old: %d, new: %d\n", - bprio, newprio, oldprio); - - return newprio <= oldprio; -} - -static int depmod_modules_search_file(struct depmod *depmod, size_t baselen, size_t namelen, const char *path) -{ - struct kmod_module *kmod; - struct mod *mod; - const char *relpath; - char modname[PATH_MAX]; - size_t modnamelen; - int err; - - if (!path_ends_with_kmod_ext(path + baselen, namelen)) - return 0; - - if (path_to_modname(path, modname, &modnamelen) == NULL) { - ERR("could not get modname from path %s\n", path); - return -EINVAL; - } - - relpath = path + depmod->cfg->dirnamelen + 1; - DBG("try %s (%s)\n", relpath, modname); - - mod = hash_find(depmod->modules_by_name, modname); - if (mod == NULL) - goto add; - - if (depmod_module_is_higher_priority(depmod, mod, baselen, - namelen, modnamelen, path)) { - DBG("Ignored lower priority: %s, higher: %s\n", - path, mod->path); - return 0; - } - - DBG("Replace lower priority %s with new module %s\n", - mod->relpath, relpath); - err = depmod_module_del(depmod, mod); - if (err < 0) { - ERR("could not del module %s: %s\n", mod->path, strerror(-err)); - return err; - } - -add: - err = kmod_module_new_from_path(depmod->ctx, path, &kmod); - if (err < 0) { - ERR("could not create module %s: %s\n", path, strerror(-err)); - return err; - } - - err = depmod_module_add(depmod, kmod); - if (err < 0) { - ERR("could not add module %s: %s\n", - path, strerror(-err)); - kmod_module_unref(kmod); - return err; - } - return 0; -} - -static int depmod_modules_search_dir(struct depmod *depmod, DIR *d, size_t baselen, char *path) -{ - struct dirent *de; - int err = 0, dfd = dirfd(d); - - while ((de = readdir(d)) != NULL) { - const char *name = de->d_name; - size_t namelen; - uint8_t is_dir; - - if (name[0] == '.' && (name[1] == '\0' || - (name[1] == '.' && name[2] == '\0'))) - continue; - if (streq(name, "build") || streq(name, "source")) - continue; - namelen = strlen(name); - if (baselen + namelen + 2 >= PATH_MAX) { - path[baselen] = '\0'; - ERR("path is too long %s%s\n", path, name); - continue; - } - memcpy(path + baselen, name, namelen + 1); - - if (de->d_type == DT_REG) - is_dir = 0; - else if (de->d_type == DT_DIR) - is_dir = 1; - else { - struct stat st; - if (fstatat(dfd, name, &st, 0) < 0) { - ERR("fstatat(%d, %s): %m\n", dfd, name); - continue; - } else if (S_ISREG(st.st_mode)) - is_dir = 0; - else if (S_ISDIR(st.st_mode)) - is_dir = 1; - else { - ERR("unsupported file type %s: %o\n", - path, st.st_mode & S_IFMT); - continue; - } - } - - if (is_dir) { - int fd; - DIR *subdir; - if (baselen + namelen + 2 + NAME_MAX >= PATH_MAX) { - ERR("directory path is too long %s\n", path); - continue; - } - fd = openat(dfd, name, O_RDONLY); - if (fd < 0) { - ERR("openat(%d, %s, O_RDONLY): %m\n", - dfd, name); - continue; - } - subdir = fdopendir(fd); - if (subdir == NULL) { - ERR("fdopendir(%d): %m\n", fd); - close(fd); - continue; - } - path[baselen + namelen] = '/'; - path[baselen + namelen + 1] = '\0'; - err = depmod_modules_search_dir(depmod, subdir, - baselen + namelen + 1, - path); - closedir(subdir); - } else { - err = depmod_modules_search_file(depmod, baselen, - namelen, path); - } - - if (err < 0) { - path[baselen + namelen] = '\0'; - ERR("failed %s: %s\n", path, strerror(-err)); - err = 0; /* ignore errors */ - } - } - - return err; -} - -static int depmod_modules_search(struct depmod *depmod) -{ - char path[PATH_MAX]; - DIR *d = opendir(depmod->cfg->dirname); - size_t baselen; - int err; - if (d == NULL) { - err = -errno; - ERR("could not open directory %s: %m\n", depmod->cfg->dirname); - return err; - } - - baselen = depmod->cfg->dirnamelen; - memcpy(path, depmod->cfg->dirname, baselen); - path[baselen] = '/'; - baselen++; - path[baselen] = '\0'; - - err = depmod_modules_search_dir(depmod, d, baselen, path); - closedir(d); - return err; -} - -static int mod_cmp(const void *pa, const void *pb) { - const struct mod *a = *(const struct mod **)pa; - const struct mod *b = *(const struct mod **)pb; - if (a->dep_loop == b->dep_loop) - return a->sort_idx - b->sort_idx; - else if (a->dep_loop) - return 1; - else if (b->dep_loop) - return -1; - return a->sort_idx - b->sort_idx; -} - -static int depmod_modules_build_array(struct depmod *depmod) -{ - struct hash_iter module_iter; - const void *v; - int err; - - hash_iter_init(depmod->modules_by_name, &module_iter); - while (hash_iter_next(&module_iter, NULL, &v)) { - struct mod *mod = (struct mod *) v; - mod->idx = depmod->modules.count; - err = array_append(&depmod->modules, mod); - if (err < 0) - return err; - } - - return 0; -} - -static void depmod_modules_sort(struct depmod *depmod) -{ - char order_file[PATH_MAX], line[PATH_MAX]; - FILE *fp; - unsigned idx = 0, total = 0; - - snprintf(order_file, sizeof(order_file), "%s/modules.order", - depmod->cfg->dirname); - fp = fopen(order_file, "r"); - if (fp == NULL) { - WRN("could not open %s: %m\n", order_file); - return; - } - - while (fgets(line, sizeof(line), fp) != NULL) { - size_t len = strlen(line); - idx++; - if (len == 0) - continue; - if (line[len - 1] != '\n') { - ERR("%s:%u corrupted line misses '\\n'\n", - order_file, idx); - goto corrupted; - } - } - total = idx + 1; - idx = 0; - fseek(fp, 0, SEEK_SET); - while (fgets(line, sizeof(line), fp) != NULL) { - size_t len = strlen(line); - struct mod *mod; - - idx++; - if (len == 0) - continue; - line[len - 1] = '\0'; - - mod = hash_find(depmod->modules_by_uncrelpath, line); - if (mod == NULL) - continue; - mod->sort_idx = idx - total; - } - - array_sort(&depmod->modules, mod_cmp); - for (idx = 0; idx < depmod->modules.count; idx++) { - struct mod *m = depmod->modules.array[idx]; - m->idx = idx; - } - -corrupted: - fclose(fp); -} - -static int depmod_symbol_add(struct depmod *depmod, const char *name, - bool prefix_skipped, uint64_t crc, - const struct mod *owner) -{ - size_t namelen; - int err; - struct symbol *sym; - - if (!prefix_skipped && (name[0] == depmod->cfg->sym_prefix)) - name++; - - namelen = strlen(name) + 1; - sym = malloc(sizeof(struct symbol) + namelen); - if (sym == NULL) - return -ENOMEM; - - sym->owner = (struct mod *)owner; - sym->crc = crc; - memcpy(sym->name, name, namelen); - - err = hash_add(depmod->symbols, sym->name, sym); - if (err < 0) { - free(sym); - return err; - } - - DBG("add %p sym=%s, owner=%p %s\n", sym, sym->name, owner, - owner != NULL ? owner->path : ""); - - return 0; -} - -static struct symbol *depmod_symbol_find(const struct depmod *depmod, - const char *name) -{ - if (name[0] == '.') /* PPC64 needs this: .foo == foo */ - name++; - if (name[0] == depmod->cfg->sym_prefix) - name++; - return hash_find(depmod->symbols, name); -} - -static int depmod_load_modules(struct depmod *depmod) -{ - struct mod **itr, **itr_end; - - DBG("load symbols (%zd modules)\n", depmod->modules.count); - - itr = (struct mod **)depmod->modules.array; - itr_end = itr + depmod->modules.count; - for (; itr < itr_end; itr++) { - struct mod *mod = *itr; - struct kmod_list *l, *list = NULL; - int err = kmod_module_get_symbols(mod->kmod, &list); - if (err < 0) { - if (err == -ENOENT) - DBG("ignoring %s: no symbols\n", mod->path); - else - ERR("failed to load symbols from %s: %s\n", - mod->path, strerror(-err)); - goto load_info; - } - kmod_list_foreach(l, list) { - const char *name = kmod_module_symbol_get_symbol(l); - uint64_t crc = kmod_module_symbol_get_crc(l); - depmod_symbol_add(depmod, name, false, crc, mod); - } - kmod_module_symbols_free_list(list); - -load_info: - kmod_module_get_info(mod->kmod, &mod->info_list); - kmod_module_get_dependency_symbols(mod->kmod, - &mod->dep_sym_list); - kmod_module_unref(mod->kmod); - mod->kmod = NULL; - } - - DBG("loaded symbols (%zd modules, %u symbols)\n", - depmod->modules.count, hash_get_count(depmod->symbols)); - - return 0; -} - -static int depmod_load_module_dependencies(struct depmod *depmod, struct mod *mod) -{ - const struct cfg *cfg = depmod->cfg; - struct kmod_list *l; - - DBG("do dependencies of %s\n", mod->path); - kmod_list_foreach(l, mod->dep_sym_list) { - const char *name = kmod_module_dependency_symbol_get_symbol(l); - uint64_t crc = kmod_module_dependency_symbol_get_crc(l); - int bindtype = kmod_module_dependency_symbol_get_bind(l); - struct symbol *sym = depmod_symbol_find(depmod, name); - uint8_t is_weak = bindtype == KMOD_SYMBOL_WEAK; - - if (sym == NULL) { - DBG("%s needs (%c) unknown symbol %s\n", - mod->path, bindtype, name); - if (cfg->print_unknown && !is_weak) - WRN("%s needs unknown symbol %s\n", - mod->path, name); - continue; - } - - if (cfg->check_symvers && sym->crc != crc && !is_weak) { - DBG("symbol %s (%#"PRIx64") module %s (%#"PRIx64")\n", - sym->name, sym->crc, mod->path, crc); - if (cfg->print_unknown) - WRN("%s disagrees about version of symbol %s\n", - mod->path, name); - } - - mod_add_dependency(mod, sym); - } - - return 0; -} - -static int depmod_load_dependencies(struct depmod *depmod) -{ - struct mod **itr, **itr_end; - - DBG("load dependencies (%zd modules, %u symbols)\n", - depmod->modules.count, hash_get_count(depmod->symbols)); - - itr = (struct mod **)depmod->modules.array; - itr_end = itr + depmod->modules.count; - for (; itr < itr_end; itr++) { - struct mod *mod = *itr; - - if (mod->dep_sym_list == NULL) { - DBG("ignoring %s: no dependency symbols\n", mod->path); - continue; - } - - depmod_load_module_dependencies(depmod, mod); - } - - DBG("loaded dependencies (%zd modules, %u symbols)\n", - depmod->modules.count, hash_get_count(depmod->symbols)); - - return 0; -} - -static int dep_cmp(const void *pa, const void *pb) -{ - const struct mod *a = *(const struct mod **)pa; - const struct mod *b = *(const struct mod **)pb; - if (a->dep_loop == b->dep_loop) - return a->dep_sort_idx - b->dep_sort_idx; - else if (a->dep_loop) - return 1; - else if (b->dep_loop) - return -1; - return a->dep_sort_idx - b->dep_sort_idx; -} - -static void depmod_sort_dependencies(struct depmod *depmod) -{ - struct mod **itr, **itr_end; - itr = (struct mod **)depmod->modules.array; - itr_end = itr + depmod->modules.count; - for (; itr < itr_end; itr++) { - struct mod *m = *itr; - if (m->deps.count > 1) - array_sort(&m->deps, dep_cmp); - } -} - -static int depmod_calculate_dependencies(struct depmod *depmod) -{ - const struct mod **itrm; - uint16_t *users, *roots, *sorted; - uint16_t i, n_roots = 0, n_sorted = 0, n_mods = depmod->modules.count; - - users = malloc(sizeof(uint16_t) * n_mods * 3); - if (users == NULL) - return -ENOMEM; - roots = users + n_mods; - sorted = roots + n_mods; - - DBG("calculate dependencies and ordering (%hu modules)\n", n_mods); - - assert(depmod->modules.count < UINT16_MAX); - - /* populate modules users (how many modules uses it) */ - itrm = (const struct mod **)depmod->modules.array; - for (i = 0; i < n_mods; i++, itrm++) { - const struct mod *m = *itrm; - users[i] = m->users; - if (users[i] == 0) { - roots[n_roots] = i; - n_roots++; - } - } - - /* topological sort (outputs modules without users first) */ - while (n_roots > 0) { - const struct mod **itr_dst, **itr_dst_end; - struct mod *src; - uint16_t src_idx = roots[--n_roots]; - - src = depmod->modules.array[src_idx]; - src->dep_sort_idx = n_sorted; - sorted[n_sorted] = src_idx; - n_sorted++; - - itr_dst = (const struct mod **)src->deps.array; - itr_dst_end = itr_dst + src->deps.count; - for (; itr_dst < itr_dst_end; itr_dst++) { - const struct mod *dst = *itr_dst; - uint16_t dst_idx = dst->idx; - assert(users[dst_idx] > 0); - users[dst_idx]--; - if (users[dst_idx] == 0) { - roots[n_roots] = dst_idx; - n_roots++; - } - } - } - - if (n_sorted < n_mods) { - WRN("found %u modules in dependency cycles!\n", - n_mods - n_sorted); - for (i = 0; i < n_mods; i++) { - struct mod *m; - if (users[i] == 0) - continue; - m = depmod->modules.array[i]; - WRN("%s in dependency cycle!\n", m->path); - m->dep_loop = 1; - m->dep_sort_idx = INT32_MAX; - depmod->dep_loops++; - } - } - - depmod_sort_dependencies(depmod); - - DBG("calculated dependencies and ordering (%u loops, %hu modules)\n", - depmod->dep_loops, n_mods); - - free(users); - return 0; -} - -static int depmod_load(struct depmod *depmod) -{ - int err; - - err = depmod_load_modules(depmod); - if (err < 0) - return err; - - err = depmod_load_dependencies(depmod); - if (err < 0) - return err; - - err = depmod_calculate_dependencies(depmod); - if (err < 0) - return err; - - return 0; -} - -static size_t mod_count_all_dependencies(const struct mod *mod) -{ - size_t i, count = 0; - for (i = 0; i < mod->deps.count; i++) { - const struct mod *d = mod->deps.array[i]; - count += 1 + mod_count_all_dependencies(d); - } - return count; -} - -static int mod_fill_all_unique_dependencies(const struct mod *mod, const struct mod **deps, size_t n_deps, size_t *last) -{ - size_t i; - int err = 0; - for (i = 0; i < mod->deps.count; i++) { - const struct mod *d = mod->deps.array[i]; - size_t j; - uint8_t exists = 0; - - for (j = 0; j < *last; j++) { - if (deps[j] == d) { - exists = 1; - break; - } - } - - if (exists) - continue; - - if (*last >= n_deps) - return -ENOSPC; - deps[*last] = d; - (*last)++; - err = mod_fill_all_unique_dependencies(d, deps, n_deps, last); - if (err < 0) - break; - } - return err; -} - -static const struct mod **mod_get_all_sorted_dependencies(const struct mod *mod, size_t *n_deps) -{ - const struct mod **deps; - size_t last = 0; - - *n_deps = mod_count_all_dependencies(mod); - if (*n_deps == 0) - return NULL; - - deps = malloc(sizeof(struct mod *) * (*n_deps)); - if (deps == NULL) - return NULL; - - if (mod_fill_all_unique_dependencies(mod, deps, *n_deps, &last) < 0) { - free(deps); - return NULL; - } - - qsort(deps, last, sizeof(struct mod *), dep_cmp); - *n_deps = last; - return deps; -} - -static inline const char *mod_get_compressed_path(const struct mod *mod) -{ - if (mod->relpath != NULL) - return mod->relpath; - return mod->path; -} - -static int output_deps(struct depmod *depmod, FILE *out) -{ - size_t i; - - for (i = 0; i < depmod->modules.count; i++) { - const struct mod **deps, *mod = depmod->modules.array[i]; - const char *p = mod_get_compressed_path(mod); - size_t j, n_deps; - - if (mod->dep_loop) { - DBG("Ignored %s due dependency loops\n", p); - continue; - } - - fprintf(out, "%s:", p); - - if (mod->deps.count == 0) - goto end; - - deps = mod_get_all_sorted_dependencies(mod, &n_deps); - if (deps == NULL) { - ERR("could not get all sorted dependencies of %s\n", p); - goto end; - } - - for (j = 0; j < n_deps; j++) { - const struct mod *d = deps[j]; - if (d->dep_loop) { - DBG("Ignored %s (dependency of %s) " - "due dependency loops\n", - mod_get_compressed_path(d), p); - continue; - } - fprintf(out, " %s", mod_get_compressed_path(d)); - } - free(deps); - end: - putc('\n', out); - } - - return 0; -} - -static int output_deps_bin(struct depmod *depmod, FILE *out) -{ - struct index_node *idx; - size_t i; - - if (out == stdout) - return 0; - - idx = index_create(); - if (idx == NULL) - return -ENOMEM; - - for (i = 0; i < depmod->modules.count; i++) { - const struct mod **deps, *mod = depmod->modules.array[i]; - const char *p = mod_get_compressed_path(mod); - char *line; - size_t j, n_deps, linepos, linelen, slen; - int duplicate; - - if (mod->dep_loop) { - DBG("Ignored %s due dependency loops\n", p); - continue; - } - - deps = mod_get_all_sorted_dependencies(mod, &n_deps); - if (deps == NULL && n_deps > 0) { - ERR("could not get all sorted dependencies of %s\n", p); - continue; - } - - linelen = strlen(p) + 1; - for (j = 0; j < n_deps; j++) { - const struct mod *d = deps[j]; - if (d->dep_loop) { - DBG("Ignored %s (dependency of %s) " - "due dependency loops\n", - mod_get_compressed_path(d), p); - continue; - } - linelen += 1 + strlen(mod_get_compressed_path(d)); - } - - line = malloc(linelen + 1); - if (line == NULL) { - free(deps); - ERR("modules.deps.bin: out of memory\n"); - continue; - } - - linepos = 0; - slen = strlen(p); - memcpy(line + linepos, p, slen); - linepos += slen; - line[linepos] = ':'; - linepos++; - - for (j = 0; j < n_deps; j++) { - const struct mod *d = deps[j]; - const char *dp; - if (d->dep_loop) - continue; - line[linepos] = ' '; - linepos++; - - dp = mod_get_compressed_path(d); - slen = strlen(dp); - memcpy(line + linepos, dp, slen); - linepos += slen; - } - line[linepos] = '\0'; - - duplicate = index_insert(idx, mod->modname, line, mod->idx); - if (duplicate && depmod->cfg->warn_dups) - WRN("duplicate module deps:\n%s\n", line); - free(line); - free(deps); - } - - index_write(idx, out); - index_destroy(idx); - - return 0; -} - -static int output_aliases(struct depmod *depmod, FILE *out) -{ - size_t i; - - fputs("# Aliases extracted from modules themselves.\n", out); - - for (i = 0; i < depmod->modules.count; i++) { - const struct mod *mod = depmod->modules.array[i]; - struct kmod_list *l; - - kmod_list_foreach(l, mod->info_list) { - const char *key = kmod_module_info_get_key(l); - const char *value = kmod_module_info_get_value(l); - - if (!streq(key, "alias")) - continue; - - fprintf(out, "alias %s %s\n", value, mod->modname); - } - } - - return 0; -} - -static int output_aliases_bin(struct depmod *depmod, FILE *out) -{ - char buf[1024]; - struct index_node *idx; - size_t i; - - if (out == stdout) - return 0; - - idx = index_create(); - if (idx == NULL) - return -ENOMEM; - - for (i = 0; i < depmod->modules.count; i++) { - const struct mod *mod = depmod->modules.array[i]; - struct kmod_list *l; - - kmod_list_foreach(l, mod->info_list) { - const char *key = kmod_module_info_get_key(l); - const char *value = kmod_module_info_get_value(l); - const char *alias; - int duplicate; - - if (!streq(key, "alias")) - continue; - - alias = underscores2(value, buf, sizeof(buf)); - if (alias == NULL) - continue; - - duplicate = index_insert(idx, alias, mod->modname, - mod->idx); - if (duplicate && depmod->cfg->warn_dups) - WRN("duplicate module alias:\n%s %s\n", - alias, mod->modname); - } - } - - index_write(idx, out); - index_destroy(idx); - - return 0; -} - -static int output_softdeps(struct depmod *depmod, FILE *out) -{ - size_t i; - - fputs("# Soft dependencies extracted from modules themselves.\n", out); - fputs("# Copy, with a .conf extension, to /etc/modprobe.d to use " - "it with modprobe.\n", out); - - for (i = 0; i < depmod->modules.count; i++) { - const struct mod *mod = depmod->modules.array[i]; - struct kmod_list *l; - - kmod_list_foreach(l, mod->info_list) { - const char *key = kmod_module_info_get_key(l); - const char *value = kmod_module_info_get_value(l); - - if (!streq(key, "softdep")) - continue; - - fprintf(out, "softdep %s %s\n", mod->modname, value); - } - } - - return 0; -} - -static int output_symbols(struct depmod *depmod, FILE *out) -{ - struct hash_iter iter; - const void *v; - - fputs("# Aliases for symbols, used by symbol_request().\n", out); - - hash_iter_init(depmod->symbols, &iter); - - while (hash_iter_next(&iter, NULL, &v)) { - const struct symbol *sym = v; - if (sym->owner == NULL) - continue; - - fprintf(out, "alias symbol:%s %s\n", - sym->name, sym->owner->modname); - } - - return 0; -} - -static int output_symbols_bin(struct depmod *depmod, FILE *out) -{ - struct index_node *idx; - char alias[1024]; - size_t baselen = sizeof("symbol:") - 1; - struct hash_iter iter; - const void *v; - - if (out == stdout) - return 0; - - idx = index_create(); - if (idx == NULL) - return -ENOMEM; - - memcpy(alias, "symbol:", baselen); - hash_iter_init(depmod->symbols, &iter); - - while (hash_iter_next(&iter, NULL, &v)) { - int duplicate; - const struct symbol *sym = v; - - if (sym->owner == NULL) - continue; - - strcpy(alias + baselen, sym->name); - duplicate = index_insert(idx, alias, sym->owner->modname, - sym->owner->idx); - - if (duplicate && depmod->cfg->warn_dups) - WRN("duplicate module syms:\n%s %s\n", - alias, sym->owner->modname); - } - - index_write(idx, out); - index_destroy(idx); - - return 0; -} - -static int output_builtin_bin(struct depmod *depmod, FILE *out) -{ - FILE *in; - struct index_node *idx; - char infile[PATH_MAX], line[PATH_MAX], modname[PATH_MAX]; - - if (out == stdout) - return 0; - - snprintf(infile, sizeof(infile), "%s/modules.builtin", - depmod->cfg->dirname); - in = fopen(infile, "r"); - if (in == NULL) { - WRN("could not open %s: %m\n", infile); - return 0; - } - - idx = index_create(); - if (idx == NULL) { - fclose(in); - return -ENOMEM; - } - - while (fgets(line, sizeof(line), in) != NULL) { - if (!isalpha(line[0])) { - ERR("Invalid modules.builtin line: %s\n", line); - continue; - } - - path_to_modname(line, modname, NULL); - index_insert(idx, modname, "", 0); - } - - index_write(idx, out); - index_destroy(idx); - fclose(in); - - return 0; -} - -static int output_devname(struct depmod *depmod, FILE *out) -{ - size_t i; - - fputs("# Device nodes to trigger on-demand module loading.\n", out); - - for (i = 0; i < depmod->modules.count; i++) { - const struct mod *mod = depmod->modules.array[i]; - struct kmod_list *l; - const char *devname = NULL; - char type = '\0'; - unsigned int major = 0, minor = 0; - - kmod_list_foreach(l, mod->info_list) { - const char *key = kmod_module_info_get_key(l); - const char *value = kmod_module_info_get_value(l); - unsigned int maj, min; - - if (!streq(key, "alias")) - continue; - - if (strstartswith(value, "devname:")) - devname = value + sizeof("devname:") - 1; - else if (sscanf(value, "char-major-%u-%u", - &maj, &min) == 2) { - type = 'c'; - major = maj; - minor = min; - } else if (sscanf(value, "block-major-%u-%u", - &maj, &min) == 2) { - type = 'b'; - major = maj; - minor = min; - } - - if (type != '\0' && devname != NULL) { - fprintf(out, "%s %s %c%u:%u\n", mod->modname, - devname, type, major, minor); - break; - } - } - } - - return 0; -} - -static int depmod_output(struct depmod *depmod, FILE *out) -{ - static const struct depfile { - const char *name; - int (*cb)(struct depmod *depmod, FILE *out); - } *itr, depfiles[] = { - { "modules.dep", output_deps }, - { "modules.dep.bin", output_deps_bin }, - { "modules.alias", output_aliases }, - { "modules.alias.bin", output_aliases_bin }, - { "modules.softdep", output_softdeps }, - { "modules.symbols", output_symbols }, - { "modules.symbols.bin", output_symbols_bin }, - { "modules.builtin.bin", output_builtin_bin }, - { "modules.devname", output_devname }, - { } - }; - const char *dname = depmod->cfg->dirname; - int dfd, err = 0; - - if (out != NULL) - dfd = -1; - else { - dfd = open(dname, O_RDONLY); - if (dfd < 0) { - err = -errno; - CRIT("could not open directory %s: %m\n", dname); - return err; - } - } - - for (itr = depfiles; itr->name != NULL; itr++) { - FILE *fp = out; - char tmp[NAME_MAX] = ""; - int r, ferr; - - if (fp == NULL) { - int flags = O_CREAT | O_TRUNC | O_WRONLY; - int mode = 0644; - int fd; - - snprintf(tmp, sizeof(tmp), "%s.tmp", itr->name); - fd = openat(dfd, tmp, flags, mode); - if (fd < 0) { - ERR("openat(%s, %s, %o, %o): %m\n", - dname, tmp, flags, mode); - continue; - } - fp = fdopen(fd, "wb"); - if (fp == NULL) { - ERR("fdopen(%d=%s/%s): %m\n", fd, dname, tmp); - close(fd); - continue; - } - } - - r = itr->cb(depmod, fp); - if (fp == out) - continue; - - ferr = ferror(fp) | fclose(fp); - - if (r < 0) { - if (unlinkat(dfd, tmp, 0) != 0) - ERR("unlinkat(%s, %s): %m\n", dname, tmp); - - ERR("Could not write index '%s': %s\n", itr->name, - strerror(-r)); - err = -errno; - break; - } - - unlinkat(dfd, itr->name, 0); - if (renameat(dfd, tmp, dfd, itr->name) != 0) { - err = -errno; - CRIT("renameat(%s, %s, %s, %s): %m\n", - dname, tmp, dname, itr->name); - break; - } - - if (ferr) { - err = -ENOSPC; - ERR("Could not create index '%s'. Output is truncated: %s\n", - itr->name, strerror(-err)); - break; - } - } - - if (dfd >= 0) - close(dfd); - - return err; -} - -static void depmod_add_fake_syms(struct depmod *depmod) -{ - /* __this_module is magic inserted by kernel loader. */ - depmod_symbol_add(depmod, "__this_module", true, 0, NULL); - /* On S390, this is faked up too */ - depmod_symbol_add(depmod, "_GLOBAL_OFFSET_TABLE_", true, 0, NULL); -} - -static int depmod_load_symvers(struct depmod *depmod, const char *filename) -{ - char line[10240]; - FILE *fp; - unsigned int linenum = 0; - - fp = fopen(filename, "r"); - if (fp == NULL) { - int err = -errno; - DBG("load symvers: %s: %m\n", filename); - return err; - } - DBG("load symvers: %s\n", filename); - - /* eg. "0xb352177e\tfind_first_bit\tvmlinux\tEXPORT_SYMBOL" */ - while (fgets(line, sizeof(line), fp) != NULL) { - const char *ver, *sym, *where; - char *verend; - uint64_t crc; - - linenum++; - - ver = strtok(line, " \t"); - sym = strtok(NULL, " \t"); - where = strtok(NULL, " \t"); - if (!ver || !sym || !where) - continue; - - if (!streq(where, "vmlinux")) - continue; - - crc = strtoull(ver, &verend, 16); - if (verend[0] != '\0') { - ERR("%s:%u Invalid symbol version %s: %m\n", - filename, linenum, ver); - continue; - } - - depmod_symbol_add(depmod, sym, false, crc, NULL); - } - depmod_add_fake_syms(depmod); - - DBG("loaded symvers: %s\n", filename); - - fclose(fp); - return 0; -} - -static int depmod_load_system_map(struct depmod *depmod, const char *filename) -{ - const char ksymstr[] = "__ksymtab_"; - const size_t ksymstr_len = sizeof(ksymstr) - 1; - char line[10240]; - FILE *fp; - unsigned int linenum = 0; - - fp = fopen(filename, "r"); - if (fp == NULL) { - int err = -errno; - DBG("load System.map: %s: %m\n", filename); - return err; - } - DBG("load System.map: %s\n", filename); - - /* eg. c0294200 R __ksymtab_devfs_alloc_devnum */ - while (fgets(line, sizeof(line), fp) != NULL) { - char *p, *end; - - linenum++; - - p = strchr(line, ' '); - if (p == NULL) - goto invalid_syntax; - p++; - p = strchr(p, ' '); - if (p == NULL) - goto invalid_syntax; - p++; - - /* skip prefix */ - if (p[0] == depmod->cfg->sym_prefix) - p++; - - /* Covers gpl-only and normal symbols. */ - if (strncmp(p, ksymstr, ksymstr_len) != 0) - continue; - - end = strchr(p, '\n'); - if (end != NULL) - *end = '\0'; - - depmod_symbol_add(depmod, p + ksymstr_len, true, 0, NULL); - continue; - - invalid_syntax: - ERR("%s:%u: invalid line: %s\n", filename, linenum, line); - } - depmod_add_fake_syms(depmod); - - DBG("loaded System.map: %s\n", filename); - - fclose(fp); - return 0; -} - - -static int depfile_up_to_date_dir(DIR *d, time_t mtime, size_t baselen, char *path) -{ - struct dirent *de; - int err = 1, dfd = dirfd(d); - - while ((de = readdir(d)) != NULL) { - const char *name = de->d_name; - size_t namelen; - struct stat st; - - if (name[0] == '.' && (name[1] == '\0' || - (name[1] == '.' && name[2] == '\0'))) - continue; - if (streq(name, "build") || streq(name, "source")) - continue; - namelen = strlen(name); - if (baselen + namelen + 2 >= PATH_MAX) { - path[baselen] = '\0'; - ERR("path is too long %s%s\n", path, name); - continue; - } - - if (fstatat(dfd, name, &st, 0) < 0) { - ERR("fstatat(%d, %s): %m\n", dfd, name); - continue; - } - - if (S_ISDIR(st.st_mode)) { - int fd; - DIR *subdir; - memcpy(path + baselen, name, namelen + 1); - if (baselen + namelen + 2 + NAME_MAX >= PATH_MAX) { - ERR("directory path is too long %s\n", path); - continue; - } - fd = openat(dfd, name, O_RDONLY); - if (fd < 0) { - ERR("openat(%d, %s, O_RDONLY): %m\n", - dfd, name); - continue; - } - subdir = fdopendir(fd); - if (subdir == NULL) { - ERR("fdopendir(%d): %m\n", fd); - close(fd); - continue; - } - path[baselen + namelen] = '/'; - path[baselen + namelen + 1] = '\0'; - err = depfile_up_to_date_dir(subdir, mtime, - baselen + namelen + 1, - path); - closedir(subdir); - } else if (S_ISREG(st.st_mode)) { - if (!path_ends_with_kmod_ext(name, namelen)) - continue; - - memcpy(path + baselen, name, namelen + 1); - err = st.st_mtime <= mtime; - if (err == 0) { - DBG("%s %"PRIu64" is newer than %"PRIu64"\n", - path, (uint64_t)st.st_mtime, - (uint64_t)mtime); - } - } else { - ERR("unsupported file type %s: %o\n", - path, st.st_mode & S_IFMT); - continue; - } - - if (err == 0) - break; /* outdated! */ - else if (err < 0) { - path[baselen + namelen] = '\0'; - ERR("failed %s: %s\n", path, strerror(-err)); - err = 1; /* ignore errors */ - } - } - - return err; -} - -/* uptodate: 1, outdated: 0, errors < 0 */ -static int depfile_up_to_date(const char *dirname) -{ - char path[PATH_MAX]; - DIR *d = opendir(dirname); - struct stat st; - size_t baselen; - int err; - if (d == NULL) { - err = -errno; - ERR("could not open directory %s: %m\n", dirname); - return err; - } - - if (fstatat(dirfd(d), "modules.dep", &st, 0) != 0) { - err = -errno; - ERR("could not fstatat(%s, modules.dep): %m\n", dirname); - closedir(d); - return err; - } - - baselen = strlen(dirname); - memcpy(path, dirname, baselen); - path[baselen] = '/'; - baselen++; - path[baselen] = '\0'; - - err = depfile_up_to_date_dir(d, st.st_mtime, baselen, path); - closedir(d); - return err; -} - -static int is_version_number(const char *version) -{ - unsigned int d1, d2; - return (sscanf(version, "%u.%u", &d1, &d2) == 2); -} - -static int do_depmod(int argc, char *argv[]) -{ - FILE *out = NULL; - int err = 0, all = 0, maybe_all = 0, n_config_paths = 0; - char *root = NULL; - const char **config_paths = NULL; - const char *system_map = NULL; - const char *module_symvers = NULL; - const char *null_kmod_config = NULL; - struct utsname un; - struct kmod_ctx *ctx = NULL; - struct cfg cfg; - struct depmod depmod; - - memset(&cfg, 0, sizeof(cfg)); - memset(&depmod, 0, sizeof(depmod)); - - for (;;) { - int c, idx = 0; - c = getopt_long(argc, argv, cmdopts_s, cmdopts, &idx); - if (c == -1) - break; - switch (c) { - case 'a': - all = 1; - break; - case 'A': - maybe_all = 1; - break; - case 'b': - root = path_make_absolute_cwd(optarg); - break; - case 'C': { - size_t bytes = sizeof(char *) * (n_config_paths + 2); - void *tmp = realloc(config_paths, bytes); - if (!tmp) { - fputs("Error: out-of-memory\n", stderr); - goto cmdline_failed; - } - config_paths = tmp; - config_paths[n_config_paths] = optarg; - n_config_paths++; - config_paths[n_config_paths] = NULL; - break; - } - case 'E': - module_symvers = optarg; - cfg.check_symvers = 1; - break; - case 'F': - system_map = optarg; - break; - case 'e': - cfg.print_unknown = 1; - break; - case 'v': - verbose++; - break; - case 'n': - out = stdout; - break; - case 'P': - if (optarg[1] != '\0') { - CRIT("-P only takes a single char\n"); - goto cmdline_failed; - } - cfg.sym_prefix = optarg[0]; - break; - case 'w': - cfg.warn_dups = 1; - break; - case 'u': - case 'q': - case 'r': - case 'm': - if (idx > 0) - WRN("Ignored deprecated option --%s\n", - cmdopts[idx].name); - else - WRN("Ignored deprecated option -%c\n", c); - - break; - case 'h': - help(); - free(config_paths); - return EXIT_SUCCESS; - case 'V': - puts(PACKAGE " version " VERSION); - free(config_paths); - return EXIT_SUCCESS; - case '?': - goto cmdline_failed; - default: - ERR("unexpected getopt_long() value '%c'.\n", c); - goto cmdline_failed; - } - } - - if (optind < argc && is_version_number(argv[optind])) { - cfg.kversion = argv[optind]; - optind++; - } else { - if (uname(&un) < 0) { - CRIT("uname() failed: %s\n", strerror(errno)); - goto cmdline_failed; - } - cfg.kversion = un.release; - } - - cfg.dirnamelen = snprintf(cfg.dirname, PATH_MAX, - "%s/lib/modules/%s", - root == NULL ? "" : root, cfg.kversion); - - if (optind == argc) - all = 1; - - if (maybe_all) { - if (out == stdout) - goto done; - /* ignore up-to-date errors (< 0) */ - if (depfile_up_to_date(cfg.dirname) == 1) { - DBG("%s/modules.dep is up to date!\n", cfg.dirname); - goto done; - } - DBG("%s/modules.dep is outdated, do -a\n", cfg.dirname); - all = 1; - } - - ctx = kmod_new(cfg.dirname, &null_kmod_config); - if (ctx == NULL) { - CRIT("kmod_new(\"%s\", {NULL}) failed: %m\n", cfg.dirname); - goto cmdline_failed; - } - - log_setup_kmod_log(ctx, verbose); - - err = depmod_init(&depmod, &cfg, ctx); - if (err < 0) { - CRIT("depmod_init: %s\n", strerror(-err)); - goto depmod_init_failed; - } - ctx = NULL; /* owned by depmod */ - - if (module_symvers != NULL) { - err = depmod_load_symvers(&depmod, module_symvers); - if (err < 0) { - CRIT("could not load %s: %s\n", module_symvers, - strerror(-err)); - goto cmdline_failed; - } - } else if (system_map != NULL) { - err = depmod_load_system_map(&depmod, system_map); - if (err < 0) { - CRIT("could not load %s: %s\n", system_map, - strerror(-err)); - goto cmdline_failed; - } - } else if (cfg.print_unknown) { - WRN("-e needs -E or -F\n"); - cfg.print_unknown = 0; - } - - if (all) { - err = cfg_load(&cfg, config_paths); - if (err < 0) { - CRIT("could not load configuration files\n"); - goto cmdline_modules_failed; - } - err = depmod_modules_search(&depmod); - if (err < 0) { - CRIT("could not search modules: %s\n", strerror(-err)); - goto cmdline_modules_failed; - } - } else { - int i; - - for (i = optind; i < argc; i++) { - const char *path = argv[i]; - struct kmod_module *mod; - - if (path[0] != '/') { - CRIT("%s: not absolute path.\n", path); - goto cmdline_modules_failed; - } - - err = kmod_module_new_from_path(depmod.ctx, path, &mod); - if (err < 0) { - CRIT("could not create module %s: %s\n", - path, strerror(-err)); - goto cmdline_modules_failed; - } - - err = depmod_module_add(&depmod, mod); - if (err < 0) { - CRIT("could not add module %s: %s\n", - path, strerror(-err)); - kmod_module_unref(mod); - goto cmdline_modules_failed; - } - } - } - - err = depmod_modules_build_array(&depmod); - if (err < 0) { - CRIT("could not build module array: %s\n", - strerror(-err)); - goto cmdline_modules_failed; - } - - depmod_modules_sort(&depmod); - err = depmod_load(&depmod); - if (err < 0) - goto cmdline_modules_failed; - - err = depmod_output(&depmod, out); - -done: - depmod_shutdown(&depmod); - cfg_free(&cfg); - free(config_paths); - return err >= 0 ? EXIT_SUCCESS : EXIT_FAILURE; - -cmdline_modules_failed: - depmod_shutdown(&depmod); -depmod_init_failed: - if (ctx != NULL) - kmod_unref(ctx); -cmdline_failed: - cfg_free(&cfg); - free(config_paths); - free(root); - return EXIT_FAILURE; -} - -const struct kmod_cmd kmod_cmd_compat_depmod = { - .name = "depmod", - .cmd = do_depmod, - .help = "compat depmod command", -}; diff --git a/tools/insmod.c b/tools/insmod.c deleted file mode 100644 index a795d89..0000000 --- a/tools/insmod.c +++ /dev/null @@ -1,158 +0,0 @@ -/* - * kmod-insmod - insert modules into linux kernel using libkmod. - * - * Copyright (C) 2011-2013 ProFUSION embedded systems - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include -#include -#include -#include -#include -#include "libkmod.h" - -#include "kmod.h" - -static const char cmdopts_s[] = "psfVh"; -static const struct option cmdopts[] = { - {"version", no_argument, 0, 'V'}, - {"help", no_argument, 0, 'h'}, - {NULL, 0, 0, 0} -}; - -static void help(void) -{ - printf("Usage:\n" - "\t%s [options] filename [args]\n" - "Options:\n" - "\t-V, --version show version\n" - "\t-h, --help show this help\n", - program_invocation_short_name); -} - -static const char *mod_strerror(int err) -{ - switch (err) { - case ENOEXEC: - return "Invalid module format"; - case ENOENT: - return "Unknown symbol in module"; - case ESRCH: - return "Module has wrong symbol version"; - case EINVAL: - return "Invalid parameters"; - default: - return strerror(err); - } -} - -static int do_insmod(int argc, char *argv[]) -{ - struct kmod_ctx *ctx; - struct kmod_module *mod; - const char *filename; - char *opts = NULL; - size_t optslen = 0; - int i, err; - const char *null_config = NULL; - - for (;;) { - int c, idx = 0; - c = getopt_long(argc, argv, cmdopts_s, cmdopts, &idx); - if (c == -1) - break; - switch (c) { - case 'p': - case 's': - case 'f': - /* ignored, for compatibility only */ - break; - case 'h': - help(); - return EXIT_SUCCESS; - case 'V': - puts(PACKAGE " version " VERSION); - return EXIT_SUCCESS; - case '?': - return EXIT_FAILURE; - default: - ERR("unexpected getopt_long() value '%c'.\n", - c); - return EXIT_FAILURE; - } - } - - if (optind >= argc) { - ERR("missing filename.\n"); - return EXIT_FAILURE; - } - - filename = argv[optind]; - if (strcmp(filename, "-") == 0) { - ERR("this tool does not support loading from stdin!\n"); - return EXIT_FAILURE; - } - - for (i = optind + 1; i < argc; i++) { - size_t len = strlen(argv[i]); - void *tmp = realloc(opts, optslen + len + 2); - if (tmp == NULL) { - ERR("out of memory\n"); - free(opts); - return EXIT_FAILURE; - } - opts = tmp; - if (optslen > 0) { - opts[optslen] = ' '; - optslen++; - } - memcpy(opts + optslen, argv[i], len); - optslen += len; - opts[optslen] = '\0'; - } - - ctx = kmod_new(NULL, &null_config); - if (!ctx) { - ERR("kmod_new() failed!\n"); - free(opts); - return EXIT_FAILURE; - } - - err = kmod_module_new_from_path(ctx, filename, &mod); - if (err < 0) { - ERR("could not load module %s: %s\n", filename, - strerror(-err)); - goto end; - } - - err = kmod_module_insert_module(mod, 0, opts); - if (err < 0) { - ERR("could not insert module %s: %s\n", filename, - mod_strerror(-err)); - } - kmod_module_unref(mod); - -end: - kmod_unref(ctx); - free(opts); - return err >= 0 ? EXIT_SUCCESS : EXIT_FAILURE; -} - -const struct kmod_cmd kmod_cmd_compat_insmod = { - .name = "insmod", - .cmd = do_insmod, - .help = "compat insmod command", -}; diff --git a/tools/kmod-depmod.c b/tools/kmod-depmod.c new file mode 100644 index 0000000..1871e18 --- /dev/null +++ b/tools/kmod-depmod.c @@ -0,0 +1,2774 @@ +/* + * kmod-depmod - calculate modules.dep using libkmod. + * + * Copyright (C) 2011-2012 ProFUSION embedded systems + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +#include "libkmod.h" +#include "libkmod-array.h" +#include "libkmod-hash.h" +#include "libkmod-util.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define DEFAULT_VERBOSE LOG_WARNING +static int verbose = DEFAULT_VERBOSE; + +static const struct kmod_ext { + const char *ext; + size_t len; +} kmod_exts[] = { + {".ko", sizeof(".ko") - 1}, +#ifdef ENABLE_ZLIB + {".ko.gz", sizeof(".ko.gz") - 1}, +#endif +#ifdef ENABLE_XZ + {".ko.xz", sizeof(".ko.xz") - 1}, +#endif + {NULL, 0}, +}; + +static const char CFG_BUILTIN_KEY[] = "built-in"; +static const char *default_cfg_paths[] = { + "/run/depmod.d", + SYSCONFDIR "/depmod.d", + ROOTPREFIX "/lib/depmod.d", + NULL +}; + +static const char cmdopts_s[] = "aAb:C:E:F:euqrvnP:wmVh"; +static const struct option cmdopts[] = { + {"all", no_argument, 0, 'a'}, + {"quick", no_argument, 0, 'A'}, + {"basedir", required_argument, 0, 'b'}, + {"config", required_argument, 0, 'C'}, + {"symvers", required_argument, 0, 'E'}, + {"filesyms", required_argument, 0, 'F'}, + {"errsyms", no_argument, 0, 'e'}, + {"unresolved-error", no_argument, 0, 'u'}, /* deprecated */ + {"quiet", no_argument, 0, 'q'}, /* deprecated */ + {"root", no_argument, 0, 'r'}, /* deprecated */ + {"verbose", no_argument, 0, 'v'}, + {"show", no_argument, 0, 'n'}, + {"dry-run", no_argument, 0, 'n'}, + {"symbol-prefix", no_argument, 0, 'P'}, + {"warn", no_argument, 0, 'w'}, + {"map", no_argument, 0, 'm'}, /* deprecated */ + {"version", no_argument, 0, 'V'}, + {"help", no_argument, 0, 'h'}, + {NULL, 0, 0, 0} +}; + +static void help(const char *progname) +{ + fprintf(stderr, + "Usage:\n" + "\t%s -[aA] [options] [forced_version]\n" + "\n" + "If no arguments (except options) are given, \"depmod -a\" is assumed\n" + "\n" + "depmod will output a dependency list suitable for the modprobe utility.\n" + "\n" + "Options:\n" + "\t-a, --all Probe all modules\n" + "\t-A, --quick Only does the work if there's a new module\n" + "\t-e, --errsyms Report not supplied symbols\n" + "\t-n, --show Write the dependency file on stdout only\n" + "\t-P, --symbol-prefix Architecture symbol prefix\n" + "\t-C, --config=PATH Read configuration from PATH\n" + "\t-v, --verbose Enable verbose mode\n" + "\t-w, --warn Warn on duplicates\n" + "\t-V, --version show version\n" + "\t-h, --help show this help\n" + "\n" + "The following options are useful for people managing distributions:\n" + "\t-b, --basedir=DIR Use an image of a module tree.\n" + "\t-F, --filesyms=FILE Use the file instead of the\n" + "\t current kernel symbols.\n" + "\t-E, --symvers=FILE Use Module.symvers file to check\n" + "\t symbol versions.\n", + progname); +} + +static inline void _show(const char *fmt, ...) +{ + va_list args; + + if (verbose <= DEFAULT_VERBOSE) + return; + + va_start(args, fmt); + vfprintf(stdout, fmt, args); + fflush(stdout); + va_end(args); +} + +static inline void _log(int prio, const char *fmt, ...) +{ + const char *prioname; + char buf[32], *msg; + va_list args; + + if (prio > verbose) + return; + + va_start(args, fmt); + if (vasprintf(&msg, fmt, args) < 0) + msg = NULL; + va_end(args); + if (msg == NULL) + return; + + switch (prio) { + case LOG_CRIT: + prioname = "FATAL"; + break; + case LOG_ERR: + prioname = "ERROR"; + break; + case LOG_WARNING: + prioname = "WARNING"; + break; + case LOG_NOTICE: + prioname = "NOTICE"; + break; + case LOG_INFO: + prioname = "INFO"; + break; + case LOG_DEBUG: + prioname = "DEBUG"; + break; + default: + snprintf(buf, sizeof(buf), "LOG-%03d", prio); + prioname = buf; + } + + fprintf(stderr, "%s: %s", prioname, msg); + free(msg); + + if (prio <= LOG_CRIT) + exit(EXIT_FAILURE); +} +#define CRIT(...) _log(LOG_CRIT, __VA_ARGS__) +#define ERR(...) _log(LOG_ERR, __VA_ARGS__) +#define WRN(...) _log(LOG_WARNING, __VA_ARGS__) +#define INF(...) _log(LOG_INFO, __VA_ARGS__) +#define DBG(...) _log(LOG_DEBUG, __VA_ARGS__) +#define SHOW(...) _show(__VA_ARGS__) + + +/* binary index write *************************************************/ +#include +#include "macro.h" +/* BEGIN: code from module-init-tools/index.c just modified to compile here. + * + * Original copyright: + * index.c: module index file shared functions for modprobe and depmod + * Copyright (C) 2008 Alan Jenkins . + * + * These programs are free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with these programs. If not, see . + */ + +/* Integers are stored as 32 bit unsigned in "network" order, i.e. MSB first. + All files start with a magic number. + + Magic spells "BOOTFAST". Second one used on newer versioned binary files. + */ +/* #define INDEX_MAGIC_OLD 0xB007FA57 */ +#define INDEX_MAGIC 0xB007F457 + +/* We use a version string to keep track of changes to the binary format + * This is stored in the form: INDEX_MAJOR (hi) INDEX_MINOR (lo) just in + * case we ever decide to have minor changes that are not incompatible. + */ + +#define INDEX_VERSION_MAJOR 0x0002 +#define INDEX_VERSION_MINOR 0x0001 +#define INDEX_VERSION ((INDEX_VERSION_MAJOR<<16)|INDEX_VERSION_MINOR) + +/* The index file maps keys to values. Both keys and values are ASCII strings. + Each key can have multiple values. Values are sorted by an integer priority. + + The reader also implements a wildcard search (including range expressions) + where the keys in the index are treated as patterns. + This feature is required for module aliases. +*/ + +/* Implementation is based on a radix tree, or "trie". + Each arc from parent to child is labelled with a character. + Each path from the root represents a string. + + == Example strings == + + ask + ate + on + once + one + + == Key == + + Normal node + * Marked node, representing a key and it's values. + + + + |-a-+-s-+-k-* + | | + | `-t-+-e-* + | + `-o-+-n-*-c-+-e-* + | + `-e-* + + Naive implementations tend to be very space inefficient; child pointers + are stored in arrays indexed by character, but most child pointers are null. + + Our implementation uses a scheme described by Wikipedia as a Patrica trie, + + "easiest to understand as a space-optimized trie where + each node with only one child is merged with its child" + + + + |-a-+-sk-* + | | + | `-te-* + | + `-on-*-ce-* + | + `-e-* + + We still use arrays of child pointers indexed by a single character; + the remaining characters of the label are stored as a "prefix" in the child. + + The paper describing the original Patrica trie works on individiual bits - + each node has a maximum of two children, which increases space efficiency. + However for this application it is simpler to use the ASCII character set. + Since the index file is read-only, it can be compressed by omitting null + child pointers at the start and end of arrays. +*/ + +#define INDEX_PRIORITY_MIN UINT32_MAX + +struct index_value { + struct index_value *next; + unsigned int priority; + char value[0]; +}; + +/* In-memory index (depmod only) */ + +#define INDEX_CHILDMAX 128 +struct index_node { + char *prefix; /* path compression */ + struct index_value *values; + unsigned char first; /* range of child nodes */ + unsigned char last; + struct index_node *children[INDEX_CHILDMAX]; /* indexed by character */ +}; + +/* Disk format: + + uint32_t magic = INDEX_MAGIC; + uint32_t version = INDEX_VERSION; + uint32_t root_offset; + + (node_offset & INDEX_NODE_MASK) specifies the file offset of nodes: + + char[] prefix; // nul terminated + + char first; + char last; + uint32_t children[last - first + 1]; + + uint32_t value_count; + struct { + uint32_t priority; + char[] value; // nul terminated + } values[value_count]; + + (node_offset & INDEX_NODE_FLAGS) indicates which fields are present. + Empty prefixes are omitted, leaf nodes omit the three child-related fields. + + This could be optimised further by adding a sparse child format + (indicated using a new flag). + */ + +/* Format of node offsets within index file */ +enum node_offset { + INDEX_NODE_FLAGS = 0xF0000000, /* Flags in high nibble */ + INDEX_NODE_PREFIX = 0x80000000, + INDEX_NODE_VALUES = 0x40000000, + INDEX_NODE_CHILDS = 0x20000000, + + INDEX_NODE_MASK = 0x0FFFFFFF, /* Offset value */ +}; + +static struct index_node *index_create(void) +{ + struct index_node *node; + + node = NOFAIL(calloc(sizeof(struct index_node), 1)); + node->prefix = NOFAIL(strdup("")); + node->first = INDEX_CHILDMAX; + + return node; +} + +static void index_values_free(struct index_value *values) +{ + while (values) { + struct index_value *value = values; + + values = value->next; + free(value); + } +} + +static void index_destroy(struct index_node *node) +{ + int c; + + for (c = node->first; c <= node->last; c++) { + struct index_node *child = node->children[c]; + + if (child) + index_destroy(child); + } + index_values_free(node->values); + free(node->prefix); + free(node); +} + +static void index__checkstring(const char *str) +{ + int i; + + for (i = 0; str[i]; i++) { + int ch = str[i]; + + if (ch >= INDEX_CHILDMAX) + CRIT("Module index: bad character '%c'=0x%x - only 7-bit ASCII is supported:" + "\n%s\n", (char) ch, (int) ch, str); + } +} + +static int index_add_value(struct index_value **values, + const char *value, unsigned int priority) +{ + struct index_value *v; + int duplicate = 0; + int len; + + /* report the presence of duplicate values */ + for (v = *values; v; v = v->next) { + if (streq(v->value, value)) + duplicate = 1; + } + + /* find position to insert value */ + while (*values && (*values)->priority < priority) + values = &(*values)->next; + + len = strlen(value); + v = NOFAIL(calloc(sizeof(struct index_value) + len + 1, 1)); + v->next = *values; + v->priority = priority; + memcpy(v->value, value, len + 1); + *values = v; + + return duplicate; +} + +static int index_insert(struct index_node *node, const char *key, + const char *value, unsigned int priority) +{ + int i = 0; /* index within str */ + int ch; + + index__checkstring(key); + index__checkstring(value); + + while(1) { + int j; /* index within node->prefix */ + + /* Ensure node->prefix is a prefix of &str[i]. + If it is not already, then we must split node. */ + for (j = 0; node->prefix[j]; j++) { + ch = node->prefix[j]; + + if (ch != key[i+j]) { + char *prefix = node->prefix; + struct index_node *n; + + /* New child is copy of node with prefix[j+1..N] */ + n = NOFAIL(calloc(sizeof(struct index_node), 1)); + memcpy(n, node, sizeof(struct index_node)); + n->prefix = NOFAIL(strdup(&prefix[j+1])); + + /* Parent has prefix[0..j], child at prefix[j] */ + memset(node, 0, sizeof(struct index_node)); + prefix[j] = '\0'; + node->prefix = prefix; + node->first = ch; + node->last = ch; + node->children[ch] = n; + + break; + } + } + /* j is now length of node->prefix */ + i += j; + + ch = key[i]; + if(ch == '\0') + return index_add_value(&node->values, value, priority); + + if (!node->children[ch]) { + struct index_node *child; + + if (ch < node->first) + node->first = ch; + if (ch > node->last) + node->last = ch; + node->children[ch] = NOFAIL(calloc(sizeof(struct index_node), 1)); + + child = node->children[ch]; + child->prefix = NOFAIL(strdup(&key[i+1])); + child->first = INDEX_CHILDMAX; + index_add_value(&child->values, value, priority); + + return 0; + } + + /* Descend into child node and continue */ + node = node->children[ch]; + i++; + } +} + +static int index__haschildren(const struct index_node *node) +{ + return node->first < INDEX_CHILDMAX; +} + +/* Recursive post-order traversal + + Pre-order would make for better read-side buffering / readahead / caching. + (post-order means you go backwards in the file as you descend the tree). + However, index reading is already fast enough. + Pre-order is simpler for writing, and depmod is already slow. + */ +static uint32_t index_write__node(const struct index_node *node, FILE *out) +{ + uint32_t *child_offs = NULL; + int child_count = 0; + long offset; + + if (!node) + return 0; + + /* Write children and save their offsets */ + if (index__haschildren(node)) { + const struct index_node *child; + int i; + + child_count = node->last - node->first + 1; + child_offs = NOFAIL(malloc(child_count * sizeof(uint32_t))); + + for (i = 0; i < child_count; i++) { + child = node->children[node->first + i]; + child_offs[i] = htonl(index_write__node(child, out)); + } + } + + /* Now write this node */ + offset = ftell(out); + + if (node->prefix[0]) { + fputs(node->prefix, out); + fputc('\0', out); + offset |= INDEX_NODE_PREFIX; + } + + if (child_count) { + fputc(node->first, out); + fputc(node->last, out); + fwrite(child_offs, sizeof(uint32_t), child_count, out); + free(child_offs); + offset |= INDEX_NODE_CHILDS; + } + + if (node->values) { + const struct index_value *v; + unsigned int value_count; + uint32_t u; + + value_count = 0; + for (v = node->values; v != NULL; v = v->next) + value_count++; + u = htonl(value_count); + fwrite(&u, sizeof(u), 1, out); + + for (v = node->values; v != NULL; v = v->next) { + u = htonl(v->priority); + fwrite(&u, sizeof(u), 1, out); + fputs(v->value, out); + fputc('\0', out); + } + offset |= INDEX_NODE_VALUES; + } + + return offset; +} + +static void index_write(const struct index_node *node, FILE *out) +{ + long initial_offset, final_offset; + uint32_t u; + + u = htonl(INDEX_MAGIC); + fwrite(&u, sizeof(u), 1, out); + u = htonl(INDEX_VERSION); + fwrite(&u, sizeof(u), 1, out); + + /* Second word is reserved for the offset of the root node */ + initial_offset = ftell(out); + u = 0; + fwrite(&u, sizeof(uint32_t), 1, out); + + /* Dump trie */ + u = htonl(index_write__node(node, out)); + + /* Update first word */ + final_offset = ftell(out); + fseek(out, initial_offset, SEEK_SET); + fwrite(&u, sizeof(uint32_t), 1, out); + fseek(out, final_offset, SEEK_SET); +} + +/* END: code from module-init-tools/index.c just modified to compile here. + */ + +/* utils (variants of libkmod-utils.c) *********************************/ +static const char *underscores2(const char *input, char *output, size_t outputlen) +{ + size_t i; + + for (i = 0; input[i] != '\0' && i < outputlen - 1; i++) { + switch (input[i]) { + case '-': + output[i] = '_'; + break; + + case ']': + WRN("Unmatched bracket in %s\n", input); + return NULL; + + case '[': { + size_t off = strcspn(input + i, "]"); + if (input[i + off] == '\0') { + WRN("Unmatched bracket in %s\n", input); + return NULL; + } + memcpy(output + i, input + i, off + 1); + i += off; + break; + } + + default: + output[i] = input[i]; + } + } + output[i] = '\0'; + + return output; +} + +/* configuration parsing **********************************************/ +struct cfg_override { + struct cfg_override *next; + size_t len; + char path[]; +}; + +struct cfg_search { + struct cfg_search *next; + uint8_t builtin; + size_t len; + char path[]; +}; + +struct cfg { + const char *kversion; + char dirname[PATH_MAX]; + size_t dirnamelen; + char sym_prefix; + uint8_t check_symvers; + uint8_t print_unknown; + uint8_t warn_dups; + struct cfg_override *overrides; + struct cfg_search *searches; +}; + +static int cfg_search_add(struct cfg *cfg, const char *path, uint8_t builtin) +{ + struct cfg_search *s; + size_t len; + + if (builtin) + len = 0; + else + len = strlen(path) + 1; + + s = malloc(sizeof(struct cfg_search) + len); + if (s == NULL) { + ERR("search add: out of memory\n"); + return -ENOMEM; + } + s->builtin = builtin; + if (builtin) + s->len = 0; + else { + s->len = len - 1; + memcpy(s->path, path, len); + } + + DBG("search add: %s, builtin=%hhu\n", path, builtin); + + s->next = cfg->searches; + cfg->searches = s; + return 0; +} + +static void cfg_search_free(struct cfg_search *s) +{ + free(s); +} + +static int cfg_override_add(struct cfg *cfg, const char *modname, const char *subdir) +{ + struct cfg_override *o; + size_t modnamelen = strlen(modname); + size_t subdirlen = strlen(subdir); + size_t i; + + o = malloc(sizeof(struct cfg_override) + subdirlen + 1 + + modnamelen + 1); + if (o == NULL) { + ERR("override add: out of memory\n"); + return -ENOMEM; + } + memcpy(o->path, subdir, subdirlen); + i = subdirlen; + o->path[i] = '/'; + i++; + + memcpy(o->path + i, modname, modnamelen); + i += modnamelen; + o->path[i] = '\0'; /* no extension, so we can match .ko/.ko.gz */ + + o->len = i; + + DBG("override add: %s\n", o->path); + + o->next = cfg->overrides; + cfg->overrides = o; + return 0; +} + +static void cfg_override_free(struct cfg_override *o) +{ + free(o); +} + +static int cfg_kernel_matches(const struct cfg *cfg, const char *pattern) +{ + regex_t re; + int status; + + /* old style */ + if (streq(pattern, "*")) + return 1; + + if (regcomp(&re, pattern, REG_EXTENDED|REG_NOSUB) != 0) + return 0; + + status = regexec(&re, cfg->kversion, 0, NULL, 0); + regfree(&re); + + return status == 0; +} + +static int cfg_file_parse(struct cfg *cfg, const char *filename) +{ + char *line; + FILE *fp; + unsigned int linenum = 0; + int err; + + fp = fopen(filename, "r"); + if (fp == NULL) { + err = -errno; + ERR("file parse %s: %m\n", filename); + return err; + } + + while ((line = getline_wrapped(fp, &linenum)) != NULL) { + char *cmd, *saveptr; + + if (line[0] == '\0' || line[0] == '#') + goto done_next; + + cmd = strtok_r(line, "\t ", &saveptr); + if (cmd == NULL) + goto done_next; + + if (streq(cmd, "search")) { + const char *sp; + while ((sp = strtok_r(NULL, "\t ", &saveptr)) != NULL) { + uint8_t builtin = streq(sp, CFG_BUILTIN_KEY); + cfg_search_add(cfg, sp, builtin); + } + } else if (streq(cmd, "override")) { + const char *modname = strtok_r(NULL, "\t ", &saveptr); + const char *version = strtok_r(NULL, "\t ", &saveptr); + const char *subdir = strtok_r(NULL, "\t ", &saveptr); + + if (modname == NULL || version == NULL || + subdir == NULL) + goto syntax_error; + + if (!cfg_kernel_matches(cfg, version)) { + INF("%s:%u: override kernel did not match %s\n", + filename, linenum, version); + goto done_next; + } + + cfg_override_add(cfg, modname, subdir); + } else if (streq(cmd, "include") + || streq(cmd, "make_map_files")) { + INF("%s:%u: command %s not implemented yet\n", + filename, linenum, cmd); + } else { +syntax_error: + ERR("%s:%u: ignoring bad line starting with '%s'\n", + filename, linenum, cmd); + } + +done_next: + free(line); + } + + fclose(fp); + + return 0; +} + +static int cfg_files_filter_out(DIR *d, const char *dir, const char *name) +{ + size_t len = strlen(name); + struct stat st; + + if (name[0] == '.') + return 1; + + if (len < 6 || !streq(name + len - 5, ".conf")) { + INF("All cfg files need .conf: %s/%s\n", dir, name); + return 1; + } + + fstatat(dirfd(d), name, &st, 0); + if (S_ISDIR(st.st_mode)) { + ERR("Directories inside directories are not supported: %s/%s\n", + dir, name); + return 1; + } + + return 0; +} + +struct cfg_file { + size_t dirlen; + size_t namelen; + const char *name; + char path[]; +}; + +static void cfg_file_free(struct cfg_file *f) +{ + free(f); +} + +static int cfg_files_insert_sorted(struct cfg_file ***p_files, size_t *p_n_files, + const char *dir, const char *name) +{ + struct cfg_file **files, *f; + size_t i, n_files, namelen, dirlen; + void *tmp; + + dirlen = strlen(dir); + if (name != NULL) + namelen = strlen(name); + else { + name = basename(dir); + namelen = strlen(name); + dirlen -= namelen + 1; + } + + n_files = *p_n_files; + files = *p_files; + for (i = 0; i < n_files; i++) { + int cmp = strcmp(name, files[i]->name); + if (cmp == 0) { + DBG("Ignoring duplicate config file: %.*s/%s\n", + (int)dirlen, dir, name); + return -EEXIST; + } else if (cmp < 0) + break; + } + + f = malloc(sizeof(struct cfg_file) + dirlen + namelen + 2); + if (f == NULL) { + ERR("files insert sorted: out of memory\n"); + return -ENOMEM; + } + + tmp = realloc(files, sizeof(struct cfg_file *) * (n_files + 1)); + if (tmp == NULL) { + ERR("files insert sorted: out of memory\n"); + free(f); + return -ENOMEM; + } + *p_files = files = tmp; + + if (i < n_files) { + memmove(files + i + 1, files + i, + sizeof(struct cfg_file *) * (n_files - i)); + } + files[i] = f; + + f->dirlen = dirlen; + f->namelen = namelen; + f->name = f->path + dirlen + 1; + memcpy(f->path, dir, dirlen); + f->path[dirlen] = '/'; + memcpy(f->path + dirlen + 1, name, namelen); + f->path[dirlen + 1 + namelen] = '\0'; + + *p_n_files = n_files + 1; + return 0; +} + +/* + * Insert configuration files ignoring duplicates + */ +static int cfg_files_list(struct cfg_file ***p_files, size_t *p_n_files, + const char *path) +{ + DIR *d; + int err = 0; + struct stat st; + + if (stat(path, &st) != 0) { + err = -errno; + DBG("could not stat '%s': %m\n", path); + return err; + } + + if (S_ISREG(st.st_mode)) { + cfg_files_insert_sorted(p_files, p_n_files, path, NULL); + return 0; + } if (!S_ISDIR(st.st_mode)) { + ERR("unsupported file mode %s: %#x\n", path, st.st_mode); + return -EINVAL; + } + + d = opendir(path); + if (d == NULL) { + ERR("files list %s: %m\n", path); + return -EINVAL; + } + + for (;;) { + struct dirent ent, *entp; + + err = readdir_r(d, &ent, &entp); + if (err != 0) { + ERR("reading entry %s\n", strerror(-err)); + break; + } + if (entp == NULL) + break; + if (cfg_files_filter_out(d, path, entp->d_name)) + continue; + + cfg_files_insert_sorted(p_files, p_n_files, path, entp->d_name); + } + + closedir(d); + DBG("parsed configuration files from %s\n", path); + return err; +} + +static int cfg_load(struct cfg *cfg, const char * const *cfg_paths) +{ + size_t i, n_files = 0; + struct cfg_file **files = NULL; + + if (cfg_paths == NULL) + cfg_paths = default_cfg_paths; + + for (i = 0; cfg_paths[i] != NULL; i++) + cfg_files_list(&files, &n_files, cfg_paths[i]); + + for (i = 0; i < n_files; i++) { + struct cfg_file *f = files[i]; + cfg_file_parse(cfg, f->path); + cfg_file_free(f); + } + free(files); + + /* For backward compatibility add "updates" to the head of the search + * list here. But only if there was no "search" option specified. + */ + if (cfg->searches == NULL) + cfg_search_add(cfg, "updates", 0); + + return 0; +} + +static void cfg_free(struct cfg *cfg) +{ + while (cfg->overrides) { + struct cfg_override *tmp = cfg->overrides; + cfg->overrides = cfg->overrides->next; + cfg_override_free(tmp); + } + + while (cfg->searches) { + struct cfg_search *tmp = cfg->searches; + cfg->searches = cfg->searches->next; + cfg_search_free(tmp); + } +} + + +/* depmod calculations ***********************************************/ +struct mod { + struct kmod_module *kmod; + const char *path; + const char *relpath; /* path relative to '$ROOT/lib/modules/$VER/' */ + struct array deps; /* struct symbol */ + size_t baselen; /* points to start of basename/filename */ + size_t modnamelen; + int sort_idx; /* sort index using modules.order */ + int dep_sort_idx; /* topological sort index */ + uint16_t idx; /* index in depmod->modules.array */ + uint16_t users; /* how many modules depend on this one */ + uint8_t dep_loop : 1; + char modname[]; +}; + +struct symbol { + struct mod *owner; + uint64_t crc; + char name[]; +}; + +struct depmod { + const struct cfg *cfg; + struct kmod_ctx *ctx; + struct array modules; + struct hash *modules_by_relpath; + struct hash *modules_by_name; + struct hash *symbols; + unsigned int dep_loops; +}; + +static void mod_free(struct mod *mod) +{ + DBG("free %p kmod=%p, path=%s\n", mod, mod->kmod, mod->path); + array_free_array(&mod->deps); + kmod_module_unref(mod->kmod); + free(mod); +} + +static int mod_add_dependency(struct mod *mod, struct symbol *sym) +{ + int err; + + DBG("%s depends on %s %s\n", mod->path, sym->name, + sym->owner != NULL ? sym->owner->path : "(unknown)"); + + if (sym->owner == NULL) + return 0; + + err = array_append_unique(&mod->deps, sym->owner); + if (err == -EEXIST) + return 0; + if (err < 0) + return err; + + sym->owner->users++; + SHOW("%s needs \"%s\": %s\n", mod->path, sym->name, sym->owner->path); + return 0; +} + +static void symbol_free(struct symbol *sym) +{ + DBG("free %p sym=%s, owner=%p %s\n", sym, sym->name, sym->owner, + sym->owner != NULL ? sym->owner->path : ""); + free(sym); +} + +static int depmod_init(struct depmod *depmod, struct cfg *cfg, + struct kmod_ctx *ctx) +{ + int err = 0; + + depmod->cfg = cfg; + depmod->ctx = ctx; + + array_init(&depmod->modules, 128); + + depmod->modules_by_relpath = hash_new(512, NULL); + if (depmod->modules_by_relpath == NULL) { + err = -errno; + goto modules_by_relpath_failed; + } + + depmod->modules_by_name = hash_new(512, NULL); + if (depmod->modules_by_name == NULL) { + err = -errno; + goto modules_by_name_failed; + } + + depmod->symbols = hash_new(2048, (void (*)(void *))symbol_free); + if (depmod->symbols == NULL) { + err = -errno; + goto symbols_failed; + } + + return 0; + +symbols_failed: + hash_free(depmod->modules_by_name); +modules_by_name_failed: + hash_free(depmod->modules_by_relpath); +modules_by_relpath_failed: + return err; +} + +static void depmod_shutdown(struct depmod *depmod) +{ + size_t i; + + hash_free(depmod->symbols); + + hash_free(depmod->modules_by_relpath); + + hash_free(depmod->modules_by_name); + + for (i = 0; i < depmod->modules.count; i++) + mod_free(depmod->modules.array[i]); + array_free_array(&depmod->modules); + + kmod_unref(depmod->ctx); +} + +static int depmod_module_add(struct depmod *depmod, struct kmod_module *kmod) +{ + const struct cfg *cfg = depmod->cfg; + const char *modname; + size_t modnamelen; + struct mod *mod; + int err; + + modname = kmod_module_get_name(kmod); + modnamelen = strlen(modname) + 1; + + mod = calloc(1, sizeof(struct mod) + modnamelen); + if (mod == NULL) + return -ENOMEM; + mod->kmod = kmod; + mod->sort_idx = depmod->modules.count + 1; + mod->dep_sort_idx = INT32_MAX; + memcpy(mod->modname, modname, modnamelen); + mod->modnamelen = modnamelen; + + array_init(&mod->deps, 4); + + mod->path = kmod_module_get_path(kmod); + mod->baselen = strrchr(mod->path, '/') - mod->path; + if (strncmp(mod->path, cfg->dirname, cfg->dirnamelen) == 0 && + mod->path[cfg->dirnamelen] == '/') + mod->relpath = mod->path + cfg->dirnamelen + 1; + else + mod->relpath = NULL; + + err = hash_add_unique(depmod->modules_by_name, mod->modname, mod); + if (err < 0) { + ERR("hash_add_unique %s: %s\n", mod->modname, strerror(-err)); + free(mod); + return err; + } + + if (mod->relpath != NULL) { + err = hash_add_unique(depmod->modules_by_relpath, + mod->relpath, mod); + if (err < 0) { + ERR("hash_add_unique %s: %s\n", + mod->relpath, strerror(-err)); + hash_del(depmod->modules_by_name, mod->modname); + free(mod); + return err; + } + } + + DBG("add %p kmod=%p, path=%s\n", mod, kmod, mod->path); + + return 0; +} + +static int depmod_module_del(struct depmod *depmod, struct mod *mod) +{ + DBG("del %p kmod=%p, path=%s\n", mod, mod->kmod, mod->path); + + if (mod->relpath != NULL) + hash_del(depmod->modules_by_relpath, mod->relpath); + + hash_del(depmod->modules_by_name, mod->modname); + + mod_free(mod); + return 0; +} + +/* returns if existing module @mod is higher priority than newpath. + * note this is the inverse of module-init-tools is_higher_priority() + */ +static int depmod_module_is_higher_priority(const struct depmod *depmod, const struct mod *mod, size_t baselen, size_t namelen, size_t modnamelen, const char *newpath) +{ + const struct cfg *cfg = depmod->cfg; + const struct cfg_override *ov; + const struct cfg_search *se; + size_t newlen = baselen + modnamelen; + size_t oldlen = mod->baselen + mod->modnamelen; + const char *oldpath = mod->path; + int i, bprio = -1, oldprio = -1, newprio = -1; + + assert(strncmp(newpath, cfg->dirname, cfg->dirnamelen) == 0); + assert(strncmp(oldpath, cfg->dirname, cfg->dirnamelen) == 0); + + newpath += cfg->dirnamelen + 1; + newlen -= cfg->dirnamelen + 1; + oldpath += cfg->dirnamelen + 1; + oldlen -= cfg->dirnamelen + 1; + + DBG("comparing priorities of %s and %s\n", + oldpath, newpath); + + for (ov = cfg->overrides; ov != NULL; ov = ov->next) { + DBG("override %s\n", ov->path); + if (newlen == ov->len && memcmp(ov->path, newpath, newlen) == 0) + return 0; + if (oldlen == ov->len && memcmp(ov->path, oldpath, oldlen) == 0) + return 1; + } + + for (i = 0, se = cfg->searches; se != NULL; se = se->next, i++) { + DBG("search %s\n", se->builtin ? "built-in" : se->path); + if (se->builtin) + bprio = i; + else if (newlen >= se->len && + memcmp(se->path, newpath, se->len) == 0) + newprio = i; + else if (oldlen >= se->len && + memcmp(se->path, oldpath, se->len) == 0) + oldprio = i; + } + + if (newprio < 0) + newprio = bprio; + if (oldprio < 0) + oldprio = bprio; + + DBG("priorities: built-in: %d, old: %d, new: %d\n", + bprio, newprio, oldprio); + + return newprio <= oldprio; +} + +static int depmod_modules_search_file(struct depmod *depmod, size_t baselen, size_t namelen, const char *path) +{ + struct kmod_module *kmod; + struct mod *mod; + const char *relpath; + char modname[PATH_MAX]; + const struct kmod_ext *eitr; + size_t modnamelen; + uint8_t matches = 0; + int err = 0; + + for (eitr = kmod_exts; eitr->ext != NULL; eitr++) { + if (namelen <= eitr->len) + continue; + if (streq(path + baselen + namelen - eitr->len, eitr->ext)) { + matches = 1; + break; + } + } + if (!matches) + return 0; + + if (path_to_modname(path, modname, &modnamelen) == NULL) { + ERR("could not get modname from path %s\n", path); + return -EINVAL; + } + + relpath = path + depmod->cfg->dirnamelen + 1; + DBG("try %s (%s)\n", relpath, modname); + + mod = hash_find(depmod->modules_by_name, modname); + if (mod == NULL) + goto add; + + if (depmod_module_is_higher_priority(depmod, mod, baselen, + namelen, modnamelen, path)) { + DBG("Ignored lower priority: %s, higher: %s\n", + path, mod->path); + return 0; + } + + DBG("Replace lower priority %s with new module %s\n", + mod->relpath, relpath); + err = depmod_module_del(depmod, mod); + if (err < 0) { + ERR("could not del module %s: %s\n", mod->path, strerror(-err)); + return err; + } + +add: + err = kmod_module_new_from_path(depmod->ctx, path, &kmod); + if (err < 0) { + ERR("could not create module %s: %s\n", path, strerror(-err)); + return err; + } + + err = depmod_module_add(depmod, kmod); + if (err < 0) { + ERR("could not add module %s: %s\n", + path, strerror(-err)); + kmod_module_unref(kmod); + return err; + } + return 0; +} + +static int depmod_modules_search_dir(struct depmod *depmod, DIR *d, size_t baselen, char *path) +{ + struct dirent *de; + int err = 0, dfd = dirfd(d); + + while ((de = readdir(d)) != NULL) { + const char *name = de->d_name; + size_t namelen; + uint8_t is_dir; + + if (name[0] == '.' && (name[1] == '\0' || + (name[1] == '.' && name[2] == '\0'))) + continue; + if (streq(name, "build") || streq(name, "source")) + continue; + namelen = strlen(name); + if (baselen + namelen + 2 >= PATH_MAX) { + path[baselen] = '\0'; + ERR("path is too long %s%s %zd\n", path, name); + continue; + } + memcpy(path + baselen, name, namelen + 1); + + if (de->d_type == DT_REG) + is_dir = 0; + else if (de->d_type == DT_DIR) + is_dir = 1; + else { + struct stat st; + if (fstatat(dfd, name, &st, 0) < 0) { + ERR("fstatat(%d, %s): %m\n", dfd, name); + continue; + } else if (S_ISREG(st.st_mode)) + is_dir = 0; + else if (S_ISDIR(st.st_mode)) + is_dir = 1; + else { + ERR("unsupported file type %s: %o\n", + path, st.st_mode & S_IFMT); + continue; + } + } + + if (is_dir) { + int fd; + DIR *subdir; + if (baselen + namelen + 2 + NAME_MAX >= PATH_MAX) { + ERR("directory path is too long %s\n", path); + continue; + } + fd = openat(dfd, name, O_RDONLY); + if (fd < 0) { + ERR("openat(%d, %s, O_RDONLY): %m\n", + dfd, name); + continue; + } + subdir = fdopendir(fd); + if (subdir == NULL) { + ERR("fdopendir(%d): %m\n", fd); + close(fd); + continue; + } + path[baselen + namelen] = '/'; + path[baselen + namelen + 1] = '\0'; + err = depmod_modules_search_dir(depmod, subdir, + baselen + namelen + 1, + path); + closedir(subdir); + } else { + err = depmod_modules_search_file(depmod, baselen, + namelen, path); + } + + if (err < 0) { + path[baselen + namelen] = '\0'; + ERR("failed %s: %s\n", path, strerror(-err)); + err = 0; /* ignore errors */ + } + } + + return err; +} + +static int depmod_modules_search(struct depmod *depmod) +{ + char path[PATH_MAX]; + DIR *d = opendir(depmod->cfg->dirname); + size_t baselen; + int err; + if (d == NULL) { + err = -errno; + ERR("could not open directory %s: %m\n", depmod->cfg->dirname); + return err; + } + + baselen = depmod->cfg->dirnamelen; + memcpy(path, depmod->cfg->dirname, baselen); + path[baselen] = '/'; + baselen++; + path[baselen] = '\0'; + + err = depmod_modules_search_dir(depmod, d, baselen, path); + closedir(d); + return 0; +} + +static int mod_cmp(const void *pa, const void *pb) { + const struct mod *a = *(const struct mod **)pa; + const struct mod *b = *(const struct mod **)pb; + if (a->dep_loop == b->dep_loop) + return a->sort_idx - b->sort_idx; + else if (a->dep_loop) + return 1; + else if (b->dep_loop) + return -1; + return a->sort_idx - b->sort_idx; +} + +static int depmod_modules_build_array(struct depmod *depmod) +{ + struct hash_iter module_iter; + const void *v; + int err; + + hash_iter_init(depmod->modules_by_name, &module_iter); + while (hash_iter_next(&module_iter, NULL, &v)) { + struct mod *mod = (struct mod *) v; + mod->idx = depmod->modules.count; + err = array_append(&depmod->modules, mod); + if (err < 0) + return err; + } + + return 0; +} + +static void depmod_modules_sort(struct depmod *depmod) +{ + char order_file[PATH_MAX], line[PATH_MAX]; + FILE *fp; + unsigned idx = 0, total = 0; + + snprintf(order_file, sizeof(order_file), "%s/modules.order", + depmod->cfg->dirname); + fp = fopen(order_file, "r"); + if (fp == NULL) { + WRN("could not open %s: %m\n", order_file); + return; + } + + while (fgets(line, sizeof(line), fp) != NULL) { + size_t len = strlen(line); + idx++; + if (len == 0) + continue; + if (line[len - 1] != '\n') { + ERR("%s:%u corrupted line misses '\\n'\n", + order_file, idx); + goto corrupted; + } + } + total = idx + 1; + idx = 0; + fseek(fp, 0, SEEK_SET); + while (fgets(line, sizeof(line), fp) != NULL) { + size_t len = strlen(line); + struct mod *mod; + + idx++; + if (len == 0) + continue; + line[len - 1] = '\0'; + + mod = hash_find(depmod->modules_by_relpath, line); + if (mod == NULL) + continue; + mod->sort_idx = idx - total; + } + + array_sort(&depmod->modules, mod_cmp); + for (idx = 0; idx < depmod->modules.count; idx++) { + struct mod *m = depmod->modules.array[idx]; + m->idx = idx; + } + +corrupted: + fclose(fp); +} + +static int depmod_symbol_add(struct depmod *depmod, const char *name, + uint64_t crc, const struct mod *owner) +{ + size_t namelen; + int err; + struct symbol *sym; + + if (name[0] == depmod->cfg->sym_prefix) + name++; + + namelen = strlen(name) + 1; + sym = malloc(sizeof(struct symbol) + namelen); + if (sym == NULL) + return -ENOMEM; + + sym->owner = (struct mod *)owner; + sym->crc = crc; + memcpy(sym->name, name, namelen); + + err = hash_add(depmod->symbols, sym->name, sym); + if (err < 0) { + free(sym); + return err; + } + + DBG("add %p sym=%s, owner=%p %s\n", sym, sym->name, owner, + owner != NULL ? owner->path : ""); + + return 0; +} + +static struct symbol *depmod_symbol_find(const struct depmod *depmod, + const char *name) +{ + if (name[0] == '.') /* PPC64 needs this: .foo == foo */ + name++; + if (name[0] == depmod->cfg->sym_prefix) + name++; + return hash_find(depmod->symbols, name); +} + +static int depmod_load_symbols(struct depmod *depmod) +{ + const struct mod **itr, **itr_end; + + DBG("load symbols (%zd modules)\n", depmod->modules.count); + + itr = (const struct mod **)depmod->modules.array; + itr_end = itr + depmod->modules.count; + for (; itr < itr_end; itr++) { + const struct mod *mod = *itr; + struct kmod_list *l, *list = NULL; + int err = kmod_module_get_symbols(mod->kmod, &list); + if (err < 0) { + DBG("ignoring %s: no symbols: %s\n", + mod->path, strerror(-err)); + continue; + } + kmod_list_foreach(l, list) { + const char *name = kmod_module_symbol_get_symbol(l); + uint64_t crc = kmod_module_symbol_get_crc(l); + depmod_symbol_add(depmod, name, crc, mod); + } + kmod_module_symbols_free_list(list); + } + + DBG("loaded symbols (%zd modules, %zd symbols)\n", + depmod->modules.count, hash_get_count(depmod->symbols)); + + return 0; +} + +static int depmod_load_module_dependencies(struct depmod *depmod, struct mod *mod) +{ + const struct cfg *cfg = depmod->cfg; + struct kmod_list *l, *list = NULL; + int err = kmod_module_get_dependency_symbols(mod->kmod, &list); + if (err < 0) { + DBG("ignoring %s: no dependency symbols: %s\n", + mod->path, strerror(-err)); + return 0; + } + + DBG("do dependencies of %s\n", mod->path); + kmod_list_foreach(l, list) { + const char *name = kmod_module_dependency_symbol_get_symbol(l); + uint64_t crc = kmod_module_dependency_symbol_get_crc(l); + int bindtype = kmod_module_dependency_symbol_get_bind(l); + struct symbol *sym = depmod_symbol_find(depmod, name); + uint8_t is_weak = bindtype == KMOD_SYMBOL_WEAK; + + if (sym == NULL) { + DBG("%s needs (%c) unknown symbol %s\n", + mod->path, bindtype, name); + if (cfg->print_unknown && !is_weak) + WRN("%s needs unknown symbol %s\n", + mod->path, name); + continue; + } + + if (cfg->check_symvers && sym->crc != crc && !is_weak) { + DBG("symbol %s (%#"PRIx64") module %s (%#"PRIx64")\n", + sym->name, sym->crc, mod->path, crc); + if (cfg->print_unknown) + WRN("%s disagrees about version of symbol %s\n", + mod->path, name); + } + + mod_add_dependency(mod, sym); + } + kmod_module_dependency_symbols_free_list(list); + return 0; +} + +static int depmod_load_dependencies(struct depmod *depmod) +{ + struct mod **itr, **itr_end; + + DBG("load dependencies (%zd modules, %zd symbols)\n", + depmod->modules.count, hash_get_count(depmod->symbols)); + + itr = (struct mod **)depmod->modules.array; + itr_end = itr + depmod->modules.count; + for (; itr < itr_end; itr++) { + struct mod *mod = *itr; + depmod_load_module_dependencies(depmod, mod); + } + + DBG("loaded dependencies (%zd modules, %zd symbols)\n", + depmod->modules.count, hash_get_count(depmod->symbols)); + + return 0; +} + +static int dep_cmp(const void *pa, const void *pb) +{ + const struct mod *a = *(const struct mod **)pa; + const struct mod *b = *(const struct mod **)pb; + if (a->dep_loop == b->dep_loop) + return a->dep_sort_idx - b->dep_sort_idx; + else if (a->dep_loop) + return 1; + else if (b->dep_loop) + return -1; + return a->dep_sort_idx - b->dep_sort_idx; +} + +static void depmod_sort_dependencies(struct depmod *depmod) +{ + struct mod **itr, **itr_end; + itr = (struct mod **)depmod->modules.array; + itr_end = itr + depmod->modules.count; + for (; itr < itr_end; itr++) { + struct mod *m = *itr; + if (m->deps.count > 1) + array_sort(&m->deps, dep_cmp); + } +} + +static int depmod_calculate_dependencies(struct depmod *depmod) +{ + const struct mod **itrm; + uint16_t *users, *roots, *sorted; + uint16_t i, n_roots = 0, n_sorted = 0, n_mods = depmod->modules.count; + + users = malloc(sizeof(uint16_t) * n_mods * 3); + if (users == NULL) + return -ENOMEM; + roots = users + n_mods; + sorted = roots + n_mods; + + DBG("calculate dependencies and ordering (%zd modules)\n", n_mods); + + assert(depmod->modules.count < UINT16_MAX); + + /* populate modules users (how many modules uses it) */ + itrm = (const struct mod **)depmod->modules.array; + for (i = 0; i < n_mods; i++, itrm++) { + const struct mod *m = *itrm; + users[i] = m->users; + if (users[i] == 0) { + roots[n_roots] = i; + n_roots++; + } + } + + /* topological sort (outputs modules without users first) */ + while (n_roots > 0) { + const struct mod **itr_dst, **itr_dst_end; + struct mod *src; + uint16_t src_idx = roots[--n_roots]; + + src = depmod->modules.array[src_idx]; + src->dep_sort_idx = n_sorted; + sorted[n_sorted] = src_idx; + n_sorted++; + + itr_dst = (const struct mod **)src->deps.array; + itr_dst_end = itr_dst + src->deps.count; + for (; itr_dst < itr_dst_end; itr_dst++) { + const struct mod *dst = *itr_dst; + uint16_t dst_idx = dst->idx; + assert(users[dst_idx] > 0); + users[dst_idx]--; + if (users[dst_idx] == 0) { + roots[n_roots] = dst_idx; + n_roots++; + } + } + } + + if (n_sorted < n_mods) { + WRN("found %hu modules in dependency cycles!\n", + n_mods - n_sorted); + for (i = 0; i < n_mods; i++) { + struct mod *m; + if (users[i] == 0) + continue; + m = depmod->modules.array[i]; + WRN("%s in dependency cycle!\n", m->path); + m->dep_loop = 1; + m->dep_sort_idx = INT32_MAX; + depmod->dep_loops++; + } + } + + depmod_sort_dependencies(depmod); + + DBG("calculated dependencies and ordering (%u loops, %zd modules)\n", + depmod->dep_loops, n_mods); + + free(users); + return 0; +} + +static int depmod_load(struct depmod *depmod) +{ + int err; + + err = depmod_load_symbols(depmod); + if (err < 0) + return err; + + err = depmod_load_dependencies(depmod); + if (err < 0) + return err; + + err = depmod_calculate_dependencies(depmod); + if (err < 0) + return err; + + return 0; +} + +static size_t mod_count_all_dependencies(const struct mod *mod) +{ + size_t i, count = 0; + for (i = 0; i < mod->deps.count; i++) { + const struct mod *d = mod->deps.array[i]; + count += 1 + mod_count_all_dependencies(d); + } + return count; +} + +static int mod_fill_all_unique_dependencies(const struct mod *mod, const struct mod **deps, size_t n_deps, size_t *last) +{ + size_t i; + int err = 0; + for (i = 0; i < mod->deps.count; i++) { + const struct mod *d = mod->deps.array[i]; + size_t j; + uint8_t exists = 0; + + for (j = 0; j < *last; j++) { + if (deps[j] == d) { + exists = 1; + break; + } + } + + if (exists) + continue; + + if (*last >= n_deps) + return -ENOSPC; + deps[*last] = d; + (*last)++; + err = mod_fill_all_unique_dependencies(d, deps, n_deps, last); + if (err < 0) + break; + } + return err; +} + +static const struct mod **mod_get_all_sorted_dependencies(const struct mod *mod, size_t *n_deps) +{ + const struct mod **deps; + size_t last = 0; + + *n_deps = mod_count_all_dependencies(mod); + if (*n_deps == 0) + return NULL; + + deps = malloc(sizeof(struct mod *) * (*n_deps)); + if (deps == NULL) + return NULL; + + if (mod_fill_all_unique_dependencies(mod, deps, *n_deps, &last) < 0) { + free(deps); + return NULL; + } + + qsort(deps, last, sizeof(struct mod *), dep_cmp); + *n_deps = last; + return deps; +} + +static inline const char *mod_get_compressed_path(const struct mod *mod) +{ + if (mod->relpath != NULL) + return mod->relpath; + return mod->path; +} + +static int output_deps(struct depmod *depmod, FILE *out) +{ + size_t i; + + for (i = 0; i < depmod->modules.count; i++) { + const struct mod **deps, *mod = depmod->modules.array[i]; + const char *p = mod_get_compressed_path(mod); + size_t j, n_deps; + + if (mod->dep_loop) { + DBG("Ignored %s due dependency loops\n", p); + continue; + } + + fprintf(out, "%s:", p); + + if (mod->deps.count == 0) + goto end; + + deps = mod_get_all_sorted_dependencies(mod, &n_deps); + if (deps == NULL) { + ERR("could not get all sorted dependencies of %s\n", p); + goto end; + } + + for (j = 0; j < n_deps; j++) { + const struct mod *d = deps[j]; + if (d->dep_loop) { + DBG("Ignored %s (dependency of %s) " + "due dependency loops\n", + mod_get_compressed_path(d), p); + continue; + } + fprintf(out, " %s", mod_get_compressed_path(d)); + } + free(deps); + end: + putc('\n', out); + } + + return 0; +} + +static int output_deps_bin(struct depmod *depmod, FILE *out) +{ + struct index_node *idx; + size_t i; + + if (out == stdout) + return 0; + + idx = index_create(); + if (idx == NULL) + return -ENOMEM; + + for (i = 0; i < depmod->modules.count; i++) { + const struct mod **deps, *mod = depmod->modules.array[i]; + const char *p = mod_get_compressed_path(mod); + char *line; + size_t j, n_deps, linepos, linelen, slen; + int duplicate; + + if (mod->dep_loop) { + DBG("Ignored %s due dependency loops\n", p); + continue; + } + + deps = mod_get_all_sorted_dependencies(mod, &n_deps); + if (deps == NULL && n_deps > 0) { + ERR("could not get all sorted dependencies of %s\n", p); + continue; + } + + linelen = strlen(p) + 1; + for (j = 0; j < n_deps; j++) { + const struct mod *d = deps[j]; + if (d->dep_loop) { + DBG("Ignored %s (dependency of %s) " + "due dependency loops\n", + mod_get_compressed_path(d), p); + continue; + } + linelen += 1 + strlen(mod_get_compressed_path(d)); + } + + line = malloc(linelen + 1); + if (line == NULL) { + free(deps); + ERR("modules.deps.bin: out of memory\n"); + continue; + } + + linepos = 0; + slen = strlen(p); + memcpy(line + linepos, p, slen); + linepos += slen; + line[linepos] = ':'; + linepos++; + + for (j = 0; j < n_deps; j++) { + const struct mod *d = deps[j]; + const char *dp; + if (d->dep_loop) + continue; + line[linepos] = ' '; + linepos++; + + dp = mod_get_compressed_path(d); + slen = strlen(dp); + memcpy(line + linepos, dp, slen); + linepos += slen; + } + line[linepos] = '\0'; + + duplicate = index_insert(idx, mod->modname, line, mod->idx); + if (duplicate && depmod->cfg->warn_dups) + WRN("duplicate module deps:\n%s\n", line); + free(line); + free(deps); + } + + index_write(idx, out); + index_destroy(idx); + + return 0; +} + +static int output_aliases(struct depmod *depmod, FILE *out) +{ + size_t i; + + fputs("# Aliases extracted from modules themselves.\n", out); + + for (i = 0; i < depmod->modules.count; i++) { + const struct mod *mod = depmod->modules.array[i]; + struct kmod_list *l, *list = NULL; + int r = kmod_module_get_info(mod->kmod, &list); + if (r < 0 || list == NULL) + continue; + kmod_list_foreach(l, list) { + const char *key = kmod_module_info_get_key(l); + const char *value = kmod_module_info_get_value(l); + + if (!streq(key, "alias")) + continue; + + fprintf(out, "alias %s %s\n", + value, kmod_module_get_name(mod->kmod)); + } + kmod_module_info_free_list(list); + } + + return 0; +} + +static int output_aliases_bin(struct depmod *depmod, FILE *out) +{ + char buf[1024]; + struct index_node *idx; + size_t i; + + if (out == stdout) + return 0; + + idx = index_create(); + if (idx == NULL) + return -ENOMEM; + + for (i = 0; i < depmod->modules.count; i++) { + const struct mod *mod = depmod->modules.array[i]; + struct kmod_list *l, *list = NULL; + int r = kmod_module_get_info(mod->kmod, &list); + if (r < 0 || list == NULL) + continue; + kmod_list_foreach(l, list) { + const char *key = kmod_module_info_get_key(l); + const char *value = kmod_module_info_get_value(l); + const char *modname, *alias; + int duplicate; + + if (!streq(key, "alias")) + continue; + + alias = underscores2(value, buf, sizeof(buf)); + if (alias == NULL) + continue; + + modname = kmod_module_get_name(mod->kmod); + duplicate = index_insert(idx, alias, modname, + mod->idx); + if (duplicate && depmod->cfg->warn_dups) + WRN("duplicate module alias:\n%s %s\n", + alias, modname); + } + kmod_module_info_free_list(list); + } + + index_write(idx, out); + index_destroy(idx); + + return 0; +} + +static int output_softdeps(struct depmod *depmod, FILE *out) +{ + size_t i; + + fputs("# Soft dependencies extracted from modules themselves.\n", out); + fputs("# Copy, with a .conf extension, to /etc/modprobe.d to use " + "it with modprobe.\n", out); + + for (i = 0; i < depmod->modules.count; i++) { + const struct mod *mod = depmod->modules.array[i]; + struct kmod_list *l, *list = NULL; + int r = kmod_module_get_info(mod->kmod, &list); + if (r < 0 || list == NULL) + continue; + kmod_list_foreach(l, list) { + const char *key = kmod_module_info_get_key(l); + const char *value = kmod_module_info_get_value(l); + + if (!streq(key, "softdep")) + continue; + + fprintf(out, "softdep %s %s\n", + kmod_module_get_name(mod->kmod), value); + } + kmod_module_info_free_list(list); + } + + return 0; +} + +static int output_symbols(struct depmod *depmod, FILE *out) +{ + struct hash_iter iter; + const void *v; + + fputs("# Aliases for symbols, used by symbol_request().\n", out); + + hash_iter_init(depmod->symbols, &iter); + + while (hash_iter_next(&iter, NULL, &v)) { + const struct symbol *sym = v; + if (sym->owner == NULL) + continue; + + fprintf(out, "alias symbol:%s %s\n", + sym->name, sym->owner->modname); + } + + return 0; +} + +static int output_symbols_bin(struct depmod *depmod, FILE *out) +{ + struct index_node *idx; + char alias[1024]; + size_t baselen = sizeof("symbol:") - 1; + struct hash_iter iter; + const void *v; + + if (out == stdout) + return 0; + + idx = index_create(); + if (idx == NULL) + return -ENOMEM; + + memcpy(alias, "symbol:", baselen); + hash_iter_init(depmod->symbols, &iter); + + while (hash_iter_next(&iter, NULL, &v)) { + int duplicate; + const struct symbol *sym = v; + + if (sym->owner == NULL) + continue; + + strcpy(alias + baselen, sym->name); + duplicate = index_insert(idx, alias, sym->owner->modname, + sym->owner->idx); + + if (duplicate && depmod->cfg->warn_dups) + WRN("duplicate module syms:\n%s %s\n", + alias, sym->owner->modname); + } + + index_write(idx, out); + index_destroy(idx); + + return 0; +} + +static int output_builtin_bin(struct depmod *depmod, FILE *out) +{ + FILE *in; + struct index_node *idx; + char infile[PATH_MAX], line[PATH_MAX], modname[PATH_MAX]; + + if (out == stdout) + return 0; + + snprintf(infile, sizeof(infile), "%s/modules.builtin", + depmod->cfg->dirname); + in = fopen(infile, "r"); + if (in == NULL) { + int err = -errno; + WRN("could not open %s: %m\n", infile); + return err; + } + + idx = index_create(); + if (idx == NULL) { + fclose(in); + return -ENOMEM; + } + + while (fgets(line, sizeof(line), in) != NULL) { + if (!isalpha(line[0])) { + ERR("Invalid modules.builtin line: %s\n", line); + continue; + } + + path_to_modname(line, modname, NULL); + index_insert(idx, modname, "", 0); + } + + index_write(idx, out); + index_destroy(idx); + fclose(in); + + return 0; +} + +static int output_devname(struct depmod *depmod, FILE *out) +{ + size_t i; + + fputs("# Device nodes to trigger on-demand module loading.\n", out); + + for (i = 0; i < depmod->modules.count; i++) { + const struct mod *mod = depmod->modules.array[i]; + struct kmod_list *l, *list = NULL; + const char *devname = NULL; + char type = '\0'; + unsigned int major = 0, minor = 0; + int r; + + r = kmod_module_get_info(mod->kmod, &list); + if (r < 0 || list == NULL) + continue; + + kmod_list_foreach(l, list) { + const char *key = kmod_module_info_get_key(l); + const char *value = kmod_module_info_get_value(l); + unsigned int maj, min; + + if (!streq(key, "alias")) + continue; + + if (strstartswith(value, "devname:")) + devname = value + sizeof("devname:") - 1; + else if (sscanf(value, "char-major-%u-%u", + &maj, &min) == 2) { + type = 'c'; + major = maj; + minor = min; + } else if (sscanf(value, "block-major-%u-%u", + &maj, &min) == 2) { + type = 'b'; + major = maj; + minor = min; + } + + if (type != '\0' && devname != NULL) { + fprintf(out, "%s %s %c%u:%u\n", + kmod_module_get_name(mod->kmod), + devname, type, major, minor); + break; + } + } + kmod_module_info_free_list(list); + } + + return 0; +} + +static int depmod_output(struct depmod *depmod, FILE *out) +{ + static const struct depfile { + const char *name; + int (*cb)(struct depmod *depmod, FILE *out); + } *itr, depfiles[] = { + {"modules.dep", output_deps}, + {"modules.dep.bin", output_deps_bin}, + {"modules.alias", output_aliases}, + {"modules.alias.bin", output_aliases_bin}, + {"modules.softdep", output_softdeps}, + {"modules.symbols", output_symbols}, + {"modules.symbols.bin", output_symbols_bin}, + {"modules.builtin.bin", output_builtin_bin}, + {"modules.devname", output_devname}, + {NULL, NULL} + }; + const char *dname = depmod->cfg->dirname; + int dfd, err = 0; + + if (out != NULL) + dfd = -1; + else { + dfd = open(dname, O_RDONLY); + if (dfd < 0) { + err = -errno; + CRIT("could not open directory %s: %m\n", dname); + return err; + } + } + + for (itr = depfiles; itr->name != NULL; itr++) { + FILE *fp = out; + char tmp[NAME_MAX] = ""; + int r; + + if (fp == NULL) { + int flags = O_CREAT | O_TRUNC | O_WRONLY; + int mode = 0644; + int fd; + + snprintf(tmp, sizeof(tmp), "%s.tmp", itr->name); + fd = openat(dfd, tmp, flags, mode); + if (fd < 0) { + ERR("openat(%s, %s, %o, %o): %m\n", + dname, tmp, flags, mode); + continue; + } + fp = fdopen(fd, "wb"); + if (fp == NULL) { + ERR("fdopen(%d=%s/%s): %m\n", fd, dname, tmp); + close(fd); + continue; + } + } + + r = itr->cb(depmod, fp); + if (fp == out) + continue; + + fclose(fp); + if (r < 0) { + if (unlinkat(dfd, tmp, 0) != 0) + ERR("unlinkat(%s, %s): %m\n", dname, tmp); + } else { + unlinkat(dfd, itr->name, 0); + if (renameat(dfd, tmp, dfd, itr->name) != 0) { + err = -errno; + CRIT("renameat(%s, %s, %s, %s): %m\n", + dname, tmp, dname, itr->name); + break; + } + } + } + + if (dfd >= 0) + close(dfd); + return err; +} + +static void depmod_add_fake_syms(struct depmod *depmod) +{ + /* __this_module is magic inserted by kernel loader. */ + depmod_symbol_add(depmod, "__this_module", 0, NULL); + /* On S390, this is faked up too */ + depmod_symbol_add(depmod, "_GLOBAL_OFFSET_TABLE_", 0, NULL); +} + +static int depmod_load_symvers(struct depmod *depmod, const char *filename) +{ + char line[10240]; + FILE *fp; + unsigned int linenum = 0; + + fp = fopen(filename, "r"); + if (fp == NULL) { + int err = -errno; + DBG("load symvers: %s: %m\n", filename); + return err; + } + DBG("load symvers: %s\n", filename); + + /* eg. "0xb352177e\tfind_first_bit\tvmlinux\tEXPORT_SYMBOL" */ + while (fgets(line, sizeof(line), fp) != NULL) { + const char *ver, *sym, *where; + char *verend; + uint64_t crc; + + linenum++; + + ver = strtok(line, " \t"); + sym = strtok(NULL, " \t"); + where = strtok(NULL, " \t"); + if (!ver || !sym || !where) + continue; + + if (!streq(where, "vmlinux")) + continue; + + crc = strtoull(ver, &verend, 16); + if (verend[0] != '\0') { + ERR("%s:%u Invalid symbol version %s: %m\n", + filename, linenum, ver); + continue; + } + + depmod_symbol_add(depmod, sym, crc, NULL); + } + depmod_add_fake_syms(depmod); + + DBG("loaded symvers: %s\n", filename); + + fclose(fp); + return 0; +} + +static int depmod_load_system_map(struct depmod *depmod, const char *filename) +{ + const char ksymstr[] = "__ksymtab_"; + const size_t ksymstr_len = sizeof(ksymstr) - 1; + char line[10240]; + FILE *fp; + unsigned int linenum = 0; + + fp = fopen(filename, "r"); + if (fp == NULL) { + int err = -errno; + DBG("load System.map: %s: %m\n", filename); + return err; + } + DBG("load System.map: %s\n", filename); + + /* eg. c0294200 R __ksymtab_devfs_alloc_devnum */ + while (fgets(line, sizeof(line), fp) != NULL) { + char *p, *end; + + linenum++; + + p = strchr(line, ' '); + if (p == NULL) + goto invalid_syntax; + p++; + p = strchr(p, ' '); + if (p == NULL) + goto invalid_syntax; + p++; + + /* Covers gpl-only and normal symbols. */ + if (strncmp(p, ksymstr, ksymstr_len) != 0) + continue; + + end = strchr(p, '\n'); + if (end != NULL) + *end = '\0'; + + depmod_symbol_add(depmod, p + ksymstr_len, 0, NULL); + continue; + + invalid_syntax: + ERR("%s:%u: invalid line: %s\n", filename, linenum, line); + } + depmod_add_fake_syms(depmod); + + DBG("loaded System.map: %s\n", filename); + + fclose(fp); + return 0; +} + + +static int depfile_up_to_date_dir(DIR *d, time_t mtime, size_t baselen, char *path) +{ + struct dirent *de; + int err = 1, dfd = dirfd(d); + + while ((de = readdir(d)) != NULL) { + const char *name = de->d_name; + size_t namelen; + struct stat st; + + if (name[0] == '.' && (name[1] == '\0' || + (name[1] == '.' && name[2] == '\0'))) + continue; + if (streq(name, "build") || streq(name, "source")) + continue; + namelen = strlen(name); + if (baselen + namelen + 2 >= PATH_MAX) { + path[baselen] = '\0'; + ERR("path is too long %s%s %zd\n", path, name); + continue; + } + + if (fstatat(dfd, name, &st, 0) < 0) { + ERR("fstatat(%d, %s): %m\n", dfd, name); + continue; + } + + if (S_ISDIR(st.st_mode)) { + int fd; + DIR *subdir; + memcpy(path + baselen, name, namelen + 1); + if (baselen + namelen + 2 + NAME_MAX >= PATH_MAX) { + ERR("directory path is too long %s\n", path); + continue; + } + fd = openat(dfd, name, O_RDONLY); + if (fd < 0) { + ERR("openat(%d, %s, O_RDONLY): %m\n", + dfd, name); + continue; + } + subdir = fdopendir(fd); + if (subdir == NULL) { + ERR("fdopendir(%d): %m\n", fd); + close(fd); + continue; + } + path[baselen + namelen] = '/'; + path[baselen + namelen + 1] = '\0'; + err = depfile_up_to_date_dir(subdir, mtime, + baselen + namelen + 1, + path); + closedir(subdir); + } else if (S_ISREG(st.st_mode)) { + const struct kmod_ext *eitr; + uint8_t matches = 0; + for (eitr = kmod_exts; eitr->ext != NULL; eitr++) { + if (namelen <= eitr->len) + continue; + if (streq(name + namelen - eitr->len, eitr->ext)) { + matches = 1; + break; + } + } + if (!matches) + continue; + memcpy(path + baselen, name, namelen + 1); + err = st.st_mtime <= mtime; + if (err == 0) { + DBG("%s %"PRIu64" is newer than %"PRIu64"\n", + path, (uint64_t)st.st_mtime, + (uint64_t)mtime); + } + } else { + ERR("unsupported file type %s: %o\n", + path, st.st_mode & S_IFMT); + continue; + } + + if (err == 0) + break; /* outdated! */ + else if (err < 0) { + path[baselen + namelen] = '\0'; + ERR("failed %s: %s\n", path, strerror(-err)); + err = 1; /* ignore errors */ + } + } + + return err; +} + +/* uptodate: 1, outdated: 0, errors < 0 */ +static int depfile_up_to_date(const char *dirname) +{ + char path[PATH_MAX]; + DIR *d = opendir(dirname); + struct stat st; + size_t baselen; + int err; + if (d == NULL) { + err = -errno; + ERR("could not open directory %s: %m\n", dirname); + return err; + } + + if (fstatat(dirfd(d), "modules.dep", &st, 0) != 0) { + err = -errno; + ERR("could not fstatat(%s, modules.dep): %m\n", dirname); + closedir(d); + return err; + } + + baselen = strlen(dirname); + memcpy(path, dirname, baselen); + path[baselen] = '/'; + baselen++; + path[baselen] = '\0'; + + err = depfile_up_to_date_dir(d, st.st_mtime, baselen, path); + closedir(d); + return err; +} + +static int is_version_number(const char *version) +{ + unsigned int d1, d2; + return (sscanf(version, "%u.%u", &d1, &d2) == 2); +} + +static int do_depmod(int argc, char *argv[]) +{ + FILE *out = NULL; + int err = 0, all = 0, maybe_all = 0, n_config_paths = 0; + char *root = NULL; + const char **config_paths = NULL; + const char *system_map = NULL; + const char *module_symvers = NULL; + const char *null_kmod_config = NULL; + struct utsname un; + struct kmod_ctx *ctx = NULL; + struct cfg cfg; + struct depmod depmod; + + memset(&cfg, 0, sizeof(cfg)); + memset(&depmod, 0, sizeof(depmod)); + + for (;;) { + int c, idx = 0; + c = getopt_long(argc, argv, cmdopts_s, cmdopts, &idx); + if (c == -1) + break; + switch (c) { + case 'a': + all = 1; + break; + case 'A': + maybe_all = 1; + break; + case 'b': + root = path_make_absolute_cwd(optarg); + break; + case 'C': { + size_t bytes = sizeof(char *) * (n_config_paths + 2); + void *tmp = realloc(config_paths, bytes); + if (!tmp) { + fputs("Error: out-of-memory\n", stderr); + goto cmdline_failed; + } + config_paths = tmp; + config_paths[n_config_paths] = optarg; + n_config_paths++; + config_paths[n_config_paths] = NULL; + break; + } + case 'E': + module_symvers = optarg; + cfg.check_symvers = 1; + break; + case 'F': + system_map = optarg; + break; + case 'e': + cfg.print_unknown = 1; + break; + case 'v': + verbose++; + break; + case 'n': + out = stdout; + break; + case 'P': + if (optarg[1] != '\0') { + CRIT("-P only takes a single char\n"); + goto cmdline_failed; + } + cfg.sym_prefix = optarg[0]; + break; + case 'w': + cfg.warn_dups = 1; + break; + case 'u': + case 'q': + case 'r': + case 'm': + if (idx > 0) { + fprintf(stderr, + "ignored deprecated option --%s\n", + cmdopts[idx].name); + } else { + fprintf(stderr, + "ignored deprecated option -%c\n", c); + } + break; + case 'h': + help(basename(argv[0])); + free(config_paths); + return EXIT_SUCCESS; + case 'V': + puts(PACKAGE " version " VERSION); + free(config_paths); + return EXIT_SUCCESS; + case '?': + goto cmdline_failed; + default: + fprintf(stderr, + "Error: unexpected getopt_long() value '%c'.\n", + c); + goto cmdline_failed; + } + } + + if (optind < argc && is_version_number(argv[optind])) { + cfg.kversion = argv[optind]; + optind++; + } else { + if (uname(&un) < 0) { + CRIT("uname() failed: %s\n", strerror(errno)); + goto cmdline_failed; + } + cfg.kversion = un.release; + } + + cfg.dirnamelen = snprintf(cfg.dirname, PATH_MAX, + "%s" ROOTPREFIX "/lib/modules/%s", + root == NULL ? "" : root, cfg.kversion); + + if (optind == argc) + all = 1; + + if (maybe_all) { + if (out == stdout) + goto done; + /* ignore up-to-date errors (< 0) */ + if (depfile_up_to_date(cfg.dirname) == 1) { + DBG("%s/modules.dep is up to date!\n", cfg.dirname); + goto done; + } + DBG("%s/modules.dep is outdated, do -a\n", cfg.dirname); + all = 1; + } + + ctx = kmod_new(cfg.dirname, &null_kmod_config); + if (ctx == NULL) { + CRIT("kmod_new(\"%s\", {NULL}) failed: %m\n", cfg.dirname); + goto cmdline_failed; + } + kmod_set_log_priority(ctx, verbose); + + err = depmod_init(&depmod, &cfg, ctx); + if (err < 0) { + CRIT("depmod_init: %s\n", strerror(-err)); + goto depmod_init_failed; + } + ctx = NULL; /* owned by depmod */ + + if (module_symvers != NULL) { + err = depmod_load_symvers(&depmod, module_symvers); + if (err < 0) { + CRIT("could not load %s: %s\n", module_symvers, + strerror(-err)); + goto cmdline_failed; + } + } else if (system_map != NULL) { + err = depmod_load_system_map(&depmod, system_map); + if (err < 0) { + CRIT("could not load %s: %s\n", system_map, + strerror(-err)); + goto cmdline_failed; + } + } else if (cfg.print_unknown) { + WRN("-e needs -E or -F\n"); + cfg.print_unknown = 0; + } + + if (all) { + err = cfg_load(&cfg, config_paths); + if (err < 0) { + CRIT("could not load configuration files\n"); + goto cmdline_modules_failed; + } + err = depmod_modules_search(&depmod); + if (err < 0) { + CRIT("could not search modules: %s\n", strerror(-err)); + goto cmdline_modules_failed; + } + } else { + int i; + + for (i = optind; i < argc; i++) { + const char *path = argv[i]; + struct kmod_module *mod; + + if (path[0] != '/') { + CRIT("%s: not absolute path.\n", path); + goto cmdline_modules_failed; + } + + err = kmod_module_new_from_path(depmod.ctx, path, &mod); + if (err < 0) { + CRIT("could not create module %s: %s\n", + path, strerror(-err)); + goto cmdline_modules_failed; + } + + err = depmod_module_add(&depmod, mod); + if (err < 0) { + CRIT("could not add module %s: %s\n", + path, strerror(-err)); + kmod_module_unref(mod); + goto cmdline_modules_failed; + } + } + } + + err = depmod_modules_build_array(&depmod); + if (err < 0) { + CRIT("could not build module array: %s\n", + strerror(-err)); + goto cmdline_modules_failed; + } + + depmod_modules_sort(&depmod); + err = depmod_load(&depmod); + if (err < 0) + goto cmdline_modules_failed; + + err = depmod_output(&depmod, out); + +done: + depmod_shutdown(&depmod); + cfg_free(&cfg); + free(config_paths); + return err >= 0 ? EXIT_SUCCESS : EXIT_FAILURE; + +cmdline_modules_failed: + depmod_shutdown(&depmod); +depmod_init_failed: + if (ctx != NULL) + kmod_unref(ctx); +cmdline_failed: + cfg_free(&cfg); + free(config_paths); + free(root); + return EXIT_FAILURE; +} + +#ifndef KMOD_BUNDLE_TOOL +int main(int argc, char *argv[]) +{ + return do_depmod(argc, argv); +} + +#else +#include "kmod.h" + +const struct kmod_cmd kmod_cmd_compat_depmod = { + .name = "depmod", + .cmd = do_depmod, + .help = "compat depmod command", +}; + +#endif diff --git a/tools/kmod-insmod.c b/tools/kmod-insmod.c new file mode 100644 index 0000000..4459cc0 --- /dev/null +++ b/tools/kmod-insmod.c @@ -0,0 +1,171 @@ +/* + * kmod-insmod - insert modules into linux kernel using libkmod. + * + * Copyright (C) 2011-2012 ProFUSION embedded systems + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include +#include +#include +#include +#include +#include "libkmod.h" + + +static const char cmdopts_s[] = "psfVh"; +static const struct option cmdopts[] = { + {"version", no_argument, 0, 'V'}, + {"help", no_argument, 0, 'h'}, + {NULL, 0, 0, 0} +}; + +static void help(const char *progname) +{ + fprintf(stderr, + "Usage:\n" + "\t%s [options] filename [args]\n" + "Options:\n" + "\t-V, --version show version\n" + "\t-h, --help show this help\n", + progname); +} + +static const char *mod_strerror(int err) +{ + switch (err) { + case ENOEXEC: + return "Invalid module format"; + case ENOENT: + return "Unknown symbol in module"; + case ESRCH: + return "Module has wrong symbol version"; + case EINVAL: + return "Invalid parameters"; + default: + return strerror(err); + } +} + +static int do_insmod(int argc, char *argv[]) +{ + struct kmod_ctx *ctx; + struct kmod_module *mod; + const char *filename; + char *opts = NULL; + size_t optslen = 0; + int i, err; + const char *null_config = NULL; + + for (;;) { + int c, idx = 0; + c = getopt_long(argc, argv, cmdopts_s, cmdopts, &idx); + if (c == -1) + break; + switch (c) { + case 'p': + case 's': + case 'f': + /* ignored, for compatibility only */ + break; + case 'h': + help(basename(argv[0])); + return EXIT_SUCCESS; + case 'V': + puts(PACKAGE " version " VERSION); + return EXIT_SUCCESS; + case '?': + return EXIT_FAILURE; + default: + fprintf(stderr, + "Error: unexpected getopt_long() value '%c'.\n", + c); + return EXIT_FAILURE; + } + } + + if (optind >= argc) { + fprintf(stderr, "Error: missing filename.\n"); + return EXIT_FAILURE; + } + + filename = argv[optind]; + if (strcmp(filename, "-") == 0) { + fputs("Error: this tool does not support loading from stdin!\n", + stderr); + return EXIT_FAILURE; + } + + for (i = optind + 1; i < argc; i++) { + size_t len = strlen(argv[i]); + void *tmp = realloc(opts, optslen + len + 2); + if (tmp == NULL) { + fputs("Error: out of memory\n", stderr); + free(opts); + return EXIT_FAILURE; + } + opts = tmp; + if (optslen > 0) { + opts[optslen] = ' '; + optslen++; + } + memcpy(opts + optslen, argv[i], len); + optslen += len; + opts[optslen] = '\0'; + } + + ctx = kmod_new(NULL, &null_config); + if (!ctx) { + fputs("Error: kmod_new() failed!\n", stderr); + free(opts); + return EXIT_FAILURE; + } + + err = kmod_module_new_from_path(ctx, filename, &mod); + if (err < 0) { + fprintf(stderr, "Error: could not load module %s: %s\n", + filename, strerror(-err)); + goto end; + } + + err = kmod_module_insert_module(mod, 0, opts); + if (err < 0) { + fprintf(stderr, "Error: could not insert module %s: %s\n", + filename, mod_strerror(-err)); + } + kmod_module_unref(mod); + +end: + kmod_unref(ctx); + free(opts); + return err >= 0 ? EXIT_SUCCESS : EXIT_FAILURE; +} + +#ifndef KMOD_BUNDLE_TOOL +int main(int argc, char *argv[]) +{ + return do_insmod(argc, argv); +} + +#else +#include "kmod.h" + +const struct kmod_cmd kmod_cmd_compat_insmod = { + .name = "insmod", + .cmd = do_insmod, + .help = "compat insmod command", +}; + +#endif diff --git a/tools/kmod-lsmod.c b/tools/kmod-lsmod.c new file mode 100644 index 0000000..ad66b75 --- /dev/null +++ b/tools/kmod-lsmod.c @@ -0,0 +1,109 @@ +/* + * kmod-lsmod - list modules from linux kernel using libkmod. + * + * Copyright (C) 2011-2012 ProFUSION embedded systems + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include +#include +#include +#include +#include +#include +#include "libkmod.h" + + +static int do_lsmod(int argc, char *argv[]) +{ + struct kmod_ctx *ctx; + const char *null_config = NULL; + struct kmod_list *list, *itr; + int err; + + if (argc != 1) { + fprintf(stderr, "Usage: %s\n", argv[0]); + return EXIT_FAILURE; + } + + ctx = kmod_new(NULL, &null_config); + if (ctx == NULL) { + fputs("Error: kmod_new() failed!\n", stderr); + return EXIT_FAILURE; + } + + err = kmod_module_new_from_loaded(ctx, &list); + if (err < 0) { + fprintf(stderr, "Error: could not get list of modules: %s\n", + strerror(-err)); + kmod_unref(ctx); + return EXIT_FAILURE; + } + + puts("Module Size Used by"); + + kmod_list_foreach(itr, list) { + struct kmod_module *mod = kmod_module_get_module(itr); + const char *name = kmod_module_get_name(mod); + int use_count = kmod_module_get_refcnt(mod); + long size = kmod_module_get_size(mod); + struct kmod_list *holders, *hitr; + int first = 1; + + printf("%-19s %8ld %d ", name, size, use_count); + holders = kmod_module_get_holders(mod); + kmod_list_foreach(hitr, holders) { + struct kmod_module *hm = kmod_module_get_module(hitr); + + if (!first) + putchar(','); + else + first = 0; + + fputs(kmod_module_get_name(hm), stdout); + kmod_module_unref(hm); + } + putchar('\n'); + kmod_module_unref_list(holders); + kmod_module_unref(mod); + } + kmod_module_unref_list(list); + kmod_unref(ctx); + + return EXIT_SUCCESS; +} + +#ifndef KMOD_BUNDLE_TOOL +int main(int argc, char *argv[]) +{ + return do_lsmod(argc, argv); +} + +#else +#include "kmod.h" + +const struct kmod_cmd kmod_cmd_compat_lsmod = { + .name = "lsmod", + .cmd = do_lsmod, + .help = "compat lsmod command", +}; + +const struct kmod_cmd kmod_cmd_list = { + .name = "list", + .cmd = do_lsmod, + .help = "list currently loaded modules", +}; + +#endif diff --git a/tools/kmod-modinfo.c b/tools/kmod-modinfo.c new file mode 100644 index 0000000..aa5223f --- /dev/null +++ b/tools/kmod-modinfo.c @@ -0,0 +1,486 @@ +/* + * kmod-modinfo - query kernel module information using libkmod. + * + * Copyright (C) 2011-2012 ProFUSION embedded systems + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "libkmod.h" + +#define LOG(fmt, ...) fprintf(stderr, "ERROR: "fmt, ##__VA_ARGS__) + +static char separator = '\n'; +static const char *field = NULL; + +struct param { + struct param *next; + const char *name; + const char *param; + const char *type; + int namelen; + int paramlen; + int typelen; +}; + +static struct param *add_param(const char *name, int namelen, const char *param, int paramlen, const char *type, int typelen, struct param **list) +{ + struct param *it; + + for (it = *list; it != NULL; it = it->next) { + if (it->namelen == namelen && + memcmp(it->name, name, namelen) == 0) + break; + } + + if (it == NULL) { + it = malloc(sizeof(struct param)); + if (it == NULL) + return NULL; + it->next = *list; + *list = it; + it->name = name; + it->namelen = namelen; + it->param = NULL; + it->type = NULL; + it->paramlen = 0; + it->typelen = 0; + } + + if (param != NULL) { + it->param = param; + it->paramlen = paramlen; + } + + if (type != NULL) { + it->type = type; + it->typelen = typelen; + } + + return it; +} + +static int process_parm(const char *key, const char *value, struct param **params) +{ + const char *name, *param, *type; + int namelen, paramlen, typelen; + struct param *it; + const char *colon = strchr(value, ':'); + if (colon == NULL) { + LOG("Found invalid \"%s=%s\": missing ':'\n", + key, value); + return 0; + } + + name = value; + namelen = colon - value; + if (strcmp(key, "parm") == 0) { + param = colon + 1; + paramlen = strlen(param); + type = NULL; + typelen = 0; + } else { + param = NULL; + paramlen = 0; + type = colon + 1; + typelen = strlen(type); + } + + it = add_param(name, namelen, param, paramlen, type, typelen, params); + if (it == NULL) { + LOG("Out of memory!\n"); + return -ENOMEM; + } + + return 0; +} + +static int modinfo_params_do(const struct kmod_list *list) +{ + const struct kmod_list *l; + struct param *params = NULL; + int err = 0; + + kmod_list_foreach(l, list) { + const char *key = kmod_module_info_get_key(l); + const char *value = kmod_module_info_get_value(l); + if (strcmp(key, "parm") != 0 && + strcmp(key, "parmtype") != 0) + continue; + + err = process_parm(key, value, ¶ms); + if (err < 0) + goto end; + } + + while (params != NULL) { + struct param *p = params; + params = p->next; + + if (p->param == NULL) + printf("%.*s: (%.*s)%c", + p->namelen, p->name, p->typelen, p->type, + separator); + else if (p->type != NULL) + printf("%.*s:%.*s (%.*s)%c", + p->namelen, p->name, + p->paramlen, p->param, + p->typelen, p->type, + separator); + else + printf("%.*s:%.*s%c", + p->namelen, p->name, + p->paramlen, p->param, + separator); + + free(p); + } + +end: + while (params != NULL) { + void *tmp = params; + params = params->next; + free(tmp); + } + + return err; +} + +static int modinfo_do(struct kmod_module *mod) +{ + struct kmod_list *l, *list = NULL; + struct param *params = NULL; + int err; + + if (field != NULL && strcmp(field, "filename") == 0) { + printf("%s%c", kmod_module_get_path(mod), separator); + return 0; + } else if (field == NULL) { + printf("%-16s%s%c", "filename:", + kmod_module_get_path(mod), separator); + } + + err = kmod_module_get_info(mod, &list); + if (err < 0) { + LOG("could not get modinfo from '%s': %s\n", + kmod_module_get_name(mod), strerror(-err)); + return err; + } + + if (field != NULL && strcmp(field, "parm") == 0) { + err = modinfo_params_do(list); + goto end; + } + + kmod_list_foreach(l, list) { + const char *key = kmod_module_info_get_key(l); + const char *value = kmod_module_info_get_value(l); + int keylen; + + if (field != NULL) { + if (strcmp(field, key) != 0) + continue; + /* filtered output contains no key, just value */ + printf("%s%c", value, separator); + continue; + } + + if (strcmp(key, "parm") == 0 || strcmp(key, "parmtype") == 0) { + err = process_parm(key, value, ¶ms); + if (err < 0) + goto end; + continue; + } + + if (separator == '\0') { + printf("%s=%s%c", key, value, separator); + continue; + } + + keylen = strlen(key); + printf("%s:%-*s%s%c", key, 15 - keylen, "", value, separator); + } + + if (field != NULL) + goto end; + + while (params != NULL) { + struct param *p = params; + params = p->next; + + if (p->param == NULL) + printf("%-16s%.*s:%.*s%c", "parm:", + p->namelen, p->name, p->typelen, p->type, + separator); + else if (p->type != NULL) + printf("%-16s%.*s:%.*s (%.*s)%c", "parm:", + p->namelen, p->name, + p->paramlen, p->param, + p->typelen, p->type, + separator); + else + printf("%-16s%.*s:%.*s%c", + "parm:", + p->namelen, p->name, + p->paramlen, p->param, + separator); + + free(p); + } + +end: + while (params != NULL) { + void *tmp = params; + params = params->next; + free(tmp); + } + kmod_module_info_free_list(list); + + return err; +} + +static int modinfo_path_do(struct kmod_ctx *ctx, const char *path) +{ + struct kmod_module *mod; + int err = kmod_module_new_from_path(ctx, path, &mod); + if (err < 0) { + LOG("Module file %s not found.\n", path); + return err; + } + err = modinfo_do(mod); + kmod_module_unref(mod); + return err; +} + +static int modinfo_alias_do(struct kmod_ctx *ctx, const char *alias) +{ + struct kmod_list *l, *filtered, *list = NULL; + int err = kmod_module_new_from_lookup(ctx, alias, &list); + if (err < 0) { + LOG("Module alias %s not found.\n", alias); + return err; + } + + if (list == NULL) { + LOG("Module %s not found.\n", alias); + return -ENOENT; + } + + err = kmod_module_apply_filter(ctx, KMOD_FILTER_BUILTIN, list, &filtered); + kmod_module_unref_list(list); + if (err < 0) { + LOG("Failed to filter list: %m\n"); + return err; + } + + if (filtered == NULL) { + LOG("Module %s not found.\n", alias); + return -ENOENT; + } + + kmod_list_foreach(l, filtered) { + struct kmod_module *mod = kmod_module_get_module(l); + int r = modinfo_do(mod); + kmod_module_unref(mod); + if (r < 0) + err = r; + } + kmod_module_unref_list(filtered); + return err; +} + +static const char cmdopts_s[] = "adlpn0F:k:b:Vh"; +static const struct option cmdopts[] = { + {"author", no_argument, 0, 'a'}, + {"description", no_argument, 0, 'd'}, + {"license", no_argument, 0, 'l'}, + {"parameters", no_argument, 0, 'p'}, + {"filename", no_argument, 0, 'n'}, + {"null", no_argument, 0, '0'}, + {"field", required_argument, 0, 'F'}, + {"set-version", required_argument, 0, 'k'}, + {"basedir", required_argument, 0, 'b'}, + {"version", no_argument, 0, 'V'}, + {"help", no_argument, 0, 'h'}, + {NULL, 0, 0, 0} +}; + +static void help(const char *progname) +{ + fprintf(stderr, + "Usage:\n" + "\t%s [options] filename [args]\n" + "Options:\n" + "\t-a, --author Print only 'author'\n" + "\t-d, --description Print only 'description'\n" + "\t-l, --license Print only 'license'\n" + "\t-p, --parameters Print only 'parm'\n" + "\t-n, --filename Print only 'filename'\n" + "\t-0, --null Use \\0 instead of \\n\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 " ROOTPREFIX "/lib/modules\n" + "\t-V, --version Show version\n" + "\t-h, --help Show this help\n", + progname); +} + +static bool is_module_filename(const char *name) +{ + struct stat st; + const char *ptr; + + if (stat(name, &st) == 0 && S_ISREG(st.st_mode) && + (ptr = strstr(name, ".ko")) != NULL) { + /* + * We screened for .ko; make sure this is either at the end of + * the name or followed by another '.' (e.g. gz or xz modules) + */ + if(ptr[3] == '\0' || ptr[3] == '.') + return true; + } + + return false; +} + +static int do_modinfo(int argc, char *argv[]) +{ + struct kmod_ctx *ctx; + char dirname_buf[PATH_MAX]; + const char *dirname = NULL; + const char *kversion = NULL; + const char *root = NULL; + const char *null_config = NULL; + int i, err; + + for (;;) { + int c, idx = 0; + c = getopt_long(argc, argv, cmdopts_s, cmdopts, &idx); + if (c == -1) + break; + switch (c) { + case 'a': + field = "author"; + break; + case 'd': + field = "description"; + break; + case 'l': + field = "license"; + break; + case 'p': + field = "parm"; + break; + case 'n': + field = "filename"; + break; + case '0': + separator = '\0'; + break; + case 'F': + field = optarg; + break; + case 'k': + kversion = optarg; + break; + case 'b': + root = optarg; + break; + case 'h': + help(basename(argv[0])); + return EXIT_SUCCESS; + case 'V': + puts(PACKAGE " version " VERSION); + return EXIT_SUCCESS; + case '?': + return EXIT_FAILURE; + default: + fprintf(stderr, + "Error: unexpected getopt_long() value '%c'.\n", + c); + return EXIT_FAILURE; + } + } + + if (optind >= argc) { + fprintf(stderr, "Error: missing module or filename.\n"); + return EXIT_FAILURE; + } + + if (root != NULL || kversion != NULL) { + struct utsname u; + if (root == NULL) + root = ""; + if (kversion == NULL) { + if (uname(&u) < 0) { + fprintf(stderr, "Error: uname() failed: %s\n", + strerror(errno)); + return EXIT_FAILURE; + } + kversion = u.release; + } + snprintf(dirname_buf, sizeof(dirname_buf), "%s" ROOTPREFIX "/lib/modules/%s", + root, kversion); + dirname = dirname_buf; + } + + ctx = kmod_new(dirname, &null_config); + if (!ctx) { + fputs("Error: kmod_new() failed!\n", stderr); + return EXIT_FAILURE; + } + + err = 0; + for (i = optind; i < argc; i++) { + const char *name = argv[i]; + int r; + + if (is_module_filename(name)) + r = modinfo_path_do(ctx, name); + else + r = modinfo_alias_do(ctx, name); + + if (r < 0) + err = r; + } + + kmod_unref(ctx); + return err >= 0 ? EXIT_SUCCESS : EXIT_FAILURE; +} + +#ifndef KMOD_BUNDLE_TOOL +int main(int argc, char *argv[]) +{ + return do_modinfo(argc, argv); +} + +#else +#include "kmod.h" + +const struct kmod_cmd kmod_cmd_compat_modinfo = { + .name = "modinfo", + .cmd = do_modinfo, + .help = "compat modinfo command", +}; + +#endif diff --git a/tools/kmod-modprobe.c b/tools/kmod-modprobe.c new file mode 100644 index 0000000..b94bdf3 --- /dev/null +++ b/tools/kmod-modprobe.c @@ -0,0 +1,1036 @@ +/* + * kmod-modprobe - manage linux kernel modules using libkmod. + * + * Copyright (C) 2011-2012 ProFUSION embedded systems + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "libkmod.h" +#include "libkmod-array.h" +#include "macro.h" + +static int log_priority = LOG_CRIT; +static int use_syslog = 0; + +#define DEFAULT_VERBOSE LOG_WARNING +static int verbose = DEFAULT_VERBOSE; +static int do_show = 0; +static int dry_run = 0; +static int ignore_loaded = 0; +static int lookup_only = 0; +static int first_time = 0; +static int ignore_commands = 0; +static int use_blacklist = 0; +static int force = 0; +static int strip_modversion = 0; +static int strip_vermagic = 0; +static int remove_dependencies = 0; +static int quiet_inuse = 0; + +static const char cmdopts_s[] = "arRibfDcnC:d:S:sqvVh"; +static const struct option cmdopts[] = { + {"all", no_argument, 0, 'a'}, + {"remove", no_argument, 0, 'r'}, + {"remove-dependencies", no_argument, 0, 5}, + {"resolve-alias", no_argument, 0, 'R'}, + {"first-time", no_argument, 0, 3}, + {"ignore-install", no_argument, 0, 'i'}, + {"ignore-remove", no_argument, 0, 'i'}, + {"use-blacklist", no_argument, 0, 'b'}, + {"force", no_argument, 0, 'f'}, + {"force-modversion", no_argument, 0, 2}, + {"force-vermagic", no_argument, 0, 1}, + + {"show-depends", no_argument, 0, 'D'}, + {"showconfig", no_argument, 0, 'c'}, + {"show-config", no_argument, 0, 'c'}, + {"show-modversions", no_argument, 0, 4}, + {"dump-modversions", no_argument, 0, 4}, + + {"dry-run", no_argument, 0, 'n'}, + {"show", no_argument, 0, 'n'}, + + {"config", required_argument, 0, 'C'}, + {"dirname", required_argument, 0, 'd'}, + {"set-version", required_argument, 0, 'S'}, + + {"syslog", no_argument, 0, 's'}, + {"quiet", no_argument, 0, 'q'}, + {"verbose", no_argument, 0, 'v'}, + {"version", no_argument, 0, 'V'}, + {"help", no_argument, 0, 'h'}, + {NULL, 0, 0, 0} +}; + +static void help(const char *progname) +{ + fprintf(stderr, + "Usage:\n" + "\t%s [options] [-i] [-b] modulename\n" + "\t%s [options] -a [-i] [-b] modulename [modulename...]\n" + "\t%s [options] -r [-i] modulename\n" + "\t%s [options] -r -a [-i] modulename [modulename...]\n" + "\t%s [options] -c\n" + "\t%s [options] --dump-modversions filename\n" + "Management Options:\n" + "\t-a, --all Consider every non-argument to\n" + "\t be a module name to be inserted\n" + "\t or removed (-r)\n" + "\t-r, --remove Remove modules instead of inserting\n" + "\t --remove-dependencies Also remove modules depending on it\n" + "\t-R, --resolve-alias Only lookup and print alias and exit\n" + "\t --first-time Fail if module already inserted or removed\n" + "\t-i, --ignore-install Ignore install commands\n" + "\t-i, --ignore-remove Ignore remove commands\n" + "\t-b, --use-blacklist Apply blacklist to resolved alias.\n" + "\t-f, --force Force module insertion or removal.\n" + "\t implies --force-modversions and\n" + "\t --force-vermagic\n" + "\t --force-modversion Ignore module's version\n" + "\t --force-vermagic Ignore module's version magic\n" + "\n" + "Query Options:\n" + "\t-D, --show-depends Only print module dependencies and exit\n" + "\t-c, --showconfig Print out known configuration and exit\n" + "\t-c, --show-config Same as --showconfig\n" + "\t --show-modversions Dump module symbol version and exit\n" + "\t --dump-modversions Same as --show-modversions\n" + "\n" + "General Options:\n" + "\t-n, --dry-run Do not execute operations, just print out\n" + "\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 " ROOTPREFIX "/lib/modules\n" + "\t-S, --set-version=VERSION Use VERSION instead of `uname -r`\n" + + "\t-s, --syslog print to syslog, not stderr\n" + "\t-q, --quiet disable messages\n" + "\t-v, --verbose enables more messages\n" + "\t-V, --version show version\n" + "\t-h, --help show this help\n", + progname, progname, progname, progname, progname, progname); +} + +static inline void _show(const char *fmt, ...) +{ + va_list args; + + if (!do_show && verbose <= DEFAULT_VERBOSE) + return; + + va_start(args, fmt); + vfprintf(stdout, fmt, args); + fflush(stdout); + va_end(args); +} + +static inline void _log(int prio, const char *fmt, ...) +{ + const char *prioname; + char buf[32], *msg; + va_list args; + + if (prio > verbose) + return; + + va_start(args, fmt); + if (vasprintf(&msg, fmt, args) < 0) + msg = NULL; + va_end(args); + if (msg == NULL) + return; + + switch (prio) { + case LOG_CRIT: + prioname = "FATAL"; + break; + case LOG_ERR: + prioname = "ERROR"; + break; + case LOG_WARNING: + prioname = "WARNING"; + break; + case LOG_NOTICE: + prioname = "NOTICE"; + break; + case LOG_INFO: + prioname = "INFO"; + break; + case LOG_DEBUG: + prioname = "DEBUG"; + break; + default: + snprintf(buf, sizeof(buf), "LOG-%03d", prio); + prioname = buf; + } + + if (use_syslog) + syslog(LOG_NOTICE, "%s: %s", prioname, msg); + else + fprintf(stderr, "%s: %s", prioname, msg); + free(msg); + + if (prio <= LOG_CRIT) + exit(EXIT_FAILURE); +} +#define ERR(...) _log(LOG_ERR, __VA_ARGS__) +#define WRN(...) _log(LOG_WARNING, __VA_ARGS__) +#define INF(...) _log(LOG_INFO, __VA_ARGS__) +#define DBG(...) _log(LOG_DEBUG, __VA_ARGS__) +#define LOG(...) _log(log_priority, __VA_ARGS__) +#define SHOW(...) _show(__VA_ARGS__) + +static int show_config(struct kmod_ctx *ctx) +{ + struct config_iterators { + const char *name; + struct kmod_config_iter *(*get_iter)(const struct kmod_ctx *ctx); + } ci[] = { + { "blacklist", kmod_config_get_blacklists }, + { "install", kmod_config_get_install_commands }, + { "remove", kmod_config_get_remove_commands }, + { "alias", kmod_config_get_aliases }, + { "option", kmod_config_get_options }, + { "softdep", kmod_config_get_softdeps }, + }; + size_t i; + + for (i = 0; i < ARRAY_SIZE(ci); i++) { + struct kmod_config_iter *iter = ci[i].get_iter(ctx); + + if (iter == NULL) + continue; + + while (kmod_config_iter_next(iter)) { + const char *val; + + printf("%s %s", ci[i].name, + kmod_config_iter_get_key(iter)); + val = kmod_config_iter_get_value(iter); + if (val != NULL) { + putchar(' '); + puts(val); + } else + putchar('\n'); + } + + kmod_config_iter_free_iter(iter); + } + + puts("\n# End of configuration files. Dumping indexes now:\n"); + fflush(stdout); + + kmod_dump_index(ctx, KMOD_INDEX_MODULES_ALIAS, STDOUT_FILENO); + kmod_dump_index(ctx, KMOD_INDEX_MODULES_SYMBOL, STDOUT_FILENO); + + return 0; +} + +static int show_modversions(struct kmod_ctx *ctx, const char *filename) +{ + struct kmod_list *l, *list = NULL; + struct kmod_module *mod; + int err = kmod_module_new_from_path(ctx, filename, &mod); + if (err < 0) { + LOG("Module %s not found.\n", filename); + return err; + } + + err = kmod_module_get_versions(mod, &list); + if (err < 0) { + LOG("could not get modversions of %s: %s\n", + filename, strerror(-err)); + kmod_module_unref(mod); + return err; + } + + kmod_list_foreach(l, list) { + const char *symbol = kmod_module_version_get_symbol(l); + uint64_t crc = kmod_module_version_get_crc(l); + printf("0x%08"PRIx64"\t%s\n", crc, symbol); + } + kmod_module_versions_free_list(list); + kmod_module_unref(mod); + return 0; +} + +static int command_do(struct kmod_module *module, const char *type, + const char *command, const char *cmdline_opts) +{ + const char *modname = kmod_module_get_name(module); + char *p, *cmd = NULL; + size_t cmdlen, cmdline_opts_len, varlen; + int ret = 0; + + if (cmdline_opts == NULL) + cmdline_opts = ""; + cmdline_opts_len = strlen(cmdline_opts); + + cmd = strdup(command); + if (cmd == NULL) + return -ENOMEM; + cmdlen = strlen(cmd); + varlen = sizeof("$CMDLINE_OPTS") - 1; + while ((p = strstr(cmd, "$CMDLINE_OPTS")) != NULL) { + size_t prefixlen = p - cmd; + size_t suffixlen = cmdlen - prefixlen - varlen; + size_t slen = cmdlen - varlen + cmdline_opts_len; + char *suffix = p + varlen; + char *s = malloc(slen + 1); + if (s == NULL) { + free(cmd); + return -ENOMEM; + } + memcpy(s, cmd, p - cmd); + memcpy(s + prefixlen, cmdline_opts, cmdline_opts_len); + memcpy(s + prefixlen + cmdline_opts_len, suffix, suffixlen); + s[slen] = '\0'; + + free(cmd); + cmd = s; + cmdlen = slen; + } + + SHOW("%s %s\n", type, cmd); + if (dry_run) + goto end; + + setenv("MODPROBE_MODULE", modname, 1); + ret = system(cmd); + unsetenv("MODPROBE_MODULE"); + if (ret == -1 || WEXITSTATUS(ret)) { + LOG("Error running %s command for %s\n", type, modname); + if (ret != -1) + ret = -WEXITSTATUS(ret); + } + +end: + free(cmd); + return ret; +} + +static int rmmod_do_remove_module(struct kmod_module *mod) +{ + const char *modname = kmod_module_get_name(mod); + struct kmod_list *deps, *itr; + int flags = 0, err; + + SHOW("rmmod %s\n", kmod_module_get_name(mod)); + + if (dry_run) + return 0; + + if (force) + flags |= KMOD_REMOVE_FORCE; + + err = kmod_module_remove_module(mod, flags); + if (err == -EEXIST) { + if (!first_time) + err = 0; + else + LOG("Module %s is not in kernel.\n", modname); + } + + deps = kmod_module_get_dependencies(mod); + if (deps != NULL) { + kmod_list_foreach(itr, deps) { + struct kmod_module *dep = kmod_module_get_module(itr); + if (kmod_module_get_refcnt(dep) == 0) + rmmod_do_remove_module(dep); + kmod_module_unref(dep); + } + kmod_module_unref_list(deps); + } + + return err; +} + +static int rmmod_do_module(struct kmod_module *mod, bool do_dependencies); + +static int rmmod_do_deps_list(struct kmod_list *list, bool stop_on_errors) +{ + struct kmod_list *l; + + kmod_list_foreach_reverse(l, list) { + struct kmod_module *m = kmod_module_get_module(l); + int r = rmmod_do_module(m, false); + kmod_module_unref(m); + + if (r < 0 && stop_on_errors) + return r; + } + + return 0; +} + +static int rmmod_do_module(struct kmod_module *mod, bool do_dependencies) +{ + const char *modname = kmod_module_get_name(mod); + struct kmod_list *pre = NULL, *post = NULL; + const char *cmd = NULL; + int err; + + if (!ignore_commands) { + err = kmod_module_get_softdeps(mod, &pre, &post); + if (err < 0) { + WRN("could not get softdeps of '%s': %s\n", + modname, strerror(-err)); + return err; + } + + cmd = kmod_module_get_remove_commands(mod); + } + + if (cmd == NULL && !ignore_loaded) { + int state = kmod_module_get_initstate(mod); + + if (state < 0) { + LOG ("Module %s not found.\n", modname); + err = -ENOENT; + goto error; + } else if (state == KMOD_MODULE_BUILTIN) { + LOG("Module %s is builtin.\n", modname); + err = -ENOENT; + goto error; + } else if (state != KMOD_MODULE_LIVE) { + if (first_time) { + LOG("Module %s is not in kernel.\n", modname); + err = -ENOENT; + goto error; + } else { + err = 0; + goto error; + } + } + } + + rmmod_do_deps_list(post, false); + + if (do_dependencies && remove_dependencies) { + struct kmod_list *deps = kmod_module_get_dependencies(mod); + + err = rmmod_do_deps_list(deps, true); + if (err < 0) + goto error; + } + + if (!ignore_loaded) { + int usage = kmod_module_get_refcnt(mod); + + if (usage > 0) { + if (!quiet_inuse) + LOG("Module %s is in use.\n", modname); + + err = -EBUSY; + goto error; + } + } + + if (cmd == NULL) + err = rmmod_do_remove_module(mod); + else + err = command_do(mod, "remove", cmd, NULL); + + if (err < 0) + goto error; + + rmmod_do_deps_list(pre, false); + +error: + kmod_module_unref_list(pre); + kmod_module_unref_list(post); + + return err; +} + +static int rmmod(struct kmod_ctx *ctx, const char *alias) +{ + struct kmod_list *l, *list = NULL; + int err; + + err = kmod_module_new_from_lookup(ctx, alias, &list); + if (err < 0) + return err; + + if (list == NULL) + LOG("Module %s not found.\n", alias); + + kmod_list_foreach(l, list) { + struct kmod_module *mod = kmod_module_get_module(l); + err = rmmod_do_module(mod, true); + kmod_module_unref(mod); + if (err < 0) + break; + } + + kmod_module_unref_list(list); + return err; +} + +static int rmmod_all(struct kmod_ctx *ctx, char **args, int nargs) +{ + int i, err = 0; + + for (i = 0; i < nargs; i++) { + int r = rmmod(ctx, args[i]); + if (r < 0) + err = r; + } + + return err; +} + +static int handle_failed_lookup(struct kmod_ctx *ctx, const char *alias) +{ + struct kmod_module *mod; + int state, err; + + DBG("lookup failed - trying to check if it's builtin\n"); + + err = kmod_module_new_from_name(ctx, alias, &mod); + if (err < 0) + return err; + + state = kmod_module_get_initstate(mod); + kmod_module_unref(mod); + + if (state != KMOD_MODULE_BUILTIN) { + LOG("Module %s not found.\n", alias); + return -ENOENT; + } + + if (first_time) { + LOG("Module %s already in kernel (builtin).\n", alias); + return -ENOENT; + } + + SHOW("builtin %s\n", alias); + return 0; +} + +static void print_action(struct kmod_module *m, bool install, + const char *options) +{ + if (install) + printf("install %s %s\n", kmod_module_get_install_commands(m), + options); + else + printf("insmod %s %s\n", kmod_module_get_path(m), options); +} + +static int insmod(struct kmod_ctx *ctx, const char *alias, + const char *extra_options) +{ + struct kmod_list *l, *list = NULL; + int err, flags = 0; + + void (*show)(struct kmod_module *m, bool install, + const char *options) = NULL; + + err = kmod_module_new_from_lookup(ctx, alias, &list); + if (err < 0) + return err; + + if (list == NULL) + return handle_failed_lookup(ctx, alias); + + if (strip_modversion || force) + flags |= KMOD_PROBE_FORCE_MODVERSION; + if (strip_vermagic || force) + flags |= KMOD_PROBE_FORCE_VERMAGIC; + if (ignore_commands) + flags |= KMOD_PROBE_IGNORE_COMMAND; + if (ignore_loaded) + flags |= KMOD_PROBE_IGNORE_LOADED; + if (dry_run) + flags |= KMOD_PROBE_DRY_RUN; + if (do_show || verbose > DEFAULT_VERBOSE) + show = &print_action; + + + if (use_blacklist) + flags |= KMOD_PROBE_APPLY_BLACKLIST; + if (first_time) + flags |= KMOD_PROBE_FAIL_ON_LOADED; + + kmod_list_foreach(l, list) { + struct kmod_module *mod = kmod_module_get_module(l); + + if (lookup_only) + printf("%s\n", kmod_module_get_name(mod)); + else { + err = kmod_module_probe_insert_module(mod, flags, + extra_options, NULL, NULL, show); + } + + if (err >= 0) + /* ignore flag return values such as a mod being blacklisted */ + err = 0; + else { + switch (err) { + case -EEXIST: + ERR("could not insert '%s': Module already in kernel\n", + kmod_module_get_name(mod)); + break; + default: + ERR("could not insert '%s': %s\n", + kmod_module_get_name(mod), + strerror(-err)); + break; + } + } + + kmod_module_unref(mod); + } + + kmod_module_unref_list(list); + return err; +} + +static int insmod_all(struct kmod_ctx *ctx, char **args, int nargs) +{ + int i, err = 0; + + for (i = 0; i < nargs; i++) { + int r = insmod(ctx, args[i], NULL); + if (r < 0) + err = r; + } + + return err; +} + +static void env_modprobe_options_append(const char *value) +{ + const char *old = getenv("MODPROBE_OPTIONS"); + char *env; + + if (old == NULL) { + setenv("MODPROBE_OPTIONS", value, 1); + return; + } + + if (asprintf(&env, "%s %s", old, value) < 0) { + ERR("could not append value to $MODPROBE_OPTIONS\n"); + return; + } + + if (setenv("MODPROBE_OPTIONS", env, 1) < 0) + ERR("could not setenv(MODPROBE_OPTIONS, \"%s\")\n", env); + free(env); +} + +static int options_from_array(char **args, int nargs, char **output) +{ + char *opts = NULL; + size_t optslen = 0; + int i, err = 0; + + for (i = 1; i < nargs; i++) { + size_t len = strlen(args[i]); + size_t qlen = 0; + const char *value; + void *tmp; + + value = strchr(args[i], '='); + if (value) { + value++; + if (*value != '"' && *value != '\'') { + if (strchr(value, ' ')) + qlen = 2; + } + } + + tmp = realloc(opts, optslen + len + qlen + 2); + if (!tmp) { + err = -errno; + free(opts); + opts = NULL; + ERR("could not gather module options: out-of-memory\n"); + break; + } + opts = tmp; + if (optslen > 0) { + opts[optslen] = ' '; + optslen++; + } + if (qlen == 0) { + memcpy(opts + optslen, args[i], len + 1); + optslen += len; + } else { + size_t keylen = value - args[i]; + size_t valuelen = len - keylen; + memcpy(opts + optslen, args[i], keylen); + optslen += keylen; + opts[optslen] = '"'; + optslen++; + memcpy(opts + optslen, value, valuelen); + optslen += valuelen; + opts[optslen] = '"'; + optslen++; + opts[optslen] = '\0'; + } + } + + *output = opts; + return err; +} + +static char **prepend_options_from_env(int *p_argc, char **orig_argv) +{ + const char *p, *env = getenv("MODPROBE_OPTIONS"); + char **new_argv, *str_start, *str_end, *str, *s, *quote; + int i, argc = *p_argc; + size_t envlen, space_count = 0; + + if (env == NULL) + return orig_argv; + + for (p = env; *p != '\0'; p++) { + if (*p == ' ') + space_count++; + } + + envlen = p - env; + new_argv = malloc(sizeof(char *) * (argc + space_count + 3 + envlen)); + if (new_argv == NULL) + return NULL; + + new_argv[0] = orig_argv[0]; + str_start = str = (char *) (new_argv + argc + space_count + 3); + memcpy(str, env, envlen + 1); + + str_end = str_start + envlen; + + quote = NULL; + for (i = 1, s = str; *s != '\0'; s++) { + if (quote == NULL) { + if (*s == ' ') { + new_argv[i] = str; + i++; + *s = '\0'; + str = s + 1; + } else if (*s == '"' || *s == '\'') + quote = s; + } else { + if (*s == *quote) { + if (quote == str) { + new_argv[i] = str + 1; + i++; + *s = '\0'; + str = s + 1; + } else { + char *it; + for (it = quote; it < s - 1; it++) + it[0] = it[1]; + for (it = s - 1; it < str_end - 2; it++) + it[0] = it[2]; + str_end -= 2; + *str_end = '\0'; + s -= 2; + } + quote = NULL; + } + } + } + if (str < s) { + new_argv[i] = str; + i++; + } + + memcpy(new_argv + i, orig_argv + 1, sizeof(char *) * (argc - 1)); + new_argv[i + argc] = NULL; + *p_argc = i + argc - 1; + + return new_argv; +} + +static void log_syslog(void *data, int priority, const char *file, int line, + const char *fn, const char *format, va_list args) +{ + char *str, buf[32]; + const char *prioname; + + switch (priority) { + case LOG_CRIT: + prioname = "FATAL"; + break; + case LOG_ERR: + prioname = "ERROR"; + break; + case LOG_WARNING: + prioname = "WARNING"; + break; + case LOG_NOTICE: + prioname = "NOTICE"; + break; + case LOG_INFO: + prioname = "INFO"; + break; + case LOG_DEBUG: + prioname = "DEBUG"; + break; + default: + snprintf(buf, sizeof(buf), "LOG-%03d", priority); + prioname = buf; + } + + if (vasprintf(&str, format, args) < 0) + return; +#ifdef ENABLE_DEBUG + syslog(LOG_NOTICE, "%s: %s:%d %s() %s", prioname, file, line, fn, str); +#else + syslog(LOG_NOTICE, "%s: %s", prioname, str); +#endif + free(str); + (void)data; +} + +static int do_modprobe(int argc, char **orig_argv) +{ + struct kmod_ctx *ctx; + char **args = NULL, **argv; + const char **config_paths = NULL; + int nargs = 0, n_config_paths = 0; + char dirname_buf[PATH_MAX]; + const char *dirname = NULL; + const char *root = NULL; + const char *kversion = NULL; + int use_all = 0; + int do_remove = 0; + int do_show_config = 0; + int do_show_modversions = 0; + int err; + + argv = prepend_options_from_env(&argc, orig_argv); + if (argv == NULL) { + fputs("Error: could not prepend options from command line\n", + stderr); + return EXIT_FAILURE; + } + + for (;;) { + int c, idx = 0; + c = getopt_long(argc, argv, cmdopts_s, cmdopts, &idx); + if (c == -1) + break; + switch (c) { + case 'a': + log_priority = LOG_WARNING; + use_all = 1; + break; + case 'r': + do_remove = 1; + break; + case 5: + remove_dependencies = 1; + break; + case 'R': + lookup_only = 1; + break; + case 3: + first_time = 1; + break; + case 'i': + ignore_commands = 1; + break; + case 'b': + use_blacklist = 1; + break; + case 'f': + force = 1; + break; + case 2: + strip_modversion = 1; + break; + case 1: + strip_vermagic = 1; + break; + case 'D': + ignore_loaded = 1; + dry_run = 1; + do_show = 1; + break; + case 'c': + do_show_config = 1; + break; + case 4: + do_show_modversions = 1; + break; + case 'n': + dry_run = 1; + break; + case 'C': { + size_t bytes = sizeof(char *) * (n_config_paths + 2); + void *tmp = realloc(config_paths, bytes); + if (!tmp) { + fputs("Error: out-of-memory\n", stderr); + goto cmdline_failed; + } + config_paths = tmp; + config_paths[n_config_paths] = optarg; + n_config_paths++; + config_paths[n_config_paths] = NULL; + + env_modprobe_options_append("-C"); + env_modprobe_options_append(optarg); + break; + } + case 'd': + root = optarg; + break; + case 'S': + kversion = optarg; + break; + case 's': + env_modprobe_options_append("-s"); + use_syslog = 1; + break; + case 'q': + env_modprobe_options_append("-q"); + verbose--; + break; + case 'v': + env_modprobe_options_append("-v"); + verbose++; + break; + case 'V': + puts(PACKAGE " version " VERSION); + if (argv != orig_argv) + free(argv); + free(config_paths); + return EXIT_SUCCESS; + case 'h': + help(basename(argv[0])); + if (argv != orig_argv) + free(argv); + free(config_paths); + return EXIT_SUCCESS; + case '?': + goto cmdline_failed; + default: + fprintf(stderr, "Error: unexpected getopt_long() value '%c'.\n", + c); + goto cmdline_failed; + } + } + + args = argv + optind; + nargs = argc - optind; + + if (!do_show_config) { + if (nargs == 0) { + fputs("Error: missing parameters. See -h.\n", stderr); + goto cmdline_failed; + } + } + + if (root != NULL || kversion != NULL) { + struct utsname u; + if (root == NULL) + root = ""; + if (kversion == NULL) { + if (uname(&u) < 0) { + fprintf(stderr, "Error: uname() failed: %s\n", + strerror(errno)); + goto cmdline_failed; + } + kversion = u.release; + } + snprintf(dirname_buf, sizeof(dirname_buf), + "%s" ROOTPREFIX "/lib/modules/%s", root, + kversion); + dirname = dirname_buf; + } + + ctx = kmod_new(dirname, config_paths); + if (!ctx) { + fputs("Error: kmod_new() failed!\n", stderr); + goto cmdline_failed; + } + kmod_load_resources(ctx); + + kmod_set_log_priority(ctx, verbose); + if (use_syslog) { + openlog("modprobe", LOG_CONS, LOG_DAEMON); + kmod_set_log_fn(ctx, log_syslog, NULL); + } + + if (do_show_config) + err = show_config(ctx); + else if (do_show_modversions) + err = show_modversions(ctx, args[0]); + else if (do_remove) + err = rmmod_all(ctx, args, use_all ? nargs : 1); + else if (use_all) + err = insmod_all(ctx, args, nargs); + else { + char *opts; + err = options_from_array(args, nargs, &opts); + if (err == 0) { + err = insmod(ctx, args[0], opts); + free(opts); + } + } + + kmod_unref(ctx); + + if (use_syslog) + closelog(); + + if (argv != orig_argv) + free(argv); + + free(config_paths); + return err >= 0 ? EXIT_SUCCESS : EXIT_FAILURE; + +cmdline_failed: + if (argv != orig_argv) + free(argv); + free(config_paths); + return EXIT_FAILURE; +} + +#ifndef KMOD_BUNDLE_TOOL +int main(int argc, char *argv[]) +{ + return do_modprobe(argc, argv); +} + +#else +#include "kmod.h" + +const struct kmod_cmd kmod_cmd_compat_modprobe = { + .name = "modprobe", + .cmd = do_modprobe, + .help = "compat modprobe command", +}; + +#endif diff --git a/tools/kmod-rmmod.c b/tools/kmod-rmmod.c new file mode 100644 index 0000000..33a73ca --- /dev/null +++ b/tools/kmod-rmmod.c @@ -0,0 +1,254 @@ +/* + * kmod-rmmod - remove modules from linux kernel using libkmod. + * + * Copyright (C) 2011-2012 ProFUSION embedded systems + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "libkmod.h" + + +static const char cmdopts_s[] = "fsvVwh"; +static const struct option cmdopts[] = { + {"force", no_argument, 0, 'f'}, + {"syslog", no_argument, 0, 's'}, + {"verbose", no_argument, 0, 'v'}, + {"version", no_argument, 0, 'V'}, + {"wait", no_argument, 0, 'w'}, + {"help", no_argument, 0, 'h'}, + {NULL, 0, 0, 0} +}; + +static void help(const char *progname) +{ + fprintf(stderr, + "Usage:\n" + "\t%s [options] modulename ...\n" + "Options:\n" + "\t-f, --force forces a module unload and may crash your\n" + "\t machine. This requires Forced Module Removal\n" + "\t option in your kernel. DANGEROUS\n" + "\t-s, --syslog print to syslog, not stderr\n" + "\t-v, --verbose enables more messages\n" + "\t-V, --version show version\n" + "\t-w, --wait begins module removal even if it is used and\n" + "\t will stop new users from accessing it.\n" + "\t-h, --help show this help\n", + progname); +} + +static void log_syslog(void *data, int priority, const char *file, int line, + const char *fn, const char *format, + va_list args) +{ + char *str, buf[32]; + const char *prioname; + + switch (priority) { + case LOG_CRIT: + prioname = "FATAL"; + break; + case LOG_ERR: + prioname = "ERROR"; + break; + case LOG_WARNING: + prioname = "WARNING"; + break; + case LOG_NOTICE: + prioname = "NOTICE"; + break; + case LOG_INFO: + prioname = "INFO"; + break; + case LOG_DEBUG: + prioname = "DEBUG"; + break; + default: + snprintf(buf, sizeof(buf), "LOG-%03d", priority); + prioname = buf; + } + + if (vasprintf(&str, format, args) < 0) + return; +#ifdef ENABLE_DEBUG + syslog(LOG_NOTICE, "%s: %s:%d %s() %s", prioname, file, line, fn, str); +#else + syslog(LOG_NOTICE, "%s: %s", prioname, str); +#endif + free(str); + (void)data; +} + +static int check_module_inuse(struct kmod_module *mod) { + struct kmod_list *holders; + + if (kmod_module_get_initstate(mod) == -ENOENT) { + fprintf(stderr, "Error: Module %s is not currently loaded\n", + kmod_module_get_name(mod)); + return -ENOENT; + } + + holders = kmod_module_get_holders(mod); + if (holders != NULL) { + struct kmod_list *itr; + + fprintf(stderr, "Error: Module %s is in use by:", + kmod_module_get_name(mod)); + + kmod_list_foreach(itr, holders) { + struct kmod_module *hm = kmod_module_get_module(itr); + fprintf(stderr, " %s", kmod_module_get_name(hm)); + kmod_module_unref(hm); + } + fputc('\n', stderr); + + kmod_module_unref_list(holders); + return -EBUSY; + } + + if (kmod_module_get_refcnt(mod) != 0) { + fprintf(stderr, "Error: Module %s is in use\n", + kmod_module_get_name(mod)); + return -EBUSY; + } + + return 0; +} + +static int do_rmmod(int argc, char *argv[]) +{ + struct kmod_ctx *ctx; + const char *null_config = NULL; + int flags = KMOD_REMOVE_NOWAIT; + int use_syslog = 0; + int verbose = 0; + int i, err, r = 0; + + for (;;) { + int c, idx = 0; + c = getopt_long(argc, argv, cmdopts_s, cmdopts, &idx); + if (c == -1) + break; + switch (c) { + case 'f': + flags |= KMOD_REMOVE_FORCE; + break; + case 's': + use_syslog = 1; + break; + case 'v': + verbose++; + break; + case 'w': + flags &= ~KMOD_REMOVE_NOWAIT; + break; + case 'h': + help(basename(argv[0])); + return EXIT_SUCCESS; + case 'V': + puts(PACKAGE " version " VERSION); + return EXIT_SUCCESS; + case '?': + return EXIT_FAILURE; + default: + fprintf(stderr, + "Error: unexpected getopt_long() value '%c'.\n", + c); + return EXIT_FAILURE; + } + } + + if (optind >= argc) { + fprintf(stderr, "Error: missing module name.\n"); + return EXIT_FAILURE; + } + + ctx = kmod_new(NULL, &null_config); + if (!ctx) { + fputs("Error: kmod_new() failed!\n", stderr); + return EXIT_FAILURE; + } + + kmod_set_log_priority(ctx, kmod_get_log_priority(ctx) + verbose); + if (use_syslog) { + openlog("rmmod", LOG_CONS, LOG_DAEMON); + kmod_set_log_fn(ctx, log_syslog, NULL); + } + + for (i = optind; i < argc; i++) { + struct kmod_module *mod; + const char *arg = argv[i]; + struct stat st; + if (stat(arg, &st) == 0) + err = kmod_module_new_from_path(ctx, arg, &mod); + else + err = kmod_module_new_from_name(ctx, arg, &mod); + + if (err < 0) { + fprintf(stderr, "Error: could not use module %s: %s\n", + arg, strerror(-err)); + break; + } + + if (!(flags & KMOD_REMOVE_FORCE) && (flags & KMOD_REMOVE_NOWAIT)) + if (check_module_inuse(mod) < 0) { + r++; + goto next; + } + + err = kmod_module_remove_module(mod, flags); + if (err < 0) { + fprintf(stderr, + "Error: could not remove module %s: %s\n", + arg, strerror(-err)); + r++; + } +next: + kmod_module_unref(mod); + } + + kmod_unref(ctx); + + if (use_syslog) + closelog(); + + return r == 0 ? EXIT_SUCCESS : EXIT_FAILURE; +} + +#ifndef KMOD_BUNDLE_TOOL +int main(int argc, char *argv[]) +{ + return do_rmmod(argc, argv); +} + +#else +#include "kmod.h" + +const struct kmod_cmd kmod_cmd_compat_rmmod = { + .name = "rmmod", + .cmd = do_rmmod, + .help = "compat rmmod command", +}; + +#endif diff --git a/tools/kmod.c b/tools/kmod.c index 347bb7d..52b0c5d 100644 --- a/tools/kmod.c +++ b/tools/kmod.c @@ -1,7 +1,7 @@ /* * kmod - one tool to rule them all * - * Copyright (C) 2011-2013 ProFUSION embedded systems + * Copyright (C) 2011-2012 ProFUSION embedded systems * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -37,7 +37,6 @@ static const struct kmod_cmd kmod_cmd_help; static const struct kmod_cmd *kmod_cmds[] = { &kmod_cmd_help, &kmod_cmd_list, - &kmod_cmd_static_nodes, }; static const struct kmod_cmd *kmod_compat_cmds[] = { @@ -158,9 +157,10 @@ static int handle_kmod_compat_commands(int argc, char *argv[]) int main(int argc, char *argv[]) { + const char *binname = basename(argv[0]); int err; - if (strcmp(program_invocation_short_name, "kmod") == 0) + if (strcmp(binname, "kmod") == 0) err = handle_kmod_commands(argc, argv); else err = handle_kmod_compat_commands(argc, argv); diff --git a/tools/kmod.h b/tools/kmod.h index 68a646a..8717aec 100644 --- a/tools/kmod.h +++ b/tools/kmod.h @@ -1,7 +1,7 @@ /* * kmod - one tool to rule them all * - * Copyright (C) 2011-2013 ProFUSION embedded systems + * Copyright (C) 2011-2012 ProFUSION embedded systems * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -17,7 +17,8 @@ * along with this program. If not, see . */ -#pragma once +#ifndef _KMOD_MACRO_H_ +#define _KMOD_MACRO_H_ #include "macro.h" @@ -35,6 +36,4 @@ extern const struct kmod_cmd kmod_cmd_compat_modprobe; extern const struct kmod_cmd kmod_cmd_compat_depmod; extern const struct kmod_cmd kmod_cmd_list; -extern const struct kmod_cmd kmod_cmd_static_nodes; - -#include "log.h" +#endif diff --git a/tools/log.c b/tools/log.c deleted file mode 100644 index 05f6b77..0000000 --- a/tools/log.c +++ /dev/null @@ -1,143 +0,0 @@ -/* - * kmod - log infrastructure - * - * Copyright (C) 2012-2013 ProFUSION embedded systems - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include -#include -#include -#include - -#include "libkmod.h" -#include "kmod.h" - -static bool log_use_syslog; -static int log_priority = LOG_ERR; - -static _always_inline_ const char *prio_to_str(int prio) -{ - const char *prioname; - char buf[32]; - - switch (prio) { - case LOG_CRIT: - prioname = "FATAL"; - break; - case LOG_ERR: - prioname = "ERROR"; - break; - case LOG_WARNING: - prioname = "WARNING"; - break; - case LOG_NOTICE: - prioname = "NOTICE"; - break; - case LOG_INFO: - prioname = "INFO"; - break; - case LOG_DEBUG: - prioname = "DEBUG"; - break; - default: - snprintf(buf, sizeof(buf), "LOG-%03d", prio); - prioname = buf; - } - - return prioname; -} - -_printf_format_(6, 0) -static void log_kmod(void *data, int priority, const char *file, int line, - const char *fn, const char *format, va_list args) -{ - const char *prioname = prio_to_str(priority); - char *str; - - if (vasprintf(&str, format, args) < 0) - return; - - if (log_use_syslog) { -#ifdef ENABLE_DEBUG - syslog(priority, "%s: %s:%d %s() %s", prioname, file, line, - fn, str); -#else - syslog(priority, "%s: %s", prioname, str); -#endif - } else { -#ifdef ENABLE_DEBUG - fprintf(stderr, "%s: %s: %s:%d %s() %s", - program_invocation_short_name, prioname, file, line, - fn, str); -#else - fprintf(stderr, "%s: %s: %s", program_invocation_short_name, - prioname, str); -#endif - } - - free(str); - (void)data; -} -void log_open(bool use_syslog) -{ - log_use_syslog = use_syslog; - - if (log_use_syslog) - openlog(program_invocation_short_name, LOG_CONS, LOG_DAEMON); -} - -void log_close(void) -{ - if (log_use_syslog) - closelog(); -} - -void log_printf(int prio, const char *fmt, ...) -{ - const char *prioname; - char *msg; - va_list args; - - if (prio > log_priority) - return; - - va_start(args, fmt); - if (vasprintf(&msg, fmt, args) < 0) - msg = NULL; - va_end(args); - if (msg == NULL) - return; - - prioname = prio_to_str(prio); - - if (log_use_syslog) - syslog(prio, "%s: %s", prioname, msg); - else - fprintf(stderr, "%s: %s: %s", program_invocation_short_name, - prioname, msg); - free(msg); - - if (prio <= LOG_CRIT) - exit(EXIT_FAILURE); -} - -void log_setup_kmod_log(struct kmod_ctx *ctx, int priority) -{ - log_priority = priority; - - kmod_set_log_priority(ctx, log_priority); - kmod_set_log_fn(ctx, log_kmod, NULL); -} diff --git a/tools/log.h b/tools/log.h deleted file mode 100644 index d55a4c6..0000000 --- a/tools/log.h +++ /dev/null @@ -1,37 +0,0 @@ -/* - * kmod - log infrastructure - * - * Copyright (C) 2012-2013 ProFUSION embedded systems - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include -#include -#include -#include - -#include "kmod.h" - -void log_open(bool use_syslog); -void log_close(void); -void log_printf(int prio, const char *fmt, ...) _printf_format_(2, 3); -#define CRIT(...) log_printf(LOG_CRIT, __VA_ARGS__) -#define ERR(...) log_printf(LOG_ERR, __VA_ARGS__) -#define WRN(...) log_printf(LOG_WARNING, __VA_ARGS__) -#define INF(...) log_printf(LOG_INFO, __VA_ARGS__) -#define DBG(...) log_printf(LOG_DEBUG, __VA_ARGS__) - -struct kmod_ctx; -void log_setup_kmod_log(struct kmod_ctx *ctx, int priority); diff --git a/tools/lsmod.c b/tools/lsmod.c deleted file mode 100644 index b00a9cd..0000000 --- a/tools/lsmod.c +++ /dev/null @@ -1,99 +0,0 @@ -/* - * kmod-lsmod - list modules from linux kernel using libkmod. - * - * Copyright (C) 2011-2013 ProFUSION embedded systems - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include -#include -#include -#include -#include -#include -#include "libkmod.h" - -#include "kmod.h" - -static int do_lsmod(int argc, char *argv[]) -{ - struct kmod_ctx *ctx; - const char *null_config = NULL; - struct kmod_list *list, *itr; - int err; - - if (argc != 1) { - fprintf(stderr, "Usage: %s\n", argv[0]); - return EXIT_FAILURE; - } - - ctx = kmod_new(NULL, &null_config); - if (ctx == NULL) { - fputs("Error: kmod_new() failed!\n", stderr); - return EXIT_FAILURE; - } - - err = kmod_module_new_from_loaded(ctx, &list); - if (err < 0) { - fprintf(stderr, "Error: could not get list of modules: %s\n", - strerror(-err)); - kmod_unref(ctx); - return EXIT_FAILURE; - } - - puts("Module Size Used by"); - - kmod_list_foreach(itr, list) { - struct kmod_module *mod = kmod_module_get_module(itr); - const char *name = kmod_module_get_name(mod); - int use_count = kmod_module_get_refcnt(mod); - long size = kmod_module_get_size(mod); - struct kmod_list *holders, *hitr; - int first = 1; - - printf("%-19s %8ld %d ", name, size, use_count); - holders = kmod_module_get_holders(mod); - kmod_list_foreach(hitr, holders) { - struct kmod_module *hm = kmod_module_get_module(hitr); - - if (!first) - putchar(','); - else - first = 0; - - fputs(kmod_module_get_name(hm), stdout); - kmod_module_unref(hm); - } - putchar('\n'); - kmod_module_unref_list(holders); - kmod_module_unref(mod); - } - kmod_module_unref_list(list); - kmod_unref(ctx); - - return EXIT_SUCCESS; -} - -const struct kmod_cmd kmod_cmd_compat_lsmod = { - .name = "lsmod", - .cmd = do_lsmod, - .help = "compat lsmod command", -}; - -const struct kmod_cmd kmod_cmd_list = { - .name = "list", - .cmd = do_lsmod, - .help = "list currently loaded modules", -}; diff --git a/tools/modinfo.c b/tools/modinfo.c deleted file mode 100644 index 9a60d71..0000000 --- a/tools/modinfo.c +++ /dev/null @@ -1,465 +0,0 @@ -/* - * kmod-modinfo - query kernel module information using libkmod. - * - * Copyright (C) 2011-2013 ProFUSION embedded systems - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "libkmod.h" -#include "libkmod-util.h" - -#include "kmod.h" - -static char separator = '\n'; -static const char *field = NULL; - -struct param { - struct param *next; - const char *name; - const char *param; - const char *type; - int namelen; - int paramlen; - int typelen; -}; - -static struct param *add_param(const char *name, int namelen, const char *param, int paramlen, const char *type, int typelen, struct param **list) -{ - struct param *it; - - for (it = *list; it != NULL; it = it->next) { - if (it->namelen == namelen && - memcmp(it->name, name, namelen) == 0) - break; - } - - if (it == NULL) { - it = malloc(sizeof(struct param)); - if (it == NULL) - return NULL; - it->next = *list; - *list = it; - it->name = name; - it->namelen = namelen; - it->param = NULL; - it->type = NULL; - it->paramlen = 0; - it->typelen = 0; - } - - if (param != NULL) { - it->param = param; - it->paramlen = paramlen; - } - - if (type != NULL) { - it->type = type; - it->typelen = typelen; - } - - return it; -} - -static int process_parm(const char *key, const char *value, struct param **params) -{ - const char *name, *param, *type; - int namelen, paramlen, typelen; - struct param *it; - const char *colon = strchr(value, ':'); - if (colon == NULL) { - ERR("Found invalid \"%s=%s\": missing ':'\n", - key, value); - return 0; - } - - name = value; - namelen = colon - value; - if (strcmp(key, "parm") == 0) { - param = colon + 1; - paramlen = strlen(param); - type = NULL; - typelen = 0; - } else { - param = NULL; - paramlen = 0; - type = colon + 1; - typelen = strlen(type); - } - - it = add_param(name, namelen, param, paramlen, type, typelen, params); - if (it == NULL) { - ERR("Out of memory!\n"); - return -ENOMEM; - } - - return 0; -} - -static int modinfo_params_do(const struct kmod_list *list) -{ - const struct kmod_list *l; - struct param *params = NULL; - int err = 0; - - kmod_list_foreach(l, list) { - const char *key = kmod_module_info_get_key(l); - const char *value = kmod_module_info_get_value(l); - if (strcmp(key, "parm") != 0 && - strcmp(key, "parmtype") != 0) - continue; - - err = process_parm(key, value, ¶ms); - if (err < 0) - goto end; - } - - while (params != NULL) { - struct param *p = params; - params = p->next; - - if (p->param == NULL) - printf("%.*s: (%.*s)%c", - p->namelen, p->name, p->typelen, p->type, - separator); - else if (p->type != NULL) - printf("%.*s:%.*s (%.*s)%c", - p->namelen, p->name, - p->paramlen, p->param, - p->typelen, p->type, - separator); - else - printf("%.*s:%.*s%c", - p->namelen, p->name, - p->paramlen, p->param, - separator); - - free(p); - } - -end: - while (params != NULL) { - void *tmp = params; - params = params->next; - free(tmp); - } - - return err; -} - -static int modinfo_do(struct kmod_module *mod) -{ - struct kmod_list *l, *list = NULL; - struct param *params = NULL; - int err; - - if (field != NULL && strcmp(field, "filename") == 0) { - printf("%s%c", kmod_module_get_path(mod), separator); - return 0; - } else if (field == NULL) { - printf("%-16s%s%c", "filename:", - kmod_module_get_path(mod), separator); - } - - err = kmod_module_get_info(mod, &list); - if (err < 0) { - ERR("could not get modinfo from '%s': %s\n", - kmod_module_get_name(mod), strerror(-err)); - return err; - } - - if (field != NULL && strcmp(field, "parm") == 0) { - err = modinfo_params_do(list); - goto end; - } - - kmod_list_foreach(l, list) { - const char *key = kmod_module_info_get_key(l); - const char *value = kmod_module_info_get_value(l); - int keylen; - - if (field != NULL) { - if (strcmp(field, key) != 0) - continue; - /* filtered output contains no key, just value */ - printf("%s%c", value, separator); - continue; - } - - if (strcmp(key, "parm") == 0 || strcmp(key, "parmtype") == 0) { - err = process_parm(key, value, ¶ms); - if (err < 0) - goto end; - continue; - } - - if (separator == '\0') { - printf("%s=%s%c", key, value, separator); - continue; - } - - keylen = strlen(key); - printf("%s:%-*s%s%c", key, 15 - keylen, "", value, separator); - } - - if (field != NULL) - goto end; - - while (params != NULL) { - struct param *p = params; - params = p->next; - - if (p->param == NULL) - printf("%-16s%.*s:%.*s%c", "parm:", - p->namelen, p->name, p->typelen, p->type, - separator); - else if (p->type != NULL) - printf("%-16s%.*s:%.*s (%.*s)%c", "parm:", - p->namelen, p->name, - p->paramlen, p->param, - p->typelen, p->type, - separator); - else - printf("%-16s%.*s:%.*s%c", - "parm:", - p->namelen, p->name, - p->paramlen, p->param, - separator); - - free(p); - } - -end: - while (params != NULL) { - void *tmp = params; - params = params->next; - free(tmp); - } - kmod_module_info_free_list(list); - - return err; -} - -static int modinfo_path_do(struct kmod_ctx *ctx, const char *path) -{ - struct kmod_module *mod; - int err = kmod_module_new_from_path(ctx, path, &mod); - if (err < 0) { - ERR("Module file %s not found.\n", path); - return err; - } - err = modinfo_do(mod); - kmod_module_unref(mod); - return err; -} - -static int modinfo_alias_do(struct kmod_ctx *ctx, const char *alias) -{ - struct kmod_list *l, *filtered, *list = NULL; - int err = kmod_module_new_from_lookup(ctx, alias, &list); - if (err < 0) { - ERR("Module alias %s not found.\n", alias); - return err; - } - - if (list == NULL) { - ERR("Module %s not found.\n", alias); - return -ENOENT; - } - - err = kmod_module_apply_filter(ctx, KMOD_FILTER_BUILTIN, list, &filtered); - kmod_module_unref_list(list); - if (err < 0) { - ERR("Failed to filter list: %m\n"); - return err; - } - - if (filtered == NULL) { - ERR("Module %s not found.\n", alias); - return -ENOENT; - } - - kmod_list_foreach(l, filtered) { - struct kmod_module *mod = kmod_module_get_module(l); - int r = modinfo_do(mod); - kmod_module_unref(mod); - if (r < 0) - err = r; - } - kmod_module_unref_list(filtered); - return err; -} - -static const char cmdopts_s[] = "adlpn0F:k:b:Vh"; -static const struct option cmdopts[] = { - {"author", no_argument, 0, 'a'}, - {"description", no_argument, 0, 'd'}, - {"license", no_argument, 0, 'l'}, - {"parameters", no_argument, 0, 'p'}, - {"filename", no_argument, 0, 'n'}, - {"null", no_argument, 0, '0'}, - {"field", required_argument, 0, 'F'}, - {"set-version", required_argument, 0, 'k'}, - {"basedir", required_argument, 0, 'b'}, - {"version", no_argument, 0, 'V'}, - {"help", no_argument, 0, 'h'}, - {NULL, 0, 0, 0} -}; - -static void help(void) -{ - printf("Usage:\n" - "\t%s [options] filename [args]\n" - "Options:\n" - "\t-a, --author Print only 'author'\n" - "\t-d, --description Print only 'description'\n" - "\t-l, --license Print only 'license'\n" - "\t-p, --parameters Print only 'parm'\n" - "\t-n, --filename Print only 'filename'\n" - "\t-0, --null Use \\0 instead of \\n\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-V, --version Show version\n" - "\t-h, --help Show this help\n", - program_invocation_short_name); -} - -static bool is_module_filename(const char *name) -{ - struct stat st; - - if (stat(name, &st) == 0 && S_ISREG(st.st_mode) && - path_ends_with_kmod_ext(name, strlen(name))) - return true; - - return false; -} - -static int do_modinfo(int argc, char *argv[]) -{ - struct kmod_ctx *ctx; - char dirname_buf[PATH_MAX]; - const char *dirname = NULL; - const char *kversion = NULL; - const char *root = NULL; - const char *null_config = NULL; - int i, err; - - for (;;) { - int c, idx = 0; - c = getopt_long(argc, argv, cmdopts_s, cmdopts, &idx); - if (c == -1) - break; - switch (c) { - case 'a': - field = "author"; - break; - case 'd': - field = "description"; - break; - case 'l': - field = "license"; - break; - case 'p': - field = "parm"; - break; - case 'n': - field = "filename"; - break; - case '0': - separator = '\0'; - break; - case 'F': - field = optarg; - break; - case 'k': - kversion = optarg; - break; - case 'b': - root = optarg; - break; - case 'h': - help(); - return EXIT_SUCCESS; - case 'V': - puts(PACKAGE " version " VERSION); - return EXIT_SUCCESS; - case '?': - return EXIT_FAILURE; - default: - ERR("unexpected getopt_long() value '%c'.\n", c); - return EXIT_FAILURE; - } - } - - if (optind >= argc) { - ERR("missing module or filename.\n"); - return EXIT_FAILURE; - } - - if (root != NULL || kversion != NULL) { - struct utsname u; - if (root == NULL) - root = ""; - if (kversion == NULL) { - if (uname(&u) < 0) { - ERR("uname() failed: %m\n"); - return EXIT_FAILURE; - } - kversion = u.release; - } - snprintf(dirname_buf, sizeof(dirname_buf), "%s/lib/modules/%s", - root, kversion); - dirname = dirname_buf; - } - - ctx = kmod_new(dirname, &null_config); - if (!ctx) { - ERR("kmod_new() failed!\n"); - return EXIT_FAILURE; - } - - err = 0; - for (i = optind; i < argc; i++) { - const char *name = argv[i]; - int r; - - if (is_module_filename(name)) - r = modinfo_path_do(ctx, name); - else - r = modinfo_alias_do(ctx, name); - - if (r < 0) - err = r; - } - - kmod_unref(ctx); - return err >= 0 ? EXIT_SUCCESS : EXIT_FAILURE; -} - -const struct kmod_cmd kmod_cmd_compat_modinfo = { - .name = "modinfo", - .cmd = do_modinfo, - .help = "compat modinfo command", -}; diff --git a/tools/modprobe.c b/tools/modprobe.c deleted file mode 100644 index 6b34658..0000000 --- a/tools/modprobe.c +++ /dev/null @@ -1,944 +0,0 @@ -/* - * kmod-modprobe - manage linux kernel modules using libkmod. - * - * Copyright (C) 2011-2013 ProFUSION embedded systems - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "libkmod.h" -#include "libkmod-array.h" -#include "macro.h" - -#include "kmod.h" - -static int log_priority = LOG_CRIT; -static int use_syslog = 0; -#define LOG(...) log_printf(log_priority, __VA_ARGS__) - -#define DEFAULT_VERBOSE LOG_WARNING -static int verbose = DEFAULT_VERBOSE; -static int do_show = 0; -static int dry_run = 0; -static int ignore_loaded = 0; -static int lookup_only = 0; -static int first_time = 0; -static int ignore_commands = 0; -static int use_blacklist = 0; -static int force = 0; -static int strip_modversion = 0; -static int strip_vermagic = 0; -static int remove_dependencies = 0; -static int quiet_inuse = 0; - -static const char cmdopts_s[] = "arRibfDcnC:d:S:sqvVh"; -static const struct option cmdopts[] = { - {"all", no_argument, 0, 'a'}, - {"remove", no_argument, 0, 'r'}, - {"remove-dependencies", no_argument, 0, 5}, - {"resolve-alias", no_argument, 0, 'R'}, - {"first-time", no_argument, 0, 3}, - {"ignore-install", no_argument, 0, 'i'}, - {"ignore-remove", no_argument, 0, 'i'}, - {"use-blacklist", no_argument, 0, 'b'}, - {"force", no_argument, 0, 'f'}, - {"force-modversion", no_argument, 0, 2}, - {"force-vermagic", no_argument, 0, 1}, - - {"show-depends", no_argument, 0, 'D'}, - {"showconfig", no_argument, 0, 'c'}, - {"show-config", no_argument, 0, 'c'}, - {"show-modversions", no_argument, 0, 4}, - {"dump-modversions", no_argument, 0, 4}, - - {"dry-run", no_argument, 0, 'n'}, - {"show", no_argument, 0, 'n'}, - - {"config", required_argument, 0, 'C'}, - {"dirname", required_argument, 0, 'd'}, - {"set-version", required_argument, 0, 'S'}, - - {"syslog", no_argument, 0, 's'}, - {"quiet", no_argument, 0, 'q'}, - {"verbose", no_argument, 0, 'v'}, - {"version", no_argument, 0, 'V'}, - {"help", no_argument, 0, 'h'}, - {NULL, 0, 0, 0} -}; - -static void help(void) -{ - printf("Usage:\n" - "\t%s [options] [-i] [-b] modulename\n" - "\t%s [options] -a [-i] [-b] modulename [modulename...]\n" - "\t%s [options] -r [-i] modulename\n" - "\t%s [options] -r -a [-i] modulename [modulename...]\n" - "\t%s [options] -c\n" - "\t%s [options] --dump-modversions filename\n" - "Management Options:\n" - "\t-a, --all Consider every non-argument to\n" - "\t be a module name to be inserted\n" - "\t or removed (-r)\n" - "\t-r, --remove Remove modules instead of inserting\n" - "\t --remove-dependencies Also remove modules depending on it\n" - "\t-R, --resolve-alias Only lookup and print alias and exit\n" - "\t --first-time Fail if module already inserted or removed\n" - "\t-i, --ignore-install Ignore install commands\n" - "\t-i, --ignore-remove Ignore remove commands\n" - "\t-b, --use-blacklist Apply blacklist to resolved alias.\n" - "\t-f, --force Force module insertion or removal.\n" - "\t implies --force-modversions and\n" - "\t --force-vermagic\n" - "\t --force-modversion Ignore module's version\n" - "\t --force-vermagic Ignore module's version magic\n" - "\n" - "Query Options:\n" - "\t-D, --show-depends Only print module dependencies and exit\n" - "\t-c, --showconfig Print out known configuration and exit\n" - "\t-c, --show-config Same as --showconfig\n" - "\t --show-modversions Dump module symbol version and exit\n" - "\t --dump-modversions Same as --show-modversions\n" - "\n" - "General Options:\n" - "\t-n, --dry-run Do not execute operations, just print out\n" - "\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-S, --set-version=VERSION Use VERSION instead of `uname -r`\n" - - "\t-s, --syslog print to syslog, not stderr\n" - "\t-q, --quiet disable messages\n" - "\t-v, --verbose enables more messages\n" - "\t-V, --version show version\n" - "\t-h, --help show this help\n", - program_invocation_short_name, program_invocation_short_name, - program_invocation_short_name, program_invocation_short_name, - program_invocation_short_name, program_invocation_short_name); -} - -_printf_format_(1, 2) -static inline void _show(const char *fmt, ...) -{ - va_list args; - - if (!do_show && verbose <= DEFAULT_VERBOSE) - return; - - va_start(args, fmt); - vfprintf(stdout, fmt, args); - fflush(stdout); - va_end(args); -} -#define SHOW(...) _show(__VA_ARGS__) - -static int show_config(struct kmod_ctx *ctx) -{ - struct config_iterators { - const char *name; - struct kmod_config_iter *(*get_iter)(const struct kmod_ctx *ctx); - } ci[] = { - { "blacklist", kmod_config_get_blacklists }, - { "install", kmod_config_get_install_commands }, - { "remove", kmod_config_get_remove_commands }, - { "alias", kmod_config_get_aliases }, - { "options", kmod_config_get_options }, - { "softdep", kmod_config_get_softdeps }, - }; - size_t i; - - for (i = 0; i < ARRAY_SIZE(ci); i++) { - struct kmod_config_iter *iter = ci[i].get_iter(ctx); - - if (iter == NULL) - continue; - - while (kmod_config_iter_next(iter)) { - const char *val; - - printf("%s %s", ci[i].name, - kmod_config_iter_get_key(iter)); - val = kmod_config_iter_get_value(iter); - if (val != NULL) { - putchar(' '); - puts(val); - } else - putchar('\n'); - } - - kmod_config_iter_free_iter(iter); - } - - puts("\n# End of configuration files. Dumping indexes now:\n"); - fflush(stdout); - - kmod_dump_index(ctx, KMOD_INDEX_MODULES_ALIAS, STDOUT_FILENO); - kmod_dump_index(ctx, KMOD_INDEX_MODULES_SYMBOL, STDOUT_FILENO); - - return 0; -} - -static int show_modversions(struct kmod_ctx *ctx, const char *filename) -{ - struct kmod_list *l, *list = NULL; - struct kmod_module *mod; - int err = kmod_module_new_from_path(ctx, filename, &mod); - if (err < 0) { - LOG("Module %s not found.\n", filename); - return err; - } - - err = kmod_module_get_versions(mod, &list); - if (err < 0) { - LOG("could not get modversions of %s: %s\n", - filename, strerror(-err)); - kmod_module_unref(mod); - return err; - } - - kmod_list_foreach(l, list) { - const char *symbol = kmod_module_version_get_symbol(l); - uint64_t crc = kmod_module_version_get_crc(l); - printf("0x%08"PRIx64"\t%s\n", crc, symbol); - } - kmod_module_versions_free_list(list); - kmod_module_unref(mod); - return 0; -} - -static int command_do(struct kmod_module *module, const char *type, - const char *command, const char *cmdline_opts) -{ - const char *modname = kmod_module_get_name(module); - char *p, *cmd = NULL; - size_t cmdlen, cmdline_opts_len, varlen; - int ret = 0; - - if (cmdline_opts == NULL) - cmdline_opts = ""; - cmdline_opts_len = strlen(cmdline_opts); - - cmd = strdup(command); - if (cmd == NULL) - return -ENOMEM; - cmdlen = strlen(cmd); - varlen = sizeof("$CMDLINE_OPTS") - 1; - while ((p = strstr(cmd, "$CMDLINE_OPTS")) != NULL) { - size_t prefixlen = p - cmd; - size_t suffixlen = cmdlen - prefixlen - varlen; - size_t slen = cmdlen - varlen + cmdline_opts_len; - char *suffix = p + varlen; - char *s = malloc(slen + 1); - if (s == NULL) { - free(cmd); - return -ENOMEM; - } - memcpy(s, cmd, p - cmd); - memcpy(s + prefixlen, cmdline_opts, cmdline_opts_len); - memcpy(s + prefixlen + cmdline_opts_len, suffix, suffixlen); - s[slen] = '\0'; - - free(cmd); - cmd = s; - cmdlen = slen; - } - - SHOW("%s %s\n", type, cmd); - if (dry_run) - goto end; - - setenv("MODPROBE_MODULE", modname, 1); - ret = system(cmd); - unsetenv("MODPROBE_MODULE"); - if (ret == -1 || WEXITSTATUS(ret)) { - LOG("Error running %s command for %s\n", type, modname); - if (ret != -1) - ret = -WEXITSTATUS(ret); - } - -end: - free(cmd); - return ret; -} - -static int rmmod_do_remove_module(struct kmod_module *mod) -{ - const char *modname = kmod_module_get_name(mod); - struct kmod_list *deps, *itr; - int flags = 0, err; - - SHOW("rmmod %s\n", kmod_module_get_name(mod)); - - if (dry_run) - return 0; - - if (force) - flags |= KMOD_REMOVE_FORCE; - - err = kmod_module_remove_module(mod, flags); - if (err == -EEXIST) { - if (!first_time) - err = 0; - else - LOG("Module %s is not in kernel.\n", modname); - } - - deps = kmod_module_get_dependencies(mod); - if (deps != NULL) { - kmod_list_foreach(itr, deps) { - struct kmod_module *dep = kmod_module_get_module(itr); - if (kmod_module_get_refcnt(dep) == 0) - rmmod_do_remove_module(dep); - kmod_module_unref(dep); - } - kmod_module_unref_list(deps); - } - - return err; -} - -static int rmmod_do_module(struct kmod_module *mod, bool do_dependencies); - -static int rmmod_do_deps_list(struct kmod_list *list, bool stop_on_errors) -{ - struct kmod_list *l; - - kmod_list_foreach_reverse(l, list) { - struct kmod_module *m = kmod_module_get_module(l); - int r = rmmod_do_module(m, false); - kmod_module_unref(m); - - if (r < 0 && stop_on_errors) - return r; - } - - return 0; -} - -static int rmmod_do_module(struct kmod_module *mod, bool do_dependencies) -{ - const char *modname = kmod_module_get_name(mod); - struct kmod_list *pre = NULL, *post = NULL; - const char *cmd = NULL; - int err; - - if (!ignore_commands) { - err = kmod_module_get_softdeps(mod, &pre, &post); - if (err < 0) { - WRN("could not get softdeps of '%s': %s\n", - modname, strerror(-err)); - return err; - } - - cmd = kmod_module_get_remove_commands(mod); - } - - if (cmd == NULL && !ignore_loaded) { - int state = kmod_module_get_initstate(mod); - - if (state < 0) { - if (first_time) { - LOG("Module %s is not in kernel.\n", modname); - err = -ENOENT; - } else { - err = 0; - } - goto error; - } else if (state == KMOD_MODULE_BUILTIN) { - LOG("Module %s is builtin.\n", modname); - err = -ENOENT; - goto error; - } - } - - rmmod_do_deps_list(post, false); - - if (do_dependencies && remove_dependencies) { - struct kmod_list *deps = kmod_module_get_dependencies(mod); - - err = rmmod_do_deps_list(deps, true); - if (err < 0) - goto error; - } - - if (!ignore_loaded && !cmd) { - int usage = kmod_module_get_refcnt(mod); - - if (usage > 0) { - if (!quiet_inuse) - LOG("Module %s is in use.\n", modname); - - err = -EBUSY; - goto error; - } - } - - if (cmd == NULL) - err = rmmod_do_remove_module(mod); - else - err = command_do(mod, "remove", cmd, NULL); - - if (err < 0) - goto error; - - rmmod_do_deps_list(pre, false); - -error: - kmod_module_unref_list(pre); - kmod_module_unref_list(post); - - return err; -} - -static int rmmod(struct kmod_ctx *ctx, const char *alias) -{ - struct kmod_list *l, *list = NULL; - int err; - - err = kmod_module_new_from_lookup(ctx, alias, &list); - if (err < 0) - return err; - - if (list == NULL) { - LOG("Module %s not found.\n", alias); - err = -ENOENT; - } - - kmod_list_foreach(l, list) { - struct kmod_module *mod = kmod_module_get_module(l); - err = rmmod_do_module(mod, true); - kmod_module_unref(mod); - if (err < 0) - break; - } - - kmod_module_unref_list(list); - return err; -} - -static int rmmod_all(struct kmod_ctx *ctx, char **args, int nargs) -{ - int i, err = 0; - - for (i = 0; i < nargs; i++) { - int r = rmmod(ctx, args[i]); - if (r < 0) - err = r; - } - - return err; -} - -static int handle_failed_lookup(struct kmod_ctx *ctx, const char *alias) -{ - struct kmod_module *mod; - int state, err; - - DBG("lookup failed - trying to check if it's builtin\n"); - - err = kmod_module_new_from_name(ctx, alias, &mod); - if (err < 0) - return err; - - state = kmod_module_get_initstate(mod); - kmod_module_unref(mod); - - if (state != KMOD_MODULE_BUILTIN) { - LOG("Module %s not found.\n", alias); - return -ENOENT; - } - - if (first_time) { - LOG("Module %s already in kernel (builtin).\n", alias); - return -ENOENT; - } - - SHOW("builtin %s\n", alias); - return 0; -} - -static void print_action(struct kmod_module *m, bool install, - const char *options) -{ - const char *path; - - if (install) { - printf("install %s %s\n", kmod_module_get_install_commands(m), - options); - return; - } - - path = kmod_module_get_path(m); - - if (path == NULL) { - /* - * Either a builtin module, or an alias, print only for - * builtin - */ - if (kmod_module_get_initstate(m) == KMOD_MODULE_BUILTIN) - printf("builtin %s\n", kmod_module_get_name(m)); - } else - printf("insmod %s %s\n", kmod_module_get_path(m), options); -} - -static int insmod(struct kmod_ctx *ctx, const char *alias, - const char *extra_options) -{ - struct kmod_list *l, *list = NULL; - int err, flags = 0; - - void (*show)(struct kmod_module *m, bool install, - const char *options) = NULL; - - err = kmod_module_new_from_lookup(ctx, alias, &list); - if (err < 0) - return err; - - if (list == NULL) - return handle_failed_lookup(ctx, alias); - - if (strip_modversion || force) - flags |= KMOD_PROBE_FORCE_MODVERSION; - if (strip_vermagic || force) - flags |= KMOD_PROBE_FORCE_VERMAGIC; - if (ignore_commands) - flags |= KMOD_PROBE_IGNORE_COMMAND; - if (ignore_loaded) - flags |= KMOD_PROBE_IGNORE_LOADED; - if (dry_run) - flags |= KMOD_PROBE_DRY_RUN; - if (do_show || verbose > DEFAULT_VERBOSE) - show = &print_action; - - flags |= KMOD_PROBE_APPLY_BLACKLIST_ALIAS_ONLY; - - if (use_blacklist) - flags |= KMOD_PROBE_APPLY_BLACKLIST; - if (first_time) - flags |= KMOD_PROBE_FAIL_ON_LOADED; - - kmod_list_foreach(l, list) { - struct kmod_module *mod = kmod_module_get_module(l); - - if (lookup_only) - printf("%s\n", kmod_module_get_name(mod)); - else { - err = kmod_module_probe_insert_module(mod, flags, - extra_options, NULL, NULL, show); - } - - if (err >= 0) - /* ignore flag return values such as a mod being blacklisted */ - err = 0; - else { - switch (err) { - case -EEXIST: - ERR("could not insert '%s': Module already in kernel\n", - kmod_module_get_name(mod)); - break; - case -ENOENT: - ERR("could not insert '%s': Unknown symbol in module, " - "or unknown parameter (see dmesg)\n", - kmod_module_get_name(mod)); - break; - default: - ERR("could not insert '%s': %s\n", - kmod_module_get_name(mod), - strerror(-err)); - break; - } - } - - kmod_module_unref(mod); - } - - kmod_module_unref_list(list); - return err; -} - -static int insmod_all(struct kmod_ctx *ctx, char **args, int nargs) -{ - int i, err = 0; - - for (i = 0; i < nargs; i++) { - int r = insmod(ctx, args[i], NULL); - if (r < 0) - err = r; - } - - return err; -} - -static void env_modprobe_options_append(const char *value) -{ - const char *old = getenv("MODPROBE_OPTIONS"); - char *env; - - if (old == NULL) { - setenv("MODPROBE_OPTIONS", value, 1); - return; - } - - if (asprintf(&env, "%s %s", old, value) < 0) { - ERR("could not append value to $MODPROBE_OPTIONS\n"); - return; - } - - if (setenv("MODPROBE_OPTIONS", env, 1) < 0) - ERR("could not setenv(MODPROBE_OPTIONS, \"%s\")\n", env); - free(env); -} - -static int options_from_array(char **args, int nargs, char **output) -{ - char *opts = NULL; - size_t optslen = 0; - int i, err = 0; - - for (i = 1; i < nargs; i++) { - size_t len = strlen(args[i]); - size_t qlen = 0; - const char *value; - void *tmp; - - value = strchr(args[i], '='); - if (value) { - value++; - if (*value != '"' && *value != '\'') { - if (strchr(value, ' ')) - qlen = 2; - } - } - - tmp = realloc(opts, optslen + len + qlen + 2); - if (!tmp) { - err = -errno; - free(opts); - opts = NULL; - ERR("could not gather module options: out-of-memory\n"); - break; - } - opts = tmp; - if (optslen > 0) { - opts[optslen] = ' '; - optslen++; - } - if (qlen == 0) { - memcpy(opts + optslen, args[i], len + 1); - optslen += len; - } else { - size_t keylen = value - args[i]; - size_t valuelen = len - keylen; - memcpy(opts + optslen, args[i], keylen); - optslen += keylen; - opts[optslen] = '"'; - optslen++; - memcpy(opts + optslen, value, valuelen); - optslen += valuelen; - opts[optslen] = '"'; - optslen++; - opts[optslen] = '\0'; - } - } - - *output = opts; - return err; -} - -static char **prepend_options_from_env(int *p_argc, char **orig_argv) -{ - const char *p, *env = getenv("MODPROBE_OPTIONS"); - char **new_argv, *str_start, *str_end, *str, *s, *quote; - int i, argc = *p_argc; - size_t envlen, space_count = 0; - - if (env == NULL) - return orig_argv; - - for (p = env; *p != '\0'; p++) { - if (*p == ' ') - space_count++; - } - - envlen = p - env; - new_argv = malloc(sizeof(char *) * (argc + space_count + 3 + envlen)); - if (new_argv == NULL) - return NULL; - - new_argv[0] = orig_argv[0]; - str_start = str = (char *) (new_argv + argc + space_count + 3); - memcpy(str, env, envlen + 1); - - str_end = str_start + envlen; - - quote = NULL; - for (i = 1, s = str; *s != '\0'; s++) { - if (quote == NULL) { - if (*s == ' ') { - new_argv[i] = str; - i++; - *s = '\0'; - str = s + 1; - } else if (*s == '"' || *s == '\'') - quote = s; - } else { - if (*s == *quote) { - if (quote == str) { - new_argv[i] = str + 1; - i++; - *s = '\0'; - str = s + 1; - } else { - char *it; - for (it = quote; it < s - 1; it++) - it[0] = it[1]; - for (it = s - 1; it < str_end - 2; it++) - it[0] = it[2]; - str_end -= 2; - *str_end = '\0'; - s -= 2; - } - quote = NULL; - } - } - } - if (str < s) { - new_argv[i] = str; - i++; - } - - memcpy(new_argv + i, orig_argv + 1, sizeof(char *) * (argc - 1)); - new_argv[i + argc] = NULL; - *p_argc = i + argc - 1; - - return new_argv; -} - -static int do_modprobe(int argc, char **orig_argv) -{ - struct kmod_ctx *ctx; - char **args = NULL, **argv; - const char **config_paths = NULL; - int nargs = 0, n_config_paths = 0; - char dirname_buf[PATH_MAX]; - const char *dirname = NULL; - const char *root = NULL; - const char *kversion = NULL; - int use_all = 0; - int do_remove = 0; - int do_show_config = 0; - int do_show_modversions = 0; - int err; - - argv = prepend_options_from_env(&argc, orig_argv); - if (argv == NULL) { - ERR("Could not prepend options from command line\n"); - return EXIT_FAILURE; - } - - for (;;) { - int c, idx = 0; - c = getopt_long(argc, argv, cmdopts_s, cmdopts, &idx); - if (c == -1) - break; - switch (c) { - case 'a': - log_priority = LOG_WARNING; - use_all = 1; - break; - case 'r': - do_remove = 1; - break; - case 5: - remove_dependencies = 1; - break; - case 'R': - lookup_only = 1; - break; - case 3: - first_time = 1; - break; - case 'i': - ignore_commands = 1; - break; - case 'b': - use_blacklist = 1; - break; - case 'f': - force = 1; - break; - case 2: - strip_modversion = 1; - break; - case 1: - strip_vermagic = 1; - break; - case 'D': - ignore_loaded = 1; - dry_run = 1; - do_show = 1; - break; - case 'c': - do_show_config = 1; - break; - case 4: - do_show_modversions = 1; - break; - case 'n': - dry_run = 1; - break; - case 'C': { - size_t bytes = sizeof(char *) * (n_config_paths + 2); - void *tmp = realloc(config_paths, bytes); - if (!tmp) { - ERR("out-of-memory\n"); - err = -1; - goto done; - } - config_paths = tmp; - config_paths[n_config_paths] = optarg; - n_config_paths++; - config_paths[n_config_paths] = NULL; - - env_modprobe_options_append("-C"); - env_modprobe_options_append(optarg); - break; - } - case 'd': - root = optarg; - break; - case 'S': - kversion = optarg; - break; - case 's': - env_modprobe_options_append("-s"); - use_syslog = 1; - break; - case 'q': - env_modprobe_options_append("-q"); - verbose = LOG_EMERG; - break; - case 'v': - env_modprobe_options_append("-v"); - verbose++; - break; - case 'V': - puts(PACKAGE " version " VERSION); - err = 0; - goto done; - case 'h': - help(); - err = 0; - goto done; - case '?': - err = -1; - goto done; - default: - ERR("unexpected getopt_long() value '%c'.\n", c); - err = -1; - goto done; - } - } - - args = argv + optind; - nargs = argc - optind; - - log_open(use_syslog); - - if (!do_show_config) { - if (nargs == 0) { - ERR("missing parameters. See -h.\n"); - err = -1; - goto done; - } - } - - if (root != NULL || kversion != NULL) { - struct utsname u; - if (root == NULL) - root = ""; - if (kversion == NULL) { - if (uname(&u) < 0) { - ERR("uname() failed: %m\n"); - err = -1; - goto done; - } - kversion = u.release; - } - snprintf(dirname_buf, sizeof(dirname_buf), - "%s/lib/modules/%s", root, - kversion); - dirname = dirname_buf; - } - - ctx = kmod_new(dirname, config_paths); - if (!ctx) { - ERR("kmod_new() failed!\n"); - err = -1; - goto done; - } - - log_setup_kmod_log(ctx, verbose); - - kmod_load_resources(ctx); - - if (do_show_config) - err = show_config(ctx); - else if (do_show_modversions) - err = show_modversions(ctx, args[0]); - else if (do_remove) - err = rmmod_all(ctx, args, nargs); - else if (use_all) - err = insmod_all(ctx, args, nargs); - else { - char *opts; - err = options_from_array(args, nargs, &opts); - if (err == 0) { - err = insmod(ctx, args[0], opts); - free(opts); - } - } - - kmod_unref(ctx); - -done: - log_close(); - - if (argv != orig_argv) - free(argv); - - free(config_paths); - - return err >= 0 ? EXIT_SUCCESS : EXIT_FAILURE; -} - -const struct kmod_cmd kmod_cmd_compat_modprobe = { - .name = "modprobe", - .cmd = do_modprobe, - .help = "compat modprobe command", -}; diff --git a/tools/rmmod.c b/tools/rmmod.c deleted file mode 100644 index bf5a408..0000000 --- a/tools/rmmod.c +++ /dev/null @@ -1,204 +0,0 @@ -/* - * kmod-rmmod - remove modules from linux kernel using libkmod. - * - * Copyright (C) 2011-2013 ProFUSION embedded systems - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include "libkmod.h" -#include "macro.h" - -#include "kmod.h" - -#define DEFAULT_VERBOSE LOG_ERR -static int verbose = DEFAULT_VERBOSE; -static int use_syslog; - -static const char cmdopts_s[] = "fsvVwh"; -static const struct option cmdopts[] = { - {"force", no_argument, 0, 'f'}, - {"syslog", no_argument, 0, 's'}, - {"verbose", no_argument, 0, 'v'}, - {"version", no_argument, 0, 'V'}, - {"wait", no_argument, 0, 'w'}, - {"help", no_argument, 0, 'h'}, - {NULL, 0, 0, 0} -}; - -static void help(void) -{ - printf("Usage:\n" - "\t%s [options] modulename ...\n" - "Options:\n" - "\t-f, --force forces a module unload and may crash your\n" - "\t machine. This requires Forced Module Removal\n" - "\t option in your kernel. DANGEROUS\n" - "\t-s, --syslog print to syslog, not stderr\n" - "\t-v, --verbose enables more messages\n" - "\t-V, --version show version\n" - "\t-h, --help show this help\n", - program_invocation_short_name); -} - -static int check_module_inuse(struct kmod_module *mod) { - struct kmod_list *holders; - int state; - - state = kmod_module_get_initstate(mod); - - if (state == KMOD_MODULE_BUILTIN) { - ERR("Module %s is builtin.\n", kmod_module_get_name(mod)); - return -ENOENT; - } else if (state < 0) { - ERR("Module %s is not currently loaded\n", - kmod_module_get_name(mod)); - return -ENOENT; - } - - holders = kmod_module_get_holders(mod); - if (holders != NULL) { - struct kmod_list *itr; - - ERR("Module %s is in use by:", kmod_module_get_name(mod)); - - kmod_list_foreach(itr, holders) { - struct kmod_module *hm = kmod_module_get_module(itr); - fprintf(stderr, " %s", kmod_module_get_name(hm)); - kmod_module_unref(hm); - } - fputc('\n', stderr); - - kmod_module_unref_list(holders); - return -EBUSY; - } - - if (kmod_module_get_refcnt(mod) != 0) { - ERR("Module %s is in use\n", kmod_module_get_name(mod)); - return -EBUSY; - } - - return 0; -} - -static int do_rmmod(int argc, char *argv[]) -{ - struct kmod_ctx *ctx; - const char *null_config = NULL; - int flags = KMOD_REMOVE_NOWAIT; - int i, err, r = 0; - - for (;;) { - int c, idx = 0; - c = getopt_long(argc, argv, cmdopts_s, cmdopts, &idx); - if (c == -1) - break; - switch (c) { - case 'f': - flags |= KMOD_REMOVE_FORCE; - break; - case 's': - use_syslog = 1; - break; - case 'v': - verbose++; - break; - case 'w': - ERR("'Wait' behavior is targeted for removal from kernel.\nWe will now sleep for 10s, and then continue.\n"); - sleep(10); - flags &= ~KMOD_REMOVE_NOWAIT; - break; - case 'h': - help(); - return EXIT_SUCCESS; - case 'V': - puts(PACKAGE " version " VERSION); - return EXIT_SUCCESS; - case '?': - return EXIT_FAILURE; - default: - ERR("unexpected getopt_long() value '%c'.\n", c); - return EXIT_FAILURE; - } - } - - log_open(use_syslog); - - if (optind >= argc) { - ERR("missing module name.\n"); - r = EXIT_FAILURE; - goto done; - } - - ctx = kmod_new(NULL, &null_config); - if (!ctx) { - ERR("kmod_new() failed!\n"); - r = EXIT_FAILURE; - goto done; - } - - log_setup_kmod_log(ctx, verbose); - - for (i = optind; i < argc; i++) { - struct kmod_module *mod; - const char *arg = argv[i]; - struct stat st; - if (stat(arg, &st) == 0) - err = kmod_module_new_from_path(ctx, arg, &mod); - else - err = kmod_module_new_from_name(ctx, arg, &mod); - - if (err < 0) { - ERR("could not use module %s: %s\n", arg, - strerror(-err)); - break; - } - - if (!(flags & KMOD_REMOVE_FORCE) && (flags & KMOD_REMOVE_NOWAIT)) - if (check_module_inuse(mod) < 0) { - r++; - goto next; - } - - err = kmod_module_remove_module(mod, flags); - if (err < 0) { - ERR("could not remove module %s: %s\n", arg, - strerror(-err)); - r++; - } -next: - kmod_module_unref(mod); - } - - kmod_unref(ctx); - -done: - log_close(); - - return r == 0 ? EXIT_SUCCESS : EXIT_FAILURE; -} - -const struct kmod_cmd kmod_cmd_compat_rmmod = { - .name = "rmmod", - .cmd = do_rmmod, - .help = "compat rmmod command", -}; diff --git a/tools/static-nodes.c b/tools/static-nodes.c deleted file mode 100644 index 03f59f1..0000000 --- a/tools/static-nodes.c +++ /dev/null @@ -1,263 +0,0 @@ -/* - * kmod-static-nodes - manage modules.devname - * - * Copyright (C) 2004-2012 Kay Sievers - * Copyright (C) 2011-2013 ProFUSION embedded systems - * Copyright (C) 2013 Tom Gundersen - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "libkmod-util.h" - -#include "kmod.h" - -struct static_nodes_format { - const char *name; - int (*write)(FILE *, char[], char[], char, unsigned int, unsigned int); - const char *description; -}; - -static const struct static_nodes_format static_nodes_format_human; -static const struct static_nodes_format static_nodes_format_tmpfiles; -static const struct static_nodes_format static_nodes_format_devname; - -static const struct static_nodes_format *static_nodes_formats[] = { - &static_nodes_format_human, - &static_nodes_format_tmpfiles, - &static_nodes_format_devname, -}; - -static const char cmdopts_s[] = "o:f:h"; -static const struct option cmdopts[] = { - { "output", required_argument, 0, 'o'}, - { "format", required_argument, 0, 'f'}, - { "help", no_argument, 0, 'h'}, - { }, -}; - -static int write_human(FILE *out, char modname[], char devname[], char type, unsigned int maj, unsigned int min) -{ - int ret; - - ret = fprintf(out, - "Module: %s\n" - "\tDevice node: /dev/%s\n" - "\t\tType: %s device\n" - "\t\tMajor: %u\n" - "\t\tMinor: %u\n", - modname, devname, - (type == 'c') ? "character" : "block", maj, min); - if (ret >= 0) - return EXIT_SUCCESS; - else - return EXIT_FAILURE; -} - -static const struct static_nodes_format static_nodes_format_human = { - .name = "human", - .write = write_human, - .description = "(default) a human readable format. Do not parse.", -}; - -static int write_tmpfiles(FILE *out, char modname[], char devname[], char type, unsigned int maj, unsigned int min) -{ - const char *dir; - int ret; - - dir = strrchr(devname, '/'); - if (dir) { - ret = fprintf(out, "d /dev/%.*s 0755 - - -\n", - (int)(dir - devname), devname); - if (ret < 0) - return EXIT_FAILURE; - } - - ret = fprintf(out, "%c /dev/%s 0600 - - - %u:%u\n", - type, devname, maj, min); - if (ret < 0) - return EXIT_FAILURE; - - return EXIT_SUCCESS; -} - -static const struct static_nodes_format static_nodes_format_tmpfiles = { - .name = "tmpfiles", - .write = write_tmpfiles, - .description = "the tmpfiles.d(5) format used by systemd-tmpfiles.", -}; - -static int write_devname(FILE *out, char modname[], char devname[], char type, unsigned int maj, unsigned int min) -{ - int ret; - - ret = fprintf(out, "%s %s %c%u:%u\n", modname, devname, type, maj, min); - if (ret >= 0) - return EXIT_SUCCESS; - else - return EXIT_FAILURE; -} - -static const struct static_nodes_format static_nodes_format_devname = { - .name = "devname", - .write = write_devname, - .description = "the modules.devname format.", -}; - -static void help(void) -{ - size_t i; - - printf("Usage:\n" - "\t%s static-nodes [options]\n" - "\n" - "kmod static-nodes outputs the static-node information of the currently running kernel.\n" - "\n" - "Options:\n" - "\t-f, --format=FORMAT use a machine-readable format\n" - "\t-o, --output=FILE write output to file\n" - "\t-h, --help show this help\n" - "\n" - "Formats:\n", - program_invocation_short_name); - - for (i = 0; i < ARRAY_SIZE(static_nodes_formats); i++) { - if (static_nodes_formats[i]->description != NULL) { - printf("\t%-12s %s\n", static_nodes_formats[i]->name, - static_nodes_formats[i]->description); - } - } -} - -static int do_static_nodes(int argc, char *argv[]) -{ - struct utsname kernel; - char modules[PATH_MAX]; - FILE *in = NULL, *out = stdout; - const struct static_nodes_format *format = &static_nodes_format_human; - char buf[4096]; - int ret = EXIT_SUCCESS; - - for (;;) { - int c, idx = 0, valid; - size_t i; - - c = getopt_long(argc, argv, cmdopts_s, cmdopts, &idx); - if (c == -1) { - break; - } - switch (c) { - case 'o': - out = fopen(optarg, "we"); - if (out == NULL) { - fprintf(stderr, "Error: could not create %s!\n", - optarg); - ret = EXIT_FAILURE; - goto finish; - } - break; - case 'f': - valid = 0; - - for (i = 0; i < ARRAY_SIZE(static_nodes_formats); i++) { - if (streq(static_nodes_formats[i]->name, optarg)) { - format = static_nodes_formats[i]; - valid = 1; - } - } - - if (!valid) { - fprintf(stderr, "Unknown format: '%s'.\n", - optarg); - help(); - ret = EXIT_FAILURE; - goto finish; - } - break; - case 'h': - help(); - goto finish; - case '?': - ret = EXIT_FAILURE; - goto finish; - default: - fprintf(stderr, "Unexpected commandline option '%c'.\n", - c); - help(); - ret = EXIT_FAILURE; - goto finish; - } - } - - if (uname(&kernel) < 0) { - fputs("Error: uname failed!\n", stderr); - ret = EXIT_FAILURE; - goto finish; - } - - snprintf(modules, sizeof(modules), "/lib/modules/%s/modules.devname", - kernel.release); - in = fopen(modules, "re"); - if (in == NULL) { - fprintf(stderr, "Error: could not open /lib/modules/%s/modules.devname - %m\n", - kernel.release); - ret = EXIT_FAILURE; - goto finish; - } - - while (fgets(buf, sizeof(buf), in) != NULL) { - char modname[PATH_MAX]; - char devname[PATH_MAX]; - char type; - unsigned int maj, min; - int matches; - - if (buf[0] == '#') - continue; - - matches = sscanf(buf, "%s %s %c%u:%u", modname, devname, - &type, &maj, &min); - if (matches != 5 || (type != 'c' && type != 'b')) { - fprintf(stderr, "Error: invalid devname entry: %s", buf); - ret = EXIT_FAILURE; - continue; - } - - format->write(out, modname, devname, type, maj, min); - } - -finish: - if (in) - fclose(in); - if (out) - fclose(out); - return ret; -} - -const struct kmod_cmd kmod_cmd_static_nodes = { - .name = "static-nodes", - .cmd = do_static_nodes, - .help = "outputs the static-node information installed with the currently running kernel", -}; -- cgit v1.2.1 From 506863b41fae31c7e57487393cc3089d9a2f90f5 Mon Sep 17 00:00:00 2001 From: Tiago Gomes Date: Mon, 1 Jul 2013 20:18:47 +0000 Subject: Disable building the manual pages --- kmod.morph | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kmod.morph b/kmod.morph index af8d1d0..6a4be49 100644 --- a/kmod.morph +++ b/kmod.morph @@ -6,7 +6,7 @@ "sed -i -e'/SUBDIRS/{s/\\S*doc\\S*//;s/\\S*man\\S*//}' Makefile.am", "sed -i -e'/AC_CONFIG_FILES(\\[/,/])/{/docs/d}' configure.ac", "autoreconf -fiv", - "./configure --prefix=/usr --bindir=/bin --libdir=/lib --sysconfdir=/etc --without-xz --with-zlib" + "./configure --prefix=/usr --bindir=/bin --libdir=/lib --sysconfdir=/etc --without-xz --with-zlib --disable-manpages" ], "build-commands": [ "make" -- cgit v1.2.1