# #
###############################################################################
+__lock_path() {
+ local name=${1}
+
+ if [ "${name:0:1}" = "/" ]; then
+ echo "${name}"
+ else
+ echo "${LOCK_DIR}/network-${name}"
+ fi
+}
+
lock_acquire() {
- local lockfile="${1}"
- assert isset lockfile
+ local name=${1}
+ assert isset name
+
+ local lockfile=$(__lock_path ${name})
# timeout value in seconds
local timeout=120
timeout=$(( ${timeout} * 4 ))
- log DEBUG "Acquiring lock '${lockfile}'"
+ log DEBUG "Acquiring lock '${name}'"
local free="false"
while [ ${timeout} -gt 0 ]; do
sleep 0.25
done
- assert ${free} "Could not acquire lock '${lockfile}'"
+ assert ${free} "Could not acquire lock '${name}'"
# Write out pid to the lockfile and make sure that
# nobody else can access it.
}
lock_release() {
- local lockfile="${1}"
+ local name=${1}
+ assert isset name
+
+ local lockfile=$(__lock_path ${name})
- log DEBUG "Releasing lock '${lockfile}'"
+ log DEBUG "Releasing lock '${name}'"
# Remove the lockfile (okay if it does not exist).
rm -f ${lockfile}