From d13e86d4c2d4c1c8970a20cc1f3214b266f57ed0 Mon Sep 17 00:00:00 2001 From: Jeffery To Date: Sun, 13 Jan 2019 02:14:22 +0800 Subject: 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 --- package/system/procd/files/procd.sh | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'package/system/procd') diff --git a/package/system/procd/files/procd.sh b/package/system/procd/files/procd.sh index 6f16b746ff..72f25fe0c0 100644 --- a/package/system/procd/files/procd.sh +++ b/package/system/procd/files/procd.sh @@ -486,6 +486,23 @@ uci_validate_section() return $_error } +uci_load_validate() { + local _package="$1" + local _type="$2" + local _name="$3" + local _function="$4" + local _option + local _result + shift; shift; shift; shift + for _option in "$@"; do + eval "local ${_option%%:*}" + done + uci_validate_section "$_package" "$_type" "$_name" "$@" + _result=$? + [ -n "$_function" ] || return $_result + eval "$_function \"\$_name\" \"\$_result\"" +} + _procd_wrapper \ procd_open_service \ procd_close_service \ -- cgit v1.2.3