Commit f16ddd53 by Eric Coissac

some small bug changes

parent 5e5c811f
...@@ -35,20 +35,69 @@ function __locktag__() { ...@@ -35,20 +35,69 @@ function __locktag__() {
echo "$(hostname).$$" echo "$(hostname).$$"
} }
function trytogetlock() {
local lname="$1"
shift
local mode="user"
logdebug "Try to get lock ${lname}"
if [[ "${1}" == "global" ]]; then
mode="global"
fi
if [[ "${mode}" == "global" ]]; then
name=$(__lockfile__ "${lname}")
else
name=$(__lockfile__ "${lname}.$(whoami)")
fi
local TAG=$(__locktag__)
local retry=0
local notgetlock=1
pushnoclobber
echo "${TAG}" 2>/dev/null 1> "${name}"
notgetlock=$?
popnoclobber
if (( notgetlock > 0 )); then
if [[ $(cat "${name}" 2> /dev/null) == "${TAG}" ]]; then
notgetlock=0
fi
fi
if (( notgetlock == 0 )); then
logdebug "Succeed to get lock ${lname}"
fi
if (( notgetlock > 0 )); then
return $notgetlock
else
chmod a+w "${name}"
return 0
fi
}
function getlock() { function getlock() {
local name="$1" local lname="$1"
shift shift
local mode="user" local mode="user"
logdebug "Try to get lock ${lname}"
if [[ "${1}" == "global" ]]; then if [[ "${1}" == "global" ]]; then
mode="global" mode="global"
fi fi
if [[ "${mode}" == "global" ]]; then if [[ "${mode}" == "global" ]]; then
name=$(__lockfile__ "${name}") name=$(__lockfile__ "${lname}")
else else
name=$(__lockfile__ "${name}.$(whoami)") name=$(__lockfile__ "${lname}.$(whoami)")
fi fi
local TAG=$(__locktag__) local TAG=$(__locktag__)
...@@ -70,7 +119,7 @@ function getlock() { ...@@ -70,7 +119,7 @@ function getlock() {
fi fi
if (( notgetlock > 0 )); then if (( notgetlock > 0 )); then
loginfo "Failed to get lock $name" logdebug "Failed to get lock ${lname}"
sleep "${LECA_LOCK_DELAY}" sleep "${LECA_LOCK_DELAY}"
retry=$((retry + 1)) retry=$((retry + 1))
fi fi
...@@ -80,25 +129,28 @@ function getlock() { ...@@ -80,25 +129,28 @@ function getlock() {
if (( notgetlock > 0 )); then if (( notgetlock > 0 )); then
return $notgetlock return $notgetlock
else else
logdebug "Succeed to get lock ${lname}"
chmod a+w "${name}" chmod a+w "${name}"
return 0 return 0
fi fi
} }
function releaselock() { function releaselock() {
local name="$1" local lname="$1"
shift shift
local mode="user" local mode="user"
logdebug "Try to release lock ${lname}"
if [[ "${1}" == "global" ]]; then if [[ "${1}" == "global" ]]; then
mode="global" mode="global"
fi fi
if [[ "${mode}" == "global" ]]; then if [[ "${mode}" == "global" ]]; then
name=$(__lockfile__ "${name}") name=$(__lockfile__ "${lname}")
else else
name=$(__lockfile__ "${name}.$(whoami)") name=$(__lockfile__ "${lname}.$(whoami)")
fi fi
local TAG=$(__locktag__) local TAG=$(__locktag__)
...@@ -113,6 +165,7 @@ function releaselock() { ...@@ -113,6 +165,7 @@ function releaselock() {
if [[ "${LOCK}" == "${TAG}" ]]; then if [[ "${LOCK}" == "${TAG}" ]]; then
rm -f "${name}" rm -f "${name}"
logdebug "Lock ${lname} released"
return 0 return 0
fi fi
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment