summaryrefslogtreecommitdiffstats
path: root/meta-oe/recipes-core/udev/udev/init
diff options
context:
space:
mode:
Diffstat (limited to 'meta-oe/recipes-core/udev/udev/init')
-rw-r--r--[-rwxr-xr-x]meta-oe/recipes-core/udev/udev/init265
1 files changed, 64 insertions, 201 deletions
diff --git a/meta-oe/recipes-core/udev/udev/init b/meta-oe/recipes-core/udev/udev/init
index a13b9afcd..c0ecdfc50 100755..100644
--- a/meta-oe/recipes-core/udev/udev/init
+++ b/meta-oe/recipes-core/udev/udev/init
@@ -1,212 +1,75 @@
1#!/bin/sh 1#!/bin/sh -e
2 2
3UDEVSTART=/sbin/udevstart 3### BEGIN INIT INFO
4 4# Provides: udev
5# defaults 5# Required-Start: mountvirtfs
6tmpfs_size="2M" 6# Required-Stop:
7udev_root="/dev" 7# Default-Start: S
8 8# Default-Stop:
9[ -x $UDEVSTART ] || exit 0 9# Short-Description: Start udevd, populate /dev and load drivers.
10 10### END INIT INFO
11. /etc/udev/udev.conf 11
12 12export TZ=/etc/localtime
13############################################################################## 13
14 14[ -d /sys/class ] || exit 1
15# we need to unmount /dev/pts/ and remount it later over the tmpfs 15[ -r /proc/mounts ] || exit 1
16unmount_devpts() { 16[ -x /sbin/udevd ] || exit 1
17 if mountpoint -q /dev/pts/; then 17[ -f /etc/default/udev ] && . /etc/default/udev
18 umount -l /dev/pts/ 18[ -f /etc/udev/udev.conf ] && . /etc/udev/udev.conf
19 fi 19
20 20kill_udevd() {
21 if mountpoint -q /dev/shm/; then 21 if [ -x /sbin/pidof ]; then
22 umount -l /dev/shm/ 22 pid=`/sbin/pidof -x udevd`
23 fi 23 [ -n "$pid" ] && kill $pid
24} 24 fi
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} 25}
84 26
85# this function is duplicated in preinst, postinst and d-i 27export ACTION=add
86supported_kernel() { 28# propagate /dev from /sys
87 case "$(uname -r)" in 29echo "Starting udev"
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 30
94# shell version of /usr/bin/tty 31# mount the tmpfs on /dev, if not already done
95my_tty() { 32LANG=C awk "\$2 == \"/dev\" && \$3 == \"tmpfs\" { exit 1 }" /proc/mounts && {
96 [ -x /bin/readlink ] || return 0 33 mount -n -o mode=0755 -t tmpfs none "/dev"
97 [ -e /proc/self/fd/0 ] || return 0 34 mkdir -m 0755 /dev/pts
98 readlink --silent /proc/self/fd/0 || true 35 mkdir -m 1777 /dev/shm
99} 36}
100 37
101warn_if_interactive() { 38if [ "$DEVCACHE" != "" ]; then
102 if [ "$RUNLEVEL" = "S" -a "$PREVLEVEL" = "N" ]; then 39 # Invalidate udev cache if the kernel or its bootargs/cmdline have changed
103 return 0 40 [ -x /bin/uname ] && /bin/uname -mrspv > /tmp/uname || touch /tmp/uname
104 fi 41 [ -r /proc/cmdline ] && cat /proc/cmdline > /tmp/cmdline || touch /tmp/cmdline
105 42 [ -r /proc/devices ] && cat /proc/devices > /tmp/devices || touch /tmp/devices
106 TTY=$(my_tty) 43 [ -r /proc/atags ] && cat /proc/atags > /tmp/atags || touch /tmp/atags
107 if [ -z "$TTY" -o "$TTY" = "/dev/console" ]; then 44 if [ -e $DEVCACHE ] && \
108 return 0 45 cmp -s /tmp/uname /etc/udev/saved.uname && \
109 fi 46 cmp -s /tmp/cmdline /etc/udev/saved.cmdline && \
110 47 cmp -s /tmp/devices /etc/udev/saved.devices && \
111 printf "\n\n\nIt has been detected that the command\n\n\t$0 $*\n\n" 48 cmp -s /tmp/atags /etc/udev/saved.atags; then
112 printf "has been run from an interactive shell.\n" 49 (cd /; tar xf $DEVCACHE > /dev/null 2>&1)
113 printf "It will probably not do what you expect, so this script will wait\n" 50 not_first_boot=1
114 printf "60 seconds before continuing. Press ^C to stop it.\n" 51 fi
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 52fi
130 53
131if ! grep -q '[[:space:]]tmpfs$' /proc/filesystems; then 54if [ ! -e "/lib/modules/$(uname -r)"/modules.dep ] ; then
132 echo "udev requires tmpfs support, not started." 55 mkdir -p /lib/modules/$(uname -r)
133 exit 1 56 depmod -ae
134fi 57fi
135 58
136if [ ! -d /sys/class/ ]; then 59# make_extra_nodes
137 echo "udev requires a mounted sysfs, not started." 60kill_udevd > "/dev/null" 2>&1
138 exit 1 61
139fi 62 # trigger the sorted events
140 63 echo -e '\000\000\000\000' > /proc/sys/kernel/hotplug
141if [ ! -e /proc/sys/kernel/hotplug ] && [ ! -e /sys/kernel/uevent_helper ]; then 64 /sbin/udevd -d
142 echo "udev requires hotplug support, not started." 65
143 exit 1 66 /sbin/udevadm control --env STARTUP=1
144fi 67 if [ "$not_first_boot" != "" ];then
145 68 /sbin/udevadm trigger --subsystem-nomatch=tty --subsystem-nomatch=mem --subsystem-nomatch=vc --subsystem-nomatch=vtconsole --subsystem-nomatch=misc --subsystem-nomatch=dcon --subsystem-nomatch=pci_bus --subsystem-nomatch=graphics --subsystem-nomatch=backlight --subsystem-nomatch=video4linux --subsystem-nomatch=platform
146############################################################################## 69 (/sbin/udevadm settle --timeout=8; /sbin/udevadm control --env STARTUP=)&
147 70 else
148# When modifying this script, do not forget that between the time that 71 /sbin/udevadm trigger
149# the new /dev has been mounted and udevstart has been run there will be 72 /sbin/udevadm settle
150# no /dev/null. This also means that you cannot use the "&" shell command. 73 fi
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 74
212exit 0 75exit 0