summaryrefslogtreecommitdiffhomepage
path: root/dummy/netifd-proto.sh
diff options
context:
space:
mode:
authorFelix Fietkau <nbd@openwrt.org>2011-10-14 01:19:06 +0200
committerFelix Fietkau <nbd@openwrt.org>2011-10-14 01:19:06 +0200
commitb9d470a3f42d0a9e12238711e25653276ab157e6 (patch)
tree4ab6f5e9c0777ce60eaa73d6def4fee182c3767c /dummy/netifd-proto.sh
parent52c36d741c05db2350ad1d240f6bd5d72237d8fd (diff)
proto-shell: allow proto handlers to export variables to child processes
Diffstat (limited to 'dummy/netifd-proto.sh')
-rwxr-xr-xdummy/netifd-proto.sh17
1 files changed, 17 insertions, 0 deletions
diff --git a/dummy/netifd-proto.sh b/dummy/netifd-proto.sh
index 0f703a2..48b1292 100755
--- a/dummy/netifd-proto.sh
+++ b/dummy/netifd-proto.sh
@@ -33,6 +33,8 @@ _proto_do_teardown() {
_proto_do_setup() {
json_load "$data"
+ _EXPORT_VAR=0
+ _EXPORT_VARS=
eval "$1_setup \"$interface\" \"$ifname\""
}
@@ -143,6 +145,13 @@ proto_send_update() {
_proto_notify "$interface"
}
+proto_export() {
+ local var="VAR${_EXPORT_VAR}"
+ _EXPORT_VAR="$(($_EXPORT_VAR + 1))"
+ export -- "$var=$1"
+ jshn_append _EXPORT_VARS "$var"
+}
+
proto_run_command() {
local interface="$1"; shift
@@ -153,6 +162,14 @@ proto_run_command() {
json_add_string "" "$1"
shift
done
+ json_close_array
+ [ -n "$_EXPORT_VARS" ] && {
+ json_add_array env
+ for var in $_EXPORT_VARS; do
+ eval "json_add_string \"\" \"\${$var}\""
+ done
+ json_close_array
+ }
_proto_notify "$interface"
}