]> git.pld-linux.org Git - packages/systemd.git/blobdiff - start_udev
- pull updates to subpackages when main package is updated
[packages/systemd.git] / start_udev
index ddb9828caf6d924e40054b139d397bdbdd8ac8c7..a2d20c0e1c89c0513472a1825f415d5e676063fc 100644 (file)
@@ -8,12 +8,12 @@
 #
 # Released under the GPL v2 only.
 #
-# This needs to be run at the earliest possible point in the boot 
+# This needs to be run at the earliest possible point in the boot
 # process.
 #
 # Based on the udev init.d script
 #
-# Thanks go out to the Gentoo developers for proving 
+# Thanks go out to the Gentoo developers for proving
 # that this is possible to do.
 #
 # Yes, it's very verbose, feel free to turn off all of the echo calls,
 # properly during development...
 
 # default value, if no config present.
-udev_root="/dev/"
+udev_root="/dev"
 sysfs_dir="/sys"
 udevd_timeout=8
 
 # don't use udev if sysfs is not mounted.
 [ -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
 bin=/sbin/udev
-udevd=/sbin/udevd
-MAKEDEV="/sbin/MAKEDEV"
+udevd=/lib/udev/udevd
+# trim traling slash, code expects it not to be there
+udev_root=${udev_root%/}
 
 make_extra_nodes () {
        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 --mode=600 $udev_root/$name $arg1 ;;
-               *) echo "links.conf: unparseable line ($type $name $arg1)" ;;
-           esac
+               [ "$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
-       cp -a /lib/udev/devices/* /dev/ >/dev/null 2>&1 || :
+       [ -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 || :
 }
 
 kill_udevd() {
        if [ -x /sbin/pidof ]; then
-               pid=`/sbin/pidof -x udevd`
+               pid=$(/sbin/pidof -x udevd)
                [ -n "$pid" ] && kill $pid
        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 
-                       [ "$where/" = "${f%$what}" ] && found="$found $f"
-               fi
-       done
-       [ -n "$found" ] && echo "$found"
-}
-
-# call hotplug with the scsi devices
-scsi_replay () {
-       HOTPLUG="/sbin/udevsend"
-
-       scsi_hosts=$(find_d /sys/devices host\*)
-       SEQNUM=1
-
-       for host in $scsi_hosts; do
-               [ -d $host ] || continue
-               devs=$(find_f $host type)
-               for dev in $devs;do
-                       [ -f $dev ] || continue
-                       DEVPATH=${dev%/type}
-                       DEVPATH=${DEVPATH#/sys}
-                       /bin/env -i DEVPATH="$DEVPATH" SUBSYSTEM=scsi_device ACTION=add $HOTPLUG scsi_device
-                       /bin/env -i DEVPATH="$DEVPATH" ACTION=add SUBSYSTEM=scsi $HOTPLUG scsi
-               done
-       done
-       return 0
-}
-
-ide_scan() {
-       if [ ! -d /proc/ide ]; then
-               return 1
-       fi
-       for i in /proc/ide/*/media; do
-               read media < "$i"
-               case "$media" in
-                       disk)
-                               module=ide-disk
-                       ;;
-                       cdrom)
-                               module=ide-cd
-                       ;;
-                       tape)
-                               module=ide-tape
-                       ;;
-                       floppy)
-                               module=ide-floppy
-                       ;;
-                       *)
-                               module=ide-generic
-                       ;;
-               esac
-               /sbin/modprobe $module
-       done
-       return 0
+set_hotplug_handler() {
+       echo "" > /proc/sys/kernel/hotplug
 }
 
-supported_kernel() {
-    case "$(uname -r)" in
-    2.[012345].*) return 1 ;;
-    esac
-    return 0
-}
+# find subdirs mounted under $udev_root
+get_dev_mounts() {
+       awk -vudev_root="$udev_root/" '
+       BEGIN {
+         len = length(udev_root);
+       }
 
-set_hotplug_handler() {
-    echo /sbin/udevsend > /proc/sys/kernel/hotplug
+       substr($2, 1, len) == udev_root {
+         print substr($2, len + 1)
+       }' /proc/mounts
 }
 
 export ACTION=add
@@ -159,69 +82,62 @@ ret=0
 show "Starting udev"
 busy
 
-if ! supported_kernel; then
-    fail
-    echo "udev requires a kernel >= 2.6.x, not started."
-    exit 0                                                
-fi
-
-# 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"
+# mount the devtmpfs on $udev_root, if not already done
+awk "\$2 == \"$udev_root\" && \$3 == \"devtmpfs\" { exit 1 }" /proc/mounts && {
+       submounts=$(get_dev_mounts)
+
+       if [ "$submounts" ]; then
+               # mount to temporary location to be able to move submounts
+               # this needs writable TMPDIR:-/tmp, so it won't work in early boot
+               # but fix is simple: use initramfs instead of romfs
+               devdir=$(mktemp -d ${TMPDIR:-/tmp}/tmpXXXXXX)
+       else
+               devdir=$udev_root
        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"
-       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
-
+       mount -n -o mode=0755 -t devtmpfs devtmpfs "$devdir"
        ret=$(( $ret + $? ))
-}
 
+       # relocate submounts
+       for dir in $submounts; do
+               mount -n --move $udev_root/$dir $devdir/$dir
+               ret=$(( $ret + $? ))
+       done
 
-kill_udevd > "$udev_root/null" 2>&1
+       if [ "$submounts" ]; then
+               mount -n --move $devdir $udev_root
+               rmdir $devdir
+       fi
+}
 
-scsi_replay > "$udev_root/null" 2>&1
+kill_udevd > "$udev_root/null" 2>&1
 
+# Start udevd daemon
+$udevd --daemon
 ret=$(( $ret + $? ))
 
-ide_scan > "$udev_root/null" 2>&1
-
-# Starting the hotplug events dispatcher
-/sbin/udevd --daemon
-
 # Making extra nodes
 make_extra_nodes
+ret=$(( $ret + $? ))
 
-# Setting default hotplug handler
-set_hotplug_handler
-
-# Synthesizing the initial hotplug events
-/sbin/${UDEV_STARTER}
+if [ -f "/sys/class/tty/console/uevent" ]; then
+       # Setting default hotplug handler
+       set_hotplug_handler
+       ret=$(( $ret + $? ))
 
-# wait for /dev to be fully populated
-while [ -d /dev/.udev/queue/ ]; do
-    sleep 0.2
-    udevd_timeout=$(($udevd_timeout - 1))
-    if [ $udevd_timeout -eq 0 ]; then
-       break
-    fi
-done
+       # retrigger all events
+       # Udev finds 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 + $? ))
 
-# Start workaround for broken Linux input subsystem
-/lib/udev/udev_input_coldplug start
+       # 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
This page took 0.034482 seconds and 4 git commands to generate.