From b9d470a3f42d0a9e12238711e25653276ab157e6 Mon Sep 17 00:00:00 2001 From: Felix Fietkau Date: Fri, 14 Oct 2011 01:19:06 +0200 Subject: proto-shell: allow proto handlers to export variables to child processes --- dummy/netifd-proto.sh | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'dummy') 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" } -- cgit v1.2.3