]> git.pld-linux.org Git - packages/systemd.git/blob - start_udev
- do not require mktemp with optional TEMPLATE parameter
[packages/systemd.git] / start_udev
1 #!/bin/sh
2 #
3 # start_udev
4 #
5 # script to initialize /dev by using udev.
6 #
7 # Copyright (C) 2004 Greg Kroah-Hartman <greg@kroah.com>
8 #
9 # Released under the GPL v2 only.
10 #
11 # This needs to be run at the earliest possible point in the boot 
12 # process.
13 #
14 # Based on the udev init.d script
15 #
16 # Thanks go out to the Gentoo developers for proving 
17 # that this is possible to do.
18 #
19 # Yes, it's very verbose, feel free to turn off all of the echo calls,
20 # they were there to make me feel better that everything was working
21 # properly during development...
22
23 # default value, if no config present.
24 udev_root="/dev/"
25 sysfs_dir="/sys"
26 udev_db="/dev/.udevdb"
27
28 # don't use udev if sysfs is not mounted.
29 [ -d $sysfs_dir/class ] || exit 1
30 [ -r /proc/mounts ] || exit 1
31 [ -x /sbin/udev ] || exit 1
32 [ -f /etc/udev/udev.conf ] && . /etc/udev/udev.conf
33
34 . /etc/rc.d/init.d/functions
35
36 prog=udev
37 bin=/sbin/udev
38 udevd=/sbin/udevd
39 MAKEDEV="/sbin/MAKEDEV"
40
41 make_extra_nodes () {
42         ln -snf /proc/self/fd $udev_root/fd
43         ln -snf /proc/self/fd/0 $udev_root/stdin
44         ln -snf /proc/self/fd/1 $udev_root/stdout
45         ln -snf /proc/self/fd/2 $udev_root/stderr
46         ln -snf /proc/kcore $udev_root/core
47
48         [ -d $udev_root/pts ] || mkdir -m 0755 $udev_root/pts
49         [ -d $udev_root/shm ] || mkdir -m 0755 $udev_root/shm
50
51         if [ -x $MAKEDEV ]; then
52                 $MAKEDEV -x $( 
53                         for i in 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15; do
54                             echo cpu/$i/microcode;
55                         done;
56                         for i in 1 2 3 4 5 6; do echo tty$i;done;
57                         for i in 0 1 2 3 4 5 6 7; do echo loop$i; done;
58                         for i in 0 1 2 3; do echo lp$i; echo parport$i;done;
59                         echo net/tun ppp console null zero;
60                 );
61                 [ -a /dev/MAKEDEV ] || ln -sf "$MAKEDEV" /dev/MAKEDEV;
62                 cp -a /etc/udev/devices/* /dev/ >/dev/null 2>&1 || :
63         fi
64 }
65
66 kill_udevd() {
67         if [ -x /sbin/pidof ]; then
68                 pid=`/sbin/pidof -x udevd`
69                 [ -n "$pid" ] && kill $pid
70         fi
71 }
72
73 # we cannot use /usr/bin/find here
74 find_d () {
75         where=$1
76         what=$2
77         found=""
78         for f in $where/*; do
79                 if [ -d "$f" -a ! -L "$f" ]; then
80                         if [ "$f" != "${f%%$what}" ];then 
81                                 # make sure we are at the path end
82                                 # we have no dirname and basename
83                                 rest="${f#*$what}"
84                                 [ "${rest##*/}" = "$rest" ] && found="$found $f"
85                         fi
86                         found="$found $(find_d $f $what)"
87                 fi
88         done
89         echo "$found"
90 }
91
92 # we cannot use /usr/bin/find here
93 find_f () {
94         where=$1
95         what=$2
96         found=""
97         for f in $where/*; do
98                 if [ -d "$f" -a ! -L "$f" ]; then
99                         found="$found $(find_f $f $what)"
100                 elif [ -e "$f" ]; then 
101                         [ "$where/" = "${f%$what}" ] && found="$found $f"
102                 fi
103         done
104         [ -n "$found" ] && echo "$found"
105 }
106
107 # call hotplug with the scsi devices
108 scsi_replay () {
109         HOTPLUG="/sbin/udevsend"
110
111         scsi_hosts=$(find_d /sys/devices host\*)
112         SEQNUM=1
113
114         for host in $scsi_hosts; do
115                 [ -d $host ] || continue
116                 devs=$(find_f $host type)
117                 for dev in $devs;do
118                         [ -f $dev ] || continue
119                         DEVPATH=${dev%/type}
120                         DEVPATH=${DEVPATH#/sys}
121                         /bin/env -i DEVPATH="$DEVPATH" SUBSYSTEM=scsi_device ACTION=add $HOTPLUG scsi_device
122                         /bin/env -i DEVPATH="$DEVPATH" ACTION=add SUBSYSTEM=scsi $HOTPLUG scsi
123                 done
124         done
125         return 0
126 }
127
128 ide_scan() {
129         if [ ! -d /proc/ide ]; then
130                 return 1
131         fi
132         for i in /proc/ide/*/media; do
133                 read media < "$i"
134                 case "$media" in
135                         disk)
136                                 module=ide-disk
137                         ;;
138                         cdrom)
139                                 module=ide-cd
140                         ;;
141                         tape)
142                                 module=ide-tape
143                         ;;
144                         floppy)
145                                 module=ide-floppy
146                         ;;
147                         *)
148                                 module=ide-generic
149                         ;;
150                 esac
151                 /sbin/modprobe $module
152         done
153         return 0
154 }
155
156 export ACTION=add
157 prog=udev
158 ret=0
159 nls "Starting udev"
160
161 # mount the tmpfs on ${udev_root%/}, if not already done
162 LANG=C awk "\$2 == \"${udev_root%/}\" && \$3 == \"tmpfs\" { exit 1 }" /proc/mounts && {
163         if LANG=C fgrep -q "none ${udev_root%/}/pts " /proc/mounts; then
164                 PTSDIR=$(mktemp -d ${TMPDIR:-/tmp}/tmpXXXXXX)
165                 mount --move $udev_root/pts "$PTSDIR"
166         fi
167         if LANG=C fgrep -q "none ${udev_root%/}/shm " /proc/mounts; then
168                 SHMDIR=$(mktemp -d ${TMPDIR:-/tmp}/tmpXXXXXX)
169                 mount --move $udev_root/shm "$SHMDIR"
170         fi
171         mount -n -o mode=0755 -t tmpfs none "$udev_root"
172         mkdir -m 0755 $udev_root/pts
173         mkdir -m 0755 $udev_root/shm
174         if [ -n "$PTSDIR" ]; then
175                 mount --move "$PTSDIR" $udev_root/pts
176                 rmdir "$PTSDIR"
177         fi
178         if [ -n "$SHMDIR" ]; then
179                 mount --move "$SHMDIR" $udev_root/shm
180                 rmdir "$SHMDIR"
181         fi
182
183         ret=$(( $ret + $? ))
184 }
185
186 rm -fr "$udev_db"
187 make_extra_nodes
188 kill_udevd > "$udev_root/null" 2>&1
189 scsi_replay > "$udev_root/null" 2>&1
190 ret=$(( $ret + $? ))
191 ide_scan > "$udev_root/null" 2>&1
192 /sbin/udevstart 
193 ret=$(( $ret + $? ))
194 [ $ret -eq 0 ] && ok || fail
195 exit 0
This page took 0.049957 seconds and 4 git commands to generate.