From db990512fcfc28326157caf8b84d82311a0d323d Mon Sep 17 00:00:00 2001 From: CentOS Sources Date: Jul 14 2020 01:51:10 +0000 Subject: import redhat-rpm-config-123-1.el8 --- diff --git a/SOURCES/brp-mangle-shebangs b/SOURCES/brp-mangle-shebangs index b4341a2..fe28768 100755 --- a/SOURCES/brp-mangle-shebangs +++ b/SOURCES/brp-mangle-shebangs @@ -70,13 +70,17 @@ done cd "$RPM_BUILD_ROOT" -trim() { - printf '%s' "$*" -} - +# Large packages such as kernel can have thousands of executable files. +# We take care to not fork/exec thousands of "file"s and "grep"s, +# but run just two of them. +# (Take care to exclude filenames which would mangle "file" output). +find -executable -type f ! -path '*:*' ! -path $'*\n*' \ +| file -N --mime-type -f - \ +| grep -P ".+(?=: text/)" \ +| { fail=0 -while IFS= read -r -d $'\0' f; do - file -N --mime-type "$f" | grep -q -P ".+(?=: text/)" || continue +while IFS= read -r line; do + f=${line%%:*} # Remove the dot path="${f#.}" @@ -88,24 +92,34 @@ while IFS= read -r -d $'\0' f; do echo "$path" | grep -q -E -f "$exclude_files_from" && continue fi - ts=$(stat -c %y "$f") - read shebang_line < "$f" || : - orig_shebang=$(trim $(echo "$shebang_line" | grep -Po "#!\K.*" || echo)) - shebang="$orig_shebang" - if [ -n "$exclude_shebangs" ]; then - echo "$shebang" | grep -q -E "$exclude_shebangs" && continue - fi - if [ -n "$exclude_shebangs_from" ]; then - echo "$shebang" | grep -q -E -f "$exclude_shebangs_from" && continue + read shebang_line < "$f" + orig_shebang="${shebang_line#\#!}" + if [ "$orig_shebang" = "$shebang_line" ]; then + echo >&2 "*** WARNING: $f is executable but has no shebang, removing executable bit" + ts=$(stat -c %y "$f") + chmod -x "$f" + touch -d "$ts" "$f" + continue fi + # Trim spaces + while shebang="${orig_shebang// / }"; [ "$shebang" != "$orig_shebang" ]; do + orig_shebang="$shebang" + done + # Treat "#! /path/to " as "#!/path/to" + orig_shebang="${orig_shebang# }" + + shebang="$orig_shebang" + if [ -z "$shebang" ]; then - echo >&2 "*** WARNING: $f is executable but has empty or no shebang, removing executable bit" + echo >&2 "*** WARNING: $f is executable but has empty shebang, removing executable bit" + ts=$(stat -c %y "$f") chmod -x "$f" touch -d "$ts" "$f" continue - elif [ -n "${shebang##/*}" ]; then + fi + if [ -n "${shebang##/*}" ]; then echo >&2 "*** ERROR: $f has shebang which doesn't start with '/' ($shebang)" fail=1 continue @@ -134,11 +148,13 @@ while IFS= read -r -d $'\0' f; do echo >&2 "*** ERROR: ambiguous python shebang in $path: #!$orig_shebang. Change it to python3 (or python2) explicitly." fail=1 elif [ "#!$shebang" != "#!$orig_shebang" ]; then - sed -i -e "1c #!$shebang" "$f" echo "mangling shebang in $path from $orig_shebang to #!$shebang" + ts=$(stat -c %y "$f") + sed -i -e "1c #!$shebang" "$f" + touch -d "$ts" "$f" fi - touch -d "$ts" "$f" -done < <(find -executable -type f -print0) +done exit $fail +} diff --git a/SOURCES/dist.sh b/SOURCES/dist.sh index 23bb032..db6c053 100755 --- a/SOURCES/dist.sh +++ b/SOURCES/dist.sh @@ -25,7 +25,7 @@ function check_rhl { } function check_rhel { - egrep -q "(Enterprise|Advanced|CentOS)" $RELEASEFILE && echo $DISTNUM + egrep -q "(Enterprise|Advanced)" $RELEASEFILE && echo $DISTNUM } function check_fedora { diff --git a/SOURCES/kmod.prov b/SOURCES/kmod.prov index f02d8a0..bbe5aa0 100644 --- a/SOURCES/kmod.prov +++ b/SOURCES/kmod.prov @@ -1,17 +1,28 @@ #!/bin/sh +x +# Kernel build can have many thousands of modules. +# kmod.prov is run for every one of them. +# Try to make this script run as fast as we can. +# For example, use shell string ops instead of external programs +# where possible. IFS=$'\n' -for i in $(grep -E '(/lib/modules/.*\.ko|/lib/modules/.*/modules.builtin)'); -do - kmod=$(basename $i | sed -e 's/.[xg]z//'); +read -r fname || exit - if [ $kmod == "modules.builtin" ]; then - for j in $(cat $i); do - j=$(basename $j); - echo "kmod($j)" - done - else - echo "kmod($kmod)" - fi -done +# Only process files from .../lib/modules/... subtree +[ "${fname#*/lib/modules/*}" != "$fname" ] || exit 0 + +kmod=${fname##*/} # like basename, but faster + +if [ "$kmod" = "modules.builtin" ]; then + for j in $(cat -- "$fname"); do + echo "kmod(${j##*/})" + done + exit 0 +fi + +kmod=${kmod%.gz} +kmod=${kmod%.xz} +if [ "${kmod%.ko}" != "$kmod" ]; then + echo "kmod($kmod)" +fi diff --git a/SPECS/redhat-rpm-config.spec b/SPECS/redhat-rpm-config.spec index 4a8ade4..7f8b443 100644 --- a/SPECS/redhat-rpm-config.spec +++ b/SPECS/redhat-rpm-config.spec @@ -4,9 +4,9 @@ # 2) When making changes, update version by +1, leave release alone. # -Summary: CentOS specific rpm configuration files +Summary: Red Hat specific rpm configuration files Name: redhat-rpm-config -Version: 122 +Version: 123 Release: 1%{?dist} # No version specified. License: GPL+ @@ -118,7 +118,7 @@ Provides: system-rpm-config = %{version}-%{release} %global rrcdir /usr/lib/rpm/redhat %description -CentOS specific rpm configuration files. +Red Hat specific rpm configuration files. %package -n kernel-rpm-macros Summary: Macros and scripts for building kernel module packages. @@ -198,6 +198,10 @@ install -p -m 755 %{SOURCE21} %{buildroot}%{_rpmconfigdir}/kabi.sh %{_rpmconfigdir}/macros.d/macros.kmp %changelog +* Tue Jun 16 2020 Florian Festi - 123-1 +- Update kmod.prov for better performance (#1794491) +- Backport performance improvements for brp-mangle-shebangs (#1794779) + * Mon Feb 24 2020 Michal Domonkos - 122-1 - Fix argument shift in %%__brp_python_bytecompile (#1724567)