/[baselayout]/branches/rc-scripts-1_6/net-scripts/init.d/net.lo
Gentoo

Diff of /branches/rc-scripts-1_6/net-scripts/init.d/net.lo

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 756 Revision 757
43need() { 43need() {
44 local x="$*" 44 local x="$*"
45 [[ $# -gt 1 ]] && x=$( echo -e "${x// /\n}" | sort | xargs ) 45 [[ $# -gt 1 ]] && x=$( echo -e "${x// /\n}" | sort | xargs )
46 eval "${MODULE}_need() { echo \"$x\"; }" 46 eval "${MODULE}_need() { echo \"$x\"; }"
47} 47}
48use() { 48installed() {
49 local x="$*" 49 local x="$*"
50 [[ $# -gt 1 ]] && x=$( echo -e "${x// /\n}" | sort | xargs ) 50 [[ $# -gt 1 ]] && x=$( echo -e "${x// /\n}" | sort | xargs )
51 # We deliberately misspell this as _installed will probably be used
52 # at some point
51 eval "${MODULE}_use() { echo \"$x\"; }" 53 eval "${MODULE}_instlled() { echo \"$x\"; }"
52} 54}
53 55
54sort() { 56sort() {
55 LC_ALL=C /bin/sort "$@" 57 LC_ALL=C /bin/sort "$@"
56} 58}
118# bool modules_load_auto() 120# bool modules_load_auto()
119# 121#
120# Load and check each module for sanity 122# Load and check each module for sanity
121# If the module is not installed, the functions are to be removed 123# If the module is not installed, the functions are to be removed
122modules_load_auto() { 124modules_load_auto() {
123 local e f i j before after beforefuncs afterfuncs diffs unload 125 local e f i j beforefuncs afterfuncs diffs unload
124 126
125 # Populate the MODULES array 127 # Populate the MODULES array
126 MODULES=( $( find ${MODULES_DIR}/ -maxdepth 1 -type f | sort ) ) 128 MODULES=( $( find ${MODULES_DIR}/ -maxdepth 1 -type f | sort ) )
127 129
128 # Each of these sources into the global namespace, so it's 130 # Each of these sources into the global namespace, so it's
129 # important that module functions and variables are prefixed with 131 # important that module functions and variables are prefixed with
130 # the module name, for example iproute2_ 132 # the module name, for example iproute2_
131 133
132# before="$( typeset -f )"
133 beforefuncs="$( typeset -F )" 134 beforefuncs="$( typeset -F )"
134 j=${#MODULES[@]} 135 j=${#MODULES[@]}
135 loaded_interface=false 136 loaded_interface=false
136 for (( i=0; i<j; i++ )); do 137 for (( i=0; i<j; i++ )); do
137 138
138 unload=false 139 unload=false
139 module_load_minimum ${MODULES[i]} || unload=true 140 module_load_minimum ${MODULES[i]} || unload=true
140 MODULES[i]=${MODULES[i]##*/} 141 MODULES[i]=${MODULES[i]##*/}
141
142# Checking if the module has modified any functions is too expensive on CPU
143# at the moment
144# Plus it isn't entirely reliable
145
146# # Double check that we've only *added* to the function list, not
147# # replaced. This is as much protection for devs as for users ;-)
148# after="$( typeset -f )"
149# diffs="$( diff -U0 -p <( echo "${before}" ) <( echo "${after}" ) 2>/dev/null | \
150# awk 'BEGIN { ORS = " "; } # no need for xargs
151# /^@@ / { f = $(NF-1); } # collect function names reported by diff
152# /^-/ && $2 == "()" { f = substr($1, 2); } # override when functions are removed
153# /^+/ && $2 == "()" { f = ""; } # ignore when functions are added
154# /^-/ && f { print f; f = ""; } # report only once per function
155# ' )"
156# if [[ -n ${diffs} ]]; then
157# eerror "${MODULES[i]} modified functions: ${diffs}"
158# return 1
159# fi
160 142
161 ! ${unload} && ${MODULES[i]}_check_installed false || unload=true 143 ! ${unload} && ${MODULES[i]}_check_installed false || unload=true
162 144
163 if [[ ${MODULES[i]} == interface ]]; then 145 if [[ ${MODULES[i]} == interface ]]; then
164 eerror "interface is a reserved name - cannot load a module called interface" 146 eerror "interface is a reserved name - cannot load a module called interface"
168 afterfuncs="$( typeset -F )" 150 afterfuncs="$( typeset -F )"
169 if ${unload} ; then 151 if ${unload} ; then
170 unset MODULES[i] 152 unset MODULES[i]
171 unsetfuncs="${unsetfuncs} $( diff -U0 <( echo "${beforefuncs}" ) <( echo "${afterfuncs}" ) 2>/dev/null \ 153 unsetfuncs="${unsetfuncs} $( diff -U0 <( echo "${beforefuncs}" ) <( echo "${afterfuncs}" ) 2>/dev/null \
172 | awk 'BEGIN { ORS = " "; } /+declare -f/ { print $3; }' )" 154 | awk 'BEGIN { ORS = " "; } /+declare -f/ { print $3; }' )"
173# before="$( typeset -f )"
174# else
175# before="${after}"
176 fi 155 fi
177 beforefuncs="${afterfuncs}" 156 beforefuncs="${afterfuncs}"
178 157
179 done 158 done
180 MODULES=( "${MODULES[@]}" ) 159 MODULES=( "${MODULES[@]}" )
181 160
182 return 0 161 return 0
183} 162}
184 163
185 164
186# bool modules_check_use(void) 165# bool modules_check_installed(void)
187# 166#
188# Ensure that all modules have the required modules loaded 167# Ensure that all modules have the required modules loaded
189# This enables us to remove modules from the MODULES array 168# This enables us to remove modules from the MODULES array
190# Whilst other modules can still explicitly call them 169# Whilst other modules can still explicitly call them
191# One example of this is essidnet which configures network 170# One example of this is essidnet which configures network
192# settings for the specific ESSID connected to as the user 171# settings for the specific ESSID connected to as the user
193# may be using a daemon to configure wireless instead of our 172# may be using a daemon to configure wireless instead of our
194# iwconfig module 173# iwconfig module
195modules_check_use() { 174modules_check_installed() {
196 local i j missingdeps nmods=${#MODULES[@]} 175 local i j missingdeps nmods=${#MODULES[@]}
197 176
198 for (( i=0; i<nmods; i++ )); do 177 for (( i=0; i<nmods; i++ )); do
199 [[ $( type -t ${MODULES[i]}_use ) != function ]] && continue 178 [[ $( type -t ${MODULES[i]}_instlled ) != function ]] && continue
200 for j in $( ${MODULES[i]}_use ); do 179 for j in $( ${MODULES[i]}_instlled ); do
201 missingdeps=true 180 missingdeps=true
202 for (( k=0; k<nmods; k++ )); do 181 if [[ $( type -t ${j}_check_installed ) == function ]]; then
203 [[ -z ${MODULES[k]} ]] && continue 182 ${j}_check_installed && missingdeps=false
204 [[ ${j} != ${MODULES[k]} && ${j} != ${PROVIDES[k]} ]] && continue 183 fi
205 missingdeps=false
206 break
207 done
208 ${missingdeps} && unset MODULES[i] && unset PROVIDES[i] 184 ${missingdeps} && unset MODULES[i] && unset PROVIDES[i] && break
209 done 185 done
210 done 186 done
211 187
212 MODULES=( "${MODULES[@]}" ) 188 MODULES=( "${MODULES[@]}" )
213 PROVIDES=( "${PROVIDES[@]}" ) 189 PROVIDES=( "${PROVIDES[@]}" )
461 for (( i=0; i<j; i++ )); do 437 for (( i=0; i<j; i++ )); do
462 PROVIDES[i]=$( ${MODULES[i]}_provides ) 438 PROVIDES[i]=$( ${MODULES[i]}_provides )
463 done 439 done
464 440
465 if [[ -z ${modules_force[@]} ]]; then 441 if [[ -z ${modules_force[@]} ]]; then
466 modules_check_use || return 1
467 if ${starting}; then 442 if ${starting}; then
468 modules_check_user || return 1 443 modules_check_user || return 1
469 fi 444 fi
470 445
471 # We unset unloaded module functions here as so we can error 446 # We unset unloaded module functions here as so we can error
474 [[ -n ${unsetfuncs} ]] && unset ${unsetfuncs} 449 [[ -n ${unsetfuncs} ]] && unset ${unsetfuncs}
475 450
476 modules_sort 451 modules_sort
477 fi 452 fi
478 453
479 [[ ${iface} != lo ]] && veinfo "modules: ${MODULES[@]}"
480 eindent
481
482 # Setup class wrappers: interface_up -> iproute2_up, for example 454 # Setup class wrappers: interface_up -> iproute2_up, for example
483 j=${#MODULES[@]} 455 j=${#MODULES[@]}
484 for (( i=0; i<j; i++ )); do 456 for (( i=0; i<j; i++ )); do
485 module_class_wrap ${MODULES[i]} ${PROVIDES[i]} 457 module_class_wrap ${MODULES[i]} ${PROVIDES[i]}
486 done 458 done
459
460 modules_check_installed || return 1
461
462 [[ ${iface} != lo ]] && veinfo "modules: ${MODULES[@]}"
463 eindent
487 464
488 [[ ${iface} != lo && ${starting} == true ]] && p=true 465 [[ ${iface} != lo && ${starting} == true ]] && p=true
489 modules_check_depends ${p} || return 1 466 modules_check_depends ${p} || return 1
490 return 0 467 return 0
491} 468}

Legend:
Removed from v.756  
changed lines
  Added in v.757

  ViewVC Help
Powered by ViewVC 1.1.20