chiark / gitweb /
[PATCH] Various typos and other litte errors in udev.8.in
[elogind.git] / etc / init.d / udev
1 #! /bin/sh
2 #
3 # udev  init script to setup /udev
4 #
5 # chkconfig: 2345 20 80
6 # description: manage user-space device nodes in /udev
7
8 . /etc/rc.d/init.d/functions
9
10 . /etc/udev/udev.conf
11
12 prog=udev
13 sysfs_dir=/sys
14 bin=/sbin/udev
15 udevd=/sbin/udevd
16 udev_root=/udev
17
18 run_udev () {
19         # handle block devices and their partitions
20         for i in ${sysfs_dir}/block/*; do
21                 # add each drive
22                 export DEVPATH=${i#${sysfs_dir}}
23                 $bin block &
24
25                 # add each partition, on each device
26                 for j in $i/*; do
27                         if [ -f $j/dev ]; then
28                                 export DEVPATH=${j#${sysfs_dir}}
29                                 $bin block &
30                         fi
31                 done
32         done
33         # all other device classes
34         for i in ${sysfs_dir}/class/*; do
35                 for j in $i/*; do
36                         if [ -f $j/dev ]; then
37                                 export DEVPATH=${j#${sysfs_dir}}
38                                 CLASS=`echo ${i#${sysfs_dir}} | \
39                                         cut --delimiter='/' --fields=3-`
40                                 $bin $CLASS &
41                         fi
42                 done
43         done
44         return 0
45 }
46
47 make_extra_nodes () {
48         # there are a few things that sysfs does not export for us.
49         # these things go here (and remember to remove them in 
50         # remove_extra_nodes()
51         #
52         # Thanks to Gentoo for the initial list of these.
53         ln -snf /proc/self/fd $udev_root/fd
54         ln -snf /proc/self/fd/0 $udev_root/stdin
55         ln -snf /proc/self/fd/1 $udev_root/stdout
56         ln -snf /proc/self/fd/2 $udev_root/stderr
57         ln -snf /proc/kcore $udev_root/core
58         #ln -snf /proc/asound/oss/sndstat $udev_root/sndstat
59 }
60
61 remove_extra_nodes () {
62         # get rid of the extra nodes created in make_extra_nodes()
63         rm $udev_root/fd
64         rm $udev_root/stdin
65         rm $udev_root/stdout
66         rm $udev_root/stderr
67         rm $udev_root/core
68         #rm $udev_root/sndstat
69 }
70
71 case "$1" in
72   start)
73         # don't use udev if sysfs is not mounted.
74         if [ ! -d $sysfs_dir/block ]; then
75                 exit 1
76         fi
77         if [ ! -d $udev_root ]; then
78                 mkdir $udev_root
79         fi
80
81         # remove the database if it is there as we always want to start fresh
82         if [ -f $udev_root/.udevdb ]; then
83                 rm -rf $udev_root/.udevdb
84         fi
85
86         # propogate /udev from /sys - we only need this while we do not
87         # have initramfs and an early user-space with which to do early
88         # device bring up
89         export ACTION=add
90         echo -n $"Creating initial udev device nodes:"
91         run_udev
92         make_extra_nodes
93
94         # We want to start udevd ourselves if it isn't already running.  This
95         # lets udevd run at a sane nice level...
96         $udevd &
97
98         success /bin/true
99         echo
100         touch /var/lock/subsys/udev
101         ;;
102   stop)
103         # be careful
104         echo -n $"Removing udev device nodes: "
105         export ACTION=remove
106         run_udev 
107         remove_extra_nodes
108         success /bin/true
109         echo
110         rm -f /var/lock/subsys/udev
111         ;;
112   status)
113         if [ -f /var/lock/subsys/udev ]; then
114                 echo $"$prog has run"
115                 exit 0
116         fi
117         echo $"$prog is stopped"
118         exit 3
119         ;;
120   restart)
121         $0 stop
122         $0 start
123         ;;
124   reload)
125         # nothing to do here
126         ;;
127   *)
128         echo "Usage: $0 {start|stop|status|restart}"
129         exit 1
130 esac
131
132 exit 0