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 (-63 / +110 lines)
Lines 397-402 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
	[ "$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-427 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
475
 	
476
 	# if it is not currently running or we are doing critical services	
477
 	if begin_service "$1" ; then
478
 	
479
 		
480
 		
481
 		if ! service_started "$1"
482
 		then
483
 			splash "svc_start" "$1"
484
 			if is_fake_service "$1" "${SOFTLEVEL}"
485
 			then
486
 				mark_service_started "$1"
487
 				splash "svc_started" "$1" "0"
488
 				end_service "$1" "0"
489
 			else
412
			
490
			
413
		if is_fake_service "$1" "${SOFTLEVEL}"
491
				if [ "${RC_PARALLEL_STARTUP}" != "yes" -o "$START_CRITICAL" == "yes" ] 
414
		then
492
				then
415
			mark_service_started "$1"
493
				
416
			splash "svc_started" "$1" "0"
494
					# if we can not start the services in parallel, then just start it and return the exit status
495
					(. /sbin/runscript.sh "/etc/init.d/$1" start)
496
					retval="$?"
497
					splash "svc_started" "$1" "${retval}"
498
					end_service "$1" "${retval}"
499
					return "${retval}"
500
				else
501
					# if parallel startup is allowed, start it in background
502
					(
503
					
504
						(. /sbin/runscript.sh "/etc/init.d/$1" start)
505
						retval="$?"
506
						splash "svc_started" "$1" "${retval}"
507
						end_service "$1" "${retval}"
508
					) &
509
				
510
				fi
511
			fi
417
		else
512
		else
418
			(. /sbin/runscript.sh "/etc/init.d/$1" start)
513
			end_service "$1"
419
			retval="$?"
420
			splash "svc_started" "$1" "${retval}"
421
			return "${retval}"
422
		fi
514
		fi
423
	fi
515
	fi
424
516
517
425
	return 0
518
	return 0
426
}
519
}
427
520
Lines 471-476 Link Here
471
mark_service_started() {
564
mark_service_started() {
472
	[ -z "$1" ] && return 1
565
	[ -z "$1" ] && return 1
473
566
567
	echo "0" > "${svcdir}/exitcodes/$1"
568
	
474
	ln -snf "/etc/init.d/$1" "${svcdir}/started/$1"
569
	ln -snf "/etc/init.d/$1" "${svcdir}/started/$1"
475
570
476
	return $?
571
	return $?
Lines 594-653 Link Here
594
#   Schedule 'service' for startup, in parallel if possible.
689
#   Schedule 'service' for startup, in parallel if possible.
595
#
690
#
596
schedule_service_startup() {
691
schedule_service_startup() {
597
	local count=0
692
	if ! iparallel "$1"
598
	local current_job=
599
600
	if [ "${RC_PARALLEL_STARTUP}" = "yes" ]
601
	then
693
	then
602
		set -m +b
694
		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
695
	fi
696
	
697
	start_service "$1"
651
698
652
	# We do not need to check the return value here, as svc_{start,stop}() do
699
	# We do not need to check the return value here, as svc_{start,stop}() do
653
	# their own error handling ...
700
	# 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 (-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

Return to bug 69854