# udev-finish - save udev log and update rules
#
# While udev runs we not only create the log file of initial device
# creation but udev rules may be generated, we need to copy both of
# these out of /dev and onto the root filesystem.

description	"save udev log and update rules"

start on (startup
	  and filesystem
	  and started udev
	  and stopped udevtrigger
	  and stopped udevmonitor)

task
script
    # Save udev log in /var/log/udev
    if [ -e /dev/.udev.log ]
    then
	mv -f /dev/.udev.log /var/log/udev || :
    fi

    # Copy any rules generated while the root filesystem was read-only
    for file in /run/udev/tmp-rules--*
    do
	[ -e "$file" ] || continue
	cat "$file" >> "/etc/udev/rules.d/${file##*tmp-rules--}"
	rm -f "$file"
    done
end script
