aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNatanael Copa <ncopa@alpinelinux.org>2009-05-17 12:37:37 +0000
committerNatanael Copa <ncopa@alpinelinux.org>2009-05-17 12:37:37 +0000
commit592e32a35be2934bf0627758a0bcd57c2ef13be1 (patch)
treeff07ba29702e2e1b29b77adfae604e1913c4f08e
parentbceef1f335c5c389a4be19b08f799bc4367c303e (diff)
downloadalpine_aports-592e32a35be2934bf0627758a0bcd57c2ef13be1.tar.bz2
alpine_aports-592e32a35be2934bf0627758a0bcd57c2ef13be1.tar.xz
alpine_aports-592e32a35be2934bf0627758a0bcd57c2ef13be1.zip
extra/udev: new aport
-rw-r--r--extra/udev/APKBUILD41
-rwxr-xr-xextra/udev/move_tmp_persistent_rules.sh25
-rwxr-xr-xextra/udev/udev-mount.initd83
-rwxr-xr-xextra/udev/udev-postmount.initd31
-rw-r--r--extra/udev/udev-start.sh51
-rwxr-xr-xextra/udev/udev.initd239
-rwxr-xr-xextra/udev/write_root_link_rule29
7 files changed, 499 insertions, 0 deletions
diff --git a/extra/udev/APKBUILD b/extra/udev/APKBUILD
new file mode 100644
index 0000000000..d25b5faa49
--- /dev/null
+++ b/extra/udev/APKBUILD
@@ -0,0 +1,41 @@
1# Maintainer: Natanael Copa <ncopa@alpinelinux.org>
2pkgname=udev
3pkgver=142
4pkgrel=0
5pkgdesc="The userspace dev tools (udev)"
6url="http://www.kernel.org/pub/linux/utils/kernel/hotplug/udev.html"
7license="GPL"
8subpackages="$pkgname-dev $pkgname-doc"
9depends="uclibc"
10makedepends=""
11install=
12source="http://www.kernel.org/pub/linux/utils/kernel/hotplug/$pkgname-$pkgver.tar.bz2
13 write_root_link_rule
14 move_tmp_persistent_rules.sh
15 udev-mount.initd
16 udev-postmount.initd
17 udev.initd"
18
19build ()
20{
21 cd "$srcdir"/$pkgname-$pkgver
22 ./configure --prefix=/usr \
23 --sysconfdir=/etc \
24 --exec-prefix="" \
25 --with-libdir-name=/lib
26 make || return 1
27 make DESTDIR="$pkgdir" install
28 chmod +x "$pkgdir"/lib/udev/write_*_rules
29 for _i in write_root_link_rule move_tmp_persistent_rules.sh; do
30 install -Dm755 ../$_i "$pkgdir"/lib/udev/$_i
31 done
32 for _i in udev udev-mount udev-postmount; do
33 install -Dm755 ../$_i.initd "$pkgdir"/etc/init.d/$_i
34 done
35}
36md5sums="3edc4cf383dccb06d866c5156d59ddd5 udev-142.tar.bz2
37c9de7581099cdfdcd105666cd98a0f0a write_root_link_rule
387bf11e11519117f743483c73e0767750 move_tmp_persistent_rules.sh
3912760065a66ccbddc9e3a86a6cd2231c udev-mount.initd
40bffb42859ca508cfe1d9fa0a169ba810 udev-postmount.initd
41e913f8f122e8879252d2a05de7dd7499 udev.initd"
diff --git a/extra/udev/move_tmp_persistent_rules.sh b/extra/udev/move_tmp_persistent_rules.sh
new file mode 100755
index 0000000000..1a0259798b
--- /dev/null
+++ b/extra/udev/move_tmp_persistent_rules.sh
@@ -0,0 +1,25 @@
1#!/bin/sh
2# Copyright 1999-2007 Gentoo Foundation
3# Distributed under the terms of the GNU General Public License v2
4
5. /etc/init.d/functions.sh
6
7# store persistent-rules that got created while booting
8# when / was still read-only
9store_persistent_rules() {
10 local file dest
11
12 for file in /dev/.udev/tmp-rules--*; do
13 dest=${file##*tmp-rules--}
14 [ "$dest" = '*' ] && break
15 type=${dest##70-persistent-}
16 type=${type%%.rules}
17 ebegin "Saving udev persistent ${type} rules to /etc/udev/rules.d"
18 cat "$file" >> /etc/udev/rules.d/"$dest" && rm -f "$file"
19 eend $? "Failed moving persistent rules!"
20 done
21}
22
23store_persistent_rules
24
25# vim:ts=4
diff --git a/extra/udev/udev-mount.initd b/extra/udev/udev-mount.initd
new file mode 100755
index 0000000000..839565a5ba
--- /dev/null
+++ b/extra/udev/udev-mount.initd
@@ -0,0 +1,83 @@
1#!/sbin/runscript
2# Copyright 1999-2008 Gentoo Foundation
3# Distributed under the terms of the GNU General Public License v2
4
5description="Mount tmpfs on /dev"
6[ -e /etc/conf.d/udev ] && . /etc/conf.d/udev
7
8mount_dev_directory()
9{
10 # No options are processed here as they should all be in /etc/fstab
11 ebegin "Mounting /dev"
12 if fstabinfo --quiet /dev; then
13 mount -n /dev
14 else
15 # Some devices require exec, Bug #92921
16 mount -n -t tmpfs -o "exec,nosuid,mode=0755,size=10M" udev /dev
17 fi
18 eend $?
19}
20
21seed_dev()
22{
23 # Seed /dev with some things that we know we need
24
25 # creating /dev/console, /dev/tty and /dev/tty1 to be able to write
26 # to $CONSOLE with/without bootsplash before udevd creates it
27 [ -c /dev/console ] || mknod -m 600 /dev/console c 5 1
28 [ -c /dev/tty1 ] || mknod -m 620 /dev/tty1 c 4 1
29 [ -c /dev/tty ] || mknod -m 666 /dev/tty c 5 0
30
31 # udevd will dup its stdin/stdout/stderr to /dev/null
32 # and we do not want a file which gets buffered in ram
33 [ -c /dev/null ] || mknod -m 666 /dev/null c 1 3
34
35 # so udev can add its start-message to dmesg
36 [ -c /dev/kmsg ] || mknod -m 660 /dev/kmsg c 1 11
37
38 # copy over any persistant things
39 if [ -d /lib/udev/devices ]; then
40 cp -RPp /lib/udev/devices/* /dev 2>/dev/null
41 fi
42
43 # Not provided by sysfs but needed
44 ln -snf /proc/self/fd /dev/fd
45 ln -snf fd/0 /dev/stdin
46 ln -snf fd/1 /dev/stdout
47 ln -snf fd/2 /dev/stderr
48 [ -e /proc/kcore ] && ln -snf /proc/kcore /dev/core
49
50 # Create problematic directories
51 mkdir -p /dev/pts /dev/shm
52 return 0
53}
54
55
56start()
57{
58 # do not run this on too old baselayout - udev-addon is already loaded!
59 if [ ! -f /etc/init.d/sysfs ]; then
60 eerror "The $SVCNAME init-script is written for baselayout-2!"
61 eerror "Please do not use it with baselayout-1!".
62 return 1
63 fi
64
65 _start
66}
67
68_start()
69{
70 mount_dev_directory || return 1
71
72 # Selinux lovin; /selinux should be mounted by selinux-patched init
73 if [ -x /sbin/restorecon -a -c /selinux/null ]; then
74 restorecon /dev > /selinux/null
75 fi
76
77 # make sure it exists
78 mkdir -p /dev/.udev
79
80 seed_dev
81
82 return 0
83}
diff --git a/extra/udev/udev-postmount.initd b/extra/udev/udev-postmount.initd
new file mode 100755
index 0000000000..96beb845bb
--- /dev/null
+++ b/extra/udev/udev-postmount.initd
@@ -0,0 +1,31 @@
1#!/sbin/runscript
2# Copyright 1999-2007 Gentoo Foundation
3# Distributed under the terms of the GNU General Public License v2
4# $Header: /var/cvsroot/gentoo-x86/sys-fs/udev/files/136/udev-postmount.initd,v 1.3 2009/02/23 16:30:53 zzam Exp $
5
6depend() {
7 need localmount
8}
9
10dir_writeable()
11{
12 mkdir "$1"/.test.$$ 2>/dev/null && rmdir "$1"/.test.$$
13}
14
15start() {
16 # check if this system uses udev
17 [ -d /dev/.udev/ ] || return 0
18
19 # only continue if rules-directory is writable
20 dir_writeable /etc/udev/rules.d || return 0
21
22 # store persistent-rules that got created while booting
23 # when / was still read-only
24 /lib/udev/move_tmp_persistent_rules.sh
25}
26
27stop() {
28 :
29}
30
31# vim:ts=4
diff --git a/extra/udev/udev-start.sh b/extra/udev/udev-start.sh
new file mode 100644
index 0000000000..87c3a6ac93
--- /dev/null
+++ b/extra/udev/udev-start.sh
@@ -0,0 +1,51 @@
1# Copyright 1999-2007 Gentoo Foundation
2# Distributed under the terms of the GNU General Public License v2
3
4[ -e /etc/conf.d/udev ] && . /etc/conf.d/udev
5
6compat_volume_nodes()
7{
8 # Only do this for baselayout-1*
9 # This check is likely to get false positives due to some multilib stuff,
10 # but that should not matter, as this can only happen on old openrc versions
11 # no longer available as ebuilds.
12 if [ ! -e /lib/librc.so ]; then
13
14 # Create nodes that udev can't
15 [ -x /sbin/lvm ] && \
16 /sbin/lvm vgscan -P --mknodes --ignorelockingfailure &>/dev/null
17 # Running evms_activate on a LiveCD causes lots of headaches
18 [ -z "${CDBOOT}" -a -x /sbin/evms_activate ] && \
19 /sbin/evms_activate -q &>/dev/null
20 fi
21}
22
23start_initd()
24{
25 (
26 . /etc/init.d/"$1"
27 _start
28 )
29}
30
31# mount tmpfs on /dev
32start_initd udev-mount || exit 1
33
34# Create a file so that our rc system knows it's still in sysinit.
35# Existance means init scripts will not directly run.
36# rc will remove the file when done with sysinit.
37# this is no longer needed as of openrc-0.4.0
38touch /dev/.rcsysinit
39
40# load device tarball
41start_initd udev-dev-tarball
42
43# run udevd
44start_initd udev || exit 1
45
46compat_volume_nodes
47
48# inject into boot runlevel
49IN_HOTPLUG=1 /etc/init.d/udev-postmount start >/dev/null 2>&1
50
51# udev started successfully
diff --git a/extra/udev/udev.initd b/extra/udev/udev.initd
new file mode 100755
index 0000000000..26774ab4ac
--- /dev/null
+++ b/extra/udev/udev.initd
@@ -0,0 +1,239 @@
1#!/sbin/runscript
2# Copyright 1999-2008 Gentoo Foundation
3# Distributed under the terms of the GNU General Public License v2
4
5description="Run udevd and create the device-nodes"
6
7[ -e /etc/udev/udev.conf ] && . /etc/udev/udev.conf
8
9rc_coldplug=${rc_coldplug:-${RC_COLDPLUG:-YES}}
10
11depend()
12{
13 provide dev
14 if yesno "${rc_device_tarball:-no}"; then
15 need sysfs udev-mount udev-dev-tarball
16 else
17 need sysfs udev-mount
18 fi
19 before checkfs fsck
20
21 # udev does not work inside vservers
22 keyword novserver
23}
24
25cleanup()
26{
27 # fail more gracely and not leave udevd running
28 start-stop-daemon --stop --exec /sbin/udevd
29 exit 1
30}
31
32disable_hotplug_agent()
33{
34 if [ -e /proc/sys/kernel/hotplug ]; then
35 echo "" >/proc/sys/kernel/hotplug
36 fi
37}
38
39root_link()
40{
41 /lib/udev/write_root_link_rule
42}
43
44rules_disable_switch()
45{
46 # this function disables rules files
47 # by creating new files with the same name
48 # in a temp rules directory with higher priority
49 local d=/dev/.udev/rules.d bname="$1" onoff="$2"
50
51 if yesno "${onoff}"; then
52 mkdir -p "$d"
53 echo "# This file disables ${bname} due to /etc/conf.d/udev" \
54 > "${d}/${bname}"
55 else
56 rm -f "${d}/${bname}"
57 fi
58}
59
60start_udevd()
61{
62 # load unix domain sockets if built as module, Bug #221253
63 if [ -e /proc/modules ] ; then
64 modprobe -q unix 2>/dev/null
65 fi
66 ebegin "Starting udevd"
67 start-stop-daemon --start --exec /sbin/udevd -- --daemon
68 eend $?
69}
70
71# populate /dev with devices already found by the kernel
72populate_dev()
73{
74 if get_bootparam "nocoldplug" ; then
75 rc_coldplug="NO"
76 ewarn "Skipping udev coldplug as requested in kernel cmdline"
77 fi
78
79 ebegin "Populating /dev with existing devices through uevents"
80 if yesno "${rc_coldplug}"; then
81 udevadm trigger
82 else
83 # Do not run any init-scripts, Bug #206518
84 udevadm control --env do_not_run_plug_service=1
85
86 # only create device nodes
87 udevadm trigger --attr-match=dev
88
89 # run persistent-net stuff, bug 191466
90 udevadm trigger --subsystem-match=net
91 fi
92 eend $?
93
94 ebegin "Waiting for uevents to be processed"
95 udevadm settle --timeout=${udev_settle_timeout:-60}
96 eend $?
97
98 udevadm control --env do_not_run_plug_service=
99 return 0
100}
101
102# for debugging
103start_udevmonitor()
104{
105 yesno "${udev_monitor:-no}" || return 0
106
107 udevmonitor_log=/dev/.udev/udevmonitor.log
108 udevmonitor_pid=/dev/.udev/udevmonitor.pid
109
110 einfo "udev: Running udevadm monitor ${udev_monitor_opts} to get a log of all events"
111 start-stop-daemon --start --stdout "${udevmonitor_log}" \
112 --make-pidfile --pidfile "${udevmonitor_pid}" \
113 --background --exec /sbin/udevadm -- monitor ${udev_monitor_opts}
114}
115
116stop_udevmonitor()
117{
118 yesno "${udev_monitor:-no}" || return 0
119
120 if yesno "${udev_monitor_keep_running:-no}"; then
121 ewarn "udev: udevmonitor is still running and writing into ${udevmonitor_log}"
122 else
123 einfo "udev: Stopping udevmonitor: Log is in ${udevmonitor_log}"
124 start-stop-daemon --stop --pidfile "${udevmonitor_pid}" --exec /sbin/udevadm
125 fi
126}
127
128display_hotplugged_services() {
129 local svcfile= svc= services=
130 for svcfile in "${RC_SVCDIR}"/hotplugged/*; do
131 svc="${svcfile##*/}"
132 [ -x "${svcfile}" ] || continue
133
134 # do not display this - better: do only inject it later :)
135 [ "$svc" = "udev-postmount" ] && continue
136
137 services="${services} ${svc}"
138 done
139 [ -n "${services}" ] && einfo "Device initiated services:${HILITE}${services}${NORMAL}"
140}
141
142inject_postmount_initd() {
143 if ! mark_service_hotplugged udev-postmount; then
144 IN_HOTPLUG=1 /etc/init.d/udev-postmount start >/dev/null 2>&1
145 fi
146 #einfo "Injected udev-postmount service"
147}
148
149check_persistent_net()
150{
151 # check if there are problems with persistent-net
152 local syspath= devs= problem=false
153 for syspath in /sys/class/net/*_rename*; do
154 if [ -d "${syspath}" ]; then
155 devs="${devs} ${syspath##*/}"
156 problem=true
157 fi
158 done
159
160 ${problem} || return 0
161
162 eerror "UDEV: Your system has a problem assigning persistent names"
163 eerror "to these network interfaces: ${devs}"
164
165 einfo "Checking persistent-net rules:"
166 # the sed-expression lists all duplicate lines
167 # from the input, like "uniq -d" does, but uniq
168 # is installed into /usr/bin and not available at boot.
169 dups=$(
170 RULES_FILE='/etc/udev/rules.d/70-persistent-net.rules'
171 . /lib/udev/rule_generator.functions
172 find_all_rules 'NAME=' '.*' | \
173 tr ' ' '\n' | \
174 sort | \
175 sed '$!N; s/^\(.*\)\n\1$/\1/; t; D'
176 )
177 if [ -n "${dups}" ]; then
178 ewarn "The rules create multiple entries assigning these names:"
179 eindent
180 ewarn "${dups}"
181 eoutdent
182 else
183 ewarn "Found no duplicate names in persistent-net rules,"
184 ewarn "there must be some other problem!"
185 fi
186 return 1
187}
188
189check_udev_works()
190{
191 # should exist on every system, else udev failed
192 if [ ! -e /dev/zero ]; then
193 eerror "Assuming udev failed somewhere, as /dev/zero does not exist."
194 return 1
195 fi
196 return 0
197}
198
199start()
200{
201 # do not run this on old baselayout where udev-addon gets loaded
202 if [ ! -f /etc/init.d/sysfs ]; then
203 eerror "The $SVCNAME init-script is written for baselayout-2!"
204 eerror "Please do not use it with baselayout-1!".
205 return 1
206 fi
207
208 _start
209
210 display_hotplugged_services
211
212 inject_postmount_initd
213}
214
215_start()
216{
217 root_link
218 rules_disable_switch 75-persistent-net-generator.rules "${persistent_net_disable:-no}"
219 rules_disable_switch 75-cd-aliases-generator.rules ${persistent_cd_disable:-no}
220
221 disable_hotplug_agent
222 start_udevd || cleanup
223 start_udevmonitor
224 populate_dev || cleanup
225
226 check_persistent_net
227
228 check_udev_works || cleanup
229 stop_udevmonitor
230
231 return 0
232}
233
234stop() {
235 ebegin "Stopping udevd"
236 start-stop-daemon --stop --exec /sbin/udevd
237 eend $?
238}
239
diff --git a/extra/udev/write_root_link_rule b/extra/udev/write_root_link_rule
new file mode 100755
index 0000000000..8eaea11769
--- /dev/null
+++ b/extra/udev/write_root_link_rule
@@ -0,0 +1,29 @@
1#!/bin/sh
2#
3# This script should run before doing udevtrigger at boot.
4# It will create a rule matching the device directory / is on, and
5# creating /dev/root symlink pointing on its device node.
6#
7# This is especially useful for hal looking at /proc/mounts containing
8# a line listing /dev/root as device:
9# /dev/root / reiserfs rw 0 0
10#
11# This program is free software; you can redistribute it and/or modify it
12# under the terms of the GNU General Public License as published by the
13# Free Software Foundation version 2 of the License.
14#
15# (c) 2007-2008 Matthias Schwarzott <zzam@gentoo.org>
16
17eval $(udevadm info --export --export-prefix="ROOT_" --device-id-of-file=/)
18
19[ $? = 0 ] || exit 0
20[ "$ROOT_MAJOR" = 0 ] && exit 0
21
22DIR=/dev/.udev/rules.d
23[ -d "$DIR" ] || mkdir -p "$DIR"
24RULES=$DIR/10-root-link.rules
25
26echo "# Created by /lib/udev/write_root_link_rule" > "${RULES}"
27echo "# This rule should create /dev/root as link to real root device." >> "${RULES}"
28echo "SUBSYSTEM==\"block\", ENV{MAJOR}==\"$ROOT_MAJOR\", ENV{MINOR}==\"$ROOT_MINOR\", SYMLINK+=\"root\"" >> "${RULES}"
29