summaryrefslogtreecommitdiffstats
path: root/projectroot/etc/init.d/udev
blob: 1020b40c795e872af90d53a040789bc9098ba1d4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#!/bin/sh

udev_root="/dev"
udev_rules="/lib/udev/rules.d"
udev_log="err"

# for new udevd
PATH=/lib/udev:$PATH

make_extra_nodes () {
	# there are a few things that sysfs does not export for us.
	# these things go here (and remember to remove them in
	# remove_extra_nodes()
	#
	# Thanks to Gentoo for the initial list of these.
	if ! mount | grep -q devtmpfs; then
		ln -snf /proc/self/fd /dev/fd
		ln -snf /proc/self/fd/0 /dev/stdin
		ln -snf /proc/self/fd/1 /dev/stdout
		ln -snf /proc/self/fd/2 /dev/stderr
		ln -snf /proc/kcore /dev/core

		mknod /dev/null c 1 3
		mknod /dev/console c 5 1
		mknod /dev/zero c 1 5
	fi

	mkdir /dev/pts
	mkdir /dev/shm
}

case $1 in
start)
	echo "starting udev"

	# don't use udev if sysfs is not mounted.
	if [ ! -d /sys/kernel ]; then
		echo "failed"
		echo "error: sysfs not mounted"
		exit 1
	fi

	# only mount a tmpfs if devtmpfs is not already there
	if ! mount | grep -q devtmpfs; then
		# The reason we don't write to mtab is because we don't ever
		# want /dev to be unavailable (such as by `umount -a').
		echo "mounting tmpfs at $udev_root"
		mount -n -t tmpfs tmpfs $udev_root -o mode=755
	fi

	# udev handles uevents itself, so we don't need to have
	# the kernel call out to any binary in response to them
	echo > /proc/sys/kernel/hotplug

	echo "creating static nodes"
	make_extra_nodes

	# Start the udev daemon to continually
	# watch for, and act on, uevents
	echo -n "starting udevd..."
	udevd --daemon
	if [ "$?" = "0" ]; then
		echo "done"
	else
		echo "failed"
	fi

	# Now traverse sys/ in order to "coldplug"
	# devices that have already been discovered
	udevadm trigger
	# Now wait for udevd to process
	# the uevents we triggered
	echo -n "waiting for devices..."
	udevadm settle --timeout=10
	if [ "$?" = "0" ]; then
		echo "done"
	else
		echo "failed"
	fi

	# We can only mount /dev/pts after initialising udev
	if [ -d "/dev/pts" ]; then
		mount /dev/pts
	fi

	exit 0

	;;
stop)
	echo "stopping udevd... error, udevd cannot be stopped, aborting"
	;;
*)
	echo "usage: $0 [start|stop]"
	;;
esac