Created
October 1, 2022 09:06
-
-
Save ormaaj/4a74059214a085060ef5b4fdb069f6f8 to your computer and use it in GitHub Desktop.
flock search test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function initializeBuiltins { | |
local - | |
typeset -a a | |
typeset x y z | |
set +m | |
typeset libdir=${fsRoot%%+(/)}/usr/lib64 | |
[[ -d ${libdir}/bash ]] || libdir=${rootPath%%+(/)}/lib64 | |
for x in "${libdir}"/{ctypes.so,bash/!(hello|truefalse|mypid|necho|*.*)}; do | |
if [[ $(file -b --mime-type -- "$x") == 'application/x-sharedlib' && !$? -ne 0 ]]; then | |
nm -CDj --without-symbol-versions -- "$x" | | |
while IFS= read -r y; do | |
[[ $y =~ ^(.+)_struct$ ]] || continue | |
a+=("${BASH_REMATCH[1]}") | |
done | |
(( PIPESTATUS[0] )) || enable -f "$x" -- "${a[@]}" 2>&3 | |
unset -v 'a[@]' | |
fi | |
done 3>/dev/null | |
for x in ln head rm stat; do | |
printf -v y '%q%.s' "$(type -P "$x")" "$((z=$?))" | |
let z && continue | |
eval -- \ | |
function "${x}" { command -- "$y" \"\$@\" \; } \; \ | |
function "${x}2" { builtin -- "$x" \"\$@\" \; } | |
done | |
return 0 | |
} | |
function f { | |
local - | |
set +m | |
typeset lock x= pid=$BASHPID | |
typeset -a output | |
typeset -g lockfile | |
# trap '${lockfile:+\:} exit; rm -f -- "$lockfile"' EXIT | |
mktemp -v lockfile >/dev/null || return | |
{ | |
unlink "$lockfile" | |
for lock in '' x s; do | |
lslocks -p "$pid" | |
x= ${x+\:} | |
${x:+\:} flock -u 3 | |
${x:+\:} flock "-${lock}" 3 | |
lsof -ap "$pid" -d 3 -F lfG0 +f g | mapfile -td '' output | |
printf '%s ' "${output[@]}"; echo | |
${lock:+\:} unset -v x | |
done | |
} 3<"$lockfile" | |
} | |
initializeBuiltins | |
echo; f; echo |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment