# -*- mode: shell-script; -*-

start on stopped udev

console output

pre-start script
    [ -x /usr/sbin/hotplug2 ] || stop
end script

script
    # Borrowed from /etc/init.d/udev
    unmount_devpts() {
        if mountpoint -q /dev/pts/; then
            umount -l /dev/pts/
        fi

        if mountpoint -q /dev/shm/; then
            umount -l /dev/shm/
        fi
    }

    # mount a tmpfs over /dev, if somebody did not already do it
    mount_tmpfs() {
        if grep -E -q "^[^[:space:]]+ /dev tmpfs" /proc/mounts; then
            return
        fi

        # /dev/.static/dev/ is used by MAKEDEV to access the real
        # /dev/ directory.  /etc/udev/ is recycled as a temporary
        # mount point because it's the only directory which is
        # guaranteed to be available.
        mount -n -o bind /dev /etc/udev

        if ! mount -n -o size=$tmpfs_size,mode=0755 -t tmpfs tmpfs /dev; then
            umount /etc/udev
            exit 1
        fi

        mkdir -p /dev/.static/dev
        chmod 700 /dev/.static/
        # The mount options in busybox are non-standard...
        if [ -x /bin/mount.util-linux ]; then
            /bin/mount.util-linux --move /etc/udev /dev/.static/dev
        elif [ -x /bin/busybox ]; then
            busybox mount -n -o move /etc/udev /dev/.static/dev
        fi
    }

    if [ ! -e "$udev_root/.udev/" ] || ! mountpoint -q /dev/; then
	    unmount_devpts
	    mount_tmpfs
	    [ -d /proc/1 ] || mount -n /proc
    fi

    /usr/sbin/hotplug2 --coldplug --no-persistent
end script
