From: John Crispin Date: Wed, 13 Nov 2013 10:49:25 +0000 (+0000) Subject: procd: update to latest git head X-Git-Url: http://git.lede-project.org./?a=commitdiff_plain;h=130d7de07ffec8d9b822180aa681e66f7fa8b569;p=openwrt%2Fstaging%2Fnbd.git procd: update to latest git head this includes the first wip version of the uci validation backend Signed-off-by: John Crispin SVN-Revision: 38786 --- diff --git a/package/system/procd/Makefile b/package/system/procd/Makefile index b2d3bf1584..b406417469 100644 --- a/package/system/procd/Makefile +++ b/package/system/procd/Makefile @@ -1,14 +1,14 @@ include $(TOPDIR)/rules.mk PKG_NAME:=procd -PKG_VERSION:=2013-11-08 +PKG_VERSION:=2013-11-13 PKG_RELEASE=$(PKG_SOURCE_VERSION)-1 PKG_SOURCE_PROTO:=git PKG_SOURCE_URL:=git://nbd.name/luci2/procd.git PKG_SOURCE_SUBDIR:=$(PKG_NAME)-$(PKG_VERSION) -PKG_SOURCE_VERSION:=315f04d8b823adda96041c17f6672b7790376ccb +PKG_SOURCE_VERSION:=f9d31edb8938341b9217ee4c14eb58111414eb97 PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION)-$(PKG_SOURCE_VERSION).tar.gz CMAKE_INSTALL:=1 @@ -30,13 +30,14 @@ define Package/procd endef define Package/procd/install - $(INSTALL_DIR) $(1)/sbin $(1)/lib/functions $(1)/etc/init.d + $(INSTALL_DIR) $(1)/sbin $(1)/lib/functions $(1)/etc/init.d $(1)/lib - $(CP) $(PKG_INSTALL_DIR)/usr/sbin/{procd,askfirst,udevtrigger,logread} $(1)/sbin/ + $(CP) $(PKG_INSTALL_DIR)/usr/sbin/{procd,askfirst,udevtrigger,logread,validate_data} $(1)/sbin/ + $(INSTALL_DATA) $(PKG_INSTALL_DIR)/usr/lib/libvalidate.so $(1)/lib/ $(INSTALL_BIN) ./files/reload_config $(1)/sbin/ $(INSTALL_BIN) ./files/log.init $(1)/etc/init.d/log $(INSTALL_DATA) ./files/hotplug*.json $(1)/etc/ - $(INSTALL_DATA) ./files/procd.sh $(1)/lib/functions/ + $(INSTALL_DATA) ./files/procd.sh ./files/procd-validate.sh $(1)/lib/functions/ ln -s /sbin/procd $(1)/sbin/init endef diff --git a/package/system/procd/files/procd.sh b/package/system/procd/files/procd.sh index 5327c1dbc3..7b8640ad72 100644 --- a/package/system/procd/files/procd.sh +++ b/package/system/procd/files/procd.sh @@ -68,9 +68,7 @@ _procd_open_service() { _procd_close_service() { json_close_object - _procd_open_trigger service_triggers - _procd_close_trigger _procd_ubus_call set } @@ -117,6 +115,10 @@ _procd_open_trigger() { json_add_array "triggers" } +_procd_open_validate() { + json_add_array "validate" +} + _procd_set_param() { local type="$1"; shift @@ -135,7 +137,8 @@ _procd_set_param() { _procd_add_config_trigger() { json_add_array - _procd_add_array_data "config.change" + _procd_add_array_data "$1" + shift json_add_array _procd_add_array_data "if" @@ -158,14 +161,15 @@ _procd_add_reload_trigger() { local script=$(readlink "$initscript") local name=$(basename ${script:-$initscript}) - _procd_add_config_trigger $1 /etc/init.d/$name reload + _procd_open_trigger + _procd_add_config_trigger "config.change" $1 /etc/init.d/$name reload + _procd_close_trigger } -_procd_add_reload_trigger() { - local script=$(readlink "$initscript") - local name=$(basename ${script:-$initscript}) - - _procd_add_config_trigger $1 /etc/init.d/$name reload +_procd_add_validation() { + _procd_open_validate + $@ + _procd_close_validate } _procd_append_param() { @@ -191,6 +195,10 @@ _procd_close_trigger() { json_close_array } +_procd_close_validate() { + json_close_array +} + _procd_add_instance() { _procd_open_instance _procd_set_param command "$@" @@ -207,6 +215,63 @@ _procd_kill() { _procd_ubus_call delete } +uci_validate_section() +{ + local error=0 + + [ "$4" = "" ] && return 1 + [ "$3" = "" ] && { + json_add_object + json_add_string "package" "$1" + json_add_string "type" "$2" + json_add_object "data" + + shift; shift; shift + + while [ -n "$1" ]; do + json_add_string "${1%:*}" "${1#*:}" + shift + done + + json_close_object + json_close_object + return 0 + } + + local section="${3}" + config_load "${1}" + shift; shift; shift + + while [ -n "$1" ]; do + local name=${1%%:*} + local tmp=${1#*:} + local type=${tmp%%:*} + local default="" + + [ "$tmp" = "$type" ] || default=${tmp#*:} + + shift + config_get "${name}" "${section}" "${name}" + eval val=\$$name + + [ "$type" = "bool" ] && { + case "$val" in + 1|on|true|enabled) val=1;; + 0|off|false|disabled) val=0;; + *) val="";; + esac + } + [ -z "$val" ] && val=${default} + eval $name=\"$val\" + [ -z "$val" ] || { + /sbin/validate_data "${type}" "${val}" + [ $? -eq 0 ] || error="$((error + 1))" + } + done + + return $error +} + _procd_wrapper \ procd_open_service \ procd_close_service \ @@ -219,4 +284,5 @@ _procd_wrapper \ procd_close_instance \ procd_set_param \ procd_append_param \ + procd_add_validation \ procd_kill