1 | #!/bin/sh
|
---|
2 | ########################################################################
|
---|
3 | # Begin $rc_base/init.d/udev
|
---|
4 | #
|
---|
5 | # Description : Udev Boot Script
|
---|
6 | #
|
---|
7 | # Authors : Based on Open Suse Udev Rules
|
---|
8 | # kay.sievers@suse.de
|
---|
9 | #
|
---|
10 | # Adapted to : Jim Gifford
|
---|
11 | # LFS
|
---|
12 | #
|
---|
13 | # Version : 00.00
|
---|
14 | #
|
---|
15 | # Notes :
|
---|
16 | #
|
---|
17 | ########################################################################
|
---|
18 |
|
---|
19 | . /etc/sysconfig/rc
|
---|
20 | . ${rc_functions}
|
---|
21 |
|
---|
22 | trigger_device_events() {
|
---|
23 | # generate events with the sysfs trigger
|
---|
24 | list=$(echo /sys/bus/*/devices/*/uevent)
|
---|
25 | list="$list $(echo /sys/class/*/*/uevent)"
|
---|
26 | list="$list $(echo /sys/block/*/uevent /sys/block/*/*/uevent)"
|
---|
27 | for i in $list; do
|
---|
28 | case "$i" in
|
---|
29 | */device/uevent|*\**)
|
---|
30 | # skip followed device symlinks
|
---|
31 | continue
|
---|
32 | ;;
|
---|
33 |
|
---|
34 | */class/mem/*|*/class/tty/*)
|
---|
35 | first="$first $i"
|
---|
36 | ;;
|
---|
37 |
|
---|
38 | */block/md*)
|
---|
39 | last="$last $i"
|
---|
40 | ;;
|
---|
41 |
|
---|
42 | */*)
|
---|
43 | default="$default $i"
|
---|
44 | ;;
|
---|
45 | esac
|
---|
46 | done
|
---|
47 |
|
---|
48 | # trigger the sorted events
|
---|
49 | for i in $first $default $last; do
|
---|
50 | echo "add" > "$i"
|
---|
51 | done
|
---|
52 | }
|
---|
53 |
|
---|
54 | case "$1" in
|
---|
55 | start)
|
---|
56 | boot_mesg "Creating /dev in tmpfs..."
|
---|
57 | mount -n -t tmpfs tmpfs /dev -o mode=755
|
---|
58 | evaluate_retval
|
---|
59 |
|
---|
60 | boot_mesg "Copying static entries..."
|
---|
61 | cp -ar /lib/udev/devices/* /dev
|
---|
62 | evaluate_retval
|
---|
63 |
|
---|
64 | boot_mesg "Executing udevstart..."
|
---|
65 | udevstart
|
---|
66 | evaluate_retval
|
---|
67 |
|
---|
68 | # disable hotplug helper, udevd listens to netlink
|
---|
69 | echo "" > /proc/sys/kernel/hotplug
|
---|
70 |
|
---|
71 | # start udevd
|
---|
72 | boot_mesg "Starting udevd..."
|
---|
73 | loadproc /sbin/udevd --daemon
|
---|
74 |
|
---|
75 | # cleanup some stuff
|
---|
76 | rm -f /var/run/sysconfig/network
|
---|
77 | rm -rf /events/*
|
---|
78 |
|
---|
79 | # start coldplugging
|
---|
80 | boot_mesg "Performing Coldplugging..."
|
---|
81 |
|
---|
82 | # unlikely, but we may be faster than the first event
|
---|
83 | mkdir -p /dev/.udev/queue
|
---|
84 |
|
---|
85 | # configure all devices
|
---|
86 | trigger_device_events
|
---|
87 |
|
---|
88 | # until we know how to do better, just wait for _all_ events to finish
|
---|
89 | loop=300
|
---|
90 | while test -d /dev/.udev/queue; do
|
---|
91 | sleep 0.1;
|
---|
92 | test "$loop" -gt 0 || break
|
---|
93 | loop=$(($loop - 1))
|
---|
94 | done
|
---|
95 |
|
---|
96 | echo_ok
|
---|
97 | ;;
|
---|
98 |
|
---|
99 | stop)
|
---|
100 | boot_mesg "Stopping udevd..."
|
---|
101 | echo "/sbin/hotplug" > /proc/sys/kernel/hotplug
|
---|
102 | killproc /sbin/udevd
|
---|
103 | ;;
|
---|
104 |
|
---|
105 | restart)
|
---|
106 | boot_mesg "Restarting udevd..."
|
---|
107 | killproc /sbin/udevd
|
---|
108 | loadproc /sbin/udevd --daemon
|
---|
109 | evaluate_retval
|
---|
110 | ;;
|
---|
111 |
|
---|
112 | status)
|
---|
113 | statusproc /sbin/udevd
|
---|
114 | ;;
|
---|
115 |
|
---|
116 | reload)
|
---|
117 | boot_mesg "Reloading udev rules..."
|
---|
118 | udevcontrol reload_rules
|
---|
119 | cp --preserve=all --recursive --update /lib/udev/devices/* /dev
|
---|
120 | evaluate_retval
|
---|
121 | ;;
|
---|
122 |
|
---|
123 | force-reload)
|
---|
124 | boot_mesg "Updating all available device nodes in /dev..."
|
---|
125 | udevcontrol reload_rules
|
---|
126 | rm -rf /dev/.udev /dev/disk
|
---|
127 | cp --preserve=all --recursive --update /lib/udev/devices/* /dev
|
---|
128 | trigger_device_events
|
---|
129 | evaluate_retval
|
---|
130 | ;;
|
---|
131 |
|
---|
132 | *)
|
---|
133 | echo "Usage: $0 {start|stop|restart|status|reload|force-reload}"
|
---|
134 | exit 1
|
---|
135 | ;;
|
---|
136 | esac
|
---|