summaryrefslogtreecommitdiffstats
path: root/meta/recipes-core/udev/files/init
diff options
context:
space:
mode:
Diffstat (limited to 'meta/recipes-core/udev/files/init')
-rwxr-xr-xmeta/recipes-core/udev/files/init212
1 files changed, 212 insertions, 0 deletions
diff --git a/meta/recipes-core/udev/files/init b/meta/recipes-core/udev/files/init
new file mode 100755
index 0000000000..8cbab188f0
--- /dev/null
+++ b/meta/recipes-core/udev/files/init
@@ -0,0 +1,212 @@
1#!/bin/sh -e
2
3UDEVSTART=/sbin/udevstart
4
5# defaults
6tmpfs_size="10M"
7udev_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
16unmount_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
27mount_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
71make_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
86supported_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
95my_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
101warn_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
121if ! supported_kernel; then
122 echo "udev requires a kernel >= 2.6.12, not started."
123 exit 1
124fi
125
126if [ ! -e /proc/filesystems ]; then
127 echo "udev requires a mounted procfs, not started."
128 exit 1
129fi
130
131if ! grep -q '[[:space:]]tmpfs$' /proc/filesystems; then
132 echo "udev requires tmpfs support, not started."
133 exit 1
134fi
135
136if [ ! -d /sys/class/ ]; then
137 echo "udev requires a mounted sysfs, not started."
138 exit 1
139fi
140
141if [ ! -e /proc/sys/kernel/hotplug ] && [ ! -e /sys/kernel/uevent_helper ]; then
142 echo "udev requires hotplug support, not started."
143 exit 1
144fi
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
152case "$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 if [ -e /sys/kernel/uevent_helper ] ; then
165 echo "" > /sys/kernel/uevent_helper
166 else
167 echo "" > /proc/sys/kernel/hotplug
168 fi
169 udevsend
170 if [ "$UDEV_DISABLED" = "yes" ]; then
171 echo "udev disabled on the kernel command line, not started."
172 exit 0
173 fi
174
175 if [ ! "$TMPFS_MOUNTED" ]; then
176 unmount_devpts
177 mount_tmpfs
178 [ -d /proc/1 ] || mount -n /proc
179 # if this directory is not present /dev will not be updated by udev
180 mkdir /dev/.udevdb/
181 echo "Creating initial device nodes..."
182 udevstart
183 fi
184 make_extra_nodes
185 ;;
186 stop)
187 warn_if_interactive
188 start-stop-daemon --stop --exec /sbin/udevd --quiet
189 unmount_devpts
190 if [ -d /dev/.static/dev/ ]; then
191 umount -l /dev/.static/dev/ || true
192 fi
193 echo "Unmounting /dev..."
194 # unmounting with -l should never fail
195 if ! umount -l /dev; then
196 exit 1
197 fi
198 ;;
199 restart|force-reload)
200 start-stop-daemon --stop --exec /sbin/udevd --quiet
201 log_begin_msg "Recreating device nodes..."
202 udevstart
203 make_extra_nodes
204 log_end_msg 0
205 ;;
206 *)
207 echo "Usage: /etc/init.d/udev {start|stop|restart|force-reload}"
208 exit 1
209 ;;
210esac
211
212exit 0