diff options
author | Richard Purdie <richard@openedhand.com> | 2005-09-20 15:19:38 +0000 |
---|---|---|
committer | Richard Purdie <richard@openedhand.com> | 2005-09-20 15:19:38 +0000 |
commit | 8d66edc4085db428e67223f0f71cde6b3640f27e (patch) | |
tree | da9dcd13d59b36f7350d3938f9094cb2ecc4449a /openembedded/packages/udev/files/init | |
parent | b4a7122cacef647dbec3db5c9ebe1e504a7670df (diff) | |
download | poky-8d66edc4085db428e67223f0f71cde6b3640f27e.tar.gz |
pcmciautils and udev updates. Slowly aiming to get rid of hotplug and pcmcia-cs
git-svn-id: https://svn.o-hand.com/repos/poky@27 311d38ba-8fff-0310-9ca6-ca027cbcb966
Diffstat (limited to 'openembedded/packages/udev/files/init')
-rwxr-xr-x | openembedded/packages/udev/files/init | 234 |
1 files changed, 126 insertions, 108 deletions
diff --git a/openembedded/packages/udev/files/init b/openembedded/packages/udev/files/init index 16efb31542..c290661c72 100755 --- a/openembedded/packages/udev/files/init +++ b/openembedded/packages/udev/files/init | |||
@@ -1,36 +1,18 @@ | |||
1 | #!/bin/sh -e | 1 | #!/bin/sh -e |
2 | 2 | ||
3 | PATH="/usr/sbin:/usr/bin:/sbin:/bin" | ||
4 | |||
5 | UDEVSTART=/sbin/udevstart | 3 | UDEVSTART=/sbin/udevstart |
6 | 4 | ||
7 | # default maximum size of the /dev ramfs | 5 | # defaults |
8 | ramfs_size="1M" | 6 | tmpfs_size="10M" |
7 | udev_root="/dev" | ||
9 | 8 | ||
10 | [ -x $UDEVSTART ] || exit 0 | 9 | [ -x $UDEVSTART ] || exit 0 |
11 | 10 | ||
12 | . /etc/udev/udev.conf | 11 | . /etc/udev/udev.conf |
13 | 12 | ||
14 | case "$(uname -r)" in | ||
15 | 2.[012345].*) | ||
16 | echo "udev requires a kernel >= 2.6, not started." | ||
17 | exit 0 | ||
18 | ;; | ||
19 | esac | ||
20 | |||
21 | if ! grep -q '[[:space:]]ramfs$' /proc/filesystems; then | ||
22 | echo "udev requires ramfs support, not started." | ||
23 | exit 0 | ||
24 | fi | ||
25 | |||
26 | if [ ! -e /proc/sys/kernel/hotplug ]; then | ||
27 | echo "udev requires hotplug support, not started." | ||
28 | exit 0 | ||
29 | fi | ||
30 | |||
31 | ############################################################################## | 13 | ############################################################################## |
32 | 14 | ||
33 | # we need to unmount /dev/pts/ and remount it later over the ramfs | 15 | # we need to unmount /dev/pts/ and remount it later over the tmpfs |
34 | unmount_devpts() { | 16 | unmount_devpts() { |
35 | if mountpoint -q /dev/pts/; then | 17 | if mountpoint -q /dev/pts/; then |
36 | umount -l /dev/pts/ | 18 | umount -l /dev/pts/ |
@@ -41,132 +23,169 @@ unmount_devpts() { | |||
41 | fi | 23 | fi |
42 | } | 24 | } |
43 | 25 | ||
44 | # mount a ramfs over /dev, if somebody did not already do it | 26 | # mount a tmpfs over /dev, if somebody did not already do it |
45 | mount_ramfs() { | 27 | mount_tmpfs() { |
46 | if grep -E -q "^[^[:space:]]+ /dev ramfs" /proc/mounts; then | 28 | if grep -E -q "^[^[:space:]]+ /dev tmpfs" /proc/mounts; then |
47 | return 0 | 29 | return 0 |
48 | fi | 30 | fi |
49 | 31 | ||
50 | # /.dev is used by /sbin/MAKEDEV to access the real /dev directory. | 32 | # /dev/.static/dev/ is used by MAKEDEV to access the real /dev/ directory. |
51 | # if you don't like this, remove /.dev/. | 33 | # /etc/udev/ is recycled as a temporary mount point because it's the only |
52 | [ -d /.dev ] && mount --bind /dev /.dev | 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 | ||
53 | 52 | ||
54 | echo -n "Mounting a ramfs over /dev..." | 53 | mkdir -p /dev/.static/dev |
55 | mount -n -o size=$ramfs_size,mode=0755 -t ramfs none /dev | 54 | chmod 700 /dev/.static/ |
56 | echo "done." | 55 | mount -n -o move /etc/udev /dev/.static/dev |
57 | } | 56 | } |
58 | 57 | ||
59 | # I hate this hack. -- Md | 58 | # I hate this hack. -- Md |
60 | make_extra_nodes() { | 59 | make_extra_nodes() { |
61 | if [ -f /etc/udev/links.conf ]; then | 60 | [ -e /etc/udev/links.conf ] || return 0 |
62 | grep '^[^#]' /etc/udev/links.conf | \ | 61 | grep '^[^#]' /etc/udev/links.conf | \ |
63 | while read type name arg1; do | 62 | while read type name arg1; do |
64 | [ "$type" -a "$name" -a ! -e "/dev/$name" -a ! -L "/dev/$name" ] ||continue | 63 | [ "$type" -a "$name" -a ! -e "/dev/$name" -a ! -L "/dev/$name" ] ||continue |
65 | case "$type" in | 64 | case "$type" in |
66 | L) | 65 | L) ln -s $arg1 /dev/$name ;; |
67 | ln -s $arg1 /dev/$name | 66 | D) mkdir -p /dev/$name ;; |
68 | ;; | 67 | M) mknod -m 600 /dev/$name $arg1 ;; |
69 | D) | 68 | *) echo "links.conf: unparseable line ($type $name $arg1)" ;; |
70 | mkdir -p /dev/$name | ||
71 | ;; | ||
72 | M) | ||
73 | mknod -m 600 /dev/$name $arg1 | ||
74 | ;; | ||
75 | *) | ||
76 | echo "unparseable line ($type $name $arg1)" | ||
77 | ;; | ||
78 | esac | 69 | esac |
79 | done | 70 | done |
80 | fi | 71 | } |
72 | |||
73 | # this function is duplicated in preinst, postinst and d-i | ||
74 | supported_kernel() { | ||
75 | case "$(uname -r)" in | ||
76 | 2.[012345].*|2.6.[0-9]|2.6.[0-9][!0-9]*) return 1 ;; | ||
77 | 2.6.1[01]|2.6.1[01][!0-9]*) return 1 ;; | ||
78 | esac | ||
79 | return 0 | ||
80 | } | ||
81 | |||
82 | # shell version of /usr/bin/tty | ||
83 | my_tty() { | ||
84 | [ -x /bin/readlink ] || return 0 | ||
85 | [ -e /proc/self/fd/0 ] || return 0 | ||
86 | readlink --silent /proc/self/fd/0 || true | ||
87 | } | ||
88 | |||
89 | warn_if_interactive() { | ||
90 | if [ "$RUNLEVEL" = "S" -a "$PREVLEVEL" = "N" ]; then | ||
91 | return 0 | ||
92 | fi | ||
93 | |||
94 | TTY=$(my_tty) | ||
95 | if [ -z "$TTY" -o "$TTY" = "/dev/console" ]; then | ||
96 | return 0 | ||
97 | fi | ||
98 | |||
99 | printf "\n\n\nIt has been detected that the command\n\n\t$0 $*\n\n" | ||
100 | printf "has been run from an interactive shell.\n" | ||
101 | printf "It will probably not do what you expect, so this script will wait\n" | ||
102 | printf "60 seconds before continuing. Press ^C to stop it.\n" | ||
103 | printf "RUNNING THIS COMMAND IS HIGHLY DISCOURAGED!\n\n\n\n" | ||
104 | sleep 60 | ||
81 | } | 105 | } |
82 | 106 | ||
83 | ############################################################################## | 107 | ############################################################################## |
84 | 108 | ||
85 | if [ "$udev_root" != "/dev" ]; then | 109 | if ! supported_kernel; then |
86 | echo "WARNING: udev_root != /dev" | 110 | echo "udev requires a kernel >= 2.6.12, not started." |
111 | exit 1 | ||
112 | fi | ||
87 | 113 | ||
88 | case "$1" in | 114 | if [ ! -e /proc/filesystems ]; then |
89 | start) | 115 | echo "udev requires a mounted procfs, not started." |
90 | if [ -e "$udev_root/.udev.tdb" ]; then | 116 | exit 1 |
91 | if mountpoint -q /dev/; then | 117 | fi |
92 | echo "FATAL: udev is already active on $udev_root." | 118 | |
93 | exit 1 | 119 | if ! grep -q '[[:space:]]tmpfs$' /proc/filesystems; then |
94 | else | 120 | echo "udev requires tmpfs support, not started." |
95 | echo "WARNING: .udev.tdb already exists on the old $udev_root!" | 121 | exit 1 |
96 | fi | 122 | fi |
97 | fi | ||
98 | mount -n -o size=$ramfs_size,mode=0755 -t ramfs none $udev_root | ||
99 | echo -n "Creating initial device nodes..." | ||
100 | $UDEVSTART | ||
101 | echo "done." | ||
102 | ;; | ||
103 | stop) | ||
104 | start-stop-daemon -K -x /sbin/udevd | ||
105 | echo -n "Unmounting $udev_root..." | ||
106 | # unmounting with -l should never fail | ||
107 | if umount -l $udev_root; then | ||
108 | echo "done." | ||
109 | else | ||
110 | echo "failed." | ||
111 | fi | ||
112 | ;; | ||
113 | restart|force-reload) | ||
114 | $0 stop | ||
115 | $0 start | ||
116 | ;; | ||
117 | *) | ||
118 | echo "Usage: /etc/init.d/udev {start|stop|restart|force-reload}" | ||
119 | exit 1 | ||
120 | ;; | ||
121 | esac | ||
122 | 123 | ||
123 | exit 0 | 124 | if [ ! -d /sys/class/ ]; then |
124 | fi # udev_root != /dev/ | 125 | echo "udev requires a mounted sysfs, not started." |
126 | exit 1 | ||
127 | fi | ||
128 | |||
129 | if [ ! -e /proc/sys/kernel/hotplug ]; then | ||
130 | echo "udev requires hotplug support, not started." | ||
131 | exit 1 | ||
132 | fi | ||
125 | 133 | ||
126 | ############################################################################## | 134 | ############################################################################## |
135 | |||
127 | # When modifying this script, do not forget that between the time that | 136 | # When modifying this script, do not forget that between the time that |
128 | # the new /dev has been mounted and udevstart has been run there will be | 137 | # the new /dev has been mounted and udevstart has been run there will be |
129 | # no /dev/null. This also means that you cannot use the "&" shell command. | 138 | # no /dev/null. This also means that you cannot use the "&" shell command. |
130 | 139 | ||
131 | case "$1" in | 140 | case "$1" in |
132 | start) | 141 | start) |
133 | if [ -e "$udev_root/.udev.tdb" ]; then | 142 | if [ -e "$udev_root/.udevdb" ]; then |
134 | if mountpoint -q /dev/; then | 143 | if mountpoint -q /dev/; then |
135 | echo "FATAL: udev is already active on $udev_root." | 144 | TMPFS_MOUNTED=1 |
136 | exit 1 | ||
137 | else | 145 | else |
138 | echo "WARNING: .udev.tdb already exists on the old $udev_root!" | 146 | echo ".udevdb already exists on the old $udev_root!" |
139 | fi | 147 | fi |
140 | fi | 148 | fi |
141 | unmount_devpts | 149 | warn_if_interactive |
142 | mount_ramfs | 150 | |
143 | ACTION=add | 151 | #echo /sbin/udevsend > /proc/sys/kernel/hotplug |
144 | echo -n "Creating initial device nodes..." | 152 | echo "" > /proc/sys/kernel/hotplug |
145 | $UDEVSTART | 153 | udevsend |
154 | if [ "$UDEV_DISABLED" = "yes" ]; then | ||
155 | echo "udev disabled on the kernel command line, not started." | ||
156 | exit 0 | ||
157 | fi | ||
158 | |||
159 | if [ ! "$TMPFS_MOUNTED" ]; then | ||
160 | unmount_devpts | ||
161 | mount_tmpfs | ||
162 | [ -d /proc/1 ] || mount -n /proc | ||
163 | # if this directory is not present /dev will not be updated by udev | ||
164 | mkdir /dev/.udevdb/ | ||
165 | echo "Creating initial device nodes..." | ||
166 | udevstart | ||
167 | fi | ||
146 | make_extra_nodes | 168 | make_extra_nodes |
147 | echo "done." | ||
148 | # /etc/init.d/mountvirtfs start | ||
149 | ;; | 169 | ;; |
150 | stop) | 170 | stop) |
151 | start-stop-daemon -K -x /sbin/udevd | 171 | warn_if_interactive |
172 | start-stop-daemon --stop --exec /sbin/udevd --quiet | ||
152 | unmount_devpts | 173 | unmount_devpts |
153 | echo -n "Unmounting /dev..." | 174 | if [ -d /dev/.static/dev/ ]; then |
175 | umount -l /dev/.static/dev/ || true | ||
176 | fi | ||
177 | echo "Unmounting /dev..." | ||
154 | # unmounting with -l should never fail | 178 | # unmounting with -l should never fail |
155 | if umount -l /dev; then | 179 | if ! umount -l /dev; then |
156 | echo "done." | 180 | exit 1 |
157 | umount -l /.dev || true | ||
158 | # /etc/init.d/mountvirtfs start | ||
159 | else | ||
160 | echo "failed." | ||
161 | fi | 181 | fi |
162 | ;; | 182 | ;; |
163 | restart|force-reload) | 183 | restart|force-reload) |
164 | start-stop-daemon -K -x /sbin/udevd | 184 | start-stop-daemon --stop --exec /sbin/udevd --quiet |
165 | echo -n "Recreating device nodes..." | 185 | log_begin_msg "Recreating device nodes..." |
166 | ACTION=add | 186 | udevstart |
167 | $UDEVSTART | ||
168 | make_extra_nodes | 187 | make_extra_nodes |
169 | echo "done." | 188 | log_end_msg 0 |
170 | ;; | 189 | ;; |
171 | *) | 190 | *) |
172 | echo "Usage: /etc/init.d/udev {start|stop|restart|force-reload}" | 191 | echo "Usage: /etc/init.d/udev {start|stop|restart|force-reload}" |
@@ -175,4 +194,3 @@ case "$1" in | |||
175 | esac | 194 | esac |
176 | 195 | ||
177 | exit 0 | 196 | exit 0 |
178 | |||