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

(-)/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 (-16 / +54 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}"
268
					
269
					
269
					if ! service_started "${mynetservice}"
270
					# If parallel startup is disabled, the exit code will be returned immediatelly
271
					# and may not be saved for later because we may not have
272
					# write access yet.
273
					if [ "$?" -ne 0 ] && ineed -t "${myservice}" "${x}" >/dev/null
270
					then
274
					then
271
						start_service "${mynetservice}"
275
						# Only worry about a net.* service if we do not have one
272
276
						# up and running already, or if RC_NET_STRICT_CHECKING
273
						# A 'need' dependency is critical for startup
277
						# is set ....
274
						if [ "$?" -ne 0 ] && ineed -t "${myservice}" "${x}" >/dev/null
278
						if ! is_net_up
275
						then
279
						then
276
							# Only worry about a net.* service if we do not have one
280
							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
281
						fi
284
					fi
282
					fi
283
				
285
				done
284
				done
286
				
285
				
287
			elif [ "${x}" != "net" ]
286
			elif [ "${x}" != "net" ]
288
			then
287
			then
289
				if ! service_started "${x}"
288
				start_service "${x}"
289
				
290
				# If parallel startup is disabled, the exit code will be returned immediatelly
291
				# and may not be saved for later because we may not have
292
				# write access yet
293
				if [ "$?" -ne 0 ] && ineed -t "${myservice}" "${x}" >/dev/null
290
				then
294
				then
291
					start_service "${x}"
295
					startfail="yes"
296
				fi
297
			fi
298
		done
299
		
300
		# wait for dependencies to finish
301
		for x in ${startupservices}
302
		do
303
			if [ "${x}" = "net" -a "${NETSERVICE}" != "yes" ]
304
			then
305
				local netservices="$(dolisting "/etc/runlevels/${BOOTLEVEL}/net.*") \
306
					$(dolisting "/etc/runlevels/${mylevel}/net.*")"
307
					
308
				for y in ${netservices}
309
				do
310
					mynetservice="${y##*/}"
311
					
312
					wait_service "${mynetservice}"
292
313
293
					# A 'need' dependacy is critical for startup
314
					# A 'need' dependency is critical for startup
294
					if [ "$?" -ne 0 ] && ineed -t "${myservice}" "${x}" >/dev/null
315
					if [ "$?" -ne 0 ] && ineed -t "${myservice}" "${x}" >/dev/null
295
					then
316
					then
296
						startfail="yes"
317
						# Only worry about a net.* service if we do not have one
318
						# up and running already, or if RC_NET_STRICT_CHECKING
319
						# is set ....
320
						if ! is_net_up
321
						then
322
							startfail="yes"
323
						fi
297
					fi
324
					fi
325
				done
326
				
327
			elif [ "${x}" != "net" ]
328
			then
329
					
330
				wait_service "${x}"
331
332
				# A 'need' dependacy is critical for startup
333
				if [ "$?" -ne 0 ] && ineed -t "${myservice}" "${x}" >/dev/null
334
				then
335
					startfail="yes"
298
				fi
336
				fi
299
			fi
337
			fi
300
		done
338
		done
(-)/lib/rcscripts/sh/rc-services.sh.orig (-65 / +118 lines)
Lines 397-427 Link Here
397
	return 1
397
	return 1
398
}
398
}
399
399
400
# bool begin_service( service )
401
#
402
#   atomically marks the service as being executed
403
#   use like this:
404
#
405
#   if begion_service service ; then
406
#         whatever is in here can only be executed by one process
407
#         end_service service
408
#   fi
409
410
begin_service()
411
{
412
	local service="$1"
413
	[ "$START_CRITICAL" == "yes" ] && return 0
414
	
415
	mkfifo "${svcdir}/exclusive/${service}" &> /dev/null
416
	return $?
417
}
418
419
# void end_exclusive(service, exitcode)
420
#
421
#   stops executing a exclusive region and
422
#   wakes up anybody who is waiting for the exclusive region
423
#
424
end_service()
425
{
426
	local service="$1"
427
	local exitstatus="$2"
428
	local tempname
429
430
	# if we are doing critical services, there is no fifo
431
	
432
	[ "$START_CRITICAL" == "yes" ] && return
433
	
434
        if [ -n "${exitstatus}" ] ; then
435
		echo "${exitstatus}" > "${svcdir}/exitcodes/${service}"
436
	fi
437
	
438
	# move the fifo to a unique name so noone is waiting for it after we touch it
439
	tempname="$(mktemp "${svcdir}/exclusive/${service}.XXXXXXXXXX")"	
440
	mv -f "${svcdir}/exclusive/${service}" "${tempname}"
441
	
442
	# wake up anybody that was waiting for the fifo
443
	touch "${tempname}"
444
	
445
	# We dont need the fifo anymore
446
	rm -f "${tempname}"
447
}
448
449
# int wait_exclusive(service)
450
451
wait_service()
452
{
453
	local service="$1"
454
	local exitstatus
455
	
456
	[ "$START_CRITICAL" == "yes" ] && return 0
457
458
	# this will block until the fifo is touched. It is touched by calling end_exclusive
459
	# if no begin_eclusive has being called or end_exclusive has already finished
460
	# this will not block
461
	cat "${svcdir}/exclusive/${service}" 2> /dev/null
462
	exitstatus="$( cat "${svcdir}/exitcodes/${service}")"
463
	return "${exitstatus}"
464
}
465
400
# int start_service(service)
466
# int start_service(service)
401
#
467
#
402
#   Start 'service' if it is not already running.
468
#   Start 'service' if it is not already running.
403
#
469
#
404
start_service() {
470
start_service() {
471
	local service="$1"
405
	local retval=0
472
	local retval=0
473
		
474
	[ -z "${service}" ] && return 1
406
	
475
	
407
	[ -z "$1" ] && return 1
476
 	#critical services can not start in parallel and begin_service fails because
408
	
477
 	#we don't have write permition to ${svcdir}
409
	if ! service_started "$1"
478
 	# so if we are doing critical services, disable the parallel feature
410
	then
479
 	
411
		splash "svc_start" "$1"
480
 	# if it is not currently running or we are doing critical services	
481
 	if begin_service "${service}" ; then
482
 	
483
 		
484
 		
485
 		if ! service_started "${service}"
486
 		then
487
 			splash "svc_start" "${service}"
488
 			if is_fake_service "${service}" "${SOFTLEVEL}"
489
 			then
490
 				mark_service_started "${service}"
491
 				splash "svc_started" "${service}" "0"
492
 				end_service "${service}" "0"
493
 			else
412
			
494
			
413
		if is_fake_service "$1" "${SOFTLEVEL}"
495
				if [ "${RC_PARALLEL_STARTUP}" != "yes" -o "$START_CRITICAL" == "yes" ] 
414
		then
496
				then
415
			mark_service_started "$1"
497
				
416
			splash "svc_started" "$1" "0"
498
					# if we can not start the services in parallel, then just start it and return the exit status
499
					(. /sbin/runscript.sh "/etc/init.d/${service}" start)
500
					retval="$?"
501
					splash "svc_started" "${service}" "${retval}"
502
					end_service "${service}" "${retval}"
503
					return "${retval}"
504
				else
505
					# if parallel startup is allowed, start it in background
506
					(
507
					
508
						(. /sbin/runscript.sh "/etc/init.d/${service}" start)
509
						retval="$?"
510
						splash "svc_started" "${service}" "${retval}"
511
						end_service "${service}" "${retval}"
512
					) &
513
				
514
				fi
515
			fi
417
		else
516
		else
418
			(. /sbin/runscript.sh "/etc/init.d/$1" start)
517
			end_service "${service}"
419
			retval="$?"
420
			splash "svc_started" "$1" "${retval}"
421
			return "${retval}"
422
		fi
518
		fi
423
	fi
519
	fi
424
520
521
425
	return 0
522
	return 0
426
}
523
}
427
524
Lines 471-476 Link Here
471
mark_service_started() {
568
mark_service_started() {
472
	[ -z "$1" ] && return 1
569
	[ -z "$1" ] && return 1
473
570
571
	echo "0" > "${svcdir}/exitcodes/$1"
572
	
474
	ln -snf "/etc/init.d/$1" "${svcdir}/started/$1"
573
	ln -snf "/etc/init.d/$1" "${svcdir}/started/$1"
475
574
476
	return $?
575
	return $?
Lines 594-653 Link Here
594
#   Schedule 'service' for startup, in parallel if possible.
693
#   Schedule 'service' for startup, in parallel if possible.
595
#
694
#
596
schedule_service_startup() {
695
schedule_service_startup() {
597
	local count=0
696
	local service="$1"
598
	local current_job=
697
	
599
698
	if ! iparallel "${service}"
600
	if [ "${RC_PARALLEL_STARTUP}" = "yes" ]
601
	then
699
	then
602
		set -m +b
700
		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
701
	fi
702
	
703
	start_service "${service}"
651
704
652
	# We do not need to check the return value here, as svc_{start,stop}() do
705
	# We do not need to check the return value here, as svc_{start,stop}() do
653
	# their own error handling ...
706
	# their own error handling ...

Return to bug 69854