/[vps]/baselayout-vserver/trunk/sbin/rc-services.sh
Gentoo

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

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

Revision 64 Revision 65
56 if [[ -z $1 || -z $2 ]] ; then 56 if [[ -z $1 || -z $2 ]] ; then
57 echo "0" 57 echo "0"
58 return 1 58 return 1
59 fi 59 fi
60 60
61 local x myservice=$1 index=$2 61 local x myservice="$1" index="$2"
62 62
63 # Do we already have the index? 63 # Do we already have the index?
64 if [[ -n ${index} && ${index} -gt 0 \ 64 if [[ -n ${index} && ${index} -gt 0 \
65 && ${myservice} == "${RC_DEPEND_TREE[${index}]}" ]] ; then 65 && ${myservice} == "${RC_DEPEND_TREE[${index}]}" ]] ; then
66 echo "${index}" 66 echo "${index}"
84# Set the Dependency variables to contain data for 'service' 84# Set the Dependency variables to contain data for 'service'
85# 85#
86get_dep_info() { 86get_dep_info() {
87 [[ -z $1 ]] && return 1 87 [[ -z $1 ]] && return 1
88 88
89 local myservice=$1 89 local myservice="$1"
90 90
91 # We already have the right stuff ... 91 # We already have the right stuff ...
92 [[ ${myservice} == "${rc_name}" && -n ${rc_mtime} ]] && return 0 92 [[ ${myservice} == "${rc_name}" && -n ${rc_mtime} ]] && return 0
93 93
94 rc_index="`get_service_index "${myservice}" "${rc_index}"`" 94 rc_index="`get_service_index "${myservice}" "${rc_index}"`"
95 rc_mtime="${RC_DEPEND_TREE[$((${rc_index} + ${rc_type_mtime}))]}" 95 rc_mtime="${RC_DEPEND_TREE[$((${rc_index} + ${rc_type_mtime}))]}"
96 96
97 # Verify that we have the correct index (rc_index) ... 97 # Verify that we have the correct index (rc_index) ...
98 # [[ ${rc_index} == "0" ]] && return 1 98 # [[ ${rc_index} == "0" ]] && return 1
99 99
100 rc_name=${RC_DEPEND_TREE[${rc_index}]} 100 rc_name="${RC_DEPEND_TREE[${rc_index}]}"
101 rc_ineed="${RC_DEPEND_TREE[$((${rc_index} + ${rc_type_ineed}))]}" 101 rc_ineed="${RC_DEPEND_TREE[$((${rc_index} + ${rc_type_ineed}))]}"
102 rc_needsme="${RC_DEPEND_TREE[$((${rc_index} + ${rc_type_needsme}))]}" 102 rc_needsme="${RC_DEPEND_TREE[$((${rc_index} + ${rc_type_needsme}))]}"
103 rc_iuse="${RC_DEPEND_TREE[$((${rc_index} + ${rc_type_iuse}))]}" 103 rc_iuse="${RC_DEPEND_TREE[$((${rc_index} + ${rc_type_iuse}))]}"
104 rc_usesme="${RC_DEPEND_TREE[$((${rc_index} + ${rc_type_usesme}))]}" 104 rc_usesme="${RC_DEPEND_TREE[$((${rc_index} + ${rc_type_usesme}))]}"
105 rc_ibefore="${RC_DEPEND_TREE[$((${rc_index} + ${rc_type_ibefore}))]}" 105 rc_ibefore="${RC_DEPEND_TREE[$((${rc_index} + ${rc_type_ibefore}))]}"
125 local x myservice deps 125 local x myservice deps
126 126
127 # Set the dependency variables to relate to 'service1' 127 # Set the dependency variables to relate to 'service1'
128 if [[ $2 == "-t" ]] ; then 128 if [[ $2 == "-t" ]] ; then
129 [[ -z $3 || -z $4 ]] && return 1 129 [[ -z $3 || -z $4 ]] && return 1
130 myservice=$3 130 myservice="$3"
131 else 131 else
132 myservice=$2 132 myservice="$2"
133 fi 133 fi
134 134
135 if ! get_dep_info "${myservice}" >/dev/null ; then 135 if ! get_dep_info "${myservice}" >/dev/null ; then
136 eerror "Could not get dependency info for \"${myservice}\"!" > /dev/stderr 136 eerror "Could not get dependency info for \"${myservice}\"!" > /dev/stderr
137 eerror "Please run:" > /dev/stderr 137 eerror "Please run:" > /dev/stderr
211is_fake_service() { 211is_fake_service() {
212 local x fake_services 212 local x fake_services
213 213
214 [[ -z $1 || -z $2 ]] && return 1 214 [[ -z $1 || -z $2 ]] && return 1
215 215
216 [[ $2 != "${BOOTLEVEL}" && -e /etc/runlevels/${BOOTLEVEL}/.fake ]] && \ 216 [[ $2 != "${BOOTLEVEL}" && -e /etc/runlevels/"${BOOTLEVEL}"/.fake ]] && \
217 fake_services=$( < /etc/runlevels/${BOOTLEVEL}/.fake ) 217 fake_services=$( < /etc/runlevels/"${BOOTLEVEL}"/.fake )
218 218
219 [[ -e /etc/runlevels/$2/.fake ]] && \ 219 [[ -e /etc/runlevels/"$2"/.fake ]] && \
220 fake_services="${fake_services} $( < /etc/runlevels/$2/.fake )" 220 fake_services="${fake_services} $( < /etc/runlevels/$2/.fake )"
221 221
222 for x in ${fake_services} ; do 222 for x in ${fake_services} ; do
223 [[ $1 == "${x##*/}" ]] && return 0 223 [[ $1 == "${x##*/}" ]] && return 0
224 done 224 done
231# Returns true if 'service' is in runlevel 'runlevel'. 231# Returns true if 'service' is in runlevel 'runlevel'.
232# 232#
233in_runlevel() { 233in_runlevel() {
234 [[ -z $1 || -z $2 ]] && return 1 234 [[ -z $1 || -z $2 ]] && return 1
235 235
236 [[ -L /etc/runlevels/$2/$1 ]] && return 0 236 [[ -L "/etc/runlevels/$2/$1" ]] && return 0
237 237
238 return 1 238 return 1
239} 239}
240 240
241# bool is_runlevel_start() 241# bool is_runlevel_start()
242# 242#
243# Returns true if it is a runlevel change, and we are busy 243# Returns true if it is a runlevel change, and we are busy
244# starting services. 244# starting services.
245# 245#
246is_runlevel_start() { 246is_runlevel_start() {
247 [[ -d ${svcdir}/softscripts.old && \ 247 [[ -d "${svcdir}/softscripts.old" && \
248 ${SOFTLEVEL} != "${OLDSOFTLEVEL}" ]] && return 0 248 ${SOFTLEVEL} != "${OLDSOFTLEVEL}" ]] && return 0
249 249
250 return 1 250 return 1
251} 251}
252 252
254# 254#
255# Returns true if it is a runlevel change, and we are busy 255# Returns true if it is a runlevel change, and we are busy
256# stopping services. 256# stopping services.
257# 257#
258is_runlevel_stop() { 258is_runlevel_stop() {
259 [[ -d ${svcdir}/softscripts.new && \ 259 [[ -d "${svcdir}/softscripts.new" && \
260 ${SOFTLEVEL} != "${OLDSOFTLEVEL}" ]] && return 0 260 ${SOFTLEVEL} != "${OLDSOFTLEVEL}" ]] && return 0
261 261
262 return 1 262 return 1
263} 263}
264 264
272 if [[ $1 == "1" || $1 == "error" || $1 == "eerror" ]] ; then 272 if [[ $1 == "1" || $1 == "error" || $1 == "eerror" ]] ; then
273 cmd="eerror" 273 cmd="eerror"
274 shift 274 shift
275 fi 275 fi
276 276
277 local r=${RC_QUIET_STDOUT} 277 local r="${RC_QUIET_STDOUT}"
278 RC_QUIET_STDOUT="no" 278 RC_QUIET_STDOUT="no"
279 ${cmd} "$@" 279 ${cmd} "$@"
280 RC_QUIET_STDOUT=${r} 280 RC_QUIET_STDOUT=${r}
281} 281}
282 282
300# 300#
301# stops executing a exclusive region and 301# stops executing a exclusive region and
302# wakes up anybody who is waiting for the exclusive region 302# wakes up anybody who is waiting for the exclusive region
303# 303#
304end_service() { 304end_service() {
305 local service=$1 exitstatus=$2 305 local service="$1" exitstatus="$2"
306 306
307 # if we are doing critical services, there is no fifo 307 # if we are doing critical services, there is no fifo
308 [[ ${START_CRITICAL} == "yes" ]] && return 308 [[ ${START_CRITICAL} == "yes" ]] && return
309 309
310 if [[ -n ${exitstatus} ]] ; then 310 if [[ -n ${exitstatus} ]] ; then
329# 329#
330# If a service has started, or a fifo does not exist return 0 330# If a service has started, or a fifo does not exist return 0
331# Otherwise, wait until we get an exit code via the fifo and return 331# Otherwise, wait until we get an exit code via the fifo and return
332# that instead. 332# that instead.
333wait_service() { 333wait_service() {
334 local service=$1 334 local service="$1"
335 local fifo="${svcdir}/exclusive/${service}" 335 local fifo="${svcdir}/exclusive/${service}"
336 336
337 [[ ${START_CRITICAL} == "yes" || ${STOP_CRITICAL} == "yes" ]] && return 0 337 [[ ${START_CRITICAL} == "yes" || ${STOP_CRITICAL} == "yes" ]] && return 0
338 [[ ! -e ${fifo} ]] && return 0 338 [[ ! -e ${fifo} ]] && return 0
339 339
348# int start_service(service) 348# int start_service(service)
349# 349#
350# Start 'service' if it is not already running. 350# Start 'service' if it is not already running.
351# 351#
352start_service() { 352start_service() {
353 local service=$1 353 local service="$1"
354 [[ -z ${service} ]] && return 1 354 [[ -z ${service} ]] && return 1
355 355
356 if [[ ! -e "/etc/init.d/${service}" ]] ; then 356 if [[ ! -e "/etc/init.d/${service}" ]] ; then
357 mark_service_stopped "${service}" 357 mark_service_stopped "${service}"
358 return 1 358 return 1
390# int stop_service(service) 390# int stop_service(service)
391# 391#
392# Stop 'service' if it is not already running. 392# Stop 'service' if it is not already running.
393# 393#
394stop_service() { 394stop_service() {
395 local service=$1 395 local service="$1"
396 [[ -z ${service} ]] && return 1 396 [[ -z ${service} ]] && return 1
397 397
398 if [[ ! -e /etc/init.d/${service} ]] ; then 398 if [[ ! -e "/etc/init.d/${service}" ]] ; then
399 mark_service_stopped "${service}" 399 mark_service_stopped "${service}"
400 return 0 400 return 0
401 fi 401 fi
402 402
403 service_stopping "${service}" && return 0 403 service_stopping "${service}" && return 0
404 service_stopped "${service}" && return 0 404 service_stopped "${service}" && return 0
405 405
406 local level="${SOFTLEVEL}" 406 local level="${SOFTLEVEL}"
407 is_runlevel_stop && level=${OLDSOFTLEVEL} 407 is_runlevel_stop && level="${OLDSOFTLEVEL}"
408 408
409 if is_fake_service "${service}" "${level}" ; then 409 if is_fake_service "${service}" "${level}" ; then
410 mark_service_stopped "${service}" 410 mark_service_stopped "${service}"
411 return 0 411 return 0
412 fi 412 fi
440 [[ -z $1 ]] && return 1 440 [[ -z $1 ]] && return 1
441 441
442 ln -snf "/etc/init.d/$1" "${svcdir}/starting/$1" 442 ln -snf "/etc/init.d/$1" "${svcdir}/starting/$1"
443 local retval=$? 443 local retval=$?
444 444
445 [[ -f ${svcdir}/started/$1 ]] && rm -f "${svcdir}/started/$1" 445 [[ -f "${svcdir}/started/$1" ]] && rm -f "${svcdir}/started/$1"
446 [[ -f ${svcdir}/inactive/$1 ]] && rm -f "${svcdir}/inactive/$1" 446 [[ -f "${svcdir}/inactive/$1" ]] && rm -f "${svcdir}/inactive/$1"
447 [[ -f ${svcdir}/stopping/$1 ]] && rm -f "${svcdir}/stopping/$1" 447 [[ -f "${svcdir}/stopping/$1" ]] && rm -f "${svcdir}/stopping/$1"
448 448
449 return "${retval}" 449 return "${retval}"
450} 450}
451 451
452# bool mark_service_started(service) 452# bool mark_service_started(service)
457 [[ -z $1 ]] && return 1 457 [[ -z $1 ]] && return 1
458 458
459 ln -snf "/etc/init.d/$1" "${svcdir}/started/$1" 459 ln -snf "/etc/init.d/$1" "${svcdir}/started/$1"
460 local retval=$? 460 local retval=$?
461 461
462 [[ -f ${svcdir}/starting/$1 ]] && rm -f "${svcdir}/starting/$1" 462 [[ -f "${svcdir}/starting/$1" ]] && rm -f "${svcdir}/starting/$1"
463 [[ -f ${svcdir}/inactive/$1 ]] && rm -f "${svcdir}/inactive/$1" 463 [[ -f "${svcdir}/inactive/$1" ]] && rm -f "${svcdir}/inactive/$1"
464 [[ -f ${svcdir}/stopping/$1 ]] && rm -f "${svcdir}/stopping/$1" 464 [[ -f "${svcdir}/stopping/$1" ]] && rm -f "${svcdir}/stopping/$1"
465 465
466 return "${retval}" 466 return "${retval}"
467} 467}
468 468
469# bool mark_service_inactive(service) 469# bool mark_service_inactive(service)
473mark_service_inactive() { 473mark_service_inactive() {
474 [[ -z $1 ]] && return 1 474 [[ -z $1 ]] && return 1
475 475
476 ln -snf "/etc/init.d/$1" "${svcdir}/inactive/$1" 476 ln -snf "/etc/init.d/$1" "${svcdir}/inactive/$1"
477 local retval=$? 477 local retval=$?
478 [[ -f ${svcdir}/started/$1 ]] && rm -f "${svcdir}/started/$1" 478 [[ -f "${svcdir}/started/$1" ]] && rm -f "${svcdir}/started/$1"
479 [[ -f ${svcdir}/starting/$1 ]] && rm -f "${svcdir}/starting/$1" 479 [[ -f "${svcdir}/starting/$1" ]] && rm -f "${svcdir}/starting/$1"
480 [[ -f ${svcdir}/stopping/$1 ]] && rm -f "${svcdir}/stopping/$1" 480 [[ -f "${svcdir}/stopping/$1" ]] && rm -f "${svcdir}/stopping/$1"
481 481
482 return "${retval}" 482 return "${retval}"
483} 483}
484 484
485# bool mark_service_stopping(service) 485# bool mark_service_stopping(service)
490 [[ -z $1 ]] && return 1 490 [[ -z $1 ]] && return 1
491 491
492 ln -snf "/etc/init.d/$1" "${svcdir}/stopping/$1" 492 ln -snf "/etc/init.d/$1" "${svcdir}/stopping/$1"
493 local retval=$? 493 local retval=$?
494 494
495 [ -f ${svcdir}/starting/$1 ] && rm -f "${svcdir}/starting/$1" 495 [[ -f "${svcdir}/starting/$1" ]] && rm -f "${svcdir}/starting/$1"
496 [ -f ${svcdir}/started/$1 ] && rm -f "${svcdir}/started/$1" 496 [[ -f "${svcdir}/started/$1" ]] && rm -f "${svcdir}/started/$1"
497 [ -f ${svcdir}/inactive/$1 ] && rm -f "${svcdir}/inactive/$1" 497 [[ -f "${svcdir}/inactive/$1" ]] && rm -f "${svcdir}/inactive/$1"
498 498
499 return "${retval}" 499 return "${retval}"
500} 500}
501 501
502# bool mark_service_stopped(service) 502# bool mark_service_stopped(service)
504# Mark 'service' as stopped. 504# Mark 'service' as stopped.
505# 505#
506mark_service_stopped() { 506mark_service_stopped() {
507 [[ -z $1 ]] && return 1 507 [[ -z $1 ]] && return 1
508 508
509 [[ -f ${svcdir}/daemons/$1 ]] && rm -f "${svcdir}/daemons/$1" 509 [[ -f "${svcdir}/daemons/$1" ]] && rm -f "${svcdir}/daemons/$1"
510 [[ -f ${svcdir}/starting/$1 ]] && rm -f "${svcdir}/starting/$1" 510 [[ -f "${svcdir}/starting/$1" ]] && rm -f "${svcdir}/starting/$1"
511 [[ -f ${svcdir}/started/$1 ]] && rm -f "${svcdir}/started/$1" 511 [[ -f "${svcdir}/started/$1" ]] && rm -f "${svcdir}/started/$1"
512 [[ -f ${svcdir}/inactive/$1 ]] && rm -f "${svcdir}/inactive/$1" 512 [[ -f "${svcdir}/inactive/$1" ]] && rm -f "${svcdir}/inactive/$1"
513 [[ -f ${svcdir}/stopping/$1 ]] && rm -f "${svcdir}/stopping/$1" 513 [[ -f "${svcdir}/stopping/$1" ]] && rm -f "${svcdir}/stopping/$1"
514 514
515 return $? 515 return $?
516} 516}
517 517
518# bool test_service_state(char *service, char *state) 518# bool test_service_state(char *service, char *state)
582# 582#
583# Mark service as failed for current runlevel. Note that 583# Mark service as failed for current runlevel. Note that
584# this is only valid on runlevel change ... 584# this is only valid on runlevel change ...
585# 585#
586mark_service_failed() { 586mark_service_failed() {
587 [[ -z $1 || ! -d ${svcdir}/failed ]] && return 1 587 [[ -z $1 || ! -d "${svcdir}/failed" ]] && return 1
588 588
589 ln -snf "/etc/init.d/$1" "${svcdir}/failed/$1" 589 ln -snf "/etc/init.d/$1" "${svcdir}/failed/$1"
590} 590}
591 591
592# bool service_failed(service) 592# bool service_failed(service)
593# 593#
594# Return true if 'service' have failed during this runlevel. 594# Return true if 'service' have failed during this runlevel.
595# 595#
596service_failed() { 596service_failed() {
597 [[ -n $1 && -L ${svcdir}/failed/$1 ]] 597 [[ -n $1 && -L "${svcdir}/failed/$1" ]]
598} 598}
599 599
600# bool service_started_daemon(char *interface, char *daemon, int index) 600# bool service_started_daemon(char *interface, char *daemon, int index)
601# Returns 0 if the service started the given daemon 601# Returns 0 if the service started the given daemon
602# via start-stop-daemon, otherwise 1. 602# via start-stop-daemon, otherwise 1.
667# This is the main code for valid_after and valid_iuse 667# This is the main code for valid_after and valid_iuse
668# No point in writing it twice! 668# No point in writing it twice!
669valid_i() { 669valid_i() {
670 local x 670 local x
671 # Just set to dummy for now (don't know if $svcdir/softlevel exists yet). 671 # Just set to dummy for now (don't know if $svcdir/softlevel exists yet).
672 local mylevel=${BOOTLEVEL} 672 local mylevel="${BOOTLEVEL}"
673 673
674 [[ $1 != "after" && $1 != "use" ]] && return 1 674 [[ $1 != "after" && $1 != "use" ]] && return 1
675 675
676 # Cannot be SOFTLEVEL, as we need to know current runlevel 676 # Cannot be SOFTLEVEL, as we need to know current runlevel
677 [[ -f ${svcdir}/softlevel ]] && mylevel=$( < "${svcdir}/softlevel" ) 677 [[ -f "${svcdir}/softlevel" ]] && mylevel=$( < "${svcdir}/softlevel" )
678 678
679 for x in $( i$1 "$2" ) ; do 679 for x in $( i$1 "$2" ) ; do
680 [[ -e /etc/runlevels/${BOOTLEVEL}/${x} || \ 680 [[ -e "/etc/runlevels/${BOOTLEVEL}/${x}" || \
681 -e "/etc/runlevels/${mylevel}/${x}" || \ 681 -e "/etc/runlevels/${mylevel}/${x}" || \
682 ${x} == "net" ]] \ 682 ${x} == "net" ]] \
683 && echo "${x}" 683 && echo "${x}"
684 done 684 done
685 685
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=( "$@" ) deps 712 local -a services=( "$@" )
713 local i j 713 local i j net_services
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
722 fi 722 fi
723 723
724 # If its a net service, just replace it with 'net' 724 net_services=$( cd "${svcdir}"/started; ls net.* 2>/dev/null )
725 if [[ -z ${deptype} ]] ; then 725 # If no net services are running or we only have net.lo up, then
726 for (( i=0; i<${#services[@]} ; i++ )) ; do 726 # assume we are in boot runlevel or starting a new runlevel
727 net_service "${services[i]}" && services[i]="net" 727 if [[ -z ${net_services} || ${net_services} == "net.lo" ]]; then
728 done 728 get_net_services() {
729 fi 729 local runlevel="$1"
730 730
731 sort_unique() { 731 if [[ -d "/etc/runlevels/${runlevel}" ]] ; then
732 set -- " ${@/%/\n}" 732 cd "/etc/runlevels/${runlevel}"
733 echo -e "$@" | sort -u 733 ls net.* 2>/dev/null
734 }
735
736 local last=""
737 while [[ ${services[@]} != "${last}" ]] ; do
738 last="${services[*]}"
739 for (( i=0; i<${#services[@]}; i++ )) ; do
740 if [[ -n ${deptype} ]] ; then
741 deps=( "${deps[@]}" $( "${deptype}" "${services[i]}" ) )
742 else
743 ndeps=(
744 $( ineed "${services[i]}" )
745 $( valid_iuse "${services[i]}" )
746 )
747
748 if is_runlevel_start || is_runlevel_stop ; then
749 ndeps=( "${ndeps[@]}" $( valid_iafter "${services[i]}" ) )
750 fi
751
752 #If its a net service, just replace it with 'net'
753 for (( j=0; j<${#ndeps[*]}; j++ )) ; do
754 net_service "${ndeps[j]}" && ndeps[j]="net"
755 done
756
757 deps=( "${deps[@]}" "${ndeps[@]}" )
758 fi 734 fi
759 done 735 }
736
737 local mylevel="${BOOTLEVEL}"
738 local x=$( get_net_services "${mylevel}" )
739
740 [[ -f "${svcdir}/softlevel" ]] && mylevel=$( < "${svcdir}/softlevel" )
741 [[ ${BOOTLEVEL} != "${mylevel}" ]] && \
742 local x="${x} $( get_net_services "${mylevel}" )"
743 [[ -n ${x} ]] && net_services="${x}"
744 fi
745
746 local -a visited
747 for (( i=0; i<${#services[@]}; i++)); do
748 [[ ${visited[@]} == *" ${services[i]} "* ]] && continue
749 if [[ -n ${deptype} ]] ; then
750 deps=( "${deps[@]}" $( "${deptype}" "${services[i]}" ) )
751 else
752 deps=(
753 $( ineed "${services[i]}" )
754 $( valid_iuse "${services[i]}" )
755 )
756
757 if is_runlevel_start || is_runlevel_stop ; then
758 deps=( "${deps[@]}" $( valid_iafter "${services[i]}" ) )
759 fi
760
761 local x=" ${deps[@]} "
762 deps=( ${x// net / ${net_services} } )
763 fi
760 services=( $(sort_unique ${services[@]} ${deps[@]}) ) 764 services=( "${services[@]}" "${deps[@]}" )
765 visited=( "${visited[@]}" "${services[i]}" )
761 done 766 done
762 767
763 # Now, we sort our services 768 # Now, we sort our services
764 # When a service is first visited, we mark it dead and then 769 # When a service is first visited, we mark it dead and then
765 # revisit any dependencies. Finally we add ourselves to the sorted list. 770 # revisit any dependencies. Finally we add ourselves to the sorted list.
766 # This should never get into an infinite loop, thanks to our dead array. 771 # This should never get into an infinite loop, thanks to our dead array.
767 local -a dead=() deadname=() sorted=() 772 local -a dead=() deadname=() sorted=()
768 for (( i=0; i<${#services[@]}; i++ )) ; do 773 for (( i=0; i<${#services[@]}; i++ )); do
769 dead[i]="false" 774 dead[i]="false";
770 deadname[i]="${services[i]}" 775 deadname[i]="${services[i]}"
771 done 776 done
772 777
773 after_visit() { 778 after_visit() {
774 local service=$1 i 779 local service="$1" i
775 780
776 for (( i=0; i<${#deadname[@]}; i++)) ; do 781 for (( i=0; i<${#deadname[@]}; i++)); do
777 [[ ${service} == ${deadname[i]} ]] && break 782 [[ ${service} == ${deadname[i]} ]] && break
778 done 783 done
779 784
780 ${dead[i]} && return 785 ${dead[i]} && return
781 dead[i]="true" 786 dead[i]="true"
782 787
783 local x deps="$( ineed ${service} ) $( valid_iuse ${service} )" 788 local x deps=" $( ineed ${service} ) $( valid_iuse ${service} ) "
784 if is_runlevel_start || is_runlevel_stop ; then 789 if is_runlevel_start || is_runlevel_stop ; then
785 deps="${deps} $( valid_iafter ${service} )" 790 deps="${deps} $( valid_iafter ${service} ) "
786 fi 791 fi
787 792
788 if [[ -z ${deptype} ]] ; then 793 if [[ -z ${deptype} ]] ; then
789 # If its a net service, just replace it with 'net' 794 # If its a net service, just replace it with 'net'
790 for (( j=0; j<${#deps[@]}; j++ )) ; do 795 deps="${deps// net / ${net_services} }"
791 net_service "${deps[j]}" && deps[j]="net"
792 done
793 fi 796 fi
794 797
795 for x in ${deps} ; do 798 for x in ${deps}; do
796 after_visit "${x}" 799 after_visit "${x}"
797 done 800 done
798 801
799 sorted=( "${sorted[@]}" "${service}" ) 802 sorted=( "${sorted[@]}" "${service}" )
800 } 803 }
801 804
802 for (( i=0; i<${#services[*]}; i++ )) ; do 805 for (( i=0; i<${#services[*]}; i++ )); do
803 after_visit "${services[i]}" 806 after_visit "${services[i]}"
804 done 807 done
805 services=( "${sorted[@]}" ) 808 services=( "${sorted[@]}" )
806 809
807 if [[ -n ${deptype} ]] ; then 810 if [[ -n ${deptype} ]] ; then
812 # If its a net service, do not include "net" 815 # If its a net service, do not include "net"
813 if net_service "${myservice}" ; then 816 if net_service "${myservice}" ; then
814 x=" ${services[@]} " 817 x=" ${services[@]} "
815 sorted=( ${services// net / } ) 818 sorted=( ${services// net / } )
816 fi 819 fi
817 else
818 local netserv y
819
820 # XXX: I dont think RC_NET_STRICT_CHECKING should be considered
821 # here, but you never know ...
822 netserv=$( cd "${svcdir}"/started; ls net.* 2>/dev/null )
823
824 get_netservices() {
825 local runlevel=$1
826
827 if [[ -d /etc/runlevels/${runlevel} ]] ; then
828 cd "/etc/runlevels/${runlevel}"
829 ls net.* 2>/dev/null
830 fi
831 }
832
833 # If no net services are running or we only have net.lo up, then
834 # assume we are in boot runlevel or starting a new runlevel
835 if [[ -z ${netserv} || ${netserv} == "net.lo" ]] ; then
836 local mylevel=${BOOTLEVEL}
837 local startnetserv=$( get_netservices "${mylevel}" )
838
839 [[ -f ${svcdir}/softlevel ]] && mylevel=$( < "${svcdir}/softlevel" )
840 [[ ${BOOTLEVEL} != "${mylevel}" ]] && \
841 startnetserv="${startnetserv} $( get_netservices "${mylevel}" )"
842 [[ -n ${startnetserv} ]] && netserv=${startnetserv}
843 fi
844
845 # Replace 'net' with the actual net services
846 x=" ${services[@]} "
847 services=( ${x// net / ${netserv} } )
848 fi 820 fi
849 821
850 echo "${services[@]}" 822 echo "${services[@]}"
851} 823}
852 824
873 done 845 done
874 846
875 return 1 847 return 1
876} 848}
877 849
878
879# vim:ts=4 850# vim:ts=4

Legend:
Removed from v.64  
changed lines
  Added in v.65

  ViewVC Help
Powered by ViewVC 1.1.20