more init fixes
[hdw-linux/hdw-linux.git] / packages / base / udev / init_udev.sh
1 #!/bin/sh
2 #
3 # hdw - linux /etc/init.d/udev
4 #
5 # populate /dev directory with device nodes
6 #
7
8 # read udev config
9 . /etc/udev/udev.conf
10
11 prog=udev
12 sysfs_dir=/sys
13 bin=/sbin/udev
14 udevd=/sbin/udevd
15
16 # add some nodes not exported by sysfs
17 run_udev()      {
18         # block devices & partitions
19         for i in ${sysfs_dir}/block/*; do
20                 export DEVPATH=${i#${sysfs_dir}}
21                 $bin block &
22                 for j in $i/*; do
23                         if [ -f $j/dev ]; then
24                                 export DEVPATH=${j#${sysfs_dir}}
25                                 $bin block &
26                         fi
27                 done
28         done
29         # all other devices
30         for i in ${sysfs_dir}/class/*; do
31                 for j in $i/*; do
32                         # cruel hack, to not add/del /dev/null
33                         if [ "$j" != "${sysfs_dir}/class/mem/null" ] ; then
34                         if [ -f $j/dev ]; then
35                                 export DEVPATH=${j#${sysfs_dir}}
36                                 CLASS=`echo ${i#${sysfs_dir}} | \
37                                         cut --delimiter='/' --fields=3-`
38                                 $bin $CLASS &
39                         fi
40                         fi
41                 done
42         done
43         return 0
44                 }
45         
46 add_nodes()     {
47         ln -snf /proc/self/fd $udev_root/fd
48         ln -snf /proc/self/fd/0 $udev_root/stdin
49         ln -snf /proc/self/fd/1 $udev_root/stdout
50         ln -snf /proc/self/fd/2 $udev_root/stderr
51         ln -snf /proc/kcore $udev_root/core
52 }
53
54 # delete them when shutting down (not used right now)
55 del_nodes()     {
56         rm -rf $udev_root/{fd,stdin,stdout,stderr,core}
57 }
58
59 # main procedures
60
61 case "$1"
62 in
63         start)
64                 echo -n "starting udev ..."
65                 echo "/sbin/udev" > /proc/sys/kernel/hotplug
66                 if [ ! -d $sysfs_dir/block ] ; then
67                         echo "fatal: sysfs not mounted"
68                         exit 1
69                 fi
70                 rm -f $udev_root/.udev.tdb
71                 mknod -m 0666 ${udev_root}/null c 1 3
72                 export ACTION=add
73                 export UDEV_NO_SLEEP=1
74                 run_udev
75                 add_nodes
76                 $udevd &
77                 echo " done"
78                 ;;
79         stop)
80                 echo -n "stopping udev ..."
81                 export ACTION=remove
82                 run_udev
83                 del_nodes
84                 rm ${udev_root}/null
85                 echo " done"
86                 ;;
87         restart)
88                 /etc/init.d/udev stop
89                 /etc/init.d/udev start
90                 ;;
91         status)
92                 if [ -f /var/lock/subsys/udev ]; then
93                         echo "udev running ..."
94                 else
95                         echo "udev not running ..."
96                 fi
97                 ;;
98         *)
99                 echo "usage: $0 { start | stop | restart }"
100                 exit 1
101                 ;;
102 esac
103
104 exit 0