diff --git a/brp-kmod-restore-perms b/brp-kmod-restore-perms new file mode 100755 index 0000000..6fc62f4 --- /dev/null +++ b/brp-kmod-restore-perms @@ -0,0 +1,20 @@ +#! /bin/bash -efu + +## A counterpart of brp-kmod-set-exec-bits that restores original kmod +## file permissions + +# If using normal root, avoid changing anything. +[ -n "$RPM_BUILD_ROOT" -a "$RPM_BUILD_ROOT" != "/" ] || exit 0 + +# Checking for required programs +which chmod >/dev/null || exit 0 + +[ -r "$RPM_BUILD_ROOT/kmod-permissions.list" ] || exit 0 + +while read perm path; do + [ -n "$perm" ] || continue + + chmod "$perm" "$RPM_BUILD_ROOT/$path" +done < "$RPM_BUILD_ROOT/kmod-permissions.list" + +rm -f "$RPM_BUILD_ROOT/kmod-permissions.list" diff --git a/brp-kmod-set-exec-bit b/brp-kmod-set-exec-bit new file mode 100755 index 0000000..eccd5b4 --- /dev/null +++ b/brp-kmod-set-exec-bit @@ -0,0 +1,14 @@ +#! /bin/bash -efux + +## A hack for making brp-strip taking into account kmod files + +# If using normal root, avoid changing anything. +[ -n "$RPM_BUILD_ROOT" -a "$RPM_BUILD_ROOT" != "/" ] || exit 0 + +# Checking for required programs +which find chmod >/dev/null || exit 0 + +find "$RPM_BUILD_ROOT" \ + -name '*.ko' \ + -printf '%#m %P\n' \ + -exec chmod u+x '{}' \; > "$RPM_BUILD_ROOT/kmod-permissions.list" diff --git a/kernel-srpm-macros.spec b/kernel-srpm-macros.spec index c0fa367..360e90b 100644 --- a/kernel-srpm-macros.spec +++ b/kernel-srpm-macros.spec @@ -34,6 +34,10 @@ Source302: symset-table Source400: kabi.attr Source401: kabi.sh +# BRPs +Source500: brp-kmod-set-exec-bit +Source501: brp-kmod-restore-perms + %global rrcdir /usr/lib/rpm/redhat @@ -48,6 +52,9 @@ Release: %{release}%{?dist}.1 Summary: Macros and scripts for building kernel module packages Requires: redhat-rpm-config >= 13 +# for brp-kmod-set-exec-bit +Requires: %{_bindir}/find + %description -n kernel-rpm-macros Macros and scripts for building kernel module packages. @@ -75,6 +82,7 @@ mkdir -p %{buildroot}%{_fileattrsdir} install -p -m 755 -t %{buildroot}%{rrcdir} kmodtool rpmsort symset-table install -p -m 755 -t %{buildroot}%{rrcdir} find-provides.ksyms find-requires.ksyms install -p -m 755 -t %{buildroot}%{rrcdir}/find-provides.d firmware.prov modalias.prov +install -p -m 755 -t %{buildroot}%{rrcdir} brp-kmod-restore-perms brp-kmod-set-exec-bit install -p -m 644 -t %{buildroot}%{_rpmconfigdir}/macros.d macros.kmp install -p -m 644 -t %{buildroot}%{_fileattrsdir} kmod.attr @@ -90,6 +98,8 @@ install -p -m 755 -t "%{buildroot}%{_rpmconfigdir}" kabi.sh %{_rpmconfigdir}/macros.d/macros.kmp %{_fileattrsdir}/kabi.attr %dir %{rrcdir}/find-provides.d +%{rrcdir}/brp-kmod-restore-perms +%{rrcdir}/brp-kmod-set-exec-bit %{rrcdir}/kmodtool %{rrcdir}/rpmsort %{rrcdir}/symset-table diff --git a/macros.kmp b/macros.kmp index 60ec494..2bc7504 100644 --- a/macros.kmp +++ b/macros.kmp @@ -2,6 +2,11 @@ redhat_kernel_module_package 1 kernel_module_package_release 1 +%__brp_kmod_set_exec_bit /usr/lib/rpm/redhat/brp-kmod-set-exec-bit +%__brp_kmod_restore_perms /usr/lib/rpm/redhat/brp-kmod-restore-perms + +%__kmod_brps_added 0 + %__find_provides /usr/lib/rpm/redhat/find-provides %__find_requires /usr/lib/rpm/redhat/find-requires @@ -12,6 +17,41 @@ kernel_module_package_release 1 kernel-devel kernel-abi-stablelists redhat-rpm-config kernel-rpm-macros elfutils-libelf-devel kmod %kernel_module_package(n:v:r:s:f:xp:) %{expand:%( \ + ## An ugly hack: we want kmods to be processed by find-debuginfo, + ## but it processes only files with executable permission set. + ## It is important now since, as of now, if debuginfo package + ## is enabled (and it is enabled), there's an RPM build error + ## as a result of lack of ether absence or emptiness of + ## debugsourcefiles.list (which is likely a bug in RPM, but it looks + ## like that there's no obvious fix and apparently no one have + ## any issues with this). + ## In order to minimise intrusiveness, usually (in Red Hat-built kmod + ## RPMs) *.ko files just have executable permission being set as a part + ## of %build section. There are two caveats with kmp, however: + ## * We have no control over %build section itself (and it wasn't + ## required previously) + ## * Changing the criteria used in find-debuginfo.sh/brp-strip + ## for selecting files that have to undergo debug section separation + ## may introduce regression. + ## As a result, we insert additional hooks in __spec_install_post + ## (__brp_kmod_set_exec_bit in the beginning and + ## __brp_kmod_restore_perms in the end) that (temporarily) set + ## executable permission for *.ko files so find-debuginfo.sh will pick + ## them up. + ## Unfortunately, __spec_install_post's body is copied here since + ## we want that __debug_package macro expansion has been performed + ## lazily and it looks like RPM has no ability to provide a body + ## of a macro verbatim. + if [ 0 = "%{__kmod_brps_added}" ]; then \ + echo "%%global __spec_install_post \\\\" \ + echo " %%{?__brp_kmod_set_exec_bit} \\\\" \ + echo " %%%%{?__debug_package:%%%%{__debug_install_post}} \\\\" \ + echo " %%{__arch_install_post} \\\\" \ + echo " %%{__os_install_post} \\\\" \ + echo " %%{?__brp_kmod_restore_perms} \\\\" \ + echo "%%{nil}" \ + fi \ + %global __kmod_brps_added 1 \ %global kmodtool %{-s*}%{!-s:/usr/lib/rpm/redhat/kmodtool} \ %global kmod_version %{-v*}%{!-v:%{version}} \ %global kmod_release %{-r*}%{!-r:%{release}} \