blob: 495949f64fbcd4ebf284f2e92eb9e34bf84421f5 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
#!/bin/sh /etc/rc.common
START=80
USE_PROCD=1
. "$IPKG_INSTROOT/usr/share/libubox/jshn.sh"
register_init() {
local config="$1"
local init="$2"
shift; shift
if [ -x "$init" ] && "$init" enabled && ! grep -sqE 'USE_PROCD=.' "$init"; then
logger -t "ucitrack" "Setting up /etc/config/$config reload trigger for non-procd $init"
procd_add_config_trigger "config.change" "$config" "$init" "$@"
fi
}
register_trigger() {
local uci="$1"
local file="$2"
local config init exec affects affected
local prev
json_set_namespace config prev
json_init
json_load_file "${file}" >/dev/null 2>&1
json_get_var config 'config'
[ "$config" = "$uci" ] || {
json_set_namespace "$prev"
return
}
json_get_var init 'init'
json_get_var exec 'exec'
json_get_values affects 'affects'
json_cleanup
json_set_namespace "$prev"
if [ -n "$init" ]; then
register_init "$config" "/etc/init.d/$init" "reload"
fi
if [ -n "$exec" ]; then
case "$exec" in
/etc/init.d/*)
set -- $exec
register_init "$config" "$@"
;;
*)
logger -t "ucitrack" "Setting up non-init /etc/config/$config reload handler: $exec"
procd_add_config_trigger "config.change" "$config" $exec
;;
esac
fi
for affected in $affects; do
logger -t "ucitrack" "Setting up /etc/config/$affected reload dependency on /etc/config/$config"
procd_add_config_trigger "config.change" "$config" \
ubus call service event \
"$(printf '{"type":"config.change","data":{"package":"%s"}}' $affected)"
done
}
check_trigger() {
local config="$1"
local file
for file in /usr/share/ucitrack/*.json; do
[ -f "$file" ] || continue
register_trigger "$config" "$file"
done
}
service_triggers() {
for config in /etc/config/*; do
check_trigger "${config##*/}"
done
}
|