]> git.plutz.net Git - serve0/commitdiff
Merge commit '3a4d7121502a5f4817a0b6ba5f871ead6cffeb63'
authorPaul Hänsch <paul@plutz.net>
Mon, 23 Aug 2021 15:33:08 +0000 (17:33 +0200)
committerPaul Hänsch <paul@plutz.net>
Mon, 23 Aug 2021 15:33:08 +0000 (17:33 +0200)
cgilite/storage.sh

index c0f9076a2e9ebc02b8db3db9f9d52da12ba4ca46..77ee29c06243eae9359c03125626a46f498cded4 100755 (executable)
@@ -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