From 9a2c3df836641d552e6223fafe623e7e9e95819d Mon Sep 17 00:00:00 2001 From: Matthias Kruk Date: Mon, 14 Feb 2022 19:52:14 +0900 Subject: [PATCH] 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. --- include/mutex.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 -- 2.47.3