]> git.corax.cc Git - toolbox/commitdiff
include/mutex: Make mutex_lock() fail if the path does not exist
authorMatthias Kruk <m@m10k.eu>
Tue, 20 Apr 2021 23:24:39 +0000 (08:24 +0900)
committerMatthias Kruk <m@m10k.eu>
Tue, 20 Apr 2021 23:24:39 +0000 (08:24 +0900)
The mutex_lock() function does not check if the path of the mutex
exists, causing it to wait forever if an invalid path was passed.
This commit makes mutex_lock() fail if it could not inotifywait on
the directory that contains the mutex.

include/mutex.sh

index edc4da76405b61903d35254773b3584f37d37833..01f67ac06d1029b59d24ebe5a74ae2c2c92125f8 100644 (file)
@@ -27,7 +27,9 @@ mutex_lock() {
        lock="$1"
 
        while ! mutex_trylock "$lock"; do
-               inotifywait -qq "${lock%/*}"
+               if ! inotifywait -qq "${lock%/*}"; then
+                       return 1
+               fi
        done
 
        return 0