developer | d243af0 | 2023-12-21 14:49:33 +0800 | [diff] [blame^] | 1 | #!/bin/sh /etc/rc.common |
| 2 | # Copyright (c) 2021 OpenWrt.org |
| 3 | |
| 4 | START=11 |
| 5 | |
| 6 | USE_PROCD=1 |
| 7 | PROG=/usr/sbin/udebugd |
| 8 | |
| 9 | start_service() { |
| 10 | procd_open_instance |
| 11 | procd_set_param command "$PROG" |
| 12 | procd_set_param respawn |
| 13 | procd_close_instance |
| 14 | } |
| 15 | |
| 16 | get_vars() { |
| 17 | local cfg="$1" |
| 18 | uci show "udebug.$cfg" | while read LINE; do |
| 19 | cur="${LINE##udebug.$1.}" |
| 20 | [[ "$cur" = "$LINE" ]] && continue |
| 21 | var="${cur%%=*}" |
| 22 | [[ "$cur" = "$var" ]] && continue |
| 23 | echo "$var" |
| 24 | done |
| 25 | } |
| 26 | |
| 27 | add_debug_service() { |
| 28 | local cfg="$1" |
| 29 | |
| 30 | json_add_object "$cfg" |
| 31 | for var in $(get_vars "$cfg"); do |
| 32 | config_get val "$cfg" "$var" |
| 33 | json_add_string "$var" "$val" |
| 34 | done |
| 35 | json_close_object "$cfg" |
| 36 | } |
| 37 | |
| 38 | reload_service() { |
| 39 | config_load udebug |
| 40 | |
| 41 | json_init |
| 42 | json_add_object service |
| 43 | config_foreach add_debug_service service |
| 44 | json_close_object |
| 45 | ubus call udebug set_config "$(json_dump)" |
| 46 | } |
| 47 | |
| 48 | service_triggers() { |
| 49 | procd_add_reload_trigger udebug |
| 50 | } |
| 51 | |
| 52 | service_started() { |
| 53 | ubus -t 10 wait_for udebug |
| 54 | [ $? = 0 ] && reload_service |
| 55 | } |