pservice: shorten code

- use uci_load_validate()
 - remove stop_service()
 - fix validation of "args" option

Signed-off-by: Yousong Zhou <yszhou4tech@gmail.com>
This commit is contained in:
Yousong Zhou 2019-08-06 04:14:47 +00:00
parent 5d7d44d605
commit 2b469232e6
2 changed files with 11 additions and 33 deletions

View File

@ -4,7 +4,7 @@ include $(TOPDIR)/rules.mk
PKG_NAME:=pservice PKG_NAME:=pservice
PKG_VERSION:=2017-08-29 PKG_VERSION:=2017-08-29
PKG_RELEASE=1 PKG_RELEASE=2
PKG_MAINTAINER:=Yousong Zhou <yszhou4tech@gmail.com> PKG_MAINTAINER:=Yousong Zhou <yszhou4tech@gmail.com>

View File

@ -1,5 +1,5 @@
#!/bin/sh /etc/rc.common #!/bin/sh /etc/rc.common
# Copyright (C) 2017 Yousong Zhou # Copyright (C) 2017-2019 Yousong Zhou
START=99 START=99
@ -12,13 +12,14 @@ pservice_list_cb() {
procd_append_param "$param" "$val" procd_append_param "$param" "$val"
} }
pservice() { pservice_instance() {
local cfg="$1" local cfg="$1"
eval "$(validate_pservice_section "$cfg" pservice_validate_mklocal)"
validate_pservice_section "$cfg" || return 1
[ "$disabled" = 0 ] || return 0 [ "$disabled" = 0 ] || return 0
[ -x "$command" ] || return 1 [ -x "$command" ] || {
echo "$command is not executable" >&2
return 1
}
procd_open_instance "$name" procd_open_instance "$name"
procd_set_param command "$command" procd_set_param command "$command"
@ -39,43 +40,20 @@ pservice() {
start_service() { start_service() {
config_load 'pservice' config_load 'pservice'
config_foreach pservice pservice config_foreach validate_pservice_section pservice pservice_instance
}
stop_service() {
true
} }
service_triggers() { service_triggers() {
procd_open_validate procd_add_validation validate_pservice_section
validate_pservice_section
procd_close_validate
}
pservice_validate_mklocal() {
local tuple opts
shift 2
for tuple in "$@"; do
opts="${tuple%%:*} $opts"
done
[ -z "$opts" ] || echo "local $opts"
}
pservice_validate() {
uci_validate_section pservice "$@"
} }
validate_pservice_section() { validate_pservice_section() {
local cfg="$1"; shift uci_load_validate pservice pservice "$1" "$2" \
local func="$1"; shift
"${func:-pservice_validate}" pservice "$cfg" \
"disabled:bool:0" \ "disabled:bool:0" \
"name:string" \ "name:string" \
"env:regex('^[a-zA-Z_][a-zA-Z0-9_]*=.*$')" \ "env:regex('^[a-zA-Z_][a-zA-Z0-9_]*=.*$')" \
"command:file" \ "command:file" \
"args:list(string)" \ "args:string" \
"stderr:bool:0" \ "stderr:bool:0" \
"stdout:bool:0" \ "stdout:bool:0" \
"respawn_threshold:uinteger:3600" \ "respawn_threshold:uinteger:3600" \