]> git.pld-linux.org Git - packages/systemd.git/blob - start_udev
- use external configuration for make_extra_nodes
[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 [ -x /sbin/udev ] || exit 1
32 [ -f /etc/udev/udev.conf ] && . /etc/udev/udev.conf
33
34 . /etc/rc.d/init.d/functions
35
36 prog=udev
37 bin=/sbin/udev
38 udevd=/sbin/udevd
39 MAKEDEV="/sbin/MAKEDEV"
40
41 make_extra_nodes () {
42         grep '^[^#]' /etc/udev/links.conf | \
43         while read type name arg1; do
44             [ "$type" -a "$name" -a ! -e "$udev_root/$name" -a ! -L "/dev/$name" ] ||continue
45             case "$type" in
46                 L) ln -s $arg1 $udev_root/$name ;;
47                 D) mkdir -p $udev_root/$name ;;
48                 M) mknod --mode=600 $udev_root/$name $arg1 ;;
49                 *) echo "links.conf: unparseable line ($type $name $arg1)" ;;
50             esac
51         done
52         cp -a /lib/udev/devices/* /dev/ >/dev/null 2>&1 || :
53 }
54
55 kill_udevd() {
56         if [ -x /sbin/pidof ]; then
57                 pid=`/sbin/pidof -x udevd`
58                 [ -n "$pid" ] && kill $pid
59         fi
60 }
61
62 # we cannot use /usr/bin/find here
63 find_d () {
64         where=$1
65         what=$2
66         found=""
67         for f in $where/*; do
68                 if [ -d "$f" -a ! -L "$f" ]; then
69                         if [ "$f" != "${f%%$what}" ];then 
70                                 # make sure we are at the path end
71                                 # we have no dirname and basename
72                                 rest="${f#*$what}"
73                                 [ "${rest##*/}" = "$rest" ] && found="$found $f"
74                         fi
75                         found="$found $(find_d $f $what)"
76                 fi
77         done
78         echo "$found"
79 }
80
81 # we cannot use /usr/bin/find here
82 find_f () {
83         where=$1
84         what=$2
85         found=""
86         for f in $where/*; do
87                 if [ -d "$f" -a ! -L "$f" ]; then
88                         found="$found $(find_f $f $what)"
89                 elif [ -e "$f" ]; then 
90                         [ "$where/" = "${f%$what}" ] && found="$found $f"
91                 fi
92         done
93         [ -n "$found" ] && echo "$found"
94 }
95
96 # call hotplug with the scsi devices
97 scsi_replay () {
98         HOTPLUG="/sbin/udevsend"
99
100         scsi_hosts=$(find_d /sys/devices host\*)
101         SEQNUM=1
102
103         for host in $scsi_hosts; do
104                 [ -d $host ] || continue
105                 devs=$(find_f $host type)
106                 for dev in $devs;do
107                         [ -f $dev ] || continue
108                         DEVPATH=${dev%/type}
109                         DEVPATH=${DEVPATH#/sys}
110                         /bin/env -i DEVPATH="$DEVPATH" SUBSYSTEM=scsi_device ACTION=add $HOTPLUG scsi_device
111                         /bin/env -i DEVPATH="$DEVPATH" ACTION=add SUBSYSTEM=scsi $HOTPLUG scsi
112                 done
113         done
114         return 0
115 }
116
117 ide_scan() {
118         if [ ! -d /proc/ide ]; then
119                 return 1
120         fi
121         for i in /proc/ide/*/media; do
122                 read media < "$i"
123                 case "$media" in
124                         disk)
125                                 module=ide-disk
126                         ;;
127                         cdrom)
128                                 module=ide-cd
129                         ;;
130                         tape)
131                                 module=ide-tape
132                         ;;
133                         floppy)
134                                 module=ide-floppy
135                         ;;
136                         *)
137                                 module=ide-generic
138                         ;;
139                 esac
140                 /sbin/modprobe $module
141         done
142         return 0
143 }
144
145 supported_kernel() {
146     case "$(uname -r)" in
147     2.[012345].*) return 1 ;;
148     esac
149     return 0
150 }
151
152 set_hotplug_handler() {
153     echo /sbin/udevsend > /proc/sys/kernel/hotplug
154 }
155
156 export ACTION=add
157 prog=udev
158 ret=0
159 show "Starting udev"
160 busy
161
162 if ! supported_kernel; then
163     fail
164     echo "udev requires a kernel >= 2.6.x, not started."
165     exit 0                                                
166 fi
167
168 # mount the tmpfs on ${udev_root%/}, if not already done
169 LANG=C awk "\$2 == \"${udev_root%/}\" && \$3 == \"tmpfs\" { exit 1 }" /proc/mounts && {
170         if LANG=C fgrep -q "none ${udev_root%/}/pts " /proc/mounts; then
171                 PTSDIR=$(mktemp -d ${TMPDIR:-/tmp}/tmpXXXXXX)
172                 mount --move $udev_root/pts "$PTSDIR"
173         fi
174         if LANG=C fgrep -q "none ${udev_root%/}/shm " /proc/mounts; then
175                 SHMDIR=$(mktemp -d ${TMPDIR:-/tmp}/tmpXXXXXX)
176                 mount --move $udev_root/shm "$SHMDIR"
177         fi
178         mount -n -o mode=0755 -t tmpfs none "$udev_root"
179         mkdir -m 0755 $udev_root/pts
180         mkdir -m 0755 $udev_root/shm
181         if [ -n "$PTSDIR" ]; then
182                 mount --move "$PTSDIR" $udev_root/pts
183                 rmdir "$PTSDIR"
184         fi
185         if [ -n "$SHMDIR" ]; then
186                 mount --move "$SHMDIR" $udev_root/shm
187                 rmdir "$SHMDIR"
188         fi
189
190         ret=$(( $ret + $? ))
191 }
192
193
194 kill_udevd > "$udev_root/null" 2>&1
195
196 scsi_replay > "$udev_root/null" 2>&1
197
198 ret=$(( $ret + $? ))
199
200 ide_scan > "$udev_root/null" 2>&1
201
202 # Starting the hotplug events dispatcher
203 /sbin/udevd --daemon
204
205 # Making extra nodes
206 make_extra_nodes
207
208 # Setting default hotplug handler
209 set_hotplug_handler
210
211 # Synthesizing the initial hotplug events
212 /sbin/${UDEV_STARTER}
213
214 # wait for /dev to be fully populated
215 while [ -d /dev/.udev/queue/ ]; do
216     sleep 0.2
217     udevd_timeout=$(($udevd_timeout - 1))
218     if [ $udevd_timeout -eq 0 ]; then
219         break
220     fi
221 done
222
223 # Start workaround for broken Linux input subsystem
224 /lib/udev/udev_input_coldplug start
225
226 ret=$(( $ret + $? ))
227 [ $ret -eq 0 ] && ok || fail
228 exit 0
This page took 0.077129 seconds and 4 git commands to generate.