hd-idle: Update init script
authorJeffery To <jeffery.to@gmail.com>
Mon, 11 Feb 2019 14:25:14 +0000 (22:25 +0800)
committerJeffery To <jeffery.to@gmail.com>
Mon, 11 Feb 2019 14:25:14 +0000 (22:25 +0800)
This replaces the use of uci_validate_section() with
uci_load_validate(), which removes the need to declare local variables
for every config option.

This also adds a service_triggers() function.

Signed-off-by: Jeffery To <jeffery.to@gmail.com>
utils/hd-idle/Makefile
utils/hd-idle/files/hd-idle.init

index f7f4645a20d2212f07b9275e1ba474e805157fb2..405753d1b98acbcec5ed833f9560e3d344b47a35 100644 (file)
@@ -9,7 +9,7 @@ include $(TOPDIR)/rules.mk
 
 PKG_NAME:=hd-idle
 PKG_VERSION:=1.05
-PKG_RELEASE:=1
+PKG_RELEASE:=2
 
 PKG_MAINTAINER:=Lim Guo Wei <limguowei@gmail.com>
 PKG_LICENSE:=GPL-2.0
index 4f6a2d7a165d058f2ee4fdd13746c0de5062628b..bdf9bb8d0ae29bade2ab8aa0e0532554513fa5c8 100644 (file)
@@ -8,7 +8,7 @@ USE_PROCD=1
 
 validate_section_hdidle()
 {
-       uci_validate_section hd-idle hd-idle "${1}" \
+       uci_load_validate hd-idle hd-idle "$1" "$2" \
                'disk:string' \
                'enabled:bool' \
                'idle_time_interval:uinteger:10' \
@@ -43,9 +43,7 @@ compute_seconds() {
 }
 
 hdidle_append() {
-       local disk enabled idle_time_interval idle_time_unit
-
-       validate_section_hdidle "${1}" || return
+       [ "$2" = 0 ] || return
 
        [ "$enabled" -gt 0 ] || return
 
@@ -63,10 +61,15 @@ start_service() {
        config_load "hd-idle"
 
        numdisks="0"
-       config_foreach hdidle_append "hd-idle"
+       config_foreach validate_section_hdidle "hd-idle" hdidle_append
 
        if [ "$numdisks" -gt 0 ]; then
                procd_set_param respawn
                procd_close_instance
        fi
 }
+
+service_triggers() {
+       procd_add_reload_trigger "hd-idle"
+       procd_add_validation validate_section_hdidle
+}