Merge pull request 'df-lockedsettings-patch' (#18) from df/webif:df-lockedsettings-patch into master

Reviewed-on: #18
This commit is contained in:
af123 2020-11-14 11:16:55 +00:00
commit 8021455a94

View File

@ -54,6 +54,28 @@ class settings {
rtschedule 0 rtschedule 0
} }
proc {settings _safer_query} { queryText args } {
global settingsdb
# allow 4 tries from 0.5s delay, doubling, to get access
for {set lockCnt 4; set delay 0.5} {true} {sleep $delay; set delay $(2*$delay)} {
try {
return [$settingsdb query $queryText {*}$args]
} on error {msg opts} {
if {[string first "database is locked" $msg] >= 0} {
if {[incr lockCnt -1] > 0} {
continue
} else {
# raise error from caller
set msg "Persistently unable to access Settings: database locked"
incr opts(-level)
}
}
return {*}$opts $msg
}
}
}
settings method hostname {{name ""}} { settings method hostname {{name ""}} {
if {$name == ""} { if {$name == ""} {
# Get # Get
@ -104,11 +126,10 @@ settings method smtp_server {{server ""}} {
} }
settings method _nval_setting {name {val -1}} { settings method _nval_setting {name {val -1}} {
global settingsdb
if {$val == -1} { if {$val == -1} {
# Get # Get
set res [$settingsdb query " set res [settings _safer_query "
select nval from settings select nval from settings
where name = '$name' where name = '$name'
"] "]
@ -118,7 +139,7 @@ settings method _nval_setting {name {val -1}} {
return 0 return 0
} else { } else {
# Set # Set
$settingsdb query " settings _safer_query "
replace into settings(name,nval) replace into settings(name,nval)
values('$name', $val) values('$name', $val)
" "
@ -127,11 +148,10 @@ settings method _nval_setting {name {val -1}} {
} }
settings method _tval_setting {name {val -1} {def 0}} { settings method _tval_setting {name {val -1} {def 0}} {
global settingsdb
if {$val eq "-1"} { if {$val eq "-1"} {
# Get # Get
set res [$settingsdb query " set res [settings _safer_query "
select tval from settings select tval from settings
where name = '$name' where name = '$name'
"] "]
@ -141,7 +161,7 @@ settings method _tval_setting {name {val -1} {def 0}} {
return $def return $def
} else { } else {
# Set # Set
$settingsdb query " settings _safer_query "
replace into settings(name,tval) replace into settings(name,tval)
values('$name', '%s') values('$name', '%s')
" $val " $val