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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
|
diff -Naurp splashutils-gentoo-0.5.4-orig/splash-functions.sh splashutils-gentoo-0.5.4/splash-functions.sh
--- splashutils-gentoo-0.5.4-orig/splash-functions.sh 2007-03-13 14:24:42.000000000 +0100
+++ splashutils-gentoo-0.5.4/splash-functions.sh 2007-03-13 14:30:14.000000000 +0100
@@ -489,10 +489,39 @@ splash_cache_prep() {
return "${retval}"
fi
+ # Copy the dependency cache and services lists to our new cache dir.
+ # With some luck, we won't have to update it.
+ cp -a ${svcdir}/{depcache,deptree} "${spl_tmpdir}" 2>/dev/null
+ cp -a ${spl_cachedir}/{svcs_start,svcs_stop,levels} "${spl_tmpdir}" 2>/dev/null
+
+ # Now that the data from the old cache is copied, move tmpdir to cachedir.
mount -n --move "${spl_tmpdir}" "${spl_cachedir}"
+ h=$(stat -c '%y' ${spl_cachedir}/deptree 2>/dev/null)
+
+ # Point depscan.sh to our cachedir
+ /sbin/depscan.sh --svcdir "${spl_cachedir}"
+
if [[ "$1" == "start" ]]; then
- echo $(splash_svclist_update "start") > ${spl_cachedir}/svcs_start
+ # Check whether the list of services that will be started during boot
+ # needs updating. This is generally the case if:
+ # - one of the caches doesn't exist
+ # - our deptree was out of date
+ # - we're booting with a different boot/default level than the last time
+ # - one of the runlevel dirs has been modified since the last boot
+ if [[ ! -e ${spl_cachedir}/levels || \
+ ! -e ${spl_cachedir}/svcs_start ]]; then
+ echo $(splash_svclist_update "start") > ${spl_cachedir}/svcs_start
+ else
+ local lastlev timestamp
+ { read lastlev; read timestamp; } < ${spl_cachedir}/levels
+ if [[ "${lastlev}" != "${BOOTLEVEL}/${DEFAULTLEVEL}" || \
+ "${timestamp}" != "$(stat -c '%y' /etc/runlevels/${BOOTLEVEL})/$(stat -c '%y' /etc/runlevels/${DEFAULTLEVEL})" || \
+ "$(stat -c '%y' ${spl_cachedir}/deptree)" != "${h}" ]]; then
+ echo $(splash_svclist_update "start") > ${spl_cachedir}/svcs_start
+ fi
+ fi
+
echo -n > ${spl_cachedir}/profile
fi
@@ -524,7 +553,17 @@ splash_cache_cleanup() {
# writable, update it to avoid stale mtab entries (bug #121827).
local mntopt=""
[[ -w /etc/mtab ]] || mntopt="-n"
- umount ${mntopt} -l "${spl_tmpdir}" 2>/dev/null
+ mount ${mntopt} --move "${spl_cachedir}" "${spl_tmpdir}" 2>/dev/null
+
+ # Don't try to copy anything if the cachedir is not writable.
+ [[ -w "${spl_cachedir}" ]] || return;
+
+ cp -a "${spl_tmpdir}"/{envcache,depcache,deptree,svcs_start,svcs_stop,profile} "${spl_cachedir}" 2>/dev/null
+ echo "${BOOTLEVEL}/${DEFAULTLEVEL}" > "${spl_cachedir}/levels"
+ echo "$(stat -c '%y' /etc/runlevels/${BOOTLEVEL})/$(stat -c '%y' /etc/runlevels/${DEFAULTLEVEL})" \
+ >> "${spl_cachedir}/levels"
+
+ umount -l "${spl_tmpdir}" 2>/dev/null
}
###########################################################################
@@ -557,32 +596,133 @@ splash_svclist_get() {
}
splash_svclist_update() {
- local svcs= order= x= dlvl="${SOFTLEVEL}"
+ (
+ # Source our own deptree and required functions
+ source ${spl_cachedir}/deptree
+ [[ ${RC_GOT_SERVICES} != "yes" ]] && source "${svclib}/sh/rc-services.sh"
+
+ svcs_started=" "
+ svcs_order=""
+
+ # We're sure our depcache is up-to-date, no need to waste
+ # time checking mtimes.
+ check_mtime() {
+ return 0
+ }
+
+ is_net_up() {
+ local netcount=0
+
+ case "${RC_NET_STRICT_CHECKING}" in
+ lo)
+ netcount="$(echo ${svcs_started} | tr ' ' '\n' | \
+ egrep -c "\/net\..*$")"
+ ;;
+ *)
+ netcount="$(echo ${svcs_started} | tr ' ' '\n' | \
+ grep -v 'net\.lo' | egrep -c "\/net\..*$")"
+ ;;
+ esac
+
+ # Only worry about net.* services if this is the last one running,
+ # or if RC_NET_STRICT_CHECKING is set ...
+ if [[ ${netcount} -lt 1 || ${RC_NET_STRICT_CHECKING} == "yes" ]]; then
+ return 1
+ fi
+
+ return 0
+ }
- for x in $(dolisting /etc/runlevels/${BOOTLEVEL}) \
- $(dolisting ${svcdir}/coldplugged) ; do
- svcs="${svcs} ${x##*/}"
- if [[ ${x##*/} == "autoconfig" ]] ; then
- svcs="${svcs} $(. /etc/init.d/autoconfig; list_services)"
+ service_started() {
+ if [[ -z "${svcs_started/* ${1} */}" ]]; then
+ return 0
+ else
+ return 1
fi
- done
- order=$(rc-depend -ineed -iuse -iafter ${svcs})
+ }
+
+ # This simulates the service startup and has to mimic the behaviour of
+ # svc_start() from /sbin/runscript.sh and start_service() from rc-functions.sh
+ # as closely as possible.
+ start_service() {
+ local svc="$1"
- # We call rc-depend twice so we get the ordering exactly right
- svcs=
- if [[ ${SOFTLEVEL} == "${BOOTLEVEL}" ]] ; then
- dlvl="${DEFAULTLEVEL}"
- fi
- for x in $(dolisting /etc/runlevels/"${dlvl}") ; do
- svcs="${svcs} ${x##*/}"
- if [[ ${x##*/} == "autoconfig" ]] ; then
- svcs="${svcs} $(. /etc/init.d/autoconfig; list_services)"
+ if service_started ${svc}; then
+ return
fi
- done
- order="${order} $(SOFTLEVEL="$dlvl" rc-depend -ineed -iuse -iafter ${svcs})"
- # Only list each service once
- uniqify ${order}
+ # Prevent recursion..
+ svcs_started="${svcs_started}$1 "
+
+ if is_fake_service "${svc}" "${mylevel}"; then
+ svcs_order="${svcs_order} ${svc}"
+ return
+ fi
+
+ svcs_startup="$(ineed "${svc}") \
+ $(valid_iuse "${svc}") \
+ $(valid_iafter "${svc}")"
+
+ for x in ${svcs_startup} ; do
+ if [[ ${x} == "net" ]] && [[ ${svc%%.*} != "net" || ${svc##*.} == ${svc} ]] && ! is_net_up ; then
+ local netservices="$(dolisting "/etc/runlevels/${BOOTLEVEL}/net.*") \
+ $(dolisting "/etc/runlevels/${mylevel}/net.*")"
+
+ for y in ${netservices} ; do
+ mynetservice="${y##*/}"
+ if ! service_started ${mynetservice} ; then
+ start_service "${mynetservice}"
+ fi
+ done
+ else
+ if ! service_started ${x} ; then
+ start_service "${x}"
+ fi
+ fi
+ done
+
+ svcs_order="${svcs_order} ${svc}"
+ return
+ }
+
+ # This function should return a list of services that will be started
+ # from /etc/init.d/autoconfig. In order to do that, we source
+ # /etc/init.d/autoconfig and use its list_services() function.
+ autoconfig_svcs() {
+ [[ -r /etc/init.d/autoconfig ]] || return
+ . /etc/init.d/autoconfig
+ echo "$(list_services)"
+ }
+
+ as="$(autoconfig_svcs)"
+ [[ -n "${SOFTLEVEL}" ]] && ss="$(dolisting "/etc/runlevels/${SOFTLEVEL}/") "
+ sb="$(dolisting "/etc/runlevels/${BOOTLEVEL}/") "
+ sd="$(dolisting "/etc/runlevels/${DEFAULTLEVEL}/") "
+
+ # If autoconfig is one of the services that will be started,
+ # insert an updated list of services into our list.
+ if [[ -z "${ss/*\/autoconfig */}" ]]; then
+ ss="${ss/\/autoconfig /\/autoconfig $as }"
+ fi
+
+ if [[ -z "${sb/*\/autoconfig */}" ]]; then
+ sb="${sb/\/autoconfig /\/autoconfig $as }"
+ fi
+
+ if [[ -z "${sd/*\/autoconfig */}" ]]; then
+ sd="${sd/\/autoconfig /\/autoconfig $as }"
+ fi
+
+ mylevel="${BOOTLEVEL}"
+ for i in ${CRITICAL_SERVICES} ${sb}; do
+ start_service "${i##*/}"
+ done
+ mylevel="${DEFAULTLEVEL}"
+ for i in ${LOGGER_SERVICE} ${sd} ${ss}; do
+ start_service "${i##*/}"
+ done
+ echo "${svcs_order}"
+ )
}
###########################################################################
|