diff options
Diffstat (limited to 'meta/packages/udev/udev-089/init')
-rw-r--r-- | meta/packages/udev/udev-089/init | 227 |
1 files changed, 227 insertions, 0 deletions
diff --git a/meta/packages/udev/udev-089/init b/meta/packages/udev/udev-089/init new file mode 100644 index 0000000000..5a60d52a9a --- /dev/null +++ b/meta/packages/udev/udev-089/init | |||
@@ -0,0 +1,227 @@ | |||
1 | #!/bin/sh -e | ||
2 | ### BEGIN INIT INFO | ||
3 | # Provides: udev | ||
4 | # Required-Start: mountvirtfs | ||
5 | # Required-Stop: | ||
6 | # Default-Start: S | ||
7 | # Default-Stop: | ||
8 | # Short-Description: Start udevd, populate /dev and load drivers. | ||
9 | ### END INIT INFO | ||
10 | |||
11 | # we need to unmount /dev/pts/ and remount it later over the tmpfs | ||
12 | unmount_devpts() { | ||
13 | if mountpoint -q /dev/pts/; then | ||
14 | umount -l /dev/pts/ | ||
15 | fi | ||
16 | |||
17 | if mountpoint -q /dev/shm/; then | ||
18 | umount -l /dev/shm/ | ||
19 | fi | ||
20 | } | ||
21 | |||
22 | # mount a tmpfs over /dev, if somebody did not already do it | ||
23 | mount_tmpfs() { | ||
24 | if grep -E -q "^[^[:space:]]+ /dev tmpfs" /proc/mounts; then | ||
25 | return | ||
26 | fi | ||
27 | |||
28 | # /dev/.static/dev/ is used by MAKEDEV to access the real /dev/ directory. | ||
29 | # /etc/udev/ is recycled as a temporary mount point because it's the only | ||
30 | # directory which is guaranteed to be available. | ||
31 | mount -n -o bind /dev /etc/udev | ||
32 | |||
33 | if ! mount -n -o size=$tmpfs_size,mode=0755 -t tmpfs tmpfs /dev; then | ||
34 | umount /etc/udev | ||
35 | echo "udev requires tmpfs support, not started." | ||
36 | exit 1 | ||
37 | fi | ||
38 | |||
39 | mkdir -p /dev/.static/dev | ||
40 | chmod 700 /dev/.static/ | ||
41 | # The mount options in busybox are non-standard... | ||
42 | if test -x /bin/mount.util-linux | ||
43 | then | ||
44 | /bin/mount.util-linux --move /etc/udev /dev/.static/dev | ||
45 | elif test -x /bin/busybox | ||
46 | then | ||
47 | busybox mount -n -o move /etc/udev /dev/.static/dev | ||
48 | else | ||
49 | echo "udev requires an identifiable mount command, not started." | ||
50 | umount /etc/udev | ||
51 | umount /dev | ||
52 | exit 1 | ||
53 | fi | ||
54 | } | ||
55 | |||
56 | # I hate this hack. -- Md | ||
57 | make_extra_nodes() { | ||
58 | if [ "$(echo /lib/udev/devices/*)" != "/lib/udev/devices/*" ]; then | ||
59 | cp -a /lib/udev/devices/* /dev/ | ||
60 | fi | ||
61 | |||
62 | [ -e /etc/udev/links.conf ] || return 0 | ||
63 | grep '^[^#]' /etc/udev/links.conf | \ | ||
64 | while read type name arg1; do | ||
65 | [ "$type" -a "$name" -a ! -e "/dev/$name" -a ! -L "/dev/$name" ] ||continue | ||
66 | case "$type" in | ||
67 | L) ln -s $arg1 /dev/$name ;; | ||
68 | D) mkdir -p /dev/$name ;; | ||
69 | M) mknod -m 600 /dev/$name $arg1 ;; | ||
70 | *) echo "links.conf: unparseable line ($type $name $arg1)" ;; | ||
71 | esac | ||
72 | done | ||
73 | } | ||
74 | |||
75 | supported_kernel() { | ||
76 | case "$(uname -r)" in | ||
77 | 2.[012345].*|2.6.[0-9]|2.6.[0-9][!0-9]*) return 1 ;; | ||
78 | 2.6.1[01]|2.6.1[01][!0-9]*) return 1 ;; | ||
79 | esac | ||
80 | return 0 | ||
81 | } | ||
82 | |||
83 | set_hotplug_handler() { | ||
84 | case "$(uname -r)" in | ||
85 | 2.6.1[0-4]|2.6.1[0-4][!0-9]*) HANDLER='/sbin/udevsend' ;; | ||
86 | esac | ||
87 | echo $HANDLER > /proc/sys/kernel/hotplug | ||
88 | } | ||
89 | |||
90 | # shell version of /usr/bin/tty | ||
91 | my_tty() { | ||
92 | [ -x /bin/readlink ] || return 0 | ||
93 | [ -e /proc/self/fd/0 ] || return 0 | ||
94 | readlink --silent /proc/self/fd/0 || true | ||
95 | } | ||
96 | |||
97 | warn_if_interactive() { | ||
98 | if [ "$RUNLEVEL" = "S" -a "$PREVLEVEL" = "N" ]; then | ||
99 | return | ||
100 | fi | ||
101 | |||
102 | TTY=$(my_tty) | ||
103 | if [ -z "$TTY" -o "$TTY" = "/dev/console" ]; then | ||
104 | return | ||
105 | fi | ||
106 | |||
107 | printf "\n\n\nIt has been detected that the command\n\n\t$0 $*\n\n" | ||
108 | printf "has been run from an interactive shell.\n" | ||
109 | printf "It will probably not do what you expect, so this script will wait\n" | ||
110 | printf "60 seconds before continuing. Press ^C to stop it.\n" | ||
111 | printf "RUNNING THIS COMMAND IS HIGHLY DISCOURAGED!\n\n\n\n" | ||
112 | sleep 60 | ||
113 | } | ||
114 | |||
115 | ############################################################################## | ||
116 | |||
117 | PATH="/sbin:/bin:/usr/bin" | ||
118 | |||
119 | [ -x /sbin/udevd ] || exit 0 | ||
120 | |||
121 | # defaults | ||
122 | tmpfs_size="10M" | ||
123 | udev_root="/dev" | ||
124 | udevd_timeout=30 | ||
125 | |||
126 | . /etc/udev/udev.conf | ||
127 | |||
128 | if ! supported_kernel; then | ||
129 | echo "udev requires a kernel >= 2.6.12, not started." | ||
130 | exit 1 | ||
131 | fi | ||
132 | |||
133 | if [ ! -e /proc/filesystems ]; then | ||
134 | echo "udev requires a mounted procfs, not started." | ||
135 | exit 1 | ||
136 | fi | ||
137 | |||
138 | if ! grep -q '[[:space:]]tmpfs$' /proc/filesystems; then | ||
139 | echo "udev requires tmpfs support, not started." | ||
140 | exit 1 | ||
141 | fi | ||
142 | |||
143 | if [ ! -d /sys/class/ ]; then | ||
144 | echo "udev requires a mounted sysfs, not started." | ||
145 | exit 1 | ||
146 | fi | ||
147 | |||
148 | if [ ! -e /proc/sys/kernel/hotplug ]; then | ||
149 | echo "udev requires hotplug support, not started." | ||
150 | exit 1 | ||
151 | fi | ||
152 | |||
153 | ############################################################################## | ||
154 | |||
155 | # When modifying this script, do not forget that between the time that | ||
156 | # the new /dev has been mounted and udevsynthesize has been run there will be | ||
157 | # no /dev/null. This also means that you cannot use the "&" shell command. | ||
158 | |||
159 | case "$1" in | ||
160 | start) | ||
161 | if [ -e "$udev_root/.udev/" ]; then | ||
162 | if mountpoint -q /dev/; then | ||
163 | TMPFS_MOUNTED=1 | ||
164 | else | ||
165 | echo ".udev/ already exists on the static $udev_root!" | ||
166 | fi | ||
167 | else | ||
168 | warn_if_interactive | ||
169 | fi | ||
170 | |||
171 | echo "Starting the hotplug events dispatcher" "udevd" | ||
172 | udevd --daemon | ||
173 | |||
174 | set_hotplug_handler | ||
175 | |||
176 | if [ -z "$TMPFS_MOUNTED" ]; then | ||
177 | unmount_devpts | ||
178 | mount_tmpfs | ||
179 | [ -d /proc/1 ] || mount -n /proc | ||
180 | fi | ||
181 | |||
182 | # if this directory is not present /dev will not be updated by udev | ||
183 | mkdir -p /dev/.udev/ /dev/.udev/db/ /dev/.udev/queue/ /dev/.udevdb/ | ||
184 | # /dev/null must be created before udevd is started | ||
185 | make_extra_nodes | ||
186 | |||
187 | echo "Synthesizing the initial hotplug events" | ||
188 | udevsynthesize | ||
189 | |||
190 | # wait for the udevd childs to finish | ||
191 | echo "Waiting for /dev to be fully populated" | ||
192 | while [ -d /dev/.udev/queue/ ]; do | ||
193 | sleep 1 | ||
194 | udevd_timeout=$(($udevd_timeout - 1)) | ||
195 | if [ $udevd_timeout -eq 0 ]; then | ||
196 | # ps axf | ||
197 | break | ||
198 | fi | ||
199 | done | ||
200 | if [ $udevd_timeout -eq 0 ]; then | ||
201 | echo 'timeout' | ||
202 | fi | ||
203 | ;; | ||
204 | |||
205 | stop) | ||
206 | echo "Stopping the hotplug events dispatcher" "udevd" | ||
207 | start-stop-daemon --stop --name udevd --quiet | ||
208 | ;; | ||
209 | |||
210 | restart|force-reload) | ||
211 | echo "Stopping the hotplug events dispatcher" "udevd" | ||
212 | if start-stop-daemon --stop --name udevd --quiet ; then | ||
213 | exit 1 | ||
214 | fi | ||
215 | |||
216 | echo "Starting the hotplug events dispatcher" "udevd" | ||
217 | udevd --daemon | ||
218 | ;; | ||
219 | |||
220 | *) | ||
221 | echo "Usage: /etc/init.d/udev {start|stop|restart|force-reload}" | ||
222 | exit 1 | ||
223 | ;; | ||
224 | esac | ||
225 | |||
226 | exit 0 | ||
227 | |||