X-Git-Url: http://git.openwrt.org/?p=openwrt%2Fopenwrt.git;a=blobdiff_plain;f=package%2Fsystem%2Fprocd%2Ffiles%2Fprocd.sh;h=e6ca8a6bc924fe65d8832f96a203d0a6edabf987;hp=1b19ba93f673963410c99e80d49f0c8c494cfcea;hb=c58e824acc3c5fcac6ce91584eaf704e99be52ef;hpb=5aef137f9eb3a3236bdb7f50af887ff63368da2f diff --git a/package/system/procd/files/procd.sh b/package/system/procd/files/procd.sh index 1b19ba93f6..e6ca8a6bc9 100644 --- a/package/system/procd/files/procd.sh +++ b/package/system/procd/files/procd.sh @@ -12,12 +12,14 @@ # procd_set_param(type, [value...]) # Available types: # command: command line (array). -# respawn info: array with 3 values $restart_timeout $fail_hreshold $max_fail +# respawn info: array with 3 values $fail_threshold $restart_timeout $max_fail # 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) # limits: resource limits (passed to the process) +# user info: array with 1 values $username +# pidfile: file name to write pid into # # No space separation is done for arrays/tables - use one function argument per command line argument # @@ -27,9 +29,13 @@ # procd_kill(service, [instance]): # Kill a service instance (or all instances) # +# procd_send_signal(service, [instance], [signal]) +# Send a signal to a service instance (or all instances) +# . $IPKG_INSTROOT/usr/share/libubox/jshn.sh +PROCD_RELOAD_DELAY=1000 _PROCD_SERVICE= _procd_call() { @@ -70,12 +76,14 @@ _procd_open_service() { _procd_close_service() { json_close_object + _procd_open_trigger service_triggers - _procd_ubus_call set + _procd_close_trigger + _procd_ubus_call ${1:-set} } _procd_add_array_data() { - while [ -n "$1" ]; do + while [ "$#" -gt 0 ]; do json_add_string "" "$1" shift done @@ -92,7 +100,7 @@ _procd_add_table_data() { while [ -n "$1" ]; do local var="${1%%=*}" local val="${1#*=}" - [[ "$1" == "$val" ]] && val= + [ "$1" = "$val" ] && val= json_add_string "$var" "$val" shift done @@ -111,16 +119,85 @@ _procd_open_instance() { _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() { + let '_procd_trigger_open = _procd_trigger_open + 1' + [ "$_procd_trigger_open" -gt 1 ] && return json_add_array "triggers" } +_procd_close_trigger() { + let '_procd_trigger_open = _procd_trigger_open - 1' + [ "$_procd_trigger_open" -lt 1 ] || return + json_close_array +} + _procd_open_validate() { + json_select .. json_add_array "validate" } +_procd_close_validate() { + json_close_array + json_select triggers +} + +_procd_add_jail() { + json_add_object "jail" + json_add_string name "$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";; + ronly) json_add_boolean "ronly" "1";; + esac + done + json_add_object "mount" + json_close_object + json_close_object +} + +_procd_add_jail_mount() { + local _json_no_warning=1 + + json_select "jail" + [ $? = 0 ] || return + json_select "mount" + [ $? = 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 ] || return + json_select "mount" + [ $? = 0 ] || { + json_select .. + return + } + for a in $@; do + json_add_string "$a" "1" + done + json_select .. + json_select .. +} + _procd_set_param() { local type="$1"; shift @@ -139,9 +216,23 @@ _procd_set_param() { nice) json_add_int "$type" "$1" ;; + reload_signal) + json_add_int "$type" $(kill -l "$1") + ;; + pidfile|user|seccomp|capabilities) + json_add_string "$type" "$1" + ;; + stdout|stderr|no_new_privs) + json_add_boolean "$type" "$1" + ;; esac } +_procd_add_timeout() { + [ "$PROCD_RELOAD_DELAY" -gt 0 ] && json_add_int "" "$PROCD_RELOAD_DELAY" + return 0 +} + _procd_add_interface_trigger() { json_add_array _procd_add_array_data "$1" @@ -160,7 +251,7 @@ _procd_add_interface_trigger() { json_close_array json_close_array - + _procd_add_timeout json_close_array } @@ -191,6 +282,24 @@ _procd_add_config_trigger() { json_close_array json_close_array + _procd_add_timeout + json_close_array +} + +_procd_add_raw_trigger() { + json_add_array + _procd_add_array_data "$1" + shift + local timeout=$1 + shift + + json_add_array + json_add_array + _procd_add_array_data "run_script" "$@" + json_close_array + json_close_array + + json_add_int "" "$timeout" json_close_array } @@ -237,15 +346,20 @@ _procd_append_param() { } _procd_close_instance() { - json_close_object -} + local respawn_vals + _json_no_warning=1 + if json_select respawn ; then + json_get_values respawn_vals + if [ -z "$respawn_vals" ]; then + local respawn_threshold=$(uci_get system.@service[0].respawn_threshold) + local respawn_timeout=$(uci_get system.@service[0].respawn_timeout) + local respawn_retry=$(uci_get system.@service[0].respawn_retry) + _procd_add_array_data ${respawn_threshold:-3600} ${respawn_timeout:-5} ${respawn_retry:-5} + fi + json_select .. + fi -_procd_close_trigger() { - json_close_array -} - -_procd_close_validate() { - json_close_array + json_close_object } _procd_add_instance() { @@ -264,6 +378,18 @@ _procd_kill() { _procd_ubus_call delete } +_procd_send_signal() { + local service="$1" + local instance="$2" + local signal="$3" + + json_init + json_add_string name "$service" + [ -n "$instance" -a "$instance" != "*" ] && json_add_string instance "$instance" + [ -n "$signal" ] && json_add_int signal "$signal" + _procd_ubus_call signal +} + procd_open_data() { local name="$1" json_set_namespace procd __procd_old_cb @@ -287,6 +413,30 @@ _procd_set_config_changed() { ubus call service 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 "$1" ] && { + json_add_array txt + for txt 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 "$@" + json_close_object + procd_close_data +} + uci_validate_section() { local _package="$1" @@ -306,19 +456,23 @@ _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_add_interface_reload \ 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 \ + procd_add_jail_mount_rw \ procd_set_param \ procd_append_param \ procd_add_validation \ procd_set_config_changed \ - procd_kill + procd_kill \ + procd_send_signal