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 | # don't use udev if sysfs is not mounted.
|
---|
24 |
|
---|
25 | sysfs_dir=/sys
|
---|
26 |
|
---|
27 | export TZ=/etc/localtime
|
---|
28 |
|
---|
29 | [ -d $sysfs_dir/class ] || exit 1
|
---|
30 | [ -r /proc/mounts ] || exit 1
|
---|
31 | [ -x /sbin/udevd ] || exit 1
|
---|
32 | [ -f /etc/udev/udev.conf ] && . /etc/udev/udev.conf
|
---|
33 | udev_root=${udev_root-/dev}
|
---|
34 |
|
---|
35 |
|
---|
36 | . /etc/init.d/functions
|
---|
37 |
|
---|
38 | umask 0022
|
---|
39 |
|
---|
40 | prog=udev
|
---|
41 | bin=/sbin/udev
|
---|
42 | udevd=/sbin/udevd
|
---|
43 | MAKEDEV="/sbin/MAKEDEV"
|
---|
44 |
|
---|
45 | xargs_simple () {
|
---|
46 | if [ "$1" = "-n" ]; then
|
---|
47 | shift
|
---|
48 | MAXNR="$1"
|
---|
49 | shift
|
---|
50 | else
|
---|
51 | MAXNR=100
|
---|
52 | fi
|
---|
53 | NR=$MAXNR
|
---|
54 | ARGS=""
|
---|
55 | [ -z "$1" ] && set echo
|
---|
56 |
|
---|
57 | while read line; do
|
---|
58 | if [ $NR -gt 0 ]; then
|
---|
59 | ARGS="$ARGS $line"
|
---|
60 | NR=$[$NR - 1]
|
---|
61 | else
|
---|
62 | "$@" $ARGS
|
---|
63 | NR=$MAXNR
|
---|
64 | ARGS="$line"
|
---|
65 | fi
|
---|
66 | done
|
---|
67 | if [ -n "$ARGS" ]; then
|
---|
68 | "$@" $ARGS
|
---|
69 | fi
|
---|
70 | }
|
---|
71 |
|
---|
72 | make_extra_nodes () {
|
---|
73 | ln -snf /proc/self/fd $udev_root/fd
|
---|
74 | ln -snf /proc/self/fd/0 $udev_root/stdin
|
---|
75 | ln -snf /proc/self/fd/1 $udev_root/stdout
|
---|
76 | ln -snf /proc/self/fd/2 $udev_root/stderr
|
---|
77 | ln -snf /proc/kcore $udev_root/core
|
---|
78 |
|
---|
79 | [ -d $udev_root/pts ] || mkdir -m 0755 $udev_root/pts
|
---|
80 | [ -d $udev_root/shm ] || mkdir -m 0755 $udev_root/shm
|
---|
81 | [ -a /dev/MAKEDEV ] || ln -s $MAKEDEV /dev/MAKEDEV;
|
---|
82 |
|
---|
83 | if [ -x $MAKEDEV ]; then
|
---|
84 | for i in /etc/udev/makedev.d/*.nodes; do
|
---|
85 | if [ -f "$i" ]; then
|
---|
86 | cat "$i" | sed -e 's,#.*,,g' | \
|
---|
87 | xargs_simple -n 100 $MAKEDEV -x
|
---|
88 | fi
|
---|
89 | done
|
---|
90 | fi
|
---|
91 | for devdir in /etc/udev/devices /lib/udev/devices; do
|
---|
92 | [ -d "$devdir" ] || continue
|
---|
93 | pushd $devdir &> "$udev_root/null"
|
---|
94 | set *
|
---|
95 | if [ "$1" != "*" ]; then
|
---|
96 | cp -ar "$@" $udev_root/
|
---|
97 | pushd "$udev_root" &> "$udev_root/null"
|
---|
98 | [ -x /sbin/restorecon ] && /sbin/restorecon "$@"
|
---|
99 | popd &> "$udev_root/null"
|
---|
100 | fi
|
---|
101 | popd &> "$udev_root/null"
|
---|
102 | done
|
---|
103 | }
|
---|
104 |
|
---|
105 | kill_udevd() {
|
---|
106 | if [ -x /sbin/pidof ]; then
|
---|
107 | pid=`/sbin/pidof -x udevd`
|
---|
108 | [ -n "$pid" ] && kill $pid
|
---|
109 | fi
|
---|
110 | }
|
---|
111 |
|
---|
112 |
|
---|
113 | wait_for_queue() {
|
---|
114 | local timeout=${1:-0}
|
---|
115 | local ret=0
|
---|
116 | if [ $timeout -gt 0 ]; then
|
---|
117 | /sbin/udevsettle --timeout=$timeout
|
---|
118 | else
|
---|
119 | /sbin/udevsettle
|
---|
120 | fi
|
---|
121 | ret=$?
|
---|
122 | if [ $ret -ne 0 ]; then
|
---|
123 | echo -n "Wait timeout. Will continue in the background."
|
---|
124 | fi
|
---|
125 | return $ret;
|
---|
126 | }
|
---|
127 |
|
---|
128 | export ACTION=add
|
---|
129 | prog=udev
|
---|
130 | ret=0
|
---|
131 | STRING=$"Starting $prog: "
|
---|
132 | # propagate $udev_root from /sys
|
---|
133 | echo -n "$STRING"
|
---|
134 |
|
---|
135 | # mount the tmpfs on ${udev_root%/}, if not already done
|
---|
136 | LANG=C awk "\$2 == \"${udev_root%/}\" && \$3 == \"tmpfs\" { exit 1 }" /proc/mounts && {
|
---|
137 | if LANG=C fgrep -q "none ${udev_root%/}/pts " /proc/mounts; then
|
---|
138 | PTSDIR=$(mktemp -d)
|
---|
139 | mount --move $udev_root/pts "$PTSDIR"
|
---|
140 | fi
|
---|
141 | if LANG=C fgrep -q "none ${udev_root%/}/shm " /proc/mounts; then
|
---|
142 | SHMDIR=$(mktemp -d)
|
---|
143 | mount --move $udev_root/shm "$SHMDIR"
|
---|
144 | fi
|
---|
145 | mount -n -o mode=0755 -t tmpfs none "$udev_root"
|
---|
146 | mkdir -m 0755 $udev_root/pts
|
---|
147 | mkdir -m 0755 $udev_root/shm
|
---|
148 | if [ -n "$PTSDIR" ]; then
|
---|
149 | mount --move "$PTSDIR" $udev_root/pts
|
---|
150 | rmdir "$PTSDIR"
|
---|
151 | fi
|
---|
152 | if [ -n "$SHMDIR" ]; then
|
---|
153 | mount --move "$SHMDIR" $udev_root/shm
|
---|
154 | rmdir "$SHMDIR"
|
---|
155 | fi
|
---|
156 |
|
---|
157 | ret=$[$ret + $?]
|
---|
158 | }
|
---|
159 |
|
---|
160 | # returns OK if $1 contains $2
|
---|
161 | strstr() {
|
---|
162 | [ "${1#*$2*}" = "$1" ] && return 1
|
---|
163 | return 0
|
---|
164 | }
|
---|
165 |
|
---|
166 | getval() {
|
---|
167 | what=$1
|
---|
168 | shift
|
---|
169 | for arg; do
|
---|
170 | if strstr "$arg" "$what="; then
|
---|
171 | val=${arg#${what}=*}
|
---|
172 | echo $val
|
---|
173 | return 0
|
---|
174 | fi
|
---|
175 | done
|
---|
176 | return 1
|
---|
177 | }
|
---|
178 |
|
---|
179 |
|
---|
180 | make_extra_nodes
|
---|
181 |
|
---|
182 | kill_udevd > "$udev_root/null" 2>&1
|
---|
183 |
|
---|
184 | rm -fr /dev/.udev > "$udev_root/null" 2>&1
|
---|
185 |
|
---|
186 | cmdline=$(cat /proc/cmdline)
|
---|
187 |
|
---|
188 | if [ -f "/sys/class/tty/console/uevent" ]; then
|
---|
189 | # trigger the sorted events
|
---|
190 | echo -e '\000\000\000\000' > /proc/sys/kernel/hotplug
|
---|
191 | if strstr "$cmdline" modprobedebug; then
|
---|
192 | touch /dev/.modprobe_debug
|
---|
193 | else
|
---|
194 | rm -f /dev/.modprobe_debug
|
---|
195 | fi
|
---|
196 | /sbin/udevd -d
|
---|
197 | ret=$[$ret + $?]
|
---|
198 | if strstr "$cmdline" udevdebug; then
|
---|
199 | /sbin/udevcontrol log_priority=debug
|
---|
200 | fi
|
---|
201 | /sbin/udevtrigger
|
---|
202 | ret=$[$ret + $?]
|
---|
203 | wait_for_queue $(getval udevtimeout $cmdline)
|
---|
204 | ret=$[$ret + $?]
|
---|
205 | else
|
---|
206 | echo -n " kernel too old for this udev version "
|
---|
207 | /sbin/udevd -d
|
---|
208 | ret=10
|
---|
209 | fi
|
---|
210 |
|
---|
211 | ret=$[$ret + $?]
|
---|
212 | [ $ret -eq 0 ] && success $"$STRING" || failure $"$STRING"
|
---|
213 | echo
|
---|
214 | exit 0
|
---|