#!/bin/sh
########################################################################
# Begin $rc_base/init.d/udev
#
# Description : Udev cold-plugging script (retry)
#
# Authors     : Zack Winkles, Alexander E. Patrakov
#
# Version     : 00.02
#
# Notes       :
#
########################################################################

. /etc/sysconfig/rc
. ${rc_functions}

case "${1}" in
	start)
		boot_mesg "Retrying failed uevents, if any..."
		# Re-trigger the failed uevents in hope they will succeed now
		# If there are none, the "No such file or directory" error
		# goes to /dev/null
		for file in /dev/.udev/failed/*/uevent ; do
			echo "add" >"${file}"
		done 2>/dev/null
		
		# Now wait for udevd to process the uevents we triggered
		/sbin/udevsettle
		failed="${?}"
		> /dev/bug
		sleep 6
        	if test -s /dev/bug; then
                	mv /dev/bug /dev/bugreport
			failed="2"
		else
                	rm -f /dev/bug
        	fi
		(exit "${failed}")
		evaluate_retval

		if [ "${failed}" -eq "2" ]; then
			boot_mesg "Some uevents escaped from the \"udevsettle\" program." ${FAILURE}
			boot_mesg "This is a bug either in the kernel or in the program itself."
			boot_mesg "Please mail the /dev/bugreport file to lfs-dev@linuxfromscratch.org."
			boot_mesg "Otherwise, the next version of LFS may be unbootable on your system!"
			echo_failure
			sleep 10
			exit 1
		fi

		;;

	*)
		echo "Usage ${0} {start}"
		exit 1
		;;
esac

# End $rc_base/init.d/udev
