procd: Add wrapper for uci_validate_section()

This adds a wrapper (uci_load_validate) for uci_validate_section() that
allows callers (through a callback function) to access the values set by
uci_validate_section(), without having to manually declare a
(potentially long) list of local variables.

The callback function receives two arguments when called, the config
section name and the return value of uci_validate_section().

If no callback function is given, then the wrapper exits with the value
returned by uci_validate_section().

This also updates several init scripts to use the new wrapper function.

Signed-off-by: Jeffery To <jeffery.to@gmail.com>

Part of the commit content is already in dropbear/files, procd/files,
ubox/files and busybox/files.
This commit is contained in:
Jeffery To 2019-01-13 02:14:22 +08:00 committed by AmadeusGhost
parent f53e2b1bd6
commit f850950e91

View File

@ -6,7 +6,7 @@ USE_PROCD=1
validate_system_section()
{
uci_validate_section system system "${1}" \
uci_load_validate system system "$1" "$2" \
'hostname:string:OpenWrt' \
'conloglevel:uinteger' \
'buffersize:uinteger' \
@ -15,11 +15,7 @@ validate_system_section()
}
system_config() {
local cfg="$1"
local hostname conloglevel buffersize timezone zonename
validate_system_section "${1}" || {
[ "$2" = 0 ] || {
echo "validation failed"
return 1
}
@ -36,7 +32,7 @@ system_config() {
reload_service() {
config_load system
config_foreach system_config system
config_foreach validate_system_section system system_config
}
service_triggers()