From 02b35b9155cbc4909a7a125e346e7fa7a7230b21 Mon Sep 17 00:00:00 2001 From: Vasiliy Stelmachenok Date: Tue, 24 Dec 2024 20:04:34 +1000 Subject: [PATCH] libmakepkg: strip - parallelize stripping of files Perform file stripping in parallel where possible. Hardlinks remain processed one at a time due to reproducibility issues. Signed-off-by: Allan McRae --- scripts/libmakepkg/tidy/strip.sh.in | 24 +++++++++++++++++++++--- scripts/makepkg.sh.in | 3 +++ 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/scripts/libmakepkg/tidy/strip.sh.in b/scripts/libmakepkg/tidy/strip.sh.in index 5eda4b00..6b14862f 100644 --- a/scripts/libmakepkg/tidy/strip.sh.in +++ b/scripts/libmakepkg/tidy/strip.sh.in @@ -190,9 +190,27 @@ tidy_strip() { mkdir -p "$dbgdir" "$dbgsrc" fi - while IFS= read -rd '' binary ; do - process_file_stripping "$binary" - done < <(find . -type f -perm -u+w -links 1 -print0 2>/dev/null) + _parallel_stripper() { + # Inherit traps in subshell to perform cleanup after an interrupt + set -E + ( + local jobs binary + + while IFS= read -rd '' binary ; do + # Be sure to keep the number of concurrently running processes less + # than limit value to prevent an accidental fork bomb. + jobs=($(jobs -p)) + (( ${#jobs[@]} >= $NPROC )) && wait -n "${jobs[@]}" + + process_file_stripping "$binary" & + done < <(find . -type f -perm -u+w -links 1 -print0 2>/dev/null) + + # Wait for all jobs to complete + wait + ) + set +E + } + _parallel_stripper # hardlinks only need processed once, but need additional links in debug packages declare -A hardlinks diff --git a/scripts/makepkg.sh.in b/scripts/makepkg.sh.in index b7edb712..591b010e 100644 --- a/scripts/makepkg.sh.in +++ b/scripts/makepkg.sh.in @@ -106,6 +106,9 @@ trap_exit() { fi [[ -n $srclinks ]] && rm -rf "$srclinks" + # Kill all child processes so that they are not left orphaned upon exit. + [[ -n "$(jobs -p)" ]] && kill "$(jobs -p)" 2>/dev/null + # unset the trap for this signal, and then call the default handler trap -- "$signal" kill "-$signal" "$$"