build: make the complain mode faster to enable.

This commit is contained in:
Alexandre Pujol 2022-09-18 11:22:19 +01:00
parent a432d656c8
commit cc7dd22244
No known key found for this signature in database
GPG Key ID: C5469996F0DF68EC

33
configure vendored
View File

@ -112,18 +112,39 @@ flags() {
done
}
# Set complain flag on all profile (Dev only)
complain() {
_msg "Set complain flag on all profiles"
for path in "${ROOT:?}/apparmor.d/"*; do
[[ -d "$path" ]] && continue
# Internal complain process
_complain() {
local start="$1" end="$2"; shift 2
files=("$@")
ii="$start"
while [[ $ii -le $end && $ii -lt $len ]]; do
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
echo -n .
sed -e "s/flags=(.*)//" \
-e "s/ {$/ flags=(complain $flags) {/" \
-i "$path"
done
}
# Set complain flag on all profile (Dev only)
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
echo
}