chiark / gitweb /
[PATCH] update the init.d udev script based on a patch from Red Hat.
[elogind.git] / etc / init.d / udev
1 #! /bin/bash
2 #
3 # random        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
16 run_udev () {
17         # handle block devices and their partitions
18         for i in ${sysfs_dir}/block/*; do
19                 # add each drive
20                 export DEVPATH=${i#${sysfs_dir}}
21                 $bin block &
22
23                 # add each partition, on each device
24                 for j in $i/*; do
25                         if [ -f $j/dev ]; then
26                                 export DEVPATH=${j#${sysfs_dir}}
27                                 $bin block &
28                         fi
29                 done
30         done
31         # all other device classes
32         for i in ${sysfs_dir}/class/*; do
33                 for j in $i/*; do
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                 done
41         done
42         return 0
43 }
44
45 case "$1" in
46   start)
47         if [ ! -d $sysfs_dir ]; then
48                 exit 1
49         fi
50         if [ ! -d $udev_root ]; then
51                 mkdir $udev_root
52         fi
53
54         # remove the database if it is there as we always want to start fresh
55         if [ -f $udev_root/.udev.tdb ]; then
56                 rm -f $udev_root/.udev.tdb
57         fi
58
59         # propogate /udev from /sys - we only need this while we do not
60         # have initramfs and an early user-space with which to do early
61         # device bring up
62         export ACTION=add
63         echo -n $"Creating initial udev device nodes:"
64         run_udev 
65         success /bin/true
66         echo
67         touch /var/lock/subsys/udev
68         ;;
69   stop)
70         # be careful
71         echo -n $"Removing udev device nodes: "
72         export ACTION=remove
73         run_udev 
74         success /bin/true
75         echo
76         rm -f /var/lock/subsys/udev
77         ;;
78   status)
79         if [ -f /var/lock/subsys/udev ]; then
80                 echo $"$prog has run"
81                 exit 0
82         fi
83         echo $"$prog is stopped"
84         exit 3
85         ;;
86   restart)
87         $0 stop
88         $0 start
89         ;;
90   reload)
91         # nothing to do here
92         ;;
93   *)
94         echo "Usage: $0 {start|stop|status|restart}"
95         exit 1
96 esac
97
98 exit 0