#!/bin/sh

source /etc/sysconfig/config
source /etc/sysconfig/helpers/functions

ERR=0;
case "$1" in
    "start")
        # Mount the /dev filesystem
        /bin/mount /dev;
        if [ "X$?" != "X0" ]; then ERR=1; fi
        # Copy over the base /dev tree
        if [ -d /lib/udev/devices ]; then
            cp -a  /lib/udev/devices/* /dev/
            if [ "X$?" != "X0" ]; then ERR=2; fi
        fi
        # Start Unix sockets needed by udev
        if [ ! -r /proc/net/unix ]; then
            load_module unix
            if [ "X$?" != "X0" ]; then ERR=2; fi
        fi
        # Start udevd
        /sbin/udevd --daemon
        if [ "X$?" != "X0" ]; then ERR=3; fi
        /sbin/udevtrigger
        if [ "X$?" != "X0" ]; then ERR=4; fi
        # Wait for all devices already in system to be created
        /sbin/udevsettle
        ;;
    "stop")
        killall udevd
        ;;
    *)
        echo "Syntax is $0 start | stop"
        exit 255;
        ;;
esac

exit ${ERR};
