procd: service_data: Support data within the service itself
authorPierre Lebleu <pme.lebleu@gmail.com>
Wed, 25 Oct 2017 16:05:15 +0000 (18:05 +0200)
committerJohn Crispin <john@phrozen.org>
Fri, 10 Nov 2017 22:31:27 +0000 (23:31 +0100)
Use the same approach than the service_triggers for the service_data.

Signed-off-by: Pierre Lebleu <pme.lebleu@gmail.com>
package/base-files/files/etc/rc.common
package/system/procd/files/procd.sh

index e80af891e684fd8b6d416343ad9e09fb0d78d333..a2ea6a5679aebc196937778d12d13271a8c764ef 100755 (executable)
@@ -88,6 +88,10 @@ service_triggers() {
        return 0
 }
 
+service_data() {
+       return 0
+}
+
 service_running() {
        return 0
 }
index c23c37b83f00d790a97d38c53ea9a39e0cfcc504..91e2371d6231c9928886d820f7c3603d5f68b22e 100644 (file)
@@ -79,6 +79,9 @@ _procd_close_service() {
        _procd_open_trigger
        service_triggers
        _procd_close_trigger
+       _procd_open_data
+       service_data
+       _procd_close_data
        _procd_ubus_call ${1:-set}
 }
 
@@ -134,6 +137,18 @@ _procd_close_trigger() {
        json_close_array
 }
 
+_procd_open_data() {
+       let '_procd_data_open = _procd_data_open + 1'
+       [ "$_procd_data_open" -gt 1 ] && return
+       json_add_object "data"
+}
+
+_procd_close_data() {
+       let '_procd_data_open = _procd_data_open - 1'
+       [ "$_procd_data_open" -lt 1 ] || return
+       json_close_object
+}
+
 _procd_open_validate() {
        json_select ..
        json_add_array "validate"