1 | #!/bin/sh
|
---|
2 | #
|
---|
3 | # start_udev
|
---|
4 | # modified by victor, added some pushd and popd
|
---|
5 | # for no space left on device bug
|
---|
6 | #
|
---|
7 | # script to initialize /dev by using udev.
|
---|
8 | #
|
---|
9 | # Copyright (C) 2004 Greg Kroah-Hartman <greg@kroah.com>
|
---|
10 | #
|
---|
11 | # Released under the GPL v2 only.
|
---|
12 | #
|
---|
13 | # This needs to be run at the earliest possible point in the boot
|
---|
14 | # process.
|
---|
15 | #
|
---|
16 | # Based on the udev init.d script
|
---|
17 | #
|
---|
18 | # Thanks go out to the Gentoo developers for proving
|
---|
19 | # that this is possible to do.
|
---|
20 | #
|
---|
21 | # Yes, it's very verbose, feel free to turn off all of the echo calls,
|
---|
22 | # they were there to make me feel better that everything was working
|
---|
23 | # properly during development...
|
---|
24 | #
|
---|
25 | # don't use udev if sysfs is not mounted.
|
---|
26 |
|
---|
27 | sysfs_dir=/sys
|
---|
28 |
|
---|
29 | export TZ=/etc/localtime
|
---|
30 |
|
---|
31 | [ -d $sysfs_dir/class ] || exit 1
|
---|
32 | [ -r /proc/mounts ] || exit 1
|
---|
33 | [ -x /sbin/udevd ] || exit 1
|
---|
34 | [ -f /etc/udev/udev.conf ] && . /etc/udev/udev.conf
|
---|
35 | udev_root=${udev_root-/dev}
|
---|
36 |
|
---|
37 |
|
---|
38 | . /etc/init.d/functions
|
---|
39 |
|
---|
40 | umask 0022
|
---|
41 |
|
---|
42 | prog=udev
|
---|
43 | bin=/sbin/udev
|
---|
44 | udevd=/sbin/udevd
|
---|
45 | MAKEDEV="/sbin/MAKEDEV"
|
---|
46 |
|
---|
47 | xargs_simple () {
|
---|
48 | if [ "$1" = "-n" ]; then
|
---|
49 | shift
|
---|
50 | MAXNR="$1"
|
---|
51 | shift
|
---|
52 | else
|
---|
53 | MAXNR=100
|
---|
54 | fi
|
---|
55 | NR=$MAXNR
|
---|
56 | ARGS=""
|
---|
57 | [ -z "$1" ] && set echo
|
---|
58 |
|
---|
59 | while read line; do
|
---|
60 | if [ $NR -gt 0 ]; then
|
---|
61 | ARGS="$ARGS $line"
|
---|
62 | NR=$[$NR - 1]
|
---|
63 | else
|
---|
64 | "$@" $ARGS
|
---|
65 | NR=$MAXNR
|
---|
66 | ARGS="$line"
|
---|
67 | fi
|
---|
68 | done
|
---|
69 | if [ -n "$ARGS" ]; then
|
---|
70 | "$@" $ARGS
|
---|
71 | fi
|
---|
72 | }
|
---|
73 |
|
---|
74 | make_extra_nodes () {
|
---|
75 | ln -snf /proc/self/fd $udev_root/fd
|
---|
76 | ln -snf /proc/self/fd/0 $udev_root/stdin
|
---|
77 | ln -snf /proc/self/fd/1 $udev_root/stdout
|
---|
78 | ln -snf /proc/self/fd/2 $udev_root/stderr
|
---|
79 | ln -snf /proc/kcore $udev_root/core
|
---|
80 |
|
---|
81 | [ -d $udev_root/pts ] || mkdir -m 0755 $udev_root/pts
|
---|
82 | [ -d $udev_root/shm ] || mkdir -m 0755 $udev_root/shm
|
---|
83 | [ -a /dev/MAKEDEV ] || ln -s $MAKEDEV /dev/MAKEDEV;
|
---|
84 |
|
---|
85 | if [ -x $MAKEDEV ]; then
|
---|
86 | for i in /etc/udev/makedev.d/*.nodes; do
|
---|
87 | if [ -f "$i" ]; then
|
---|
88 | cat "$i" | sed -e 's,#.*,,g' | \
|
---|
89 | xargs_simple -n 100 $MAKEDEV -x
|
---|
90 | fi
|
---|
91 | done
|
---|
92 | fi
|
---|
93 | for devdir in /etc/udev/devices /lib/udev/devices; do
|
---|
94 | [ -d "$devdir" ] || continue
|
---|
95 | pushd / &> "$udev_root/null"
|
---|
96 | pushd $devdir &> "$udev_root/null"
|
---|
97 | set *
|
---|
98 | if [ "$1" != "*" ]; then
|
---|
99 | cp -ar "$@" $udev_root/
|
---|
100 | pushd "$udev_root" &> "$udev_root/null"
|
---|
101 | [ -x /sbin/restorecon ] && /sbin/restorecon "$@"
|
---|
102 | popd &> "$udev_root/null"
|
---|
103 | fi
|
---|
104 | popd &> "$udev_root/null"
|
---|
105 | popd &> "$udev_root/null"
|
---|
106 | done
|
---|
107 | }
|
---|
108 |
|
---|
109 | kill_udevd() {
|
---|
110 | if [ -x /sbin/pidof ]; then
|
---|
111 | pid=`/sbin/pidof -x udevd`
|
---|
112 | [ -n "$pid" ] && kill $pid
|
---|
113 | fi
|
---|
114 | }
|
---|
115 |
|
---|
116 |
|
---|
117 | wait_for_queue() {
|
---|
118 | local timeout=${1:-0}
|
---|
119 | local ret=0
|
---|
120 | if [ $timeout -gt 0 ]; then
|
---|
121 | /sbin/udevsettle --timeout=$timeout
|
---|
122 | else
|
---|
123 | /sbin/udevsettle
|
---|
124 | fi
|
---|
125 | ret=$?
|
---|
126 | if [ $ret -ne 0 ]; then
|
---|
127 | echo -n "Wait timeout. Will continue in the background."
|
---|
128 | fi
|
---|
129 | return $ret;
|
---|
130 | }
|
---|
131 |
|
---|
132 | export ACTION=add
|
---|
133 | prog=udev
|
---|
134 | ret=0
|
---|
135 | STRING=$"Starting $prog: "
|
---|
136 | # propagate $udev_root from /sys
|
---|
137 | echo -n "$STRING"
|
---|
138 |
|
---|
139 | # mount the tmpfs on ${udev_root%/}, if not already done
|
---|
140 | LANG=C awk "\$2 == \"${udev_root%/}\" && ( \$3 == \"devtmpfs\" || \$3 == \"tmpfs\" ) { exit 1 }" /proc/mounts && {
|
---|
141 | if LANG=C fgrep -q "none ${udev_root%/}/pts " /proc/mounts; then
|
---|
142 | PTSDIR=$(mktemp -d)
|
---|
143 | mount --move $udev_root/pts "$PTSDIR"
|
---|
144 | fi
|
---|
145 | if LANG=C fgrep -q "none ${udev_root%/}/shm " /proc/mounts; then
|
---|
146 | SHMDIR=$(mktemp -d)
|
---|
147 | mount --move $udev_root/shm "$SHMDIR"
|
---|
148 | fi
|
---|
149 | # First try to mount a devtmpfs on $udev_root
|
---|
150 | mount -n -o mode=0755 -t devtmpfs none "$udev_root" 2>/dev/null \
|
---|
151 | || mount -n -o mode=0755 -t tmpfs none "$udev_root"
|
---|
152 | mkdir -m 0755 $udev_root/pts
|
---|
153 | mkdir -m 0755 $udev_root/shm
|
---|
154 | if [ -n "$PTSDIR" ]; then
|
---|
155 | mount --move "$PTSDIR" $udev_root/pts
|
---|
156 | rmdir "$PTSDIR"
|
---|
157 | fi
|
---|
158 | if [ -n "$SHMDIR" ]; then
|
---|
159 | mount --move "$SHMDIR" $udev_root/shm
|
---|
160 | rmdir "$SHMDIR"
|
---|
161 | fi
|
---|
162 |
|
---|
163 | ret=$[$ret + $?]
|
---|
164 | }
|
---|
165 |
|
---|
166 | # returns OK if $1 contains $2
|
---|
167 | strstr() {
|
---|
168 | [ "${1#*$2*}" = "$1" ] && return 1
|
---|
169 | return 0
|
---|
170 | }
|
---|
171 |
|
---|
172 | getval() {
|
---|
173 | what=$1
|
---|
174 | shift
|
---|
175 | for arg; do
|
---|
176 | if strstr "$arg" "$what="; then
|
---|
177 | val=${arg#${what}=*}
|
---|
178 | echo $val
|
---|
179 | return 0
|
---|
180 | fi
|
---|
181 | done
|
---|
182 | return 1
|
---|
183 | }
|
---|
184 |
|
---|
185 |
|
---|
186 | make_extra_nodes
|
---|
187 |
|
---|
188 | kill_udevd > "$udev_root/null" 2>&1
|
---|
189 |
|
---|
190 | rm -fr /dev/.udev > "$udev_root/null" 2>&1
|
---|
191 |
|
---|
192 | cmdline=$(cat /proc/cmdline)
|
---|
193 |
|
---|
194 | if [ -f "/sys/class/tty/console/uevent" ]; then
|
---|
195 | # trigger the sorted events
|
---|
196 | echo -e '\000\000\000\000' > /proc/sys/kernel/hotplug
|
---|
197 | if strstr "$cmdline" modprobedebug; then
|
---|
198 | touch /dev/.modprobe_debug
|
---|
199 | else
|
---|
200 | rm -f /dev/.modprobe_debug
|
---|
201 | fi
|
---|
202 | /sbin/udevd -d
|
---|
203 | ret=$[$ret + $?]
|
---|
204 | if strstr "$cmdline" udevdebug; then
|
---|
205 | /sbin/udevcontrol log_priority=debug
|
---|
206 | fi
|
---|
207 | /sbin/udevtrigger
|
---|
208 | ret=$[$ret + $?]
|
---|
209 | wait_for_queue $(getval udevtimeout $cmdline)
|
---|
210 | ret=$[$ret + $?]
|
---|
211 | else
|
---|
212 | echo -n " kernel too old for this udev version "
|
---|
213 | /sbin/udevd -d
|
---|
214 | ret=10
|
---|
215 | fi
|
---|
216 |
|
---|
217 | ret=$[$ret + $?]
|
---|
218 | [ $ret -eq 0 ] && success $"$STRING" || failure $"$STRING"
|
---|
219 | echo
|
---|
220 | exit 0
|
---|