diff --git a/dkms.in b/dkms.in index d021cbae..095178a6 100644 --- a/dkms.in +++ b/dkms.in @@ -138,6 +138,16 @@ die() { [[ $die_is_fatal = yes ]] && exit $ret || return $ret } +# Print a warning message and die with the passed error code. +diewarn() { + # $1 = error code to return with + # rest = strings to print before we exit. + ret=$1 + shift + warn "$@" + [[ $die_is_fatal = yes ]] && exit $ret || return $ret +} + mktemp_or_die() { local t t=$(mktemp "$@") && echo "$t" && return @@ -324,6 +334,13 @@ do_depmod() else depmod -a "$1" fi + if [ -f /lib/modules/$1/modules.dep ] && [ ! -s /lib/modules/$1/modules.dep ]; then + # if modules.dep is empty, we just removed the last kernel module from + # no longer installed kernel $1, so do not leave stale depmod files around + rm -fv /lib/modules/$1/modules.{alias,dep,devname,softdep,symbols,*.bin} + rmdir --ignore-fail-on-non-empty /lib/modules/$1 + test -d /lib/modules/$1 || echo $"Removed /lib/modules/$1" + fi } # Grab distro information from os-release. @@ -1014,8 +1031,10 @@ prepare_build() read_conf_or_die "$kernelver" "$arch" # Error out if build_exclude is set - [[ $build_exclude ]] && die 77 \ - $"The $base_dir/dkms.conf for module $module includes a BUILD_EXCLUSIVE directive which does not match this kernel/arch/config."\ + [[ $build_exclude ]] && diewarn 77 \ + $"The $base_dir/dkms.conf"\ + $"for module $module includes a BUILD_EXCLUSIVE directive"\ + $"which does not match this kernel/arch/config."\ $"This indicates that it should not be built." # Error out if source_tree is basically empty (binary-only dkms tarball w/ --force check) diff --git a/dkms_autoinstaller.in b/dkms_autoinstaller.in index 10c93484..0d4e46ca 100755 --- a/dkms_autoinstaller.in +++ b/dkms_autoinstaller.in @@ -71,9 +71,11 @@ case "$1" in elif ! _check_kernel_dir $kernel; then log_action_msg "$prog: autoinstall for kernel $kernel was skipped since the kernel headers for this kernel do not seem to be installed" else - log_daemon_msg "$prog: running auto installation service for kernel $kernel" + log_action_msg "$prog: running auto installation service for kernel $kernel" dkms autoinstall --kernelver $kernel - log_end_msg $? + res=$? + log_daemon_msg "$prog: autoinstall for kernel" "$kernel" + log_end_msg $res fi ;; stop|restart|force-reload|status|reload) diff --git a/dkms_common.postinst b/dkms_common.postinst index 52fb3a49..18459ff0 100644 --- a/dkms_common.postinst +++ b/dkms_common.postinst @@ -127,7 +127,7 @@ if [ -r /etc/dkms/framework.conf ]; then . /etc/dkms/framework.conf fi -KERNELS=$(ls -v /lib/modules/ 2>/dev/null || true) +KERNELS=$(ls -dv /lib/modules/*/build 2>/dev/null | cut -d/ -f4 || true) CURRENT_KERNEL=$(uname -r) #We never want to keep an older version side by side to prevent conflicts diff --git a/run_test.sh b/run_test.sh index c7318925..acc9575a 100755 --- a/run_test.sh +++ b/run_test.sh @@ -20,6 +20,7 @@ export parallel_jobs=1 # Temporary files, directories, and modules created during tests TEST_MODULES=( "dkms_test" + "dkms_noautoinstall_test" "dkms_failing_test" "dkms_dependencies_test" "dkms_multiver_test" @@ -31,8 +32,9 @@ TEST_MODULES=( "dkms_build_exclusive_dependencies_test" ) TEST_TMPDIRS=( - "/usr/src/dkms_test-1.0/" - "/usr/src/dkms_failing_test-1.0/" + "/usr/src/dkms_test-1.0" + "/usr/src/dkms_noautoinstall_test-1.0" + "/usr/src/dkms_failing_test-1.0" "/usr/src/dkms_dependencies_test-1.0" "/usr/src/dkms_multiver_test-1.0" "/usr/src/dkms_multiver_test-2.0" @@ -676,6 +678,9 @@ Running module version sanity check. depmod... dkms autoinstall on ${KERNEL_VER}/${KERNEL_ARCH} succeeded for dkms_test EOF +run_status_with_expected_output 'dkms_test' << EOF +dkms_test/1.0, ${KERNEL_VER}, ${KERNEL_ARCH}: installed +EOF echo "Running dkms autoinstall for a kernel without headers installed (expected error)" run_with_expected_error 11 dkms autoinstall -k "${KERNEL_VER}-noheaders" << EOF @@ -714,6 +719,104 @@ rm -r /usr/src/dkms_test-1.0 echo 'Checking that the environment is clean again' check_no_dkms_test +############################################################################ +### Testing dkms on a regular module with AUTOINSTALL="" ### +############################################################################ + +echo 'Adding the noautoinstall test module by directory' +run_with_expected_output dkms add test/dkms_noautoinstall_test-1.0 << EOF +Creating symlink /var/lib/dkms/dkms_noautoinstall_test/1.0/source -> /usr/src/dkms_noautoinstall_test-1.0 +EOF +run_status_with_expected_output 'dkms_noautoinstall_test' << EOF +dkms_noautoinstall_test/1.0: added +EOF +if ! [[ -d /usr/src/dkms_noautoinstall_test-1.0 ]] ; then + echo >&2 'Error: directory /usr/src/dkms_noautoinstall_test-1.0 was not created' + exit 1 +fi + +echo "Running dkms autoinstall" +run_with_expected_output dkms autoinstall -k "${KERNEL_VER}" << EOF +EOF +run_status_with_expected_output 'dkms_noautoinstall_test' << EOF +dkms_noautoinstall_test/1.0: added +EOF + +echo 'Building the noautoinstall test module' +set_signing_message "dkms_noautoinstall_test" "1.0" +run_with_expected_output dkms build -k "${KERNEL_VER}" -m dkms_noautoinstall_test -v 1.0 << EOF + +Building module: +Cleaning build area... +make -j1 KERNELRELEASE=${KERNEL_VER} -C /lib/modules/${KERNEL_VER}/build M=/var/lib/dkms/dkms_noautoinstall_test/1.0/build... +${SIGNING_MESSAGE}Cleaning build area... +EOF +run_status_with_expected_output 'dkms_noautoinstall_test' << EOF +dkms_noautoinstall_test/1.0, ${KERNEL_VER}, ${KERNEL_ARCH}: built +EOF + +echo 'Installing the noautoinstall test module' +run_with_expected_output dkms install -k "${KERNEL_VER}" -m dkms_noautoinstall_test -v 1.0 << EOF + +dkms_noautoinstall_test.ko${mod_compression_ext}: +Running module version sanity check. + - Original module + - No original module exists within this kernel + - Installation + - Installing to /lib/modules/${KERNEL_VER}/${expected_dest_loc}/ +depmod... +EOF +run_status_with_expected_output 'dkms_noautoinstall_test' << EOF +dkms_noautoinstall_test/1.0, ${KERNEL_VER}, ${KERNEL_ARCH}: installed +EOF + +echo 'Uninstalling the noautoinstall test module' +run_with_expected_output dkms uninstall -k "${KERNEL_VER}" -m dkms_noautoinstall_test -v 1.0 << EOF +Module dkms_noautoinstall_test-1.0 for kernel ${KERNEL_VER} (${KERNEL_ARCH}). +Before uninstall, this module version was ACTIVE on this kernel. + +dkms_noautoinstall_test.ko${mod_compression_ext}: + - Uninstallation + - Deleting from: /lib/modules/${KERNEL_VER}/${expected_dest_loc}/ + - Original module + - No original module was found for this module on this kernel. + - Use the dkms install command to reinstall any previous module version. +EOF +run_status_with_expected_output 'dkms_noautoinstall_test' << EOF +dkms_noautoinstall_test/1.0, ${KERNEL_VER}, ${KERNEL_ARCH}: built +EOF +if [[ -e "/lib/modules/${KERNEL_VER}/${expected_dest_loc}/dkms_noautoinstall_test.ko${mod_compression_ext}" ]] ; then + echo >&2 "Error: module not removed in /lib/modules/${KERNEL_VER}/${expected_dest_loc}/dkms_noautoinstall_test.ko${mod_compression_ext}" + exit 1 +fi + +echo 'Unbuilding the noautoinstall test module' +run_with_expected_output dkms unbuild -k "${KERNEL_VER}" -m dkms_noautoinstall_test -v 1.0 << EOF +Module dkms_noautoinstall_test 1.0 is not installed for kernel ${KERNEL_VER} (${KERNEL_ARCH}). Skipping... +EOF +run_status_with_expected_output 'dkms_noautoinstall_test' << EOF +dkms_noautoinstall_test/1.0: added +EOF + +echo 'Removing the noautoinstall test module' +run_with_expected_output dkms remove -k "${KERNEL_VER}" -m dkms_noautoinstall_test -v 1.0 << EOF +Module dkms_noautoinstall_test 1.0 is not installed for kernel ${KERNEL_VER} (${KERNEL_ARCH}). Skipping... +Module dkms_noautoinstall_test 1.0 is not built for kernel ${KERNEL_VER} (${KERNEL_ARCH}). Skipping... +Deleting module dkms_noautoinstall_test-1.0 completely from the DKMS tree. +EOF +run_status_with_expected_output 'dkms_noautoinstall_test' << EOF +EOF +if ! [[ -d /usr/src/dkms_noautoinstall_test-1.0 ]] ; then + echo >&2 'Error: directory /usr/src/dkms_noautoinstall_test-1.0 was removed' + exit 1 +fi + +echo 'Removing /usr/src/dkms_noautoinstall_test-1.0' +rm -r /usr/src/dkms_noautoinstall_test-1.0 + +echo 'Checking that the environment is clean again' +check_no_dkms_test + ############################################################################ ### Testing malformed/borderline dkms.conf ### ############################################################################ @@ -757,10 +860,15 @@ dkms.conf: Warning! Zero modules specified. dkms.conf: Warning! Zero modules specified. Creating symlink /var/lib/dkms/dkms_conf_test/1.0/source -> /usr/src/dkms_conf_test-1.0 EOF +run_status_with_expected_output 'dkms_conf_test' << EOF +dkms_conf_test/1.0: added +EOF run_with_expected_output dkms remove --all -m dkms_conf_test -v 1.0 << EOF Deleting module dkms_conf_test-1.0 completely from the DKMS tree. EOF +run_status_with_expected_output 'dkms_conf_test' << EOF +EOF echo 'Testing add/build/install of a test module building zero kernel modules' run_with_expected_output dkms install -k "${KERNEL_VER}" -m dkms_conf_test -v 1.0 << EOF @@ -973,6 +1081,9 @@ EOF echo 'Removing /usr/src/dkms_multiver_test-1.0 /usr/src/dkms_multiver_test-2.0' rm -r /usr/src/dkms_multiver_test-1.0 /usr/src/dkms_multiver_test-2.0 +echo 'Checking that the environment is clean again' +check_no_dkms_test + ############################################################################ ### Testing dkms operations ... ############################################################################ @@ -1366,7 +1477,9 @@ fi # Should this really fail? echo '(Not) building the build-exclusive test module' run_with_expected_error 77 dkms build -k "${KERNEL_VER}" -m dkms_build_exclusive_test -v 1.0 << EOF -Error! The /var/lib/dkms/dkms_build_exclusive_test/1.0/${KERNEL_VER}/${KERNEL_ARCH}/dkms.conf for module dkms_build_exclusive_test includes a BUILD_EXCLUSIVE directive which does not match this kernel/arch/config. +Warning: The /var/lib/dkms/dkms_build_exclusive_test/1.0/${KERNEL_VER}/${KERNEL_ARCH}/dkms.conf +for module dkms_build_exclusive_test includes a BUILD_EXCLUSIVE directive +which does not match this kernel/arch/config. This indicates that it should not be built. EOF run_status_with_expected_output 'dkms_build_exclusive_test' << EOF @@ -1375,7 +1488,9 @@ EOF echo "Running dkms autoinstall (1 x skip)" run_with_expected_output dkms autoinstall -k "${KERNEL_VER}" << EOF -Error! The /var/lib/dkms/dkms_build_exclusive_test/1.0/${KERNEL_VER}/${KERNEL_ARCH}/dkms.conf for module dkms_build_exclusive_test includes a BUILD_EXCLUSIVE directive which does not match this kernel/arch/config. +Warning: The /var/lib/dkms/dkms_build_exclusive_test/1.0/${KERNEL_VER}/${KERNEL_ARCH}/dkms.conf +for module dkms_build_exclusive_test includes a BUILD_EXCLUSIVE directive +which does not match this kernel/arch/config. This indicates that it should not be built. dkms autoinstall on ${KERNEL_VER}/${KERNEL_ARCH} was skipped for dkms_build_exclusive_test EOF @@ -1393,7 +1508,9 @@ EOF echo "Running dkms autoinstall (1 x skip, 1 x pass)" run_with_expected_output dkms autoinstall -k "${KERNEL_VER}" << EOF -Error! The /var/lib/dkms/dkms_build_exclusive_test/1.0/${KERNEL_VER}/${KERNEL_ARCH}/dkms.conf for module dkms_build_exclusive_test includes a BUILD_EXCLUSIVE directive which does not match this kernel/arch/config. +Warning: The /var/lib/dkms/dkms_build_exclusive_test/1.0/${KERNEL_VER}/${KERNEL_ARCH}/dkms.conf +for module dkms_build_exclusive_test includes a BUILD_EXCLUSIVE directive +which does not match this kernel/arch/config. This indicates that it should not be built. Building module: @@ -1441,7 +1558,9 @@ EOF echo "Running dkms autoinstall (1 x skip, 1 x fail, 1 x pass) (expected error)" run_with_expected_error 11 dkms autoinstall -k "${KERNEL_VER}" << EOF -Error! The /var/lib/dkms/dkms_build_exclusive_test/1.0/${KERNEL_VER}/${KERNEL_ARCH}/dkms.conf for module dkms_build_exclusive_test includes a BUILD_EXCLUSIVE directive which does not match this kernel/arch/config. +Warning: The /var/lib/dkms/dkms_build_exclusive_test/1.0/${KERNEL_VER}/${KERNEL_ARCH}/dkms.conf +for module dkms_build_exclusive_test includes a BUILD_EXCLUSIVE directive +which does not match this kernel/arch/config. This indicates that it should not be built. Building module: @@ -1510,9 +1629,13 @@ fi echo "Running dkms autoinstall (2 x skip, with dependency)" run_with_expected_output dkms autoinstall -k "${KERNEL_VER}" << EOF -Error! The /var/lib/dkms/dkms_build_exclusive_test/1.0/${KERNEL_VER}/${KERNEL_ARCH}/dkms.conf for module dkms_build_exclusive_test includes a BUILD_EXCLUSIVE directive which does not match this kernel/arch/config. +Warning: The /var/lib/dkms/dkms_build_exclusive_test/1.0/${KERNEL_VER}/${KERNEL_ARCH}/dkms.conf +for module dkms_build_exclusive_test includes a BUILD_EXCLUSIVE directive +which does not match this kernel/arch/config. This indicates that it should not be built. -Error! The /var/lib/dkms/dkms_build_exclusive_dependencies_test/1.0/${KERNEL_VER}/${KERNEL_ARCH}/dkms.conf for module dkms_build_exclusive_dependencies_test includes a BUILD_EXCLUSIVE directive which does not match this kernel/arch/config. +Warning: The /var/lib/dkms/dkms_build_exclusive_dependencies_test/1.0/${KERNEL_VER}/${KERNEL_ARCH}/dkms.conf +for module dkms_build_exclusive_dependencies_test includes a BUILD_EXCLUSIVE directive +which does not match this kernel/arch/config. This indicates that it should not be built. dkms autoinstall on ${KERNEL_VER}/${KERNEL_ARCH} was skipped for dkms_build_exclusive_test dkms_build_exclusive_dependencies_test EOF @@ -1541,6 +1664,9 @@ EOF echo 'Removing /usr/src/dkms_build_exclusive_test-1.0' rm -r /usr/src/dkms_build_exclusive_test-1.0 +echo 'Checking that the environment is clean again' +check_no_dkms_test + ############################################################################ ### Testing os-release detection ### ############################################################################ diff --git a/test/dkms_noautoinstall_test-1.0/Makefile b/test/dkms_noautoinstall_test-1.0/Makefile new file mode 100644 index 00000000..3452b7e0 --- /dev/null +++ b/test/dkms_noautoinstall_test-1.0/Makefile @@ -0,0 +1,7 @@ +obj-m += dkms_noautoinstall_test.o + +all: + make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules + +clean: + make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean diff --git a/test/dkms_noautoinstall_test-1.0/dkms.conf b/test/dkms_noautoinstall_test-1.0/dkms.conf new file mode 100644 index 00000000..f816acb2 --- /dev/null +++ b/test/dkms_noautoinstall_test-1.0/dkms.conf @@ -0,0 +1,7 @@ +PACKAGE_NAME="dkms_noautoinstall_test" +PACKAGE_VERSION="1.0" +BUILT_MODULE_NAME="dkms_noautoinstall_test" + +AUTOINSTALL="" + +DEST_MODULE_LOCATION="/kernel/extra" diff --git a/test/dkms_noautoinstall_test-1.0/dkms_noautoinstall_test.c b/test/dkms_noautoinstall_test-1.0/dkms_noautoinstall_test.c new file mode 100644 index 00000000..93d00982 --- /dev/null +++ b/test/dkms_noautoinstall_test-1.0/dkms_noautoinstall_test.c @@ -0,0 +1,23 @@ +#include +#include +#include + +#define DKMS_TEST_VER "1.0" + +MODULE_LICENSE("GPL"); +MODULE_DESCRIPTION("A Simple dkms test module"); + +static int __init dkms_test_init(void) +{ + printk(KERN_INFO "DKMS Test Module -%s Loaded\n",DKMS_TEST_VER); + return 0; +} + +static void __exit dkms_test_cleanup(void) +{ + printk(KERN_INFO "Cleaning up after dkms test module.\n"); +} + +module_init(dkms_test_init); +module_exit(dkms_test_cleanup); +MODULE_VERSION(DKMS_TEST_VER);