The openwrt/lib/functions/procd.sh script will listen to the HotPlug implementation after the/SBIN/PROCD process is started, and when there is a HotPlug event, Hotplug.json will be used to execute/ etc/hotplug.d/the script file that corresponds to the event
[Root@pandorabox:/lib/functions] #cat/lib/functions/procd.sh # PROCD API: # # Procd_open_service (name, [script]): # Ini Tialize 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 A instance to the service described by the Prev IOUs Procd_open_service Call # # Procd_set_param (type, [value ...]) # Available types: # Command:command Line (array
). # respawn Info:array with 3 values $restart _timeout $fail _hreshold $max _fail # env:environment variable (passed to the process) # Data:arbitrary Name/value pairs for detecting config changes (table) # file:configuration file S (array) # Netdev:bound network device (detects ifindex changes) # Limits:resource limits (passed to the Proces s) # user Info:array with 1 values $username # # No spaces separation is do for arrays/tables-use one function a Rgument per command line argument # procd_close_instance (): # Complete 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_namespac
E procd old_cb "$@" Json_set_namespace $old _CB} _procd_wrapper () {while [n ' $]; do
Eval "$ () {_procd_call _$1 \ \$@\";} " Shift done} _procd_ubus_call () {local cmd= "$" [-N "$PROCD _debug"] && json_dump > &2 Ubus Call service "$cmd" "$ (Json_dump)" Json_cleanup} _procd_open_service () {Local name= "$" local script= "$" _procd_service= "$name" _procd_instance_seq=0 Json_init JS on_add_string name "$name" [-N "$script"] && json_add_string Script "$script" Json_add_object in Stances} _procd_close_service() {Json_close_object service_triggers _procd_ubus_call set} _procd_add_array_data () { While ["$#"-GT 0]; Do json_add_string "", "Shift Done} _procd_add_array () {Json_add_arr Ay "" "Shift _procd_add_array_data" $@ "Json_close_array} _procd_add_table_data () {WHI Le [-N "$"]; Do local var= ' ${1%%=*} ' local val= ' ${1#*=} ' [' $ ' = ' $val '] && V al= json_add_string "$var" "$val" Shift Done} _procd_add_table () {Json_
Add_object "" "Shift _procd_add_table_data" $@ "Json_close_object} _procd_open_instance () { Local name= "$";
Shift _procd_instance_seq= "$ (($_procd_instance_seq + 1))" Name= "${name:-instance$_procd_instance_seq}" Json_add_object "$name" [-N "$TRACE _syscalls"] && Json_add_booLean trace "1"} _procd_open_trigger () {Json_add_array "triggers"} _procd_open_validate () {json_add_a Rray "Validate"} _procd_add_jail () {json_add_object "jail" json_add_string name "$" json_add_s Tring Root "/tmp/.jail/$1" shift for a in $@;
Do case $a in log) Json_add_boolean "Log" "1";
Ubus) Json_add_boolean "Ubus" "1";
PROCFS) Json_add_boolean "Procfs" "1";
SYSFS) Json_add_boolean "Sysfs" "1"; Esac done Json_add_object "mount" Json_close_object Json_close_object} _procd_add_jail_m Ount () {local _json_no_warning=1 json_select ' jail ' [$? = 0] | | return json_select "mo Unt "[$? = 0] | |
{Json_select.. return} for a in $@; Do json_add_string "$a" "0" done Json_Select..
Json_select..
} _PROCD_ADD_JAIL_MOUNT_RW () {local _json_no_warning=1 json_select "jail" [$? = 0] | | Json_select "Mount" [$? = 0] | |
{Json_select.. return} for a in $@;
Do json_add_string "$a" "1" has done json_select.
Json_select..
} _procd_set_param () {local type= ' $ '; shift case ' $type ' in env|data|limits)
_procd_add_table "$type" "$@";;
Command|netdev|file|respawn|watch) _procd_add_array "$type" "$@";
Error) Json_add_array "$type" json_add_string "" $@ "
Json_close_array;;
Nice) json_add_int "$type" "$"; User|seccoMP) json_add_string "$type" "$";
Stdout|stderr) Json_add_boolean "$type" "$";
ESAC} _procd_add_interface_trigger () {Json_add_array _procd_add_array_data "" "Shift Json_add_array _procd_add_array_data "If" Json_add_array _procd_add_array_data "eq" "Interface" "
"Shift Json_close_array Json_add_array _procd_add_array_data" Run_script "$@" Json_close_array Json_close_array Json_close_array} _procd_add_reload_interface_trigger () {L
Ocal script=$ (readlink "$initscript") Local name=$ (basename ${script:-$initscript}) _procd_open_trigger _procd_add_interface_trigger "interface.*" $1/etc/init.d/$name reload _procd_close_trigger} _procd_add_c
Onfig_trigger () {Json_add_array _procd_add_array_data "$" Shift Json_add_array _procd_add_array_data "if" Json_add_array _procd_add_array_data "EQ" "package" "Shift Json_close_array Json_add_array _procd_add_array_data" Run_scr
IPT "" $@ "Json_close_array Json_close_array Json_close_array} _procd_add_raw_trigger () { Json_add_array _procd_add_array_data "Shift" local timeout=$1 shift Json_ad D_array json_add_array _procd_add_array_data "Run_script" "$@" Json_close_array json_close _array json_add_int "" "$timeout" Json_close_array} _procd_add_reload_trigger () {Local script =$ (readlink "$initscript") Local name=$ (basename ${script:-$initscript}) Local file _procd_open_t Rigger for file in "$@";
Do _procd_add_config_trigger "Config.change", "$file"/etc/init.d/$name Reload Done _procd_close_trigger} _procd_add_validation () {_procd_open_validate $@ _procd_close_validate
} _procd_append_param () {local type= "$"; shift local _json_no_warning=1 Json_select "$type" [$? = 0] | | {_procd_set_param "$type" "$@" return} case "$type" in E
nv|data|limits) _procd_add_table_data "$@";;
Command|netdev|file|respawn|watch) _procd_add_array_data "$@";;
Error) json_add_string "" "$@";;
Esac Json_select. } _procd_close_instance () {json_close_object} _procd_close_trigger () {Json_close_array} _procd_clos E_validate () {Json_close_array} _procd_add_instance () {_procd_open_instance _procd_set_param C Ommand "$@" _procd_close_instance} _procd_kill () {local service= ' $ ' instance= ' $ ' json_init [-n ' $service
] && json_add_string name "$service" [-N "$instance"] && json_add_string instance "$instance" _procd_ubus_call Delete} procd_open_data () {local name= ' $ ' json_set_namespace procd __procd_old_ CB Json_add_object Data} procd_close_data () {json_close_object json_set_namespace $__procd_old_ CB} _procd_set_config_changed () {local package= ' $ ' json_init json_add_string type Config.chan GE json_add_object Data json_add_string package "$package" json_close_object ubus call SE
Rvice Event "$ (json_dump)"} procd_add_mdns_service () {Local Service proto port Service=$1; shift proto=$1; Shift port=$1;
Shift Json_add_object "${service}_$port" json_add_string "service" "_$service._$proto.local" Json_add_int Port "$port" [-N ' $] && {Json_add_array txt for TX T in $@; Do json_add_string "" $txt;
Done Json_select.
} json_select. } procd_add_mdns () {procd_open_data json_add_object "MDNs" Procd_add_mdns_service $@ JSO
N_close_object Procd_close_data} uci_validate_section () {local _package= "$" local _type= "$" Local _name= "$" local _result the local _error shift; Shift
Shift _result= '/sbin/validate_data "$_package" "$_type" "$_name" "$@" 2>/dev/null "_error=$"? Eval "$_result" ["$_error" = "0"] | |
'/sbin/validate_data ' $_package ' "$_type" "$_name" "$@" 1>/dev/null ' return $_error} _procd_wrapper \
Procd_open_service \ procd_close_service \ procd_add_instance \ procd_add_raw_trigger \
Procd_add_config_trigger \ Procd_add_interface_trigger \ procd_add_reload_trigger \ procd_add_reload_interface_trigger \
Procd_open_trigger \ procd_close_trigger \ procd_open_instance \ procd_close_instance \ procd_open_validate \ procd_close_validate \ procd_add_jail \ procd_add_jail_mount \ Pro CD_ADD_JAIL_MOUNT_RW \ procd_set_param \ procd_append_param \ procd_add_validation \ ProCD _set_config_changed \ Procd_kill