base-files: network.sh: gracefully handle missing network.interface ubus ns
When attempting to use any of the functions in network.sh while netifd is not started yet, the ubus interface dump query will fail with "Not found", yielding an empty response. Subsequently, jsonfilter is invoked with an empty string instead of a valid JSON document, causing it to emit a second "unexpected end of data" error. This caused the dnsmasq init script to log the following errors during early boot on some systems: procd: /etc/rc.d/S19dnsmasq: Command failed: Not found. procd: /etc/rc.d/S19dnsmasq: Failed to parse json data: unexpected end of data. Fix the issue by allowing the ubus query to fail with "Not found" but still logging other failures, and by passing an empty JSON object to jsonfilter if the interface status cache is empty. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
This commit is contained in:
parent
18b87b10a9
commit
1bad852ff5
2 changed files with 10 additions and 4 deletions
|
@ -12,7 +12,7 @@ include $(INCLUDE_DIR)/version.mk
|
||||||
include $(INCLUDE_DIR)/feeds.mk
|
include $(INCLUDE_DIR)/feeds.mk
|
||||||
|
|
||||||
PKG_NAME:=base-files
|
PKG_NAME:=base-files
|
||||||
PKG_RELEASE:=191
|
PKG_RELEASE:=192
|
||||||
PKG_FLAGS:=nonshared
|
PKG_FLAGS:=nonshared
|
||||||
|
|
||||||
PKG_FILE_DEPENDS:=$(PLATFORM_DIR)/ $(GENERIC_PLATFORM_DIR)/base-files/
|
PKG_FILE_DEPENDS:=$(PLATFORM_DIR)/ $(GENERIC_PLATFORM_DIR)/base-files/
|
||||||
|
|
|
@ -6,10 +6,16 @@
|
||||||
__network_ifstatus() {
|
__network_ifstatus() {
|
||||||
local __tmp
|
local __tmp
|
||||||
|
|
||||||
[ -z "$__NETWORK_CACHE" ] && \
|
[ -z "$__NETWORK_CACHE" ] && {
|
||||||
export __NETWORK_CACHE="$(ubus call network.interface dump)"
|
__tmp="$(ubus call network.interface dump 2>&1)"
|
||||||
|
case "$?" in
|
||||||
|
4) : ;;
|
||||||
|
0) export __NETWORK_CACHE="$__tmp" ;;
|
||||||
|
*) echo "$__tmp" >&2 ;;
|
||||||
|
esac
|
||||||
|
}
|
||||||
|
|
||||||
__tmp="$(jsonfilter ${4:+-F "$4"} ${5:+-l "$5"} -s "$__NETWORK_CACHE" -e "$1=@.interface${2:+[@.interface='$2']}$3")"
|
__tmp="$(jsonfilter ${4:+-F "$4"} ${5:+-l "$5"} -s "${__NETWORK_CACHE:-{}}" -e "$1=@.interface${2:+[@.interface='$2']}$3")"
|
||||||
|
|
||||||
[ -z "$__tmp" ] && \
|
[ -z "$__tmp" ] && \
|
||||||
unset "$1" && \
|
unset "$1" && \
|
||||||
|
|
Loading…
Reference in a new issue