Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 69854 | Differences between
and this patch

Collapse All | Expand All

(-)/lib/rcscripts/sh/rc-services.sh.orig (-67 / +106 lines)
Lines 397-402 Link Here
397
	return 1
397
	return 1
398
}
398
}
399
399
400
# bool begin_exclusive( service )
401
#
402
#   atomically marks the service as being executed
403
#   use like this:
404
#
405
#   if begion_exclusive myexclusive ; then
406
#         whatever is in here can only be executed by one process
407
#         end_exclusive myexclusive
408
#   fi
409
410
begin_service()
411
{
412
	[ "$START_CRITICAL" == "yes" ] && return 0
413
	
414
	mkfifo "${svcdir}/exclusive/$1" &> /dev/null
415
	return $?
416
}
417
418
# void end_exclusive(service, exitcode)
419
#
420
#   stops executing a exclusive region and
421
#   wakes up anybody who is waiting for the exclusive region
422
#
423
end_service()
424
{
425
	local newname
426
	
427
	# if we are doing critical services, there is no fifo
428
	
429
	[ "$START_CRITICAL" == "yes" ] && return
430
	
431
        if [ -n "$2" ] ; then
432
		echo "$2" > "${svcdir}/exitcodes/$1"
433
	fi
434
	
435
	# move the fifo to a unique name so noone is waiting for it after we touch it
436
	newname="$(mktemp "${svcdir}/exclusive/$1.XXXXXXXXXX")"	
437
	mv -f "${svcdir}/exclusive/$1" "${newname}"
438
	
439
	# wake up anybody that was waiting for the fifo
440
	touch "${newname}"
441
	
442
	# We dont need the fifo anymore
443
	rm -f "${newname}"
444
}
445
446
# int wait_exclusive(service)
447
448
wait_service()
449
{
450
	
451
	local retval
452
	
453
	[ "$START_CRITICAL" == "yes" ] && return 0
454
455
	# this will block until the fifo is touched. It is touched by calling end_exclusive
456
	# if no begin_eclusive has being called or end_exclusive has already finished
457
	# this will not block
458
	cat "${svcdir}/exclusive/$1" 2> /dev/null
459
	retval="$( cat "${svcdir}/exitcodes/$1")"
460
	return "${retval}"
461
}
462
400
# int start_service(service)
463
# int start_service(service)
401
#
464
#
402
#   Start 'service' if it is not already running.
465
#   Start 'service' if it is not already running.
Lines 406-426 Link Here
406
	
469
	
407
	[ -z "$1" ] && return 1
470
	[ -z "$1" ] && return 1
408
	
471
	
409
	if ! service_started "$1"
472
 	#critical services can not start in parallel and begin_service fails because
410
	then
473
 	#we don't have write permition to ${svcdir}
411
		splash "svc_start" "$1"
474
 	# so if we are doing critical services, disable the parallel feature
412
			
475
 	
413
		if is_fake_service "$1" "${SOFTLEVEL}"
476
 	# if it is not currently running or we are doing critical services	
414
		then
477
 	if begin_service "$1" ; then
415
			mark_service_started "$1"
478
 	
416
			splash "svc_started" "$1" "0"
479
 		
417
		else
480
 		
418
			(. /sbin/runscript.sh "/etc/init.d/$1" start)
481
 		if ! service_started "$1"
419
			retval="$?"
482
 		then
420
			splash "svc_started" "$1" "${retval}"
483
 			splash "svc_start" "$1"
421
			return "${retval}"
484
 			if is_fake_service "$1" "${SOFTLEVEL}"
422
		fi
485
 			then
423
	fi
486
 				mark_service_started "$1"
487
 				splash "svc_started" "$1" "0"
488
 				end_service "$1" "0"
489
 			else
490
 				(
491
 				
492
 					(. /sbin/runscript.sh "/etc/init.d/$1" start)
493
 					retval="$?"
494
 					splash "svc_started" "$1" "${retval}"
495
 					end_service "$1" "${retval}"
496
 				) &
497
 				
498
 				# if startup is not parallel, or we are doing criticall services
499
 				if [ "${RC_PARALLEL_STARTUP}" != "yes" -o "$START_CRITICAL" == "yes" ] ; then
500
 					wait
501
 				fi
502
 				
503
 			fi
504
 		else
505
 			end_service "$1"
506
 		fi
507
 	fi
508
424
509
425
	return 0
510
	return 0
426
}
511
}
Lines 471-476 Link Here
471
mark_service_started() {
556
mark_service_started() {
472
	[ -z "$1" ] && return 1
557
	[ -z "$1" ] && return 1
473
558
559
	echo "0" > "${svcdir}/exitcodes/$1"
560
	
474
	ln -snf "/etc/init.d/$1" "${svcdir}/started/$1"
561
	ln -snf "/etc/init.d/$1" "${svcdir}/started/$1"
475
562
476
	return $?
563
	return $?
Lines 594-653 Link Here
594
#   Schedule 'service' for startup, in parallel if possible.
681
#   Schedule 'service' for startup, in parallel if possible.
595
#
682
#
596
schedule_service_startup() {
683
schedule_service_startup() {
597
	local count=0
684
	if ! iparallel "$1"
598
	local current_job=
599
600
	if [ "${RC_PARALLEL_STARTUP}" = "yes" ]
601
	then
685
	then
602
		set -m +b
686
		wait
603
604
		if [ "$(jobs | grep -c "Running")" -gt 0 ]
605
		then
606
			if [ "$(jobs | grep -c "Running")" -eq 1 ]
607
			then
608
				if [ -n "$(jobs)" ]
609
				then
610
					current_job="$(jobs | awk '/Running/ { print $4}')"
611
				fi
612
				
613
				# Wait if we cannot start this service with the already running
614
				# one (running one might start this one ...).
615
				query_before "$1" "${current_job}" && wait
616
617
			elif [ "$(jobs | grep -c "Running")" -ge 2 ]
618
			then
619
				count="$(jobs | grep -c "Running")"
620
621
				# Wait until we have only one service running
622
				while [ "${count}" -gt 1 ]
623
				do
624
					count="$(jobs | grep -c "Running")"
625
				done
626
627
				if [ -n "$(jobs)" ]
628
				then
629
					current_job="$(jobs | awk '/Running/ { print $4}')"
630
				fi
631
632
				# Wait if we cannot start this service with the already running
633
				# one (running one might start this one ...).
634
				query_before "$1" "${current_job}" && wait
635
			fi
636
		fi
637
638
		if iparallel "$1"
639
		then
640
			eval start_service "$1" \&
641
		else
642
			# Do not start with any service running if we cannot start
643
			# this service in parallel ...
644
#			wait
645
			
646
			start_service "$1"
647
		fi
648
	else
649
		start_service "$1"
650
	fi
687
	fi
688
	
689
	start_service "$1"
651
690
652
	# We do not need to check the return value here, as svc_{start,stop}() do
691
	# We do not need to check the return value here, as svc_{start,stop}() do
653
	# their own error handling ...
692
	# their own error handling ...
(-)/sbin/depscan.sh.orig (-1 / +1 lines)
Lines 13-19 Link Here
13
	fi
13
	fi
14
fi
14
fi
15
15
16
for x in softscripts snapshot options started
16
for x in softscripts snapshot options started exclusive exitcodes
17
do
17
do
18
	if [ ! -d "${svcdir}/${x}" ]
18
	if [ ! -d "${svcdir}/${x}" ]
19
	then
19
	then
(-)/sbin/rc.orig (+5 lines)
Lines 417-422 Link Here
417
417
418
	splash "rc_init" "${argv1}"
418
	splash "rc_init" "${argv1}"
419
419
420
	export START_CRITICAL="yes"
421
	
420
	# We do not want to break compatibility, so we do not fully integrate
422
	# We do not want to break compatibility, so we do not fully integrate
421
	# these into /sbin/rc, but rather start them by hand ...
423
	# these into /sbin/rc, but rather start them by hand ...
422
	for x in ${CRITICAL_SERVICES}
424
	for x in ${CRITICAL_SERVICES}
Lines 440-445 Link Here
440
442
441
		splash "svc_started" "${x}" "0"
443
		splash "svc_started" "${x}" "0"
442
	done
444
	done
445
	
446
	unset START_CRITICAL
447
	
443
	# Check that $svcdir exists ...
448
	# Check that $svcdir exists ...
444
	check_statedir "${svcdir}"
449
	check_statedir "${svcdir}"
445
450
(-)/sbin/runscript.sh.orig (-20 / +35 lines)
Lines 265-300 Link Here
265
				for y in ${netservices}
265
				for y in ${netservices}
266
				do
266
				do
267
					mynetservice="${y##*/}"
267
					mynetservice="${y##*/}"
268
					start_service "${mynetservice}"
269
				done
270
				
271
			elif [ "${x}" != "net" ]
272
			then
273
				start_service "${x}"
274
			fi
275
		done
276
		
277
		# wait for dependencies to finish
278
		for x in ${startupservices}
279
		do
280
			if [ "${x}" = "net" -a "${NETSERVICE}" != "yes" ]
281
			then
282
				local netservices="$(dolisting "/etc/runlevels/${BOOTLEVEL}/net.*") \
283
					$(dolisting "/etc/runlevels/${mylevel}/net.*")"
268
					
284
					
269
					if ! service_started "${mynetservice}"
285
				for y in ${netservices}
270
					then
286
				do
271
						start_service "${mynetservice}"
287
					mynetservice="${y##*/}"
288
					
289
					wait_service "${mynetservice}"
272
290
273
						# A 'need' dependency is critical for startup
291
					# A 'need' dependency is critical for startup
274
						if [ "$?" -ne 0 ] && ineed -t "${myservice}" "${x}" >/dev/null
292
					if [ "$?" -ne 0 ] && ineed -t "${myservice}" "${x}" >/dev/null
293
					then
294
						# Only worry about a net.* service if we do not have one
295
						# up and running already, or if RC_NET_STRICT_CHECKING
296
						# is set ....
297
						if ! is_net_up
275
						then
298
						then
276
							# Only worry about a net.* service if we do not have one
299
							startfail="yes"
277
							# up and running already, or if RC_NET_STRICT_CHECKING
278
							# is set ....
279
							if ! is_net_up
280
							then
281
								startfail="yes"
282
							fi
283
						fi
300
						fi
284
					fi
301
					fi
285
				done
302
				done
286
				
303
				
287
			elif [ "${x}" != "net" ]
304
			elif [ "${x}" != "net" ]
288
			then
305
			then
289
				if ! service_started "${x}"
306
					
290
				then
307
				wait_service "${x}"
291
					start_service "${x}"
292
308
293
					# A 'need' dependacy is critical for startup
309
				# A 'need' dependacy is critical for startup
294
					if [ "$?" -ne 0 ] && ineed -t "${myservice}" "${x}" >/dev/null
310
				if [ "$?" -ne 0 ] && ineed -t "${myservice}" "${x}" >/dev/null
295
					then
311
				then
296
						startfail="yes"
312
					startfail="yes"
297
					fi
298
				fi
313
				fi
299
			fi
314
			fi
300
		done
315
		done

Return to bug 69854