Skip to content

Commit 4bb2e99

Browse files
Fine-Tuning & Improvements WRT the FLock
Just some code improvements and fine-tuning WRT the FLock mechanism.
1 parent 35a4b9a commit 4bb2e99

2 files changed

Lines changed: 31 additions & 13 deletions

File tree

MerlinAU.sh

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ set -u
1010

1111
## Set version for each Production Release ##
1212
readonly SCRIPT_VERSION=1.6.0
13-
readonly SCRIPT_VERSTAG="26031800"
13+
readonly SCRIPT_VERSTAG="26031823"
1414
readonly SCRIPT_NAME="MerlinAU"
1515
## Set to "master" for Production Releases ##
1616
SCRIPT_BRANCH="dev"
@@ -409,7 +409,7 @@ readonly LockTypeRegEx="(cliMenuLock|cliOptsLock|cliFileLock)"
409409
_FindLockFileTypes_()
410410
{ grep -woE "$LockTypeRegEx" "$LockFilePath" | tr '\n' ' ' | sed 's/[ ]*$//' ; }
411411

412-
_ReleaseLock_()
412+
_ReleaseLock_()
413413
{
414414
local lockType
415415
if [ $# -eq 0 ] || [ -z "$1" ]
@@ -421,7 +421,7 @@ _ReleaseLock_()
421421
then
422422
if [ -z "$lockType" ]
423423
then sed -i "/^$$|/d" "$LockFilePath"
424-
else sed -i "/.*|${1}$/d" "$LockFilePath"
424+
else sed -i "/^$$|${1}$/d" "$LockFilePath"
425425
fi
426426
[ -s "$LockFilePath" ] && return 0
427427
fi
@@ -535,11 +535,19 @@ _AcquireLock_()
535535
##-------------------------------------##
536536
fwupMutexFLock_FD=576
537537
fwupMutexFLock_FN="/tmp/var/${ScriptFNameTag}_FW_Update.FLock"
538+
fwupMutexFLock_OK=false #DO NOT have FLock#
538539

539540
_ReleaseMutexFLock_()
540541
{
542+
if [ $# -gt 0 ] && \
543+
[ "$1" = "checkLockOK" ] && \
544+
[ "$fwupMutexFLock_OK" != "true" ]
545+
then return 0
546+
fi
547+
541548
printf '' > "$fwupMutexFLock_FN"
542549
flock -u "$fwupMutexFLock_FD" 2>/dev/null
550+
fwupMutexFLock_OK=false
543551
}
544552

545553
##-------------------------------------##
@@ -554,7 +562,7 @@ _ReleaseMutexFLock_()
554562
_AcquireMutexFLock_()
555563
{
556564
local retCode savedVerbose
557-
local procInfo procName="" procIDno="" procIDof=""
565+
local procInfo procName procIDno procIDof=""
558566

559567
savedVerbose="$isVerbose" ; isVerbose=true
560568

@@ -566,7 +574,8 @@ _AcquireMutexFLock_()
566574
if [ -n "$procName" ] && [ -n "$procIDno" ]
567575
then procIDof="$(pidof "$procName")"
568576
fi
569-
if [ -z "$procIDof" ] || ! echo "$procIDof" | grep -qow "$procIDno"
577+
if [ -z "$procIDof" ] || \
578+
! echo "$procIDof" | grep -qow "$procIDno"
570579
then
571580
Say "Stale F/W Update Lock Found. Resetting lock file..."
572581
_ReleaseMutexFLock_
@@ -579,11 +588,14 @@ _AcquireMutexFLock_()
579588
if flock -x -n "$fwupMutexFLock_FD" 2>/dev/null
580589
then
581590
printf "$(basename "$0")|$$\n" > "$fwupMutexFLock_FN"
582-
retCode=0
591+
retCode=0 ; fwupMutexFLock_OK=true
583592
else
584593
procInfo="$(head -n1 "$fwupMutexFLock_FN")"
594+
if [ -n "$procInfo" ]
595+
then procInfo="$(echo "$procInfo" | sed 's/|/, PID=/')"
596+
fi
585597
Say "${REDct}**ERROR**${NOct}: Another process [$procInfo] has the F/W Update Lock file."
586-
retCode=1
598+
retCode=1 ; fwupMutexFLock_OK=false
587599
fi
588600

589601
isVerbose="$savedVerbose"
@@ -603,7 +615,9 @@ _DoExit_()
603615
{
604616
local exitCode=0
605617
[ $# -gt 0 ] && [ -n "$1" ] && exitCode="$1"
606-
_ReleaseLock_ ; exit "$exitCode"
618+
_ReleaseLock_
619+
_ReleaseMutexFLock_ checkLockOK
620+
exit "$exitCode"
607621
}
608622

609623
##-------------------------------------##
@@ -9189,9 +9203,11 @@ _RunOfflineUpdateNow_()
91899203
_AcquireMutexFLock_
91909204
then
91919205
_RunFirmwareUpdateNow_
9192-
_ReleaseLock_ cliFileLock
9193-
_ReleaseMutexFLock_
9206+
else
9207+
_WaitForEnterKey_
91949208
fi
9209+
_ReleaseLock_ cliFileLock
9210+
_ReleaseMutexFLock_ checkLockOK
91959211
_ClearOfflineUpdateState_
91969212
else
91979213
_ClearOfflineUpdateState_ 1
@@ -11682,10 +11698,12 @@ _MainMenu_()
1168211698
_AcquireMutexFLock_
1168311699
then
1168411700
_RunFirmwareUpdateNow_
11685-
_ReleaseLock_ cliFileLock
11686-
_ReleaseMutexFLock_
1168711701
FlashStarted=false
11702+
else
11703+
_WaitForEnterKey_
1168811704
fi
11705+
_ReleaseLock_ cliFileLock
11706+
_ReleaseMutexFLock_ checkLockOK
1168911707
;;
1169011708
2) _GetLoginCredentials_
1169111709
;;

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# MerlinAU - AsusWRT-Merlin Firmware Auto Updater
22

33
## v1.6.0
4-
## 2026-Mar-18
4+
## 2026-Mar-19
55

66
## WebUI:
77
![image](https://github.com/user-attachments/assets/9c1dff99-9c13-491b-a7fa-aff924d5f02e)

0 commit comments

Comments
 (0)