From 25bb62f6226f04f132a7533c6935110f6a059440 Mon Sep 17 00:00:00 2001 From: prpr Date: Sat, 10 Sep 2022 15:31:33 +0100 Subject: [PATCH] Improve lock handling of /var/lib/humaxtv/setup.db --- webif/lib/system.class | 37 +++++++++++++++++++++++++++++++------ 1 file changed, 31 insertions(+), 6 deletions(-) diff --git a/webif/lib/system.class b/webif/lib/system.class index cb19d18..dbb30a6 100644 --- a/webif/lib/system.class +++ b/webif/lib/system.class @@ -569,16 +569,41 @@ proc {system restartpending} {{mode 1}} { } } -proc {system param} {param {type Value} {tbl MENUCONFIG}} { +proc {system param} {param {type Value} {tbl MENUCONFIG}} {{newdb ""}} { if {[catch {set db [sqlite3.open /var/lib/humaxtv/setup.db]} msg]} { return 0 } + catch {$db query {pragma busy_timeout(50)}} set val 0 - set ret [$db query " - select item$type - from TBL_$tbl - where itemName = '$param' - "] + loop _ 2 { + try { + set ret [$db query " + select item$type + from TBL_$tbl + where itemName = '$param' + "] + break + } on error {msg opts} { + if {[string first "database is locked" $msg] >= 0} { + try { + if {$newdb eq ""} { + set newdb [file tempfile /tmp/setupXXXXXX] + defer "catch {file delete $newdb}" + } + file copy -force /var/lib/humaxtv/setup.db $newdb + set db [sqlite3.open $newdb] + } on error {msg opts} { + file delete $newdb + break + } + continue + } + + catch {$db close} + return {*}$opts $msg + } + } + if {[llength $ret] == 1} { lassign [lindex $ret 0] x val }