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