3 [ "$include_sessionlock" ] && return 0
4 include_sessionlock="$0"
6 . "$_EXEC/cgilite/storage.sh"
7 . "$_EXEC/cgilite/session.sh"
9 LOCK_TIMEOUT="${LOCK_TIMEOUT:-1200}"
12 local file="$1" timeout="${2:-$LOCK_TIMEOUT}"
15 printf "%i %s\n" "$_DATE" "$SESSION_ID" >>"${file}.lock"
17 if ! read date sid <"${file}.lock"; then
18 debug "Unable to access lock: ${file}.lock"
20 elif [ $((date + timeout)) -lt $_DATE ]; then
22 if LOCK "${file}.lock" 1; then
23 debug "Overriding stale lock: ${file}.lock"
24 printf "%i %s\n" "$_DATE" "$SESSION_ID" >"${file}.lock"
25 RELEASE "${file}.lock"
31 elif [ "$sid" = "$SESSION_ID" -a "$date" -ne "$_DATE" ]; then
33 printf "%i %s\n" "$_DATE" "$SESSION_ID" >"${file}.lock"
36 elif [ "$sid" = "$SESSION_ID" ]; then
46 local file="$1" timeout="${2:-$LOCK_TIMEOUT}"
49 if ! read date sid <"${file}.lock"; then
53 elif [ "$sid" = "$SESSION_ID" -a $((date + timeout)) -lt $_DATE ]; then
54 # if lock is stale, protect against stale override before release
55 if LOCK "${file}.lock" 1; then
57 RELEASE "${file}.lock"
63 elif [ "$sid" = "$SESSION_ID" ]; then