summaryrefslogtreecommitdiffstats
path: root/meta/recipes-core/udev/udev/init
diff options
context:
space:
mode:
Diffstat (limited to 'meta/recipes-core/udev/udev/init')
-rw-r--r--meta/recipes-core/udev/udev/init131
1 files changed, 131 insertions, 0 deletions
diff --git a/meta/recipes-core/udev/udev/init b/meta/recipes-core/udev/udev/init
new file mode 100644
index 0000000000..e048a171da
--- /dev/null
+++ b/meta/recipes-core/udev/udev/init
@@ -0,0 +1,131 @@
1#!/bin/sh
2
3### BEGIN INIT INFO
4# Provides: udev
5# Required-Start: mountvirtfs
6# Required-Stop:
7# Default-Start: S
8# Default-Stop:
9# Short-Description: Start udevd, populate /dev and load drivers.
10### END INIT INFO
11
12export TZ=/etc/localtime
13
14[ -d /sys/class ] || exit 1
15[ -r /proc/mounts ] || exit 1
16[ -x @UDEVD@ ] || exit 1
17[ -f /etc/default/udev-cache ] && . /etc/default/udev-cache
18[ -f /etc/udev/udev.conf ] && . /etc/udev/udev.conf
19[ -f /etc/default/rcS ] && . /etc/default/rcS
20
21readfiles () {
22 READDATA=""
23 for filename in $@; do
24 if [ -r $filename ]; then
25 while read line; do
26 READDATA="$READDATA$line"
27 done < $filename
28 fi
29 done
30}
31
32kill_udevd () {
33 pid=`pidof -x udevd`
34 [ -n "$pid" ] && kill $pid
35}
36
37case "$1" in
38 start)
39 export ACTION=add
40 # propagate /dev from /sys
41 echo "Starting udev"
42
43 # Check for requireed devtmpfs before trying to start udev and
44 # mount a no-existant fs.
45 if ! grep -q devtmpfs /proc/filesystems
46 then
47 echo "Missing devtmpfs, which is required for udev to run";
48 echo "Halting..."
49 halt
50 fi
51 # mount the devtmpfs on /dev, if not already done
52 LANG=C awk '$2 == "/dev" && ($3 == "devtmpfs") { exit 1 }' /proc/mounts && {
53 mount -n -o mode=0755 -t devtmpfs none "/dev"
54 }
55 [ -e /dev/pts ] || mkdir -m 0755 /dev/pts
56 [ -e /dev/shm ] || mkdir -m 1777 /dev/shm
57 mount -a -t tmpfs 2>/dev/null
58 mkdir -p /var/volatile/tmp
59
60 # Cache handling.
61 # A list of files which are used as a criteria to judge whether the udev cache could be reused.
62 CMP_FILE_LIST="/proc/version /proc/cmdline /proc/devices /proc/atags"
63 if [ "$DEVCACHE" != "" ]; then
64 if [ -e $DEVCACHE ]; then
65 readfiles $CMP_FILE_LIST
66 NEWDATA="$READDATA"
67 readfiles /etc/udev/cache.data
68 OLDDATA="$READDATA"
69 if [ "$OLDDATA" = "$NEWDATA" ]; then
70 (cd /; tar xf $DEVCACHE > /dev/null 2>&1)
71 not_first_boot=1
72 [ "$VERBOSE" != "no" ] && echo "udev: using cache file $DEVCACHE"
73 [ -e /dev/shm/udev.cache ] && rm -f /dev/shm/udev.cache
74 else
75 # Output detailed reason why the cached /dev is not used
76 if [ "$VERBOSE" != "no" ]; then
77 echo "udev: udev cache not used"
78 echo "udev: we use $CMP_FILE_LIST as criteria to judge whether the cache /dev could be resued"
79 echo "udev: olddata: $OLDDATA"
80 echo "udev: newdata: $NEWDATA"
81 fi
82 echo "$NEWDATA" > /dev/shm/udev.cache
83 fi
84 else
85 if [ "$ROOTFS_READ_ONLY" != "yes" ]; then
86 # If rootfs is not read-only, it's possible that a new udev cache would be generated;
87 # otherwise, we do not bother to read files.
88 readfiles $CMP_FILE_LIST
89 echo "$READDATA" > /dev/shm/udev.cache
90 fi
91 fi
92 fi
93
94 # make_extra_nodes
95 kill_udevd > "/dev/null" 2>&1
96
97 # trigger the sorted events
98 echo -e '\000\000\000\000' > /proc/sys/kernel/hotplug
99 @UDEVD@ -d
100
101 udevadm control --env=STARTUP=1
102 if [ "$not_first_boot" != "" ];then
103 udevadm trigger --action=add --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
104 (udevadm settle --timeout=3; udevadm control --env=STARTUP=)&
105 else
106 udevadm trigger --action=add
107 udevadm settle
108 fi
109 ;;
110 stop)
111 echo "Stopping udevd"
112 start-stop-daemon --stop --name udevd --quiet
113 ;;
114 restart)
115 $0 stop
116 sleep 1
117 $0 start
118 ;;
119 status)
120 pid=`pidof -x udevd`
121 if [ -n "$pid" ]; then
122 echo "udevd (pid $pid) is running ..."
123 else
124 echo "udevd is stopped"
125 fi
126 ;;
127 *)
128 echo "Usage: $0 {start|stop|status|restart}"
129 exit 1
130esac
131exit 0