From 77c60129b33d4bb23b566868b7f2fbbcc36daada Mon Sep 17 00:00:00 2001 From: Alexandre Pujol Date: Tue, 24 Jan 2023 19:55:03 +0000 Subject: [PATCH] build: improve complain flag replacement. --- configure | 43 +++++++++++++++++++++++++------------------ 1 file changed, 25 insertions(+), 18 deletions(-) diff --git a/configure b/configure index 47197226..eb2c9cff 100755 --- a/configure +++ b/configure @@ -22,6 +22,24 @@ _displace_files() { done } +# Process management function to run a function over all the profile files +# $1 The function to run. +_process() { + local len nprof nproc fct="$1" + mapfile -t files < <(find "${ROOT:?}/apparmor.d" -type f) + len="${#files[@]}" + nproc=$(nproc) + (( nprof = len/nproc + 1 )) + start=0 + end=$nprof + for ((ii = 0 ; ii < nproc ; ii++)); do + $fct $start $end "${files[@]}" & + (( start = end + 1 )) + (( end = end + nprof )) + done + wait +} + # Initialize a new clean apparmor.d build directory initialize() { rm -rf "${ROOT:?}" @@ -122,30 +140,19 @@ _complain() { path="${files[$ii]}" (( ii = ii + 1 )) [[ -f "$path" ]] || continue - flags="$(grep -o -m 1 'flags=(.*)' "$path" | cut -d '(' -f2 | cut -d ')' -f1)" - [[ "$flags" =~ complain ]] && continue + mapfile -t flags < <(grep -o -m 1 'flags=(.*)' "$path" | cut -d '(' -f2 | cut -d ')' -f1) + [[ "${flags[*]}" =~ complain ]] && continue + flags+=(complain) sed -e "s/flags=(.*)//" \ - -e "s/ {$/ flags=(complain $flags) {/" \ + -e "s/ {$/ flags=(${flags[*]}) {/" \ -i "$path" done } -# Set complain flag on all profile (Dev only) +# Set complain flag on all profile complain() { - local len nprof nproc _msg "Set complain flag on all profiles" - mapfile -t files < <(find "${ROOT:?}/apparmor.d" -type f) - len="${#files[@]}" - nproc=$(nproc) - (( nprof = len/nproc + 1 )) - start=0 - end=$nprof - for ((ii = 0 ; ii < nproc ; ii++)); do - _complain $start $end "${files[@]}" & - (( start = end + 1 )) - (( end = end + nprof )) - done - wait + _process _complain } # Set AppArmor for full system policy @@ -187,7 +194,7 @@ main() { initialize || _die "initializing build directory" ignore || _die "removing ignored profiles" synchronise || _die "merging profiles" - configure || _die "configuring distributaion" + configure || _die "configuring distribution" flags || _die "settings flags" [[ "$COMPLAIN" == 1 ]] && complain [[ "$FULL" == 1 ]] && full