如何找到调用的函数。
blackspace
|
1#
blackspace 发表于 2006-05-10 16:17
如何找到调用的函数。
如何找到调用的函数。
[CODE]# bool iface_start(char *interface) # # iface_start is called from start. It's expected to start the base # interface (for example "eth0"), aliases (for example "eth0:1") and to start # VLAN interfaces (for example eth0.0, eth0.1). VLAN setup is accomplished by # calling itself recursively. iface_start() { local iface=${1} mod config_counter=-1 x warn=false config_worked=false local RC_INDENTATION=${RC_INDENTATION} # so it will reset after function local -a config fallback fallback_route conf local ifvar=$( interface_variable ${iface} ) # pre Start any modules with for mod in ${MODULES[@]}; do if [[ $( type -t ${mod}_pre_start ) == function ]]; then ${mod}_pre_start ${iface} || { eend 1; return 1; } fi done # New style config - one variable fits all eval config=( \"\$\{config_${ifvar}\[@\]\}\" ) eval fallback=( \"\$\{fallback_${ifvar}\[@\]\}\" ) eval fallback_route=( \"\$\{fallback_route_${ifvar}\[@\]\}\" ) # We must support old configs if [[ -z ${config} ]]; then interface_get_old_config ${iface} || return 1 fi # Handle "noop" correctly if [[ ${config[0]} == "noop" ]]; then if interface_is_up ${iface} true ; then einfo "Keeping current configuration for ${iface}" eend 0 return 0 fi # Remove noop from the config var config=( "${config[@]:1}" ) fi # Provide a default of DHCP if no configuration is set if [[ -z ${config} ]]; then if [[ $( type -t dhcp_start ) == function ]]; then config=( "dhcp" ) warn=true else eerror "Cannot default to dhcp as there is no dhcp module loaded" eerror "No configuration for ${iface}" return 1 fi fi einfo "Bringing up ${iface}" eindent for (( config_counter=0; config_counter<${#config[@]}; config_counter++ )); do # Handle null and noop correctly if [[ ${config[config_counter]} == "null" \ || ${config[config_counter]} == "noop" ]]; then eend 0 config_worked=true continue fi if ${warn}; then ewarn "Configuration not set for ${iface} - assuming dhcp" warn=false fi # We convert it to an array - this has the added # bonus of trimming spaces! conf=( ${config[config_counter]} ) einfo "${conf[0]}" # Do we have a function for our config? if [[ $( type -t ${conf[0]}_start ) == function ]]; then # Check that the module is valid x=false for mod in ${MODULES[@]}; do if [[ $( ${mod}_provides ) == ${conf[0]} ]]; then x=true break fi done if ! ${x}; then [[ $( type -t ${conf[0]}_check_installed == function ) ]] && ${conf[0]}_check_installed true eerror "No loaded modules provide \"${conf[0]}\" (${conf[0]}_start)" else eindent ${conf[0]}_start ${iface} ; x=$? #${conf[0]}_start的值是dhcp_start 如何找到调用的dhcp_start()函数的定义? [/COLOR] eoutdent [[ ${x} == 0 ]] && config_worked=true && continue fi # We need to test to see if it's an IP address or a function # We do this by testing if the 1st character is a digit elif [[ ${conf[0]:0:1} == [[:digit:]] || ${conf[0]} == *:* ]]; then x=0 # if [[ $(type -t address_exists ) == function ]]; then # if address_exists ${iface} ${conf[0]} ; then # eerror "${conf[0]%%/*} already taken on ${iface}" # x=1 # fi # fi [[ ${x} == 0 ]] && interface_add_address ${iface} ${conf[@]} ; x=$? eend ${x} && config_worked=true && continue else eerror "No loaded modules provide \"${conf[0]}\" (${conf[0]}_start)" fi if [[ -n ${fallback[config_counter]} ]]; then einfo "Trying fallback configuration" config[config_counter]=${fallback[config_counter]} fallback[config_counter]='' # Do we have a fallback route? if [[ -n ${fallback_route[config_counter]} ]]; then eval "routes_${ifvar}=( "\"\$\{fallback_route\[${config_counter}\]\[@\]\}\"" )" fallback_route[config_counter]='' fi (( config_counter-- )) # since the loop will increment it continue fi done eoutdent # We return failure if no configuration parameters worked ${config_worked} || return 1 # Start any modules with _post_start for mod in ${MODULES[@]}; do if [[ function == $( type -t ${mod}_post_start ) ]]; then ${mod}_post_start ${iface} || return 1 fi done return 0 }[/CODE] ${conf[0]}_start ${iface} ; x=$? #${conf[0]}_start的值是dhcp_start 如何找到调用的dhcp_start()函数的定义? [/COLOR] |