Skip to content

Commit c09cdd4

Browse files
committed
librc-depend: Split deptree generation into three functions
rc_deptree_generate does the generation of the deptree, rc_deptree_backref does back references and sanity checks, lastly rc_deptree_save write it to disk.
1 parent 9fc02ee commit c09cdd4

File tree

2 files changed

+307
-235
lines changed

2 files changed

+307
-235
lines changed

sh/gendepends.sh.in

Lines changed: 67 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,71 @@ keyword() {
5252
depend() {
5353
:
5454
}
55+
gendepend() {
56+
[ -x "$RC_SERVICE" -a -f "$RC_SERVICE" ] || return
57+
58+
# Only generate dependencies for OpenRC scripts
59+
read one two three <"$RC_SERVICE"
60+
case "$one" in
61+
\#*/openrc-run) ;;
62+
\#*/runscript) ;;
63+
\#!)
64+
case "$two" in
65+
*/openrc-run) ;;
66+
*/runscript) ;;
67+
*)
68+
return
69+
;;
70+
esac
71+
;;
72+
*)
73+
return
74+
;;
75+
esac
76+
unset one two three
77+
78+
RC_SVCNAME=${RC_SERVICE##*/} ; export RC_SVCNAME
79+
80+
# Compat
81+
SVCNAME=$RC_SVCNAME ; export SVCNAME
82+
83+
(
84+
# Save stdout in fd3, then remap it to stderr
85+
exec 3>&1 1>&2
86+
87+
_rc_c=${RC_SVCNAME%%.*}
88+
if [ -n "$_rc_c" -a "$_rc_c" != "$RC_SVCNAME" ]; then
89+
if [ -e "$_dir/../conf.d/$_rc_c" ]; then
90+
. "$_dir/../conf.d/$_rc_c"
91+
fi
92+
fi
93+
unset _rc_c
94+
95+
if [ -e "$_dir/../conf.d/$RC_SVCNAME" ]; then
96+
. "$_dir/../conf.d/$RC_SVCNAME"
97+
fi
98+
99+
[ -e @SYSCONFDIR@/rc.conf ] && . @SYSCONFDIR@/rc.conf
100+
if [ -d "@SYSCONFDIR@/rc.conf.d" ]; then
101+
for _f in "@SYSCONFDIR@"/rc.conf.d/*.conf; do
102+
[ -e "$_f" ] && . "$_f"
103+
done
104+
fi
105+
106+
if . "$RC_SERVICE"; then
107+
echo "$RC_SVCNAME" >&3
108+
_depend
109+
fi
110+
)
111+
}
112+
113+
if [ $# -gt 0 ]; then
114+
_dir="$RC_SCRIPTDIR"
115+
cd "$_dir"
116+
for RC_SERVICE in "$@"; do
117+
gendepend
118+
done
119+
fi
55120

56121
_done_dirs=
57122
for _dir in $RC_SCRIPTDIRS
@@ -67,61 +132,7 @@ do
67132
_done_dirs="$_done_dirs $_dir"
68133

69134
cd "$_dir"
70-
for RC_SERVICE in *; do
71-
[ -x "$RC_SERVICE" -a -f "$RC_SERVICE" ] || continue
72-
73-
# Only generate dependencies for OpenRC scripts
74-
read one two three <"$RC_SERVICE"
75-
case "$one" in
76-
\#*/openrc-run) ;;
77-
\#*/runscript) ;;
78-
\#!)
79-
case "$two" in
80-
*/openrc-run) ;;
81-
*/runscript) ;;
82-
*)
83-
continue
84-
;;
85-
esac
86-
;;
87-
*)
88-
continue
89-
;;
90-
esac
91-
unset one two three
92-
93-
RC_SVCNAME=${RC_SERVICE##*/} ; export RC_SVCNAME
94-
95-
# Compat
96-
SVCNAME=$RC_SVCNAME ; export SVCNAME
97-
98-
(
99-
# Save stdout in fd3, then remap it to stderr
100-
exec 3>&1 1>&2
101-
102-
_rc_c=${RC_SVCNAME%%.*}
103-
if [ -n "$_rc_c" -a "$_rc_c" != "$RC_SVCNAME" ]; then
104-
if [ -e "$_dir/../conf.d/$_rc_c" ]; then
105-
. "$_dir/../conf.d/$_rc_c"
106-
fi
107-
fi
108-
unset _rc_c
109-
110-
if [ -e "$_dir/../conf.d/$RC_SVCNAME" ]; then
111-
. "$_dir/../conf.d/$RC_SVCNAME"
112-
fi
113-
114-
[ -e @SYSCONFDIR@/rc.conf ] && . @SYSCONFDIR@/rc.conf
115-
if [ -d "@SYSCONFDIR@/rc.conf.d" ]; then
116-
for _f in "@SYSCONFDIR@"/rc.conf.d/*.conf; do
117-
[ -e "$_f" ] && . "$_f"
118-
done
119-
fi
120-
121-
if . "$_dir/$RC_SVCNAME"; then
122-
echo "$RC_SVCNAME" >&3
123-
_depend
124-
fi
125-
)
135+
for RC_SERVICE in "$_dir"/*; do
136+
gendepend
126137
done
127138
done

0 commit comments

Comments
 (0)