# Diff of /baselayout-vserver/trunk/sbin/rc-services.sh

Revision 126 Revision 127
707# string trace_dependencies(service[s]) 707# string trace_dependencies(service[s])
708# 708#
709# Get and sort the dependencies of given service[s]. 709# Get and sort the dependencies of given service[s].
710# 710#
711trace_dependencies() { 711trace_dependencies() {
712 local -a services=( "\$@" ) 712 local -a services=( "\$@" ) net_deps
713 local i j net_services 713 local i j net_services x
714 714
715 if [[ \$1 == -* ]]; then 715 if [[ \$1 == -* ]]; then
716 deptype="\${1/-}" 716 deptype="\${1/-/}"
717 if net_service "\${myservice}" ; then 717 if net_service "\${myservice}" ; then
718 services=( "net" "\${myservice}" ) 718 services=( "net" "\${myservice}" )
719 else 719 else
720 services=( "\${myservice}" ) 720 services=( "\${myservice}" )
721 fi 721 fi
741 [[ \${BOOTLEVEL} != "\${mylevel}" ]] && \ 741 [[ \${BOOTLEVEL} != "\${mylevel}" ]] && \
742 local x="\${x} \$( get_net_services "\${mylevel}" )" 742 local x="\${x} \$( get_net_services "\${mylevel}" )"
743 [[ -n \${x} ]] && net_services="\${x}" 743 [[ -n \${x} ]] && net_services="\${x}"
744 fi 744 fi
745 745
746 # Cache the generic "net" depends
747 net_deps=( \$( ineed net ) \$( valid_iuse net ) )
748 if is_runlevel_start || is_runlevel_stop ; then
749 net_deps=( "\${net_deps[@]}" \$( valid_iafter net ) )
750 fi
751
746 # OK, this is a topological sort 752 # OK, this is a topological sort
747 # The bonus about doing it in bash is that we can calculate our sort 753 # The bonus about doing it in bash is that we can calculate our sort
748 # order as we calculate our dependencies 754 # order as we calculate our dependencies
749 local -a visited sorted 755 local -a visited sorted
750 visit_service() { 756 visit_service() {
751 local service="\$1" dep 757 local service="\$1" dep x
752 local -a deps 758 local -a deps
753 759
754 [[ " \${visited[@]} " == *" \${service} "* ]] && return 760 [[ " \${visited[@]} " == *" \${service} "* ]] && return
755 visited=( "\${visited[@]}" "\${service}" ) 761 visited=( "\${visited[@]}" "\${service}" )
756 762
757 if [[ -n \${deptype} ]] ; then 763 if [[ -n \${deptype} ]] ; then
758 deps=( "\${deps[@]}" \$( "\${deptype}" "\${service}" ) ) 764 deps=( \$( "\${deptype}" "\${service}" ) )
759 else 765 else
760 deps=( 766 deps=( \$( ineed "\${service}" ) \$( valid_iuse "\${service}" ) )
761 \$( ineed "\${service}" )
762 \$( valid_iuse "\${service}" )
763 )
764
765 if is_runlevel_start || is_runlevel_stop ; then 767 if is_runlevel_start || is_runlevel_stop ; then
766 deps=( "\${deps[@]}" \$( valid_iafter "\${service}" ) ) 768 deps=( "\${deps[@]}" \$( valid_iafter "\${service}" ) )
767 fi 769 fi
768 770
771 # If we're a net service, we have to get deps for ourself
772 # and the net service as we're both
773 net_service "\${service}" && deps=( "\${deps[@]}" "\${net_deps[@]}" )
774
769 local x=" \${deps[@]} " 775 x=" \${deps[@]} "
770 deps=( \${x// net / \${net_services} } ) 776 deps=( "\${deps[@]}" \${x// net / \${net_services} } )
771 fi 777 fi
772 778
773 services=( "\${services[@]}" "\${deps[@]}" ) 779 services=( "\${services[@]}" "\${deps[@]}" )
774 for dep in \${deps[@]}; do 780 for dep in \${deps[@]}; do
775 visit_service "\${dep}" 781 visit_service "\${dep}"

Legend:
 Removed from v.126 changed lines Added in v.127