]> git.pld-linux.org Git - packages/systemd.git/blob - start_udev
- rel 12
[packages/systemd.git] / start_udev
1 #!/bin/sh
2 #
3 # start_udev
4 #
5 # script to initialize /dev by using udev.
6 #
7 # Copyright (C) 2004 Greg Kroah-Hartman <greg@kroah.com>
8 #
9 # Released under the GPL v2 only.
10 #
11 # This needs to be run at the earliest possible point in the boot 
12 # process.
13 #
14 # Based on the udev init.d script
15 #
16 # Thanks go out to the Gentoo developers for proving 
17 # that this is possible to do.
18 #
19 # Yes, it's very verbose, feel free to turn off all of the echo calls,
20 # they were there to make me feel better that everything was working
21 # properly during development...
22
23 # default value, if no config present.
24 udev_root="/dev/"
25 sysfs_dir="/sys"
26 udevd_timeout=8
27
28 # don't use udev if sysfs is not mounted.
29 [ -d $sysfs_dir/class ] || exit 1
30 [ -r /proc/mounts ] || exit 1
31 [ -f /etc/udev/udev.conf ] && . /etc/udev/udev.conf
32
33 . /etc/rc.d/init.d/functions
34
35 prog=udev
36 bin=/sbin/udev
37 udevd=/lib/udev/udevd
38
39 make_extra_nodes () {
40         grep '^[^#]' /etc/udev/links.conf | \
41         while read type name arg1; do
42             [ "$type" -a "$name" -a ! -e "$udev_root/$name" -a ! -L "/dev/$name" ] ||continue
43             case "$type" in
44                 L) ln -s $arg1 $udev_root/$name ;;
45                 D) mkdir -p $udev_root/$name ;;
46                 M) mknod -m 600 /dev/$name $arg1 ;;
47                 *) echo "links.conf: unparseable line ($type $name $arg1)" ;;
48             esac
49         done
50         [ -d /lib/udev/devices ] && cp -a /lib/udev/devices/* /dev/ >/dev/null 2>&1 || :
51         [ -d /lib64/udev/devices ] && cp -a /lib64/udev/devices/* /dev/ >/dev/null 2>&1 || :
52 }
53
54 kill_udevd() {
55         if [ -x /sbin/pidof ]; then
56                 pid=`/sbin/pidof -x udevd`
57                 [ -n "$pid" ] && kill $pid
58         fi
59 }
60
61 set_hotplug_handler() {
62     echo "" > /proc/sys/kernel/hotplug
63 }
64
65 export ACTION=add
66 prog=udev
67 ret=0
68 show "Starting udev"
69 busy
70
71 # mount the tmpfs on ${udev_root%/}, if not already done
72 LANG=C awk "\$2 == \"${udev_root%/}\" && \$3 == \"tmpfs\" { exit 1 }" /proc/mounts && {
73         if LANG=C fgrep -q "none ${udev_root%/}/pts " /proc/mounts; then
74                 PTSDIR=$(mktemp -d ${TMPDIR:-/tmp}/tmpXXXXXX)
75                 mount --move $udev_root/pts "$PTSDIR"
76         fi
77         if LANG=C fgrep -q "none ${udev_root%/}/shm " /proc/mounts; then
78                 SHMDIR=$(mktemp -d ${TMPDIR:-/tmp}/tmpXXXXXX)
79                 mount --move $udev_root/shm "$SHMDIR"
80         fi
81         mount -n -o mode=0755 -t tmpfs none "$udev_root"
82         mkdir -m 0755 $udev_root/pts
83         mkdir -m 0755 $udev_root/shm
84         if [ -n "$PTSDIR" ]; then
85                 mount --move "$PTSDIR" $udev_root/pts
86                 rmdir "$PTSDIR"
87         fi
88         if [ -n "$SHMDIR" ]; then
89                 mount --move "$SHMDIR" $udev_root/shm
90                 rmdir "$SHMDIR"
91         fi
92
93         ret=$(( $ret + $? ))
94 }
95
96 kill_udevd > "$udev_root/null" 2>&1
97
98         # Start udevd daemon
99         $udevd --daemon
100         ret=$(( $ret + $? ))
101         
102         # Making extra nodes
103         make_extra_nodes
104         ret=$(( $ret + $? ))
105         
106 if [ -f "/sys/class/tty/console/uevent" ]; then
107
108         # Setting default hotplug handler
109         set_hotplug_handler
110         ret=$(( $ret + $? ))
111
112         # retrigger all events
113         # Udev find's it's own way of making this dir
114         # and making it by hand makes udevsettle
115         # work forever
116         #mkdir -p /dev/.udev/queue
117         udevadm trigger 
118         ret=$(( $ret + $? ))
119         
120         # wait for the events to finish
121         udevadm settle  
122         ret=$(( $ret + $? ))
123 else
124         echo "Kernel too old for this udev version"
125 fi
126
127 ret=$(( $ret + $? ))
128 [ $ret -eq 0 ] && ok || fail
129 exit 0
This page took 0.075464 seconds and 3 git commands to generate.