]> git.pld-linux.org Git - packages/systemd.git/blobdiff - start_udev
- package more *.target.wants dirs
[packages/systemd.git] / start_udev
index 7ae90d72c9fa9f60845a2455f087aab1cca13f79..d50eb7f9130d5a80f6822a5030028426effbff0f 100644 (file)
 # Yes, it's very verbose, feel free to turn off all of the echo calls,
 # they were there to make me feel better that everything was working
 # properly during development...
-#
+
+# default value, if no config present.
+udev_root="/dev/"
+sysfs_dir="/sys"
+udevd_timeout=8
+
 # don't use udev if sysfs is not mounted.
-[ -d $sysfs_dir/class ] || exit 1
+[ -d $sysfs_dir/class ] || exit 1
 [ -r /proc/mounts ] || exit 1
-[ -x /sbin/udev ] || exit 1
 [ -f /etc/udev/udev.conf ] && . /etc/udev/udev.conf
 
-
 . /etc/rc.d/init.d/functions
 
 prog=udev
-sysfs_dir=/sys
 bin=/sbin/udev
-udevd=/sbin/udevd
-MAKEDEV="/sbin/MAKEDEV"
+udevd=/lib/udev/udevd
 
 make_extra_nodes () {
-       ln -snf /proc/self/fd $udev_root/fd
-       ln -snf /proc/self/fd/0 $udev_root/stdin
-       ln -snf /proc/self/fd/1 $udev_root/stdout
-       ln -snf /proc/self/fd/2 $udev_root/stderr
-       ln -snf /proc/kcore $udev_root/core
-
-       [ -d $udev_root/pts ] || (mkdir $udev_root/pts;chmod 0755 $udev_root/pts)
-       [ -d $udev_root/shm ] || (mkdir $udev_root/shm;chmod 0755 $udev_root/shm)
-
-       if [ -x $MAKEDEV ]; then
-               $MAKEDEV -x $( 
-                       for i in 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15; do
-                           echo cpu/$i/microcode;
-                       done;
-                       for i in 1 2 3 4 5 6; do echo tty$i;done;
-                       for i in 0 1 2 3 4 5 6 7; do echo loop$i; done;
-                       for i in 0 1 2 3; do echo lp$i; echo par$i;done;
-                       echo net/tun ppp console null zero;
-               );
-               [ -a /dev/MAKEDEV ] || ln -s $MAKEDEV /dev/MAKEDEV;
-               cp -a /etc/udev/devices/* /dev/ >/dev/null 2>&1 || :
-       fi
-}
-
-# we cannot use /usr/bin/find here
-find_d () {
-        where=$1
-        what=$2
-        found=""
-        for f in $where/*; do
-                if [ -d "$f" -a ! -L "$f" ]; then
-                       if [ "$f" != "${f%%$what}" ];then 
-                               # make sure we are at the path end
-                               # we have no dirname and basename
-                               rest="${f#*$what}"
-                               [ "${rest##*/}" = "$rest" ] && found="$found $f"
-                       fi
-                        found="$found $(find_d $f $what)"
-                fi
-        done
-        echo "$found"
-}
-
-# we cannot use /usr/bin/find here
-find_f () {
-       where=$1
-       what=$2
-       found=""
-       for f in $where/*; do
-               if [ -d "$f" -a ! -L "$f" ]; then
-                       found="$found $(find_f $f $what)"
-               elif [ -e "$f" ]; then 
-                       [ "$f" != "${f%$what}" ] && found="$found $f"
-               fi
+       grep '^[^#]' /etc/udev/links.conf | \
+       while read type name arg1; do
+           [ "$type" -a "$name" -a ! -e "$udev_root/$name" -a ! -L "/dev/$name" ] ||continue
+           case "$type" in
+               L) ln -s $arg1 $udev_root/$name ;;
+               D) mkdir -p $udev_root/$name ;;
+               M) mknod -m 600 /dev/$name $arg1 ;;
+               *) echo "links.conf: unparseable line ($type $name $arg1)" ;;
+           esac
        done
-       echo "$found"
+       [ -d /lib/udev/devices ] && cp -a /lib/udev/devices/* /dev/ >/dev/null 2>&1 || :
+       [ -d /lib64/udev/devices ] && cp -a /lib64/udev/devices/* /dev/ >/dev/null 2>&1 || :
 }
 
-# call hotplug with the scsi devices
-scsi_replay () {
-        HOTPLUG=$(cat /proc/sys/kernel/hotplug)
-        [ -z "$HOTPLUG" ] && return 1
-
-        scsi_hosts=$(find_d /sys/devices host\*)
-        SEQNUM=1
+kill_udevd() {
+       if [ -x /sbin/pidof ]; then
+               pid=`/sbin/pidof -x udevd`
+               [ -n "$pid" ] && kill $pid
+       fi
+}
 
-        for host in $scsi_hosts; do
-                [ -d $host ] || continue
-                devs=$(find_f $host type)
-                for dev in $devs;do
-                        [ -f $dev ] || continue
-                        export SEQNUM
-                        DEVPATH=${dev%/type}
-                        DEVPATH=${DEVPATH#/sys}
-                        export DEVPATH
-                        export ACTION=add
-                        $HOTPLUG scsi_device
-                        SEQNUM=$(($SEQNUM + 1)
-                        $HOTPLUG scsi 
-                        SEQNUM=$(($SEQNUM + 1)
-                done
-        done
-        return 0
+set_hotplug_handler() {
+    echo "" > /proc/sys/kernel/hotplug
 }
 
 export ACTION=add
-export UDEV_NO_SLEEP=1
 prog=udev
 ret=0
-nls "Starting udev"
-# propagate $udev_root from /sys
-grep -q "none ${udev_root%/} " /proc/mounts || { 
+show "Starting udev"
+busy
+
+# mount the tmpfs on ${udev_root%/}, if not already done
+LANG=C awk "\$2 == \"${udev_root%/}\" && \$3 == \"tmpfs\" { exit 1 }" /proc/mounts && {
+       if LANG=C fgrep -q "none ${udev_root%/}/pts " /proc/mounts; then
+               PTSDIR=$(mktemp -d ${TMPDIR:-/tmp}/tmpXXXXXX)
+               mount --move $udev_root/pts "$PTSDIR"
+       fi
+       if LANG=C fgrep -q "none ${udev_root%/}/shm " /proc/mounts; then
+               SHMDIR=$(mktemp -d ${TMPDIR:-/tmp}/tmpXXXXXX)
+               mount --move $udev_root/shm "$SHMDIR"
+       fi
        mount -n -o mode=0755 -t tmpfs none "$udev_root"
-       ret=$(($ret + $?))
+       mkdir -m 0755 $udev_root/pts
+       mkdir -m 0755 $udev_root/shm
+       if [ -n "$PTSDIR" ]; then
+               mount --move "$PTSDIR" $udev_root/pts
+               rmdir "$PTSDIR"
+       fi
+       if [ -n "$SHMDIR" ]; then
+               mount --move "$SHMDIR" $udev_root/shm
+               rmdir "$SHMDIR"
+       fi
+
+       ret=$(( $ret + $? ))
 }
-make_extra_nodes
-scsi_replay >/dev/null 2>&1
-ret=$(($ret + $?))
-rm -f $udev_root/.udev.tdb
-/sbin/udevstart 
-ret=$(($ret + $?))
+
+kill_udevd > "$udev_root/null" 2>&1
+
+       # Start udevd daemon
+       $udevd --daemon
+       ret=$(( $ret + $? ))
+       
+       # Making extra nodes
+       make_extra_nodes
+       ret=$(( $ret + $? ))
+       
+if [ -f "/sys/class/tty/console/uevent" ]; then
+
+       # Setting default hotplug handler
+       set_hotplug_handler
+       ret=$(( $ret + $? ))
+
+       # retrigger all events
+       # Udev find's it's own way of making this dir
+       # and making it by hand makes udevsettle
+       # work forever
+       #mkdir -p /dev/.udev/queue
+       udevadm trigger 
+       ret=$(( $ret + $? ))
+       
+       # wait for the events to finish
+       udevadm settle  
+       ret=$(( $ret + $? ))
+else
+       echo "Kernel too old for this udev version"
+fi
+
+ret=$(( $ret + $? ))
 [ $ret -eq 0 ] && ok || fail
 exit 0
This page took 0.039499 seconds and 4 git commands to generate.