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/runscript.sh.old (-23 / +38 lines)
Lines 269-306 Link Here
269
				do
269
				do
270
					mynetservice="${y##*/}"
270
					mynetservice="${y##*/}"
271
					
271
					
272
					if ! service_started "${mynetservice}"
272
					start_service "${mynetservice}"
273
					then
273
				done
274
						start_service "${mynetservice}"
274
				
275
			elif [ "${x}" != "net" ]
276
			then
277
				start_service "${x}"
278
			fi
279
		done
280
		
281
		# Start dependencies, if any
282
		for x in ${startupservices}
283
		do
284
			if [ "${x}" = "net" -a "${NETSERVICE}" != "yes" ]
285
			then
286
				local netservices="$(dolisting "/etc/runlevels/${BOOTLEVEL}/net.*") \
287
					$(dolisting "/etc/runlevels/${mylevel}/net.*")"
288
					
289
				for y in ${netservices}
290
				do
291
					mynetservice="${y##*/}"
292
					
293
					wait_service "${mynetservice}"
275
294
276
						# A 'need' dependency is critical for startup
295
					# A 'need' dependency is critical for startup
277
						if [ "$?" -ne 0 ] && ineed -t "${myservice}" "${x}" >/dev/null
296
					if [ "$?" -ne 0 ] && ineed -t "${myservice}" "${x}" >/dev/null
297
					then
298
						local netcount="$(ls -1 ${svcdir}/started/net.* 2> /dev/null | \
299
							grep -v 'net\.lo' | egrep -c "\/net\.[[:alnum:]]+$")"
300
					
301
						# Only worry about a net.* service if we do not have one
302
						# up and running already, or if RC_NET_SCTRICT_CHECKING
303
						# is set ....
304
						if [ "${netcount}" -lt 1 -o "${RC_NET_STRICT_CHECKING}" = "yes" ]
278
						then
305
						then
279
							local netcount="$(ls -1 ${svcdir}/started/net.* 2> /dev/null | \
306
							startfail="yes"
280
								grep -v 'net\.lo' | egrep -c "\/net\.[[:alnum:]]+$")"
281
						
282
							# Only worry about a net.* service if we do not have one
283
							# up and running already, or if RC_NET_SCTRICT_CHECKING
284
							# is set ....
285
							if [ "${netcount}" -lt 1 -o "${RC_NET_STRICT_CHECKING}" = "yes" ]
286
							then
287
								startfail="yes"
288
							fi
289
						fi
307
						fi
290
					fi
308
					fi
291
				done
309
				done
292
				
310
				
293
			elif [ "${x}" != "net" ]
311
			elif [ "${x}" != "net" ]
294
			then
312
			then
295
				if ! service_started "${x}"
313
				wait_service "${x}"
296
				then
297
					start_service "${x}"
298
314
299
					# A 'need' dependacy is critical for startup
315
				# A 'need' dependacy is critical for startup
300
					if [ "$?" -ne 0 ] && ineed -t "${myservice}" "${x}" >/dev/null
316
				if [ "$?" -ne 0 ] && ineed -t "${myservice}" "${x}" >/dev/null
301
					then
317
				then
302
						startfail="yes"
318
					startfail="yes"
303
					fi
304
				fi
319
				fi
305
			fi
320
			fi
306
		done
321
		done
(-)/sbin/rc.old (+4 lines)
Lines 353-358 Link Here
353
353
354
	splash "rc_init" "${argv1}"
354
	splash "rc_init" "${argv1}"
355
355
356
	export START_CRITICAL="yes"
357
	
356
	# We do not want to break compatibility, so we do not fully integrate
358
	# We do not want to break compatibility, so we do not fully integrate
357
	# these into /sbin/rc, but rather start them by hand ...
359
	# these into /sbin/rc, but rather start them by hand ...
358
	for x in ${CRITICAL_SERVICES}
360
	for x in ${CRITICAL_SERVICES}
Lines 376-381 Link Here
376
		splash "svc_started" "${x}" "0"
378
		splash "svc_started" "${x}" "0"
377
	done
379
	done
378
	
380
	
381
	unset START_CRITICAL
382
	
379
	# Check that $svcdir exists ...
383
	# Check that $svcdir exists ...
380
	check_statedir "${svcdir}"
384
	check_statedir "${svcdir}"
381
385
(-)/lib/rcscripts/sh.old/rc-services.sh (-63 / +103 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-429 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
		if is_fake_service "$1" "${SOFTLEVEL}"
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"
413
		then
482
		then
414
			mark_service_started "$1"
483
			splash "svc_start" "$1"
415
			splash "svc_started" "$1" "0"
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
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
416
		else
504
		else
417
			(. /sbin/runscript.sh "/etc/init.d/$1" start)
505
			end_service "$1"
418
			retval="$?"	
419
			splash "svc_started" "$1" "${retval}"
420
			return "${retval}"
421
		fi
506
		fi
422
	fi
507
	fi
423
508
	
424
	return 0
509
	return 0
425
}
510
}
426
511
512
427
# int stop_service(service)
513
# int stop_service(service)
428
#
514
#
429
#   Stop 'service' if it is not already running.
515
#   Stop 'service' if it is not already running.
Lines 469-474 Link Here
469
mark_service_started() {
555
mark_service_started() {
470
	[ -z "$1" ] && return 1
556
	[ -z "$1" ] && return 1
471
557
558
	echo "0" > "${svcdir}/exitcodes/$1"
559
	
472
	ln -snf "/etc/init.d/$1" "${svcdir}/started/$1"
560
	ln -snf "/etc/init.d/$1" "${svcdir}/started/$1"
473
561
474
	return $?
562
	return $?
Lines 559-618 Link Here
559
#   Schedule 'service' for startup, in parallel if possible.
647
#   Schedule 'service' for startup, in parallel if possible.
560
#
648
#
561
schedule_service_startup() {
649
schedule_service_startup() {
562
	local count=0
650
	if ! iparallel "$1"
563
	local current_job=
564
565
	if [ "${RC_PARALLEL_STARTUP}" = "yes" ]
566
	then
651
	then
567
		set -m +b
652
		wait
568
569
		if [ "$(jobs | grep -c "Running")" -gt 0 ]
570
		then
571
			if [ "$(jobs | grep -c "Running")" -eq 1 ]
572
			then
573
				if [ -n "$(jobs)" ]
574
				then
575
					current_job="$(jobs | awk '/Running/ { print $4}')"
576
				fi
577
				
578
				# Wait if we cannot start this service with the already running
579
				# one (running one might start this one ...).
580
				query_before "$1" "${current_job}" && wait
581
582
			elif [ "$(jobs | grep -c "Running")" -ge 2 ]
583
			then
584
				count="$(jobs | grep -c "Running")"
585
586
				# Wait until we have only one service running
587
				while [ "${count}" -gt 1 ]
588
				do
589
					count="$(jobs | grep -c "Running")"
590
				done
591
592
				if [ -n "$(jobs)" ]
593
				then
594
					current_job="$(jobs | awk '/Running/ { print $4}')"
595
				fi
596
597
				# Wait if we cannot start this service with the already running
598
				# one (running one might start this one ...).
599
				query_before "$1" "${current_job}" && wait
600
			fi
601
		fi
602
603
		if iparallel "$1"
604
		then
605
			eval start_service "$1" \&
606
		else
607
			# Do not start with any service running if we cannot start
608
			# this service in parallel ...
609
#			wait
610
			
611
			start_service "$1"
612
		fi
613
	else
614
		start_service "$1"
615
	fi
653
	fi
654
	
655
	start_service "$1"
616
656
617
	# We do not need to check the return value here, as svc_{start,stop}() do
657
	# We do not need to check the return value here, as svc_{start,stop}() do
618
	# their own error handling ...
658
	# their own error handling ...
(-)/sbin/depscan.sh.old (-1 / +1 lines)
Lines 15-21 Link Here
15
	fi
15
	fi
16
fi
16
fi
17
17
18
for x in softscripts snapshot options started
18
for x in softscripts snapshot options started exclusive exitcodes
19
do
19
do
20
	if [ ! -d "${svcdir}/${x}" ]
20
	if [ ! -d "${svcdir}/${x}" ]
21
	then
21
	then

Return to bug 69854