summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTony Ambardar <itugrok@yahoo.com>2018-03-07 21:00:45 -0800
committerHans Dedecker <dedeckeh@gmail.com>2018-06-06 15:03:29 +0200
commitb6a1f43075f96b0028e33ed1af1fe31068791d24 (patch)
treef507f6e430c9d72c5ed8a5feb2ec5bb3a8481b5d
parent6734f32d91cd31ec5c2cc44a021a9839232fe587 (diff)
downloadmtk-20170518-b6a1f43075f96b0028e33ed1af1fe31068791d24.zip
mtk-20170518-b6a1f43075f96b0028e33ed1af1fe31068791d24.tar.gz
mtk-20170518-b6a1f43075f96b0028e33ed1af1fe31068791d24.tar.bz2
base-files: fix UCI config parsing and callback handling
There are several long-standing issues present in the UCI shell API as documented in https://wiki.openwrt.org/doc/devel/config-scripting. They relate both to high-level, user-defined callback functions used to process UCI config files, and also to low-level functions used within scripts generally. The related problems have been encountered now and in the past, e.g. https://forum.openwrt.org/viewtopic.php?id=54295, and include: a) UCI parsing option() function and user-defined option_cb() callbacks being erroneously called during processing of "list" config file entries; b) normal usage of the low-level config_set() unexpectedy calling any defined option_cb() if present; and c) handling of the list_cb() not respecting the NO_CALLBACK variable. Root causes include a function stack "inversion", where the low-level config_set() function incorrectly calls the high-level option() function, intended only for processing the "option" keyword of UCI config files. This change addresses the inversion and other issues, making the option handling code more consistent and smaller, and simplifying developers' usage of UCI callbacks. Signed-off-by: Tony Ambardar <itugrok@yahoo.com> Signed-off-by: Hans Dedecker <dedeckeh@gmail.com> [PKG_RELEASE increase]
-rw-r--r--package/base-files/Makefile2
-rwxr-xr-xpackage/base-files/files/lib/functions.sh13
2 files changed, 6 insertions, 9 deletions
diff --git a/package/base-files/Makefile b/package/base-files/Makefile
index 1d034fd..4fbc9a2 100644
--- a/package/base-files/Makefile
+++ b/package/base-files/Makefile
@@ -11,7 +11,7 @@ include $(INCLUDE_DIR)/kernel.mk
include $(INCLUDE_DIR)/version.mk
PKG_NAME:=base-files
-PKG_RELEASE:=173.6
+PKG_RELEASE:=173.7
PKG_FLAGS:=nonshared
PKG_FILE_DEPENDS:=$(PLATFORM_DIR)/ $(GENERIC_PLATFORM_DIR)/base-files/
diff --git a/package/base-files/files/lib/functions.sh b/package/base-files/files/lib/functions.sh
index c69feb3..36ee491 100755
--- a/package/base-files/files/lib/functions.sh
+++ b/package/base-files/files/lib/functions.sh
@@ -57,16 +57,16 @@ config () {
export ${NO_EXPORT:+-n} CONFIG_NUM_SECTIONS=$(($CONFIG_NUM_SECTIONS + 1))
name="${name:-cfg$CONFIG_NUM_SECTIONS}"
append CONFIG_SECTIONS "$name"
- [ -n "$NO_CALLBACK" ] || config_cb "$cfgtype" "$name"
export ${NO_EXPORT:+-n} CONFIG_SECTION="$name"
- export ${NO_EXPORT:+-n} "CONFIG_${CONFIG_SECTION}_TYPE=$cfgtype"
+ config_set "$CONFIG_SECTION" "TYPE" "${cfgtype}"
+ [ -n "$NO_CALLBACK" ] || config_cb "$cfgtype" "$name"
}
option () {
local varname="$1"; shift
local value="$*"
- export ${NO_EXPORT:+-n} "CONFIG_${CONFIG_SECTION}_${varname}=$value"
+ config_set "$CONFIG_SECTION" "${varname}" "${value}"
[ -n "$NO_CALLBACK" ] || option_cb "$varname" "$*"
}
@@ -81,7 +81,7 @@ list() {
config_set "$CONFIG_SECTION" "${varname}_ITEM$len" "$value"
config_set "$CONFIG_SECTION" "${varname}_LENGTH" "$len"
append "CONFIG_${CONFIG_SECTION}_${varname}" "$value" "$LIST_SEP"
- list_cb "$varname" "$*"
+ [ -n "$NO_CALLBACK" ] || list_cb "$varname" "$*"
}
config_unset() {
@@ -113,11 +113,8 @@ config_set() {
local section="$1"
local option="$2"
local value="$3"
- local old_section="$CONFIG_SECTION"
- CONFIG_SECTION="$section"
- option "$option" "$value"
- CONFIG_SECTION="$old_section"
+ export ${NO_EXPORT:+-n} "CONFIG_${section}_${option}=${value}"
}
config_foreach() {