X-Git-Url: http://git.plutz.net/?p=cgilite;a=blobdiff_plain;f=storage.sh;h=f5a0ac6c58feb4de7ae8285b32f28e4b4c47780d;hp=d4fbca36714a0cfe08db9ea9d465d43b3ef83b9c;hb=813580b4cdebfe5161ef01bcbd126405c3162d7a;hpb=aa4821bae04b2022828cbbb725874db96ca249fd diff --git a/storage.sh b/storage.sh index d4fbca3..f5a0ac6 100755 --- a/storage.sh +++ b/storage.sh @@ -17,6 +17,9 @@ # You should have received a copy of the GNU Affero General Public License # along with CGIlite. If not, see . +[ -n "$include_storage" ] && return 0 +include_storage="$0" + LOCK(){ lock="${1}.lock" timeout="${2-20}" @@ -25,7 +28,7 @@ LOCK(){ return 1 fi - while ! mkdir "$lock"; do + while ! mkdir "$lock" 2>&-; do block="$(cat "$lock/pid" || printf 1)" if ! { ps -eo pid |grep -qwF "$block"; }; then printf 'Overriding stale lock: %s\n' "$lock" >&2 @@ -39,7 +42,7 @@ LOCK(){ sleep 1 done printf '%i\n' $$ >"${lock}/pid" - return 1 + return 0 } RELEASE(){ @@ -51,6 +54,7 @@ RELEASE(){ printf '%i\n' $$ >"${lock}/pid" return 1 fi + return 0 else printf 'Refusing to release foreign lock: %s\n' "$lock" >&2 return 1