Remove stale lock files

Signed-off-by: Tom Eastep <teastep@shorewall.net>
This commit is contained in:
Tom Eastep 2011-08-21 10:53:24 -07:00
parent 8c8326fa58
commit 56addf3d4c
2 changed files with 30 additions and 0 deletions

View File

@ -101,6 +101,7 @@ mutex_on()
try=0
local lockf
lockf=${LOCKFILE:=${VARDIR}/lock}
local lockpid
MUTEX_TIMEOUT=${MUTEX_TIMEOUT:-60}
@ -108,8 +109,22 @@ mutex_on()
[ -d ${VARDIR} ] || mkdir -p ${VARDIR}
if [ -f $lockf ]; then
lockpid=`cat ${lockf} 2> /dev/null`
if [ -z "$lockpid" -o $lockpid = 0 ]; then
rm -f ${lockf}
error_message "WARNING: Stale lockfile ${lockf} removed"
elif ! qt ps p ${lockpid}; then
rm -f ${lockf}
error_message "WARNING: Stale lockfile ${lockf} from pid ${lockpid} removed"
fi
fi
if qt mywhich lockfile; then
lockfile -${MUTEX_TIMEOUT} -r1 ${lockf}
chmod u+w ${lockf}
echo $$ > ${lockf}
chmod u-w ${lockf}
else
while [ -f ${lockf} -a ${try} -lt ${MUTEX_TIMEOUT} ] ; do
sleep 1

View File

@ -105,6 +105,7 @@ mutex_on()
try=0
local lockf
lockf=${LOCKFILE:=${VARDIR}/lock}
local lockpid
MUTEX_TIMEOUT=${MUTEX_TIMEOUT:-60}
@ -112,8 +113,22 @@ mutex_on()
[ -d ${VARDIR} ] || mkdir -p ${VARDIR}
if [ -f $lockf ]; then
lockpid=`cat ${lockf} 2> /dev/null`
if [ -z "$lockpid" -o $lockpid = 0 ]; then
rm -f ${lockf}
error_message "WARNING: Stale lockfile ${lockf} removed"
elif ! qt ps p ${lockpid}; then
rm -f ${lockf}
error_message "WARNING: Stale lockfile ${lockf} from pid ${lockpid} removed"
fi
fi
if qt mywhich lockfile; then
lockfile -${MUTEX_TIMEOUT} -r1 ${lockf}
chmod u+w ${lockf}
echo $$ > ${lockf}
chmod u-w ${lockf}
else
while [ -f ${lockf} -a ${try} -lt ${MUTEX_TIMEOUT} ] ; do
sleep 1