Ticket #600: start_udev-RHEL-5.7

File start_udev-RHEL-5.7, 4.4 KB (added by victor gattegno, 12 years ago)

RHEL 5 start_udev (not modified)

Line 
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# don't use udev if sysfs is not mounted.
24
25sysfs_dir=/sys
26
27export TZ=/etc/localtime
28
29[ -d $sysfs_dir/class ] || exit 1
30[ -r /proc/mounts ] || exit 1
31[ -x /sbin/udevd ] || exit 1
32[ -f /etc/udev/udev.conf ] && . /etc/udev/udev.conf
33udev_root=${udev_root-/dev}
34
35
36. /etc/init.d/functions
37
38umask 0022
39
40prog=udev
41bin=/sbin/udev
42udevd=/sbin/udevd
43MAKEDEV="/sbin/MAKEDEV"
44
45xargs_simple () {
46 if [ "$1" = "-n" ]; then
47 shift
48 MAXNR="$1"
49 shift
50 else
51 MAXNR=100
52 fi
53 NR=$MAXNR
54 ARGS=""
55 [ -z "$1" ] && set echo
56
57 while read line; do
58 if [ $NR -gt 0 ]; then
59 ARGS="$ARGS $line"
60 NR=$[$NR - 1]
61 else
62 "$@" $ARGS
63 NR=$MAXNR
64 ARGS="$line"
65 fi
66 done
67 if [ -n "$ARGS" ]; then
68 "$@" $ARGS
69 fi
70}
71
72make_extra_nodes () {
73 ln -snf /proc/self/fd $udev_root/fd
74 ln -snf /proc/self/fd/0 $udev_root/stdin
75 ln -snf /proc/self/fd/1 $udev_root/stdout
76 ln -snf /proc/self/fd/2 $udev_root/stderr
77 ln -snf /proc/kcore $udev_root/core
78
79 [ -d $udev_root/pts ] || mkdir -m 0755 $udev_root/pts
80 [ -d $udev_root/shm ] || mkdir -m 0755 $udev_root/shm
81 [ -a /dev/MAKEDEV ] || ln -s $MAKEDEV /dev/MAKEDEV;
82
83 if [ -x $MAKEDEV ]; then
84 for i in /etc/udev/makedev.d/*.nodes; do
85 if [ -f "$i" ]; then
86 cat "$i" | sed -e 's,#.*,,g' | \
87 xargs_simple -n 100 $MAKEDEV -x
88 fi
89 done
90 fi
91 for devdir in /etc/udev/devices /lib/udev/devices; do
92 [ -d "$devdir" ] || continue
93 pushd $devdir &> "$udev_root/null"
94 set *
95 if [ "$1" != "*" ]; then
96 cp -ar "$@" $udev_root/
97 pushd "$udev_root" &> "$udev_root/null"
98 [ -x /sbin/restorecon ] && /sbin/restorecon "$@"
99 popd &> "$udev_root/null"
100 fi
101 popd &> "$udev_root/null"
102 done
103}
104
105kill_udevd() {
106 if [ -x /sbin/pidof ]; then
107 pid=`/sbin/pidof -x udevd`
108 [ -n "$pid" ] && kill $pid
109 fi
110}
111
112
113wait_for_queue() {
114 local timeout=${1:-0}
115 local ret=0
116 if [ $timeout -gt 0 ]; then
117 /sbin/udevsettle --timeout=$timeout
118 else
119 /sbin/udevsettle
120 fi
121 ret=$?
122 if [ $ret -ne 0 ]; then
123 echo -n "Wait timeout. Will continue in the background."
124 fi
125 return $ret;
126}
127
128export ACTION=add
129prog=udev
130ret=0
131STRING=$"Starting $prog: "
132# propagate $udev_root from /sys
133echo -n "$STRING"
134
135# mount the tmpfs on ${udev_root%/}, if not already done
136LANG=C awk "\$2 == \"${udev_root%/}\" && \$3 == \"tmpfs\" { exit 1 }" /proc/mounts && {
137 if LANG=C fgrep -q "none ${udev_root%/}/pts " /proc/mounts; then
138 PTSDIR=$(mktemp -d)
139 mount --move $udev_root/pts "$PTSDIR"
140 fi
141 if LANG=C fgrep -q "none ${udev_root%/}/shm " /proc/mounts; then
142 SHMDIR=$(mktemp -d)
143 mount --move $udev_root/shm "$SHMDIR"
144 fi
145 mount -n -o mode=0755 -t tmpfs none "$udev_root"
146 mkdir -m 0755 $udev_root/pts
147 mkdir -m 0755 $udev_root/shm
148 if [ -n "$PTSDIR" ]; then
149 mount --move "$PTSDIR" $udev_root/pts
150 rmdir "$PTSDIR"
151 fi
152 if [ -n "$SHMDIR" ]; then
153 mount --move "$SHMDIR" $udev_root/shm
154 rmdir "$SHMDIR"
155 fi
156
157 ret=$[$ret + $?]
158}
159
160# returns OK if $1 contains $2
161strstr() {
162 [ "${1#*$2*}" = "$1" ] && return 1
163 return 0
164}
165
166getval() {
167 what=$1
168 shift
169 for arg; do
170 if strstr "$arg" "$what="; then
171 val=${arg#${what}=*}
172 echo $val
173 return 0
174 fi
175 done
176 return 1
177}
178
179
180make_extra_nodes
181
182kill_udevd > "$udev_root/null" 2>&1
183
184rm -fr /dev/.udev > "$udev_root/null" 2>&1
185
186cmdline=$(cat /proc/cmdline)
187
188if [ -f "/sys/class/tty/console/uevent" ]; then
189 # trigger the sorted events
190 echo -e '\000\000\000\000' > /proc/sys/kernel/hotplug
191 if strstr "$cmdline" modprobedebug; then
192 touch /dev/.modprobe_debug
193 else
194 rm -f /dev/.modprobe_debug
195 fi
196 /sbin/udevd -d
197 ret=$[$ret + $?]
198 if strstr "$cmdline" udevdebug; then
199 /sbin/udevcontrol log_priority=debug
200 fi
201 /sbin/udevtrigger
202 ret=$[$ret + $?]
203 wait_for_queue $(getval udevtimeout $cmdline)
204 ret=$[$ret + $?]
205else
206 echo -n " kernel too old for this udev version "
207 /sbin/udevd -d
208 ret=10
209fi
210
211ret=$[$ret + $?]
212[ $ret -eq 0 ] && success $"$STRING" || failure $"$STRING"
213echo
214exit 0