blob: b57e962f6fac216dfc323e438c3a0a1287084bf6 [file] [log] [blame]
developerd243af02023-12-21 14:49:33 +08001#!/bin/sh /etc/rc.common
2# Copyright (c) 2021 OpenWrt.org
3
4START=11
5
6USE_PROCD=1
7PROG=/usr/sbin/udebugd
8
9start_service() {
10 procd_open_instance
11 procd_set_param command "$PROG"
12 procd_set_param respawn
13 procd_close_instance
14}
15
16get_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
27add_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
38reload_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
48service_triggers() {
49 procd_add_reload_trigger udebug
50}
51
52service_started() {
53 ubus -t 10 wait_for udebug
54 [ $? = 0 ] && reload_service
55}