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