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