X-Git-Url: https://git.plutz.net/?a=blobdiff_plain;f=cgilite%2Fstorage.sh;h=77ee29c06243eae9359c03125626a46f498cded4;hb=f307cfa12e5dbdd445ca787011eefbefd5c47dc5;hp=c0f9076a2e9ebc02b8db3db9f9d52da12ba4ca46;hpb=0499c5946553b5ce74c234f07d200d31548c3ae4;p=serve0 diff --git a/cgilite/storage.sh b/cgilite/storage.sh index c0f9076..77ee29c 100755 --- a/cgilite/storage.sh +++ b/cgilite/storage.sh @@ -1,6 +1,6 @@ #!/bin/sh -# Copyright 2018, 2019 Paul Hänsch +# Copyright 2018, 2019, 2021 Paul Hänsch # # This is a file format helper, part of CGIlite. # @@ -25,9 +25,7 @@ BR=' ' LOCK(){ - local lock timeout block - lock="${1}.lock" - timeout="${2-20}" + local lock="${1}.lock" timeout="${2-20}" block if [ \! -w "${lock%/*}" ] || [ -e "$lock" -a \! -f "$lock" ]; then debug "Impossible to get lock: $lock" @@ -40,14 +38,14 @@ LOCK(){ if [ "$block" = $$ ]; then return 0 elif ! { ps -eo pid |grep -qwF "$block"; }; then - debug "Overriding stale lock: $lock" + debug "Trying to override stale lock: $lock" if LOCK "$lock" 1; then rm -- "$lock" RELEASE "$lock" fi else timeout=$((timeout - 1)) - sleep 1 + [ $timeout -gt 0 ] && sleep 1 fi done @@ -56,8 +54,7 @@ LOCK(){ } RELEASE(){ - local lock block - lock="${1}.lock" + local lock="${1}.lock" block read block <"$lock" if [ "$block" = $$ ]; then