From: Matthias Kruk Date: Mon, 14 Feb 2022 10:52:14 +0000 (+0900) Subject: include/mutex: Use $$ instead of $BASHPID to identify the owner X-Git-Url: https://git.corax.cc/?a=commitdiff_plain;h=9a2c3df836641d552e6223fafe623e7e9e95819d;p=toolbox include/mutex: Use $$ instead of $BASHPID to identify the owner The mutex module uses $BASHPID to identify the owner of a mutex, causing scripts to be unable to unlock a mutex that was created in a subshell (which is what happens when using the ipc module). This commit changes the mutex module to use $$ to identify the owner of a mutex, allowing child processes to unlock their parent's mutexes and vice-versa. --- diff --git a/include/mutex.sh b/include/mutex.sh index 1d04ce0..32ee320 100644 --- a/include/mutex.sh +++ b/include/mutex.sh @@ -23,7 +23,7 @@ __init() { mutex_trylock() { local lock="$1" - if ! ln -s "$BASHPID" "$lock" &> /dev/null; then + if ! ln -s "$$" "$lock" &> /dev/null; then return 1 fi @@ -58,7 +58,7 @@ mutex_unlock() { return 1 fi - if (( owner != BASHPID )); then + if (( owner != $$ )); then return 2 fi