More mutex changes for LEDE

Signed-off-by: Tom Eastep <teastep@shorewall.net>
This commit is contained in:
Tom Eastep 2018-07-31 15:03:58 -07:00
parent 82e84f724d
commit 9cbcb328af
No known key found for this signature in database
GPG Key ID: 96E6B3F2423A4D10

View File

@ -751,6 +751,8 @@ mutex_on()
lockf=${LOCKFILE:=${VARDIR}/lock}
local lockpid
local lockd
local lockbin
local openwrt
MUTEX_TIMEOUT=${MUTEX_TIMEOUT:-60}
@ -760,28 +762,33 @@ mutex_on()
[ -d "$lockd" ] || mkdir -p "$lockd"
lockbin=$(mywhich lock)
[ -n "$lockbin" -a -h "$lockbin" ] && openwrt=Yes
if [ -f $lockf ]; then
lockpid=`cat ${lockf} 2> /dev/null`
if [ -z "$lockpid" ] || [ $lockpid = 0 ]; then
rm -f ${lockf}
error_message "WARNING: Stale lockfile ${lockf} removed"
elif [ $lockpid -eq $$ ]; then
fatal_error "Mutex_on confusion"
elif ! qt ps --pid ${lockpid}; then
rm -f ${lockf}
error_message "WARNING: Stale lockfile ${lockf} from pid ${lockpid} removed"
elif [ -z "$openwrt" ]; then
if [ $lockpid -eq $$ ]; then
fatal_error "Mutex_on confusion"
elif ! qt ps --pid ${lockpid}; then
rm -f ${lockf}
error_message "WARNING: Stale lockfile ${lockf} from pid ${lockpid} removed"
fi
fi
fi
if qt mywhich lockfile; then
if [ -n "$openwrt" ]; then
lock ${lockf} || fatal_error "Can't lock ${lockf}"
g_havemutex="lock -u ${lockf}"
elif qt mywhich lockfile; then
lockfile -${MUTEX_TIMEOUT} -r1 ${lockf} || fatal_error "Can't lock ${lockf}"
g_havemutex="rm -f ${lockf}"
chmod u+w ${lockf}
echo $$ > ${lockf}
chmod u-w ${lockf}
elif qt mywhich lock; then
lock ${lockf} || fatal_error "Can't lock ${lockf}"
g_havemutex="lock -u ${lockf}"
else
while [ -f ${lockf} -a ${try} -lt ${MUTEX_TIMEOUT} ] ; do
sleep 1