Fix mutex on OpenWRT - patch 1

Signed-off-by: Tom Eastep <teastep@shorewall.net>
This commit is contained in:
Tom Eastep 2018-07-26 11:47:51 -07:00
parent 5083246266
commit 1fa77ac470
No known key found for this signature in database
GPG Key ID: 96E6B3F2423A4D10

View File

@ -766,23 +766,22 @@ mutex_on()
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 [ $lockpid -eq $$ ]; then
return 0 fatal_error "Mutex_on confusion"
elif ! ps | grep -v grep | qt grep ${lockpid}; then elif ! qt ps --pid ${lockpid}; then
rm -f ${lockf} rm -f ${lockf}
error_message "WARNING: Stale lockfile ${lockf} from pid ${lockpid} removed" error_message "WARNING: Stale lockfile ${lockf} from pid ${lockpid} removed"
fi fi
fi fi
if qt mywhich lockfile; then if qt mywhich lockfile; then
lockfile -${MUTEX_TIMEOUT} -r1 ${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 elif qt mywhich lock; then
lock ${lockf} lock ${lockf} || fatal_error "Can't lock ${lockf}"
g_havemutex="lock -u ${lockf} && rm -f ${lockf}" g_havemutex="lock -u ${lockf}"
chmod u=r ${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