]> git.pld-linux.org Git - packages/systemd.git/blame - start_udev
- stop debugging events
[packages/systemd.git] / start_udev
CommitLineData
05149ed5
AM
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...
940e3565
ER
22
23# default value, if no config present.
24udev_root="/dev/"
b44e0a3d 25sysfs_dir="/sys"
d35df3ca 26udevd_timeout=8
940e3565 27
05149ed5 28# don't use udev if sysfs is not mounted.
dda87135 29[ -d $sysfs_dir/class ] || exit 1
05149ed5
AM
30[ -r /proc/mounts ] || exit 1
31[ -x /sbin/udev ] || exit 1
32[ -f /etc/udev/udev.conf ] && . /etc/udev/udev.conf
33
401263e1 34. /etc/rc.d/init.d/functions
05149ed5
AM
35
36prog=udev
05149ed5
AM
37bin=/sbin/udev
38udevd=/sbin/udevd
39MAKEDEV="/sbin/MAKEDEV"
40
41make_extra_nodes () {
42 ln -snf /proc/self/fd $udev_root/fd
43 ln -snf /proc/self/fd/0 $udev_root/stdin
44 ln -snf /proc/self/fd/1 $udev_root/stdout
45 ln -snf /proc/self/fd/2 $udev_root/stderr
46 ln -snf /proc/kcore $udev_root/core
47
120a2def
AM
48 [ -d $udev_root/pts ] || mkdir -m 0755 $udev_root/pts
49 [ -d $udev_root/shm ] || mkdir -m 0755 $udev_root/shm
05149ed5
AM
50
51 if [ -x $MAKEDEV ]; then
52 $MAKEDEV -x $(
05149ed5
AM
53 for i in 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15; do
54 echo cpu/$i/microcode;
55 done;
6ba94d68
AM
56 for i in 1 2 3 4 5 6; do echo tty$i;done;
57 for i in 0 1 2 3 4 5 6 7; do echo loop$i; done;
d8394a8d 58 for i in 0 1 2 3; do echo lp$i; echo parport$i;done;
6ba94d68 59 echo net/tun ppp console null zero;
05149ed5 60 );
bf62c441 61 [ -a /dev/MAKEDEV ] || ln -sf "$MAKEDEV" /dev/MAKEDEV;
05149ed5 62 fi
44abfb53 63 cp -a /lib/udev/devices/* /dev/ >/dev/null 2>&1 || :
05149ed5
AM
64}
65
d8394a8d
AM
66kill_udevd() {
67 if [ -x /sbin/pidof ]; then
68 pid=`/sbin/pidof -x udevd`
69 [ -n "$pid" ] && kill $pid
70 fi
71}
72
6ba94d68
AM
73# we cannot use /usr/bin/find here
74find_d () {
84853a2e
ER
75 where=$1
76 what=$2
77 found=""
78 for f in $where/*; do
79 if [ -d "$f" -a ! -L "$f" ]; then
6ba94d68 80 if [ "$f" != "${f%%$what}" ];then
84853a2e
ER
81 # make sure we are at the path end
82 # we have no dirname and basename
6ba94d68
AM
83 rest="${f#*$what}"
84 [ "${rest##*/}" = "$rest" ] && found="$found $f"
85 fi
84853a2e
ER
86 found="$found $(find_d $f $what)"
87 fi
88 done
89 echo "$found"
05149ed5
AM
90}
91
6ba94d68
AM
92# we cannot use /usr/bin/find here
93find_f () {
94 where=$1
95 what=$2
96 found=""
97 for f in $where/*; do
98 if [ -d "$f" -a ! -L "$f" ]; then
99 found="$found $(find_f $f $what)"
100 elif [ -e "$f" ]; then
120a2def 101 [ "$where/" = "${f%$what}" ] && found="$found $f"
6ba94d68
AM
102 fi
103 done
120a2def 104 [ -n "$found" ] && echo "$found"
05149ed5 105}
05149ed5 106
6ba94d68
AM
107# call hotplug with the scsi devices
108scsi_replay () {
84853a2e 109 HOTPLUG="/sbin/udevsend"
6ba94d68 110
84853a2e
ER
111 scsi_hosts=$(find_d /sys/devices host\*)
112 SEQNUM=1
6ba94d68 113
84853a2e
ER
114 for host in $scsi_hosts; do
115 [ -d $host ] || continue
116 devs=$(find_f $host type)
117 for dev in $devs;do
118 [ -f $dev ] || continue
120a2def 119 DEVPATH=${dev%/type}
84853a2e
ER
120 DEVPATH=${DEVPATH#/sys}
121 /bin/env -i DEVPATH="$DEVPATH" SUBSYSTEM=scsi_device ACTION=add $HOTPLUG scsi_device
122 /bin/env -i DEVPATH="$DEVPATH" ACTION=add SUBSYSTEM=scsi $HOTPLUG scsi
123 done
124 done
125 return 0
6ba94d68 126}
05149ed5 127
d8394a8d
AM
128ide_scan() {
129 if [ ! -d /proc/ide ]; then
130 return 1
131 fi
132 for i in /proc/ide/*/media; do
133 read media < "$i"
134 case "$media" in
135 disk)
136 module=ide-disk
137 ;;
138 cdrom)
139 module=ide-cd
140 ;;
141 tape)
142 module=ide-tape
143 ;;
144 floppy)
145 module=ide-floppy
146 ;;
147 *)
148 module=ide-generic
149 ;;
150 esac
151 /sbin/modprobe $module
152 done
153 return 0
154}
155
294ac9d6 156supported_kernel() {
157 case "$(uname -r)" in
684be8e9 158 2.[012345].*) return 1 ;;
294ac9d6 159 esac
160 return 0
161}
162
163set_hotplug_handler() {
164 echo /sbin/udevsend > /proc/sys/kernel/hotplug
165}
166
05149ed5 167export ACTION=add
6ba94d68
AM
168prog=udev
169ret=0
170nls "Starting udev"
294ac9d6 171
684be8e9 172if ! supported_kernel; then
173 echo "udev requires a kernel >= 2.6.x, not started."
174 exit 0
175fi
120a2def
AM
176
177# mount the tmpfs on ${udev_root%/}, if not already done
178LANG=C awk "\$2 == \"${udev_root%/}\" && \$3 == \"tmpfs\" { exit 1 }" /proc/mounts && {
84853a2e 179 if LANG=C fgrep -q "none ${udev_root%/}/pts " /proc/mounts; then
5cccdef0 180 PTSDIR=$(mktemp -d ${TMPDIR:-/tmp}/tmpXXXXXX)
84853a2e
ER
181 mount --move $udev_root/pts "$PTSDIR"
182 fi
183 if LANG=C fgrep -q "none ${udev_root%/}/shm " /proc/mounts; then
5cccdef0 184 SHMDIR=$(mktemp -d ${TMPDIR:-/tmp}/tmpXXXXXX)
84853a2e
ER
185 mount --move $udev_root/shm "$SHMDIR"
186 fi
187 mount -n -o mode=0755 -t tmpfs none "$udev_root"
188 mkdir -m 0755 $udev_root/pts
189 mkdir -m 0755 $udev_root/shm
190 if [ -n "$PTSDIR" ]; then
191 mount --move "$PTSDIR" $udev_root/pts
192 rmdir "$PTSDIR"
193 fi
194 if [ -n "$SHMDIR" ]; then
195 mount --move "$SHMDIR" $udev_root/shm
196 rmdir "$SHMDIR"
197 fi
198
199 ret=$(( $ret + $? ))
6ba94d68 200}
120a2def 201
ec7c0939 202
120a2def 203kill_udevd > "$udev_root/null" 2>&1
ec7c0939 204
120a2def 205scsi_replay > "$udev_root/null" 2>&1
ec7c0939 206
120a2def 207ret=$(( $ret + $? ))
ec7c0939 208
120a2def 209ide_scan > "$udev_root/null" 2>&1
ec7c0939 210
d35df3ca 211# Starting the hotplug events dispatcher
212/sbin/udevd --daemon
213
214# Making extra nodes
215make_extra_nodes
216
217# Setting default hotplug handler
294ac9d6 218set_hotplug_handler
ec7c0939 219
d35df3ca 220# Synthesizing the initial hotplug events
b06b7ca8 221/sbin/${UDEV_STARTER}
ec7c0939 222
d35df3ca 223# wait for the udev/udevd childs to finish
ead9902f 224while [ "$(cat /proc/[0-9]*/status 2> /dev/null | \
225 grep -c -E '^Name:[[:space:]]*udevd?$')" -gt 1 ]; do
d35df3ca 226 sleep 1
227 udevd_timeout=$(($udevd_timeout - 1))
228 if [ $udevd_timeout -eq 0 ]; then
229 break
230 fi
231done
ec7c0939 232
d35df3ca 233# Start workaround for broken Linux input subsystem
f3702bb9 234/lib/udev/udev_input_coldplug start
b8861549 235
120a2def 236ret=$(( $ret + $? ))
6ba94d68 237[ $ret -eq 0 ] && ok || fail
05149ed5 238exit 0
This page took 0.07072 seconds and 4 git commands to generate.