]> git.pld-linux.org Git - packages/systemd.git/blame - start_udev
- apply uclibc patch only when building with uclibc
[packages/systemd.git] / start_udev
CommitLineData
05149ed5
AM
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#
7e0b6014 11# This needs to be run at the earliest possible point in the boot
05149ed5
AM
12# process.
13#
14# Based on the udev init.d script
15#
7e0b6014 16# Thanks go out to the Gentoo developers for proving
05149ed5
AM
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...
940e3565
ER
22
23# default value, if no config present.
12bbae40 24udev_root="/dev"
b44e0a3d 25sysfs_dir="/sys"
d35df3ca 26udevd_timeout=8
940e3565 27
05149ed5 28# don't use udev if sysfs is not mounted.
dda87135 29[ -d $sysfs_dir/class ] || exit 1
05149ed5 30[ -r /proc/mounts ] || exit 1
05149ed5
AM
31[ -f /etc/udev/udev.conf ] && . /etc/udev/udev.conf
32
401263e1 33. /etc/rc.d/init.d/functions
05149ed5
AM
34
35prog=udev
05149ed5 36bin=/sbin/udev
ab4c8ae1 37udevd=/lib/udev/udevd
05149ed5
AM
38
39make_extra_nodes () {
ba060a4b 40 grep '^[^#]' /etc/udev/links.conf | \
41 while read type name arg1; do
7e0b6014
ER
42 [ "$type" -a "$name" -a ! -e "$udev_root/$name" -a ! -L "/dev/$name" ] ||continue
43 case "$type" in
44 L) ln -s $arg1 $udev_root/$name ;;
45 D) mkdir -p $udev_root/$name ;;
46 M) mknod -m 600 /dev/$name $arg1 ;;
47 *) echo "links.conf: unparseable line ($type $name $arg1)" ;;
48 esac
ba060a4b 49 done
584c4247
AM
50 [ -d /lib/udev/devices ] && cp -a /lib/udev/devices/* /dev/ >/dev/null 2>&1 || :
51 [ -d /lib64/udev/devices ] && cp -a /lib64/udev/devices/* /dev/ >/dev/null 2>&1 || :
05149ed5
AM
52}
53
d8394a8d
AM
54kill_udevd() {
55 if [ -x /sbin/pidof ]; then
7e0b6014 56 pid=$(/sbin/pidof -x udevd)
d8394a8d
AM
57 [ -n "$pid" ] && kill $pid
58 fi
59}
60
294ac9d6 61set_hotplug_handler() {
7e0b6014 62 echo "" > /proc/sys/kernel/hotplug
294ac9d6 63}
15874c6e 64
97d4074c
ER
65# find subdirs mounted under $udev_root
66get_dev_mounts() {
67 awk -vudev_root="$udev_root/" '
68 BEGIN {
69 len = length(udev_root);
70 }
71
72 substr($2, 1, len) == udev_root {
73 print substr($2, len + 1)
74 }' /proc/mounts
75}
76
05149ed5 77export ACTION=add
6ba94d68
AM
78prog=udev
79ret=0
90d90678
AM
80show "Starting udev"
81busy
294ac9d6 82
12bbae40
ER
83# mount the devtmpfs on $udev_root, if not already done
84awk "\$2 == \"$udev_root\" && \$3 == \"devtmpfs\" { exit 1 }" /proc/mounts && {
97d4074c
ER
85 # mount to temporary location to be able to move submounts, if any
86 devdir=$(mktemp -d ${TMPDIR:-/tmp}/tmpXXXXXX)
87 mount -n -o mode=0755 -t devtmpfs devtmpfs "$devdir"
88 ret=$(( $ret + $? ))
7e0b6014 89
97d4074c
ER
90 # relocate submounts
91 for dir in $(get_dev_mounts); do
92 mount -n --move $udev_root/$dir $devdir/$dir
93 ret=$(( $ret + $? ))
94 done
84853a2e 95
97d4074c 96 mount -n --move $devdir $udev_root
6ba94d68 97}
120a2def 98
120a2def 99kill_udevd > "$udev_root/null" 2>&1
ec7c0939 100
7e0b6014
ER
101# Start udevd daemon
102$udevd --daemon
103ret=$(( $ret + $? ))
104
105# Making extra nodes
106make_extra_nodes
107ret=$(( $ret + $? ))
855c97b3 108
7e0b6014
ER
109if [ -f "/sys/class/tty/console/uevent" ]; then
110 # Setting default hotplug handler
855c97b3 111 set_hotplug_handler
112 ret=$(( $ret + $? ))
113
d95b8af3 114 # retrigger all events
7e0b6014 115 # Udev finds it's own way of making this dir
c5ffe681 116 # and making it by hand makes udevsettle
117 # work forever
118 #mkdir -p /dev/.udev/queue
7e0b6014 119 udevadm trigger
15874c6e 120 ret=$(( $ret + $? ))
7e0b6014 121
d95b8af3 122 # wait for the events to finish
7e0b6014 123 udevadm settle
15874c6e 124 ret=$(( $ret + $? ))
de6b464e 125else
855c97b3 126 echo "Kernel too old for this udev version"
de6b464e 127fi
d95b8af3 128
120a2def 129ret=$(( $ret + $? ))
6ba94d68 130[ $ret -eq 0 ] && ok || fail
05149ed5 131exit 0
This page took 0.067037 seconds and 4 git commands to generate.