update proxy drivers and utils
[vuplus_openvuplus_3.0] / meta-openvuplus / recipes-core / udev / udev-124 / init
1 #!/bin/sh -e
2 ### BEGIN INIT INFO
3 # Provides:          udev
4 # Required-Start:    mountkernfs
5 # Required-Stop:
6 # Default-Start:     S
7 # Default-Stop:
8 # Short-Description: Start udevd, populate /dev and load drivers.
9 ### END INIT INFO
10
11 # This script is based on Debian's.
12
13 COLDPLUG=no
14 COLDPLUG_TARBALL="/lib/udev/devices.tar.gz"
15
16 for x in $(cat /proc/cmdline); do
17         case $x in
18         coldplug)
19                 COLDPLUG=yes
20                 ;;
21         esac
22 done
23
24 # we need to unmount /dev/pts/ and remount it later over the tmpfs
25 unmount_devpts() {
26   if mountpoint -q /dev/pts/; then
27     umount -n -l /dev/pts/
28   fi
29
30   if mountpoint -q /dev/shm/; then
31     umount -n -l /dev/shm/
32   fi
33 }
34
35 # mount a tmpfs over /dev, if somebody did not already do it
36 mount_tmpfs() {
37   if grep -q "/dev tmpfs" /proc/mounts; then
38     return
39   fi
40
41   if ! mount -n -o size=$tmpfs_size,mode=0755 -t tmpfs udev /dev; then
42     echo "udev requires tmpfs support, not started."
43     exit 1
44   fi
45
46   return 0
47 }
48
49 create_dev_makedev() {
50   if [ -e /sbin/MAKEDEV ]; then
51     ln -sf /sbin/MAKEDEV /dev/MAKEDEV
52   else
53     ln -sf /bin/true /dev/MAKEDEV
54   fi
55 }
56
57 make_extra_nodes() {
58   ret=1
59   if [ "$(echo /lib/udev/devices/*)" != "/lib/udev/devices/*" ]; then
60     cp -a /lib/udev/devices/* /$1/
61     ret=0
62   fi
63
64   [ -e /etc/udev/links.conf ] || return $ret
65
66   grep '^[^#]' /etc/udev/links.conf | \
67   while read type name arg1; do
68     [ "$type" -a "$name" -a ! -e "/$1/$name" -a ! -L "/$1/$name" ] || continue
69     case "$type" in
70       L) ln -s $arg1 /$1/$name ;;
71       D) mkdir -p /$1/$name ;;
72       M) mknod -m 600 /$1/$name $arg1 ;;
73       *) echo "links.conf: unparseable line ($type $name $arg1)" >&2 ;;
74     esac
75   done
76
77   return $ret
78 }
79
80 ##############################################################################
81
82 [ -x /sbin/udevd ] || exit 0
83
84 PATH="/sbin:/bin"
85
86 # defaults
87 tmpfs_size="2M"
88 udev_root="/dev"
89
90 if [ -e /etc/udev/udev.conf ]; then
91   . /etc/udev/udev.conf
92 fi
93
94 ##############################################################################
95
96 # When modifying this script, do not forget that between the time that the
97 # new /dev has been mounted and udevadm trigger has been run there will be
98 # no /dev/null. This also means that you cannot use the "&" shell command.
99
100 case "$1" in
101     start)
102     if [ -e "$udev_root/.udev/" ]; then
103         if mountpoint -q $udev_root/; then
104             TMPFS_MOUNTED=1
105         else
106             echo ".udev/ already exists on the static $udev_root!"
107         fi
108     fi
109
110     echo > /sys/kernel/uevent_helper
111
112     if [ -z "$TMPFS_MOUNTED" ]; then
113         unmount_devpts
114         mount_tmpfs
115     else
116         # and clean up the database of the initramfs udev
117         rm -rf /dev/.udev/
118     fi
119
120     # /dev/null must be created before udevd is started
121     if ! make_extra_nodes "$udev_root"; then
122         COLDPLUG=yes
123     fi
124     if [ ! -f "$COLDPLUG_TARBALL" ]; then
125         COLDPLUG=yes
126     fi
127
128     # if this directory is not present /dev will not be updated by udev
129     mkdir -p /dev/.udev/db/
130
131     echo "Startting the hotplug events dispatcher"
132     udevd --daemon
133
134     mkdir -p /dev/.udev/queue/ /dev/.udev/rules.d/
135
136     create_dev_makedev
137
138     if [ $COLDPLUG != "no" ]; then
139         echo "Synthesizing the initial hotplug events"
140         udevadm trigger
141
142         # wait for the udevd childs to finish
143         echo "Waiting for /dev to be fully populated"
144         if udevadm settle; then
145             echo 'done'
146         else
147             echo 'timeout'
148         fi
149     fi
150
151     ;;
152
153     stop)
154     echo "Stopping the hotplug events dispatcher"
155     start-stop-daemon --stop --name udevd --quiet --oknodo
156     ;;
157
158     restart)
159     echo "Stopping the hotplug events dispatcher"
160     start-stop-daemon --stop --name udevd --quiet --oknodo
161
162     echo "Startting the hotplug events dispatcher"
163     udevd --daemon
164     ;;
165
166     reload|force-reload)
167     udevadm control --reload_rules
168     ;;
169
170     *)
171     echo "Usage: /etc/init.d/udev {start|stop|restart|reload|force-reload}"
172     exit 1
173     ;;
174 esac
175
176 exit 0
177