blob: 0ab028b391eb3e75243f963d2384ed1e479c7ed1 [file] [log] [blame]
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001#!/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
17SYSCONF_CACHED="/etc/udev/cache.data"
18SYSCONF_TMP="/dev/shm/udev.cache"
19DEVCACHE_REGEN="/dev/shm/udev-regen" # create to request cache regen
20
21# A list of files which are used as a criteria to judge whether the udev cache could be reused.
22CMP_FILE_LIST="/proc/version /proc/cmdline /proc/devices"
23[ -f /proc/atags ] && CMP_FILE_LIST="$CMP_FILE_LIST /proc/atags"
24
25# List of files whose metadata (size/mtime/name) will be included in cached
26# system state.
27META_FILE_LIST="lib/udev/rules.d/* etc/udev/rules.d/*"
28
29# Command to compute system configuration.
30sysconf_cmd () {
31 cat -- $CMP_FILE_LIST
32 stat -c '%s %Y %n' -- $META_FILE_LIST | awk -F/ '{print $1 " " $NF;}'
33}
34
35[ -f /etc/default/udev-cache ] && . /etc/default/udev-cache
36[ -f /etc/udev/udev.conf ] && . /etc/udev/udev.conf
37[ -f /etc/default/rcS ] && . /etc/default/rcS
38
39kill_udevd () {
40 pid=`pidof -x udevd`
41 [ -n "$pid" ] && kill $pid
42}
43
44case "$1" in
45 start)
46 export ACTION=add
47 # propagate /dev from /sys
48 echo "Starting udev"
49
50 # Check for requireed devtmpfs before trying to start udev and
51 # mount a no-existant fs.
52 if ! grep -q devtmpfs /proc/filesystems
53 then
54 echo "Missing devtmpfs, which is required for udev to run";
55 echo "Halting..."
56 halt
57 fi
58 # mount the devtmpfs on /dev, if not already done
59 LANG=C awk '$2 == "/dev" && ($3 == "devtmpfs") { exit 1 }' /proc/mounts && {
60 mount -n -o mode=0755 -t devtmpfs none "/dev"
61 }
62 [ -e /dev/pts ] || mkdir -m 0755 /dev/pts
63 [ -e /dev/shm ] || mkdir -m 1777 /dev/shm
64 # the automount rule for udev needs /tmp directory available, as /tmp is a symlink
65 # to /var/tmp which in turn is a symlink to /var/volatile/tmp, we need to make sure
66 # /var/volatile/tmp directory to be available.
67 mkdir -m 1777 -p /var/volatile/tmp
68
69 # Cache handling.
70 if [ "$DEVCACHE" != "" ]; then
71 if [ -e $DEVCACHE ]; then
72 sysconf_cmd > "$SYSCONF_TMP"
73 if cmp $SYSCONF_CACHED $SYSCONF_TMP >/dev/null; then
74 tar xmf $DEVCACHE -C / -m
75 not_first_boot=1
76 [ "$VERBOSE" != "no" ] && echo "udev: using cache file $DEVCACHE"
77 [ -e $SYSCONF_TMP ] && rm -f "$SYSCONF_TMP"
78 [ -e "$DEVCACHE_REGEN" ] && rm -f "$DEVCACHE_REGEN"
79 else
80 # Output detailed reason why the cached /dev is not used
81 cat <<EOF
82udev: Not using udev cache because of changes detected in the following files:
83udev: $CMP_FILE_LIST
84udev: $META_FILE_LIST
85udev: The udev cache will be regenerated. To identify the detected changes,
86udev: compare the cached sysconf at $SYSCONF_CACHED
87udev: against the current sysconf at $SYSCONF_TMP
88EOF
89 touch "$DEVCACHE_REGEN"
90 fi
91 else
92 if [ "$ROOTFS_READ_ONLY" != "yes" ]; then
93 # If rootfs is not read-only, it's possible that a new udev cache would be generated;
94 # otherwise, we do not bother to read files.
95 touch "$DEVCACHE_REGEN"
96 fi
97 fi
98 fi
99
100 # make_extra_nodes
101 kill_udevd > "/dev/null" 2>&1
102
103 # trigger the sorted events
104 [ -e /proc/sys/kernel/hotplug ] && echo -e '\000' >/proc/sys/kernel/hotplug
105 @UDEVD@ -d
106
107 udevadm control --env=STARTUP=1
108 if [ "$not_first_boot" != "" ];then
109 if [ "$PROBE_PLATFORM_BUS" != "yes" ]; then
110 PLATFORM_BUS_NOMATCH="--subsystem-nomatch=platform"
111 else
112 PLATFORM_BUS_NOMATCH=""
113 fi
114 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 $PLATFORM_BUS_NOMATCH
115 (udevadm settle --timeout=3; udevadm control --env=STARTUP=)&
116 else
117 udevadm trigger --action=add
118 udevadm settle
119 fi
120 ;;
121 stop)
122 echo "Stopping udevd"
123 start-stop-daemon --stop --name udevd --quiet
124 ;;
125 restart)
126 $0 stop
127 sleep 1
128 $0 start
129 ;;
130 status)
131 pid=`pidof -x udevd`
132 if [ -n "$pid" ]; then
133 echo "udevd (pid $pid) is running ..."
134 else
135 echo "udevd is stopped"
136 fi
137 ;;
138 *)
139 echo "Usage: $0 {start|stop|status|restart}"
140 exit 1
141esac
142exit 0