aboutsummaryrefslogtreecommitdiffstats
path: root/package/procd
diff options
context:
space:
mode:
authorJames <>2013-03-17 12:16:37 +0000
committerJames <>2013-03-17 12:16:37 +0000
commit27b76ab0671089c47506615a796a261e993896a7 (patch)
tree61213d67e7fa87b20356b23798558e2c4212c42f /package/procd
downloadtrunk-36060-27b76ab0671089c47506615a796a261e993896a7.tar.gz
trunk-36060-27b76ab0671089c47506615a796a261e993896a7.tar.bz2
trunk-36060-27b76ab0671089c47506615a796a261e993896a7.zip
Diffstat (limited to 'package/procd')
-rw-r--r--package/procd/.svn/entries65
-rw-r--r--package/procd/.svn/text-base/Makefile.svn-base50
-rw-r--r--package/procd/Makefile50
-rw-r--r--package/procd/files/.svn/entries164
-rw-r--r--package/procd/files/.svn/text-base/hotplug-preinit.json.svn-base21
-rw-r--r--package/procd/files/.svn/text-base/hotplug.json.svn-base80
-rw-r--r--package/procd/files/.svn/text-base/procd.init.svn-base19
-rw-r--r--package/procd/files/.svn/text-base/procd.sh.svn-base171
-rw-r--r--package/procd/files/hotplug-preinit.json21
-rw-r--r--package/procd/files/hotplug.json80
-rw-r--r--package/procd/files/procd.init19
-rw-r--r--package/procd/files/procd.sh171
12 files changed, 911 insertions, 0 deletions
diff --git a/package/procd/.svn/entries b/package/procd/.svn/entries
new file mode 100644
index 0000000..9eea338
--- /dev/null
+++ b/package/procd/.svn/entries
@@ -0,0 +1,65 @@
+10
+
+dir
+36060
+svn://svn.openwrt.org/openwrt/trunk/package/procd
+svn://svn.openwrt.org/openwrt
+
+
+
+2013-03-14T18:44:03.692388Z
+36032
+blogic
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+3c298f89-4303-0410-b956-a3cf2f4a3e73
+
+files
+dir
+
+Makefile
+file
+
+
+
+
+2013-03-17T12:13:10.000000Z
+b3ce8463bcac4a73c7b1d9799bc7da79
+2013-03-14T18:44:03.692388Z
+36032
+blogic
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+1355
+
diff --git a/package/procd/.svn/text-base/Makefile.svn-base b/package/procd/.svn/text-base/Makefile.svn-base
new file mode 100644
index 0000000..762fb5f
--- /dev/null
+++ b/package/procd/.svn/text-base/Makefile.svn-base
@@ -0,0 +1,50 @@
+include $(TOPDIR)/rules.mk
+
+PKG_NAME:=procd
+PKG_VERSION:=2013-03-14
+PKG_RELEASE=$(PKG_SOURCE_VERSION)
+
+PKG_SOURCE_PROTO:=git
+PKG_SOURCE_URL:=git://nbd.name/luci2/procd.git
+PKG_SOURCE_SUBDIR:=$(PKG_NAME)-$(PKG_VERSION)
+PKG_SOURCE_VERSION:=9fcc900e301e0c304488b6b83f10c8db5b8f4ce0
+PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION)-$(PKG_SOURCE_VERSION).tar.gz
+CMAKE_INSTALL:=1
+
+PKG_LICENSE:=GPLv2
+PKG_LICENSE_FILES:=
+
+PKG_CONFIG_DEPENDS:=CONFIG_PROCD_INIT
+
+PKG_MAINTAINER:=Felix Fietkau <nbd@openwrt.org>
+
+include $(INCLUDE_DIR)/package.mk
+include $(INCLUDE_DIR)/cmake.mk
+
+define Package/procd
+ SECTION:=base
+ CATEGORY:=Base system
+ DEPENDS:=+ubusd +ubus +libjson-script
+ TITLE:=OpenWrt system process manager
+endef
+
+ifneq ($(CONFIG_PROCD_INIT),)
+define Package/procd/install
+ $(INSTALL_DIR) $(1)/sbin $(1)/lib/functions $(1)/etc
+
+ $(CP) $(PKG_INSTALL_DIR)/usr/sbin/{procd,askfirst,udevtrigger,logread} $(1)/sbin/
+ $(INSTALL_DATA) ./files/hotplug*.json $(1)/etc/
+ $(INSTALL_DATA) ./files/procd.sh $(1)/lib/functions/
+ ln -s /sbin/procd $(1)/sbin/init
+endef
+else
+define Package/procd/install
+ $(INSTALL_DIR) $(1)/sbin $(1)/lib/functions $(1)/etc/init.d
+
+ $(CP) $(PKG_INSTALL_DIR)/usr/sbin/procd $(1)/sbin/
+ $(INSTALL_BIN) ./files/procd.init $(1)/etc/init.d/procd
+ $(INSTALL_DATA) ./files/procd.sh $(1)/lib/functions/
+endef
+endif
+
+$(eval $(call BuildPackage,procd))
diff --git a/package/procd/Makefile b/package/procd/Makefile
new file mode 100644
index 0000000..762fb5f
--- /dev/null
+++ b/package/procd/Makefile
@@ -0,0 +1,50 @@
+include $(TOPDIR)/rules.mk
+
+PKG_NAME:=procd
+PKG_VERSION:=2013-03-14
+PKG_RELEASE=$(PKG_SOURCE_VERSION)
+
+PKG_SOURCE_PROTO:=git
+PKG_SOURCE_URL:=git://nbd.name/luci2/procd.git
+PKG_SOURCE_SUBDIR:=$(PKG_NAME)-$(PKG_VERSION)
+PKG_SOURCE_VERSION:=9fcc900e301e0c304488b6b83f10c8db5b8f4ce0
+PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION)-$(PKG_SOURCE_VERSION).tar.gz
+CMAKE_INSTALL:=1
+
+PKG_LICENSE:=GPLv2
+PKG_LICENSE_FILES:=
+
+PKG_CONFIG_DEPENDS:=CONFIG_PROCD_INIT
+
+PKG_MAINTAINER:=Felix Fietkau <nbd@openwrt.org>
+
+include $(INCLUDE_DIR)/package.mk
+include $(INCLUDE_DIR)/cmake.mk
+
+define Package/procd
+ SECTION:=base
+ CATEGORY:=Base system
+ DEPENDS:=+ubusd +ubus +libjson-script
+ TITLE:=OpenWrt system process manager
+endef
+
+ifneq ($(CONFIG_PROCD_INIT),)
+define Package/procd/install
+ $(INSTALL_DIR) $(1)/sbin $(1)/lib/functions $(1)/etc
+
+ $(CP) $(PKG_INSTALL_DIR)/usr/sbin/{procd,askfirst,udevtrigger,logread} $(1)/sbin/
+ $(INSTALL_DATA) ./files/hotplug*.json $(1)/etc/
+ $(INSTALL_DATA) ./files/procd.sh $(1)/lib/functions/
+ ln -s /sbin/procd $(1)/sbin/init
+endef
+else
+define Package/procd/install
+ $(INSTALL_DIR) $(1)/sbin $(1)/lib/functions $(1)/etc/init.d
+
+ $(CP) $(PKG_INSTALL_DIR)/usr/sbin/procd $(1)/sbin/
+ $(INSTALL_BIN) ./files/procd.init $(1)/etc/init.d/procd
+ $(INSTALL_DATA) ./files/procd.sh $(1)/lib/functions/
+endef
+endif
+
+$(eval $(call BuildPackage,procd))
diff --git a/package/procd/files/.svn/entries b/package/procd/files/.svn/entries
new file mode 100644
index 0000000..3fc54f5
--- /dev/null
+++ b/package/procd/files/.svn/entries
@@ -0,0 +1,164 @@
+10
+
+dir
+36060
+svn://svn.openwrt.org/openwrt/trunk/package/procd/files
+svn://svn.openwrt.org/openwrt
+
+
+
+2013-03-13T18:11:07.862775Z
+36001
+blogic
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+3c298f89-4303-0410-b956-a3cf2f4a3e73
+
+procd.sh
+file
+
+
+
+
+2013-03-17T12:13:10.000000Z
+005e731331cb253b6cb861c0a52cbbf8
+2012-12-22T18:56:06.049092Z
+34865
+nbd
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+3213
+
+hotplug-preinit.json
+file
+
+
+
+
+2013-03-17T12:13:10.000000Z
+6a4f2c3a950ab8bf89e29b096167d29b
+2013-03-13T18:11:07.862775Z
+36001
+blogic
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+358
+
+procd.init
+file
+
+
+
+
+2013-03-17T12:13:10.000000Z
+d995bcc944cca803ac7c18467fd1db47
+2012-12-22T18:56:06.049092Z
+34865
+nbd
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+195
+
+hotplug.json
+file
+
+
+
+
+2013-03-17T12:13:10.000000Z
+39aba6959706732425e016853dde5552
+2013-03-13T18:11:07.862775Z
+36001
+blogic
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+1512
+
diff --git a/package/procd/files/.svn/text-base/hotplug-preinit.json.svn-base b/package/procd/files/.svn/text-base/hotplug-preinit.json.svn-base
new file mode 100644
index 0000000..d212b22
--- /dev/null
+++ b/package/procd/files/.svn/text-base/hotplug-preinit.json.svn-base
@@ -0,0 +1,21 @@
+[
+ [ "case", "ACTION", {
+ "add": [
+ [ "if",
+ [ "has", "FIRMWARE" ],
+ [
+ [ "exec", "/sbin/hotplug-call", "%SUBSYSTEM%" ],
+ [ "load-firmware", "/lib/firmware" ],
+ [ "return" ]
+ ]
+ ],
+ ],
+ }, ],
+ [ "if",
+ [ "and",
+ [ "eq", "SUBSYSTEM", "button" ],
+ [ "eq", "BUTTON", "reset" ],
+ ],
+ [ "exec", "/etc/rc.button/failsafe" ]
+ ],
+]
diff --git a/package/procd/files/.svn/text-base/hotplug.json.svn-base b/package/procd/files/.svn/text-base/hotplug.json.svn-base
new file mode 100644
index 0000000..43fec0c
--- /dev/null
+++ b/package/procd/files/.svn/text-base/hotplug.json.svn-base
@@ -0,0 +1,80 @@
+[
+ [ "case", "ACTION", {
+ "add": [
+ [ "if",
+ [ "and",
+ [ "has", "MAJOR" ],
+ [ "has", "MINOR" ],
+ ],
+ [
+ [ "if",
+ [ "or",
+ [ "eq", "DEVNAME",
+ [ "null", "full", "ptmx", "zero" ],
+ ],
+ [ "regex", "DEVNAME",
+ [ "^gpio", "^hvc", "^tty" ],
+ ],
+ ],
+ [
+ [ "makedev", "/dev/%DEVNAME%", "0666" ],
+ [ "return" ],
+ ]
+ ],
+ [ "if",
+ [ "or",
+ [ "eq", "DEVNAME", "mapper/control" ],
+ [ "regex", "DEVPATH", "^ppp" ],
+ ],
+ [
+ [ "makedev", "/dev/%DEVNAME%", "0600" ],
+ [ "return" ],
+ ],
+ ],
+ [ "if",
+ [ "has", "DEVNAME" ],
+ [
+ [ "makedev", "/dev/%DEVNAME%", "0644" ],
+ [ "return" ],
+ ],
+ ],
+ ],
+ ],
+ [ "if",
+ [ "has", "FIRMWARE" ],
+ [
+ [ "exec", "/sbin/hotplug-call", "%SUBSYSTEM%" ],
+ [ "load-firmware", "/lib/firmware" ],
+ [ "return" ]
+ ]
+ ],
+ ],
+ "remove" : [
+ [ "if",
+ [ "and",
+ [ "has", "DEVNAME" ],
+ [ "has", "MAJOR" ],
+ [ "has", "MINOR" ],
+ ],
+ [ "rm", "/dev/%DEVNAME%" ]
+ ]
+ ]
+ } ],
+ [ "if",
+ [ "eq", "SUBSYSTEM", "platform" ],
+ [ "exec", "/sbin/hotplug-call", "%SUBSYSTEM%" ]
+ ],
+ [ "if",
+ [ "and",
+ [ "has", "BUTTON" ],
+ [ "eq", "SUBSYSTEM", "button" ],
+ ],
+ [ "exec", "/etc/rc.button/%BUTTON%" ]
+ ],
+ [ "if",
+ [ "eq", "SUBSYSTEM",
+ [ "net", "input", "usb", "ieee1394", "block", "atm", "zaptel", "tty" ]
+ ],
+ [ "exec", "/sbin/hotplug-call", "%SUBSYSTEM%" ]
+ ],
+]
diff --git a/package/procd/files/.svn/text-base/procd.init.svn-base b/package/procd/files/.svn/text-base/procd.init.svn-base
new file mode 100644
index 0000000..3df5f48
--- /dev/null
+++ b/package/procd/files/.svn/text-base/procd.init.svn-base
@@ -0,0 +1,19 @@
+#!/bin/sh /etc/rc.common
+
+START=11
+
+start_stop() {
+ start-stop-daemon $1 -b -m -p /var/run/procd.pid -x /sbin/procd
+}
+
+start() {
+ start_stop -S
+}
+
+reload() {
+ return
+}
+
+stop() {
+ start_stop -K
+}
diff --git a/package/procd/files/.svn/text-base/procd.sh.svn-base b/package/procd/files/.svn/text-base/procd.sh.svn-base
new file mode 100644
index 0000000..e771e0c
--- /dev/null
+++ b/package/procd/files/.svn/text-base/procd.sh.svn-base
@@ -0,0 +1,171 @@
+# procd API:
+#
+# procd_open_service(name, [script]):
+# Initialize a new procd command message containing a service with one or more instances
+#
+# procd_close_service()
+# Send the command message for the service
+#
+# procd_open_instance([name]):
+# Add an instance to the service described by the previous procd_open_service call
+#
+# procd_set_param(type, [value...])
+# Available types:
+# command: command line (array).
+# env: environment variable (passed to the process)
+# data: arbitrary name/value pairs for detecting config changes (table)
+# file: configuration files (array)
+# netdev: bound network device (detects ifindex changes)
+#
+# No space separation is done for arrays/tables - use one function argument per command line argument
+#
+# procd_close_instance():
+# Complete the instance being prepared
+#
+# procd_kill(service, [instance]):
+# Kill a service instance (or all instances)
+#
+
+. $IPKG_INSTROOT/usr/share/libubox/jshn.sh
+
+_PROCD_SERVICE=
+
+_procd_call() {
+ local old_cb
+
+ json_set_namespace procd old_cb
+ "$@"
+ json_set_namespace $old_cb
+}
+
+_procd_wrapper() {
+ while [ -n "$1" ]; do
+ eval "$1() { _procd_call _$1 \"\$@\"; }"
+ shift
+ done
+}
+
+_procd_ubus_call() {
+ local cmd="$1"
+
+ ubus call service "$cmd" "$(json_dump)"
+ json_cleanup
+}
+
+_procd_open_service() {
+ local name="$1"
+ local script="$2"
+
+ _PROCD_SERVICE="$name"
+ _PROCD_INSTANCE_SEQ=0
+
+ json_init
+ json_add_string name "$name"
+ [ -n "$script" ] && json_add_string script "$script"
+ json_add_object instances
+}
+
+_procd_close_service() {
+ json_close_object
+ _procd_ubus_call set
+}
+
+_procd_add_array_data() {
+ while [ -n "$1" ]; do
+ json_add_string "" "$1"
+ shift
+ done
+}
+
+_procd_add_array() {
+ json_add_array "$1"
+ shift
+ _procd_add_array_data "$@"
+ json_close_array
+}
+
+_procd_add_table_data() {
+ while [ -n "$1" ]; do
+ local var="${1%%=*}"
+ local val="${1#*=}"
+ [[ "$1" == "$val" ]] && val=
+ json_add_string "$var" "$val"
+ shift
+ done
+}
+
+_procd_add_table() {
+ json_add_object "$1"
+ shift
+ _procd_add_table_data "$@"
+ json_close_object
+}
+
+_procd_open_instance() {
+ local name="$1"; shift
+
+ _PROCD_INSTANCE_SEQ="$(($_PROCD_INSTANCE_SEQ + 1))"
+ name="${name:-instance$_PROCD_INSTANCE_SEQ}"
+ json_add_object "$name"
+}
+
+_procd_set_param() {
+ local type="$1"; shift
+
+ case "$type" in
+ env|data)
+ _procd_add_table "$type" "$@"
+ ;;
+ command|netdev|file)
+ _procd_add_array "$type" "$@"
+ ;;
+ nice)
+ json_add_int "$type" "$1"
+ ;;
+ esac
+}
+
+_procd_append_param() {
+ local type="$1"; shift
+
+ json_select "$type"
+ case "$type" in
+ env|data)
+ _procd_add_table_data "$@"
+ ;;
+ command|netdev|file)
+ _procd_add_array_data "$@"
+ ;;
+ esac
+ json_select ..
+}
+
+_procd_close_instance() {
+ json_close_object
+}
+
+_procd_add_instance() {
+ _procd_open_instance
+ _procd_set_command "$@"
+ _procd_close_instance
+}
+
+_procd_kill() {
+ local service="$1"
+ local instance="$2"
+
+ json_init
+ [ -n "$service" ] && json_add_string service "$service"
+ [ -n "$instance" ] && json_add_string instance "$instance"
+ _procd_ubus_call delete
+}
+
+_procd_wrapper \
+ procd_open_service \
+ procd_close_service \
+ procd_add_instance \
+ procd_open_instance \
+ procd_close_instance \
+ procd_set_param \
+ procd_append_param \
+ procd_kill
diff --git a/package/procd/files/hotplug-preinit.json b/package/procd/files/hotplug-preinit.json
new file mode 100644
index 0000000..d212b22
--- /dev/null
+++ b/package/procd/files/hotplug-preinit.json
@@ -0,0 +1,21 @@
+[
+ [ "case", "ACTION", {
+ "add": [
+ [ "if",
+ [ "has", "FIRMWARE" ],
+ [
+ [ "exec", "/sbin/hotplug-call", "%SUBSYSTEM%" ],
+ [ "load-firmware", "/lib/firmware" ],
+ [ "return" ]
+ ]
+ ],
+ ],
+ }, ],
+ [ "if",
+ [ "and",
+ [ "eq", "SUBSYSTEM", "button" ],
+ [ "eq", "BUTTON", "reset" ],
+ ],
+ [ "exec", "/etc/rc.button/failsafe" ]
+ ],
+]
diff --git a/package/procd/files/hotplug.json b/package/procd/files/hotplug.json
new file mode 100644
index 0000000..43fec0c
--- /dev/null
+++ b/package/procd/files/hotplug.json
@@ -0,0 +1,80 @@
+[
+ [ "case", "ACTION", {
+ "add": [
+ [ "if",
+ [ "and",
+ [ "has", "MAJOR" ],
+ [ "has", "MINOR" ],
+ ],
+ [
+ [ "if",
+ [ "or",
+ [ "eq", "DEVNAME",
+ [ "null", "full", "ptmx", "zero" ],
+ ],
+ [ "regex", "DEVNAME",
+ [ "^gpio", "^hvc", "^tty" ],
+ ],
+ ],
+ [
+ [ "makedev", "/dev/%DEVNAME%", "0666" ],
+ [ "return" ],
+ ]
+ ],
+ [ "if",
+ [ "or",
+ [ "eq", "DEVNAME", "mapper/control" ],
+ [ "regex", "DEVPATH", "^ppp" ],
+ ],
+ [
+ [ "makedev", "/dev/%DEVNAME%", "0600" ],
+ [ "return" ],
+ ],
+ ],
+ [ "if",
+ [ "has", "DEVNAME" ],
+ [
+ [ "makedev", "/dev/%DEVNAME%", "0644" ],
+ [ "return" ],
+ ],
+ ],
+ ],
+ ],
+ [ "if",
+ [ "has", "FIRMWARE" ],
+ [
+ [ "exec", "/sbin/hotplug-call", "%SUBSYSTEM%" ],
+ [ "load-firmware", "/lib/firmware" ],
+ [ "return" ]
+ ]
+ ],
+ ],
+ "remove" : [
+ [ "if",
+ [ "and",
+ [ "has", "DEVNAME" ],
+ [ "has", "MAJOR" ],
+ [ "has", "MINOR" ],
+ ],
+ [ "rm", "/dev/%DEVNAME%" ]
+ ]
+ ]
+ } ],
+ [ "if",
+ [ "eq", "SUBSYSTEM", "platform" ],
+ [ "exec", "/sbin/hotplug-call", "%SUBSYSTEM%" ]
+ ],
+ [ "if",
+ [ "and",
+ [ "has", "BUTTON" ],
+ [ "eq", "SUBSYSTEM", "button" ],
+ ],
+ [ "exec", "/etc/rc.button/%BUTTON%" ]
+ ],
+ [ "if",
+ [ "eq", "SUBSYSTEM",
+ [ "net", "input", "usb", "ieee1394", "block", "atm", "zaptel", "tty" ]
+ ],
+ [ "exec", "/sbin/hotplug-call", "%SUBSYSTEM%" ]
+ ],
+]
diff --git a/package/procd/files/procd.init b/package/procd/files/procd.init
new file mode 100644
index 0000000..3df5f48
--- /dev/null
+++ b/package/procd/files/procd.init
@@ -0,0 +1,19 @@
+#!/bin/sh /etc/rc.common
+
+START=11
+
+start_stop() {
+ start-stop-daemon $1 -b -m -p /var/run/procd.pid -x /sbin/procd
+}
+
+start() {
+ start_stop -S
+}
+
+reload() {
+ return
+}
+
+stop() {
+ start_stop -K
+}
diff --git a/package/procd/files/procd.sh b/package/procd/files/procd.sh
new file mode 100644
index 0000000..e771e0c
--- /dev/null
+++ b/package/procd/files/procd.sh
@@ -0,0 +1,171 @@
+# procd API:
+#
+# procd_open_service(name, [script]):
+# Initialize a new procd command message containing a service with one or more instances
+#
+# procd_close_service()
+# Send the command message for the service
+#
+# procd_open_instance([name]):
+# Add an instance to the service described by the previous procd_open_service call
+#
+# procd_set_param(type, [value...])
+# Available types:
+# command: command line (array).
+# env: environment variable (passed to the process)
+# data: arbitrary name/value pairs for detecting config changes (table)
+# file: configuration files (array)
+# netdev: bound network device (detects ifindex changes)
+#
+# No space separation is done for arrays/tables - use one function argument per command line argument
+#
+# procd_close_instance():
+# Complete the instance being prepared
+#
+# procd_kill(service, [instance]):
+# Kill a service instance (or all instances)
+#
+
+. $IPKG_INSTROOT/usr/share/libubox/jshn.sh
+
+_PROCD_SERVICE=
+
+_procd_call() {
+ local old_cb
+
+ json_set_namespace procd old_cb
+ "$@"
+ json_set_namespace $old_cb
+}
+
+_procd_wrapper() {
+ while [ -n "$1" ]; do
+ eval "$1() { _procd_call _$1 \"\$@\"; }"
+ shift
+ done
+}
+
+_procd_ubus_call() {
+ local cmd="$1"
+
+ ubus call service "$cmd" "$(json_dump)"
+ json_cleanup
+}
+
+_procd_open_service() {
+ local name="$1"
+ local script="$2"
+
+ _PROCD_SERVICE="$name"
+ _PROCD_INSTANCE_SEQ=0
+
+ json_init
+ json_add_string name "$name"
+ [ -n "$script" ] && json_add_string script "$script"
+ json_add_object instances
+}
+
+_procd_close_service() {
+ json_close_object
+ _procd_ubus_call set
+}
+
+_procd_add_array_data() {
+ while [ -n "$1" ]; do
+ json_add_string "" "$1"
+ shift
+ done
+}
+
+_procd_add_array() {
+ json_add_array "$1"
+ shift
+ _procd_add_array_data "$@"
+ json_close_array
+}
+
+_procd_add_table_data() {
+ while [ -n "$1" ]; do
+ local var="${1%%=*}"
+ local val="${1#*=}"
+ [[ "$1" == "$val" ]] && val=
+ json_add_string "$var" "$val"
+ shift
+ done
+}
+
+_procd_add_table() {
+ json_add_object "$1"
+ shift
+ _procd_add_table_data "$@"
+ json_close_object
+}
+
+_procd_open_instance() {
+ local name="$1"; shift
+
+ _PROCD_INSTANCE_SEQ="$(($_PROCD_INSTANCE_SEQ + 1))"
+ name="${name:-instance$_PROCD_INSTANCE_SEQ}"
+ json_add_object "$name"
+}
+
+_procd_set_param() {
+ local type="$1"; shift
+
+ case "$type" in
+ env|data)
+ _procd_add_table "$type" "$@"
+ ;;
+ command|netdev|file)
+ _procd_add_array "$type" "$@"
+ ;;
+ nice)
+ json_add_int "$type" "$1"
+ ;;
+ esac
+}
+
+_procd_append_param() {
+ local type="$1"; shift
+
+ json_select "$type"
+ case "$type" in
+ env|data)
+ _procd_add_table_data "$@"
+ ;;
+ command|netdev|file)
+ _procd_add_array_data "$@"
+ ;;
+ esac
+ json_select ..
+}
+
+_procd_close_instance() {
+ json_close_object
+}
+
+_procd_add_instance() {
+ _procd_open_instance
+ _procd_set_command "$@"
+ _procd_close_instance
+}
+
+_procd_kill() {
+ local service="$1"
+ local instance="$2"
+
+ json_init
+ [ -n "$service" ] && json_add_string service "$service"
+ [ -n "$instance" ] && json_add_string instance "$instance"
+ _procd_ubus_call delete
+}
+
+_procd_wrapper \
+ procd_open_service \
+ procd_close_service \
+ procd_add_instance \
+ procd_open_instance \
+ procd_close_instance \
+ procd_set_param \
+ procd_append_param \
+ procd_kill