equally named config sections of different type cannot coexist
Username: Karol Babioch
Origin: https://bugs.openwrt.org/index.php?do=details&task_id=225
Fiddling around with UCI and a more advanced configuration files I just realized that introducing a new section with the same name of an already existing but with a different type makes the first one disappear.
Lets take this file as an example:
anonymous dnsmasq section
config dnsmasq
another anonymous dnsmasq section
config dnsmasq
named dnsmasq section
config dnsmasq foo
another dnsmasq section
config dnsmasq bar
named dhcp section: this makes the dnsmasq section named bar disappear
config dhcp bar
There is a dnsmasq config section named “foo”. But as soon as I put another section named bar (of a different type) into the file (e.g. the last line) it is no longer parsed correctly. For instance config_cb is no longer invoked for the dnsmasq section. I have a test script like this:
#!/bin/sh
. /lib/functions.sh
config_cb() {
echo "$@"
}
config_load test
The output of this script is:
root@lede:~# ./test.sh
dnsmasq cfg02411c
dnsmasq cfg04411c
dnsmasq foo
dhcp bar
Note how the dnsmasq section named bar is missing from the output. The output is expected to look like this:
root@lede:~# ./test.sh
dnsmasq cfg02411c
dnsmasq cfg04411c
dnsmasq foo
dnsmasq bar
dhcp bar
When removing the last section from the configuration file the output actually includes the line “dnsmasq bar”, which is correct.
This bug makes it pretty much impossible to have two section of different type with the same name within a configuration file, since one cannot be sure that it is parsed correctly.