]> git.corax.cc Git - toolbox/commitdiff
include/mutex: Use $$ instead of $BASHPID to identify the owner
authorMatthias Kruk <m@m10k.eu>
Mon, 14 Feb 2022 10:52:14 +0000 (19:52 +0900)
committerMatthias Kruk <m@m10k.eu>
Mon, 14 Feb 2022 10:52:14 +0000 (19:52 +0900)
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

index 1d04ce05faa9d2a1630b65c1c58c11d118a0dbbd..32ee3209ddbdf8bc0ee3e486e7564f7c162896f5 100644 (file)
@@ -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