Gentoo Archives: gentoo-commits

From: "Matthias Schwarzott (zzam)" <zzam@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] gentoo-x86 commit in sys-fs/udev/files/151: udev-dev-tarball.initd udev-start.sh shell-compat-addon.sh udev-postmount.initd udev-stop.sh udev-mount.initd udev.confd shell-compat-KV.sh udev.initd
Date: Fri, 29 Jan 2010 21:14:50
Message-Id: E1NayAv-0006TF-LB@stork.gentoo.org
1 zzam 10/01/29 21:14:45
2
3 Added: udev-dev-tarball.initd udev-start.sh
4 shell-compat-addon.sh udev-postmount.initd
5 udev-stop.sh udev-mount.initd udev.confd
6 shell-compat-KV.sh udev.initd
7 Log:
8 Version bumped. Fix selinux, Bug #297317. Add use-flag old-hd-rules to control re-adding of rules for /dev/hd*, Bug #300627.
9 (Portage version: 2.1.7.16/cvs/Linux x86_64)
10
11 Revision Changes Path
12 1.1 sys-fs/udev/files/151/udev-dev-tarball.initd
13
14 file : http://sources.gentoo.org/viewcvs.py/gentoo-x86/sys-fs/udev/files/151/udev-dev-tarball.initd?rev=1.1&view=markup
15 plain: http://sources.gentoo.org/viewcvs.py/gentoo-x86/sys-fs/udev/files/151/udev-dev-tarball.initd?rev=1.1&content-type=text/plain
16
17 Index: udev-dev-tarball.initd
18 ===================================================================
19 #!/sbin/runscript
20 # Copyright 1999-2008 Gentoo Foundation
21 # Distributed under the terms of the GNU General Public License v2
22
23 description="Maintain a tarball of not udev managed device nodes"
24 [ -e /etc/conf.d/udev ] && . /etc/conf.d/udev
25
26 rc_device_tarball=${rc_device_tarball:-${RC_DEVICE_TARBALL:-NO}}
27 device_tarball=/lib/udev/state/devices.tar.bz2
28
29 depend() {
30 if [ -f /etc/init.d/sysfs ]; then
31 need udev-mount
32 fi
33 }
34
35 start()
36 {
37 _start
38 }
39
40 _start() {
41 if yesno "${rc_device_tarball}" && \
42 [ -s "${device_tarball}" ]
43 then
44 ebegin "Populating /dev with saved device nodes"
45 tar -jxpf "${device_tarball}" -C /dev
46 eend $?
47 fi
48 }
49
50 stop() {
51 if [ -e /dev/.devfsd ] || [ ! -e /dev/.udev ] || [ ! -z "${CDBOOT}" ] || \
52 ! yesno "${rc_device_tarball}" || \
53 ! touch "${device_tarball}" 2>/dev/null
54 then
55 return 0
56 fi
57
58 ebegin "Saving device nodes"
59 # Handle our temp files
60 save_tmp_base=/tmp/udev.savedevices."$$"
61 devices_udev="${save_tmp_base}"/devices.udev
62 devices_real="${save_tmp_base}"/devices.real
63 devices_totar="${save_tmp_base}"/devices.totar
64 device_tmp_tarball="${save_tmp_base}"/devices
65
66 rm -rf "${save_tmp_base}"
67 mkdir "${save_tmp_base}"
68 touch "${devices_udev}" "${devices_real}" \
69 "${devices_totar}" "${device_tmp_tarball}"
70
71 if [ -f "${devices_udev}" -a -f "${devices_real}" -a \
72 -f "${devices_totar}" -a -f "${device_tmp_tarball}" ]
73 then
74 cd /dev
75 # Find all devices, but ignore .udev directory
76 find . -xdev -type b -or -type c -or -type l | \
77 cut -d/ -f2- | \
78 grep -v ^\\.udev >"${devices_real}"
79
80 # Figure out what udev created
81 udevadm info --export-db | sed -ne 's,^[SN]: \(.*\),\1,p' >"${devices_udev}"
82 # These ones we also do not want in there
83 for x in MAKEDEV core fd initctl pts shm stderr stdin stdout root; do
84 echo "${x}" >> "${devices_udev}"
85 done
86 if [ -d /lib/udev/devices ]; then
87 cd /lib/udev/devices
88 find . -xdev -type b -or -type c -or -type l | \
89 cut -d/ -f2- >> "${devices_udev}"
90 cd /dev
91 fi
92
93 fgrep -x -v -f "${devices_udev}" "${devices_real}" > "${devices_totar}"
94
95 # Now only tarball those not created by udev if we have any
96 if [ -s "${devices_totar}" ]; then
97 # we dont want to descend into mounted filesystems (e.g. devpts)
98 # looking up username may involve NIS/network
99 # and net may be down
100 tar --one-file-system --numeric-owner \
101 -jcpf "${device_tmp_tarball}" -T "${devices_totar}"
102 mv -f "${device_tmp_tarball}" "${device_tarball}"
103 else
104 rm -f "${device_tarball}"
105 fi
106 eend 0
107 else
108 eend 1 "Could not create temporary files!"
109 fi
110
111 rm -rf "${save_tmp_base}"
112 }
113
114
115
116
117 1.1 sys-fs/udev/files/151/udev-start.sh
118
119 file : http://sources.gentoo.org/viewcvs.py/gentoo-x86/sys-fs/udev/files/151/udev-start.sh?rev=1.1&view=markup
120 plain: http://sources.gentoo.org/viewcvs.py/gentoo-x86/sys-fs/udev/files/151/udev-start.sh?rev=1.1&content-type=text/plain
121
122 Index: udev-start.sh
123 ===================================================================
124 # Copyright 1999-2007 Gentoo Foundation
125 # Distributed under the terms of the GNU General Public License v2
126
127 [ -e /etc/conf.d/udev ] && . /etc/conf.d/udev
128
129 . /lib/udev/shell-compat-addon.sh
130
131 compat_volume_nodes()
132 {
133 # Only do this for baselayout-1*
134 # This check is likely to get false positives due to some multilib stuff,
135 # but that should not matter, as this can only happen on old openrc versions
136 # no longer available as ebuilds.
137 if [ ! -e /lib/librc.so ]; then
138
139 # Create nodes that udev can't
140 [ -x /sbin/lvm ] && \
141 /sbin/lvm vgscan -P --mknodes --ignorelockingfailure &>/dev/null
142 # Running evms_activate on a LiveCD causes lots of headaches
143 [ -z "${CDBOOT}" -a -x /sbin/evms_activate ] && \
144 /sbin/evms_activate -q &>/dev/null
145 fi
146 }
147
148 start_initd()
149 {
150 (
151 . /etc/init.d/"$1"
152 _start
153 )
154 }
155
156 # set it as openrc does
157 RC_BOOTLEVEL=${BOOTLEVEL:-default}
158 RC_DEFAULTLEVEL=${DEFAULTLEVEL:-default}
159
160 # mount tmpfs on /dev
161 start_initd udev-mount || exit 1
162
163 # Create a file so that our rc system knows it's still in sysinit.
164 # Existance means init scripts will not directly run.
165 # rc will remove the file when done with sysinit.
166 # this is no longer needed as of openrc-0.4.0
167 touch /dev/.rcsysinit
168
169 # load device tarball
170 start_initd udev-dev-tarball
171
172 # run udevd
173 start_initd udev || exit 1
174
175 compat_volume_nodes
176
177 # udev started successfully
178 exit 0
179
180
181
182 1.1 sys-fs/udev/files/151/shell-compat-addon.sh
183
184 file : http://sources.gentoo.org/viewcvs.py/gentoo-x86/sys-fs/udev/files/151/shell-compat-addon.sh?rev=1.1&view=markup
185 plain: http://sources.gentoo.org/viewcvs.py/gentoo-x86/sys-fs/udev/files/151/shell-compat-addon.sh?rev=1.1&content-type=text/plain
186
187 Index: shell-compat-addon.sh
188 ===================================================================
189 # Copyright 1999-2008 Gentoo Foundation
190 # Distributed under the terms of the GNU General Public License v2
191
192 # functions that may not be defined, but are used by the udev-start and udev-stop addon
193 # used by baselayout-1 and openrc before version 0.4.0
194
195 cmd_exist()
196 {
197 type "$1" >/dev/null 2>&1
198 }
199
200 # does not exist in baselayout-1, does exist in openrc
201 if ! cmd_exist yesno; then
202 yesno() {
203 [ -z "$1" ] && return 1
204 case "$1" in
205 yes|Yes|YES) return 0 ;;
206 esac
207 return 1
208 }
209 fi
210
211 # does not exist in baselayout-1, does exist in openrc
212 #
213 # mountinfo <path>
214 # check if some filesystem is mounted at mountpoint <path>
215 #
216 # return value:
217 # 0 filesystem is mounted at <path>
218 # 1 no filesystem is mounted exactly at <path>
219 if ! cmd_exist mountinfo; then
220 mountinfo() {
221 [ "$1" = "-q" ] && shift
222 local dir="$1"
223
224 # check if entry is in /proc/mounts
225 local ret=$(gawk 'BEGIN { found="false"; }
226 $1 ~ "^#" { next }
227 $2 == "'$dir'" { found="true"; }
228 END { print found; }
229 ' /proc/mounts)
230
231 "${ret}"
232 }
233 fi
234
235 # does not exist in baselayout-1, does exist in openrc
236 #
237 # used syntax: fstabinfo --mount /dev
238 # it should mount /dev if an entry exists in /etc/fstab
239 #
240 # return value:
241 # 0 mount succeeded
242 # 1 mount failed or no entry exists
243 #
244 if ! cmd_exist fstabinfo; then
245 fstabinfo() {
246 [ "$1" = "--mount" ] || return 1
247 local dir="$2"
248
249 # RC_USE_FSTAB does only exist in baselayout-1
250 # this emulation is only needed on bl-1, so check always
251 yesno "${RC_USE_FSTAB}" || return 1
252
253 # no need to check fstab, mount does this already for us
254
255 # try mounting - better first check fstab and then mount without surpressing errors
256 mount -n "${dir}" 2>/dev/null
257 return $?
258 }
259 fi
260
261
262
263 1.1 sys-fs/udev/files/151/udev-postmount.initd
264
265 file : http://sources.gentoo.org/viewcvs.py/gentoo-x86/sys-fs/udev/files/151/udev-postmount.initd?rev=1.1&view=markup
266 plain: http://sources.gentoo.org/viewcvs.py/gentoo-x86/sys-fs/udev/files/151/udev-postmount.initd?rev=1.1&content-type=text/plain
267
268 Index: udev-postmount.initd
269 ===================================================================
270 #!/sbin/runscript
271 # Copyright 1999-2007 Gentoo Foundation
272 # Distributed under the terms of the GNU General Public License v2
273 # $Header: /var/cvsroot/gentoo-x86/sys-fs/udev/files/151/udev-postmount.initd,v 1.1 2010/01/29 21:14:43 zzam Exp $
274
275 depend() {
276 need localmount
277 after dbus # for trigger failed
278 }
279
280 dir_writeable()
281 {
282 mkdir "$1"/.test.$$ 2>/dev/null && rmdir "$1"/.test.$$
283 }
284
285 start() {
286 # check if this system uses udev
287 [ -d /dev/.udev/ ] || return 0
288
289 # Run the events that failed at first udev trigger
290 udevadm trigger --type=failed -v
291
292 # only continue if rules-directory is writable
293 dir_writeable /etc/udev/rules.d || return 0
294
295 # store persistent-rules that got created while booting
296 # when / was still read-only
297 /lib/udev/move_tmp_persistent_rules.sh
298 }
299
300 stop() {
301 :
302 }
303
304 # vim:ts=4
305
306
307
308 1.1 sys-fs/udev/files/151/udev-stop.sh
309
310 file : http://sources.gentoo.org/viewcvs.py/gentoo-x86/sys-fs/udev/files/151/udev-stop.sh?rev=1.1&view=markup
311 plain: http://sources.gentoo.org/viewcvs.py/gentoo-x86/sys-fs/udev/files/151/udev-stop.sh?rev=1.1&content-type=text/plain
312
313 Index: udev-stop.sh
314 ===================================================================
315 # Copyright 1999-2007 Gentoo Foundation
316 # Distributed under the terms of the GNU General Public License v2
317
318 # for function yesno
319 . /lib/udev/shell-compat-addon.sh
320
321 # store device tarball
322 (
323 . /etc/init.d/udev-dev-tarball
324 stop
325 )
326
327 exit 0
328
329
330
331 1.1 sys-fs/udev/files/151/udev-mount.initd
332
333 file : http://sources.gentoo.org/viewcvs.py/gentoo-x86/sys-fs/udev/files/151/udev-mount.initd?rev=1.1&view=markup
334 plain: http://sources.gentoo.org/viewcvs.py/gentoo-x86/sys-fs/udev/files/151/udev-mount.initd?rev=1.1&content-type=text/plain
335
336 Index: udev-mount.initd
337 ===================================================================
338 #!/sbin/runscript
339 # Copyright 1999-2008 Gentoo Foundation
340 # Distributed under the terms of the GNU General Public License v2
341
342 description="Mount tmpfs on /dev"
343 [ -e /etc/conf.d/udev ] && . /etc/conf.d/udev
344
345 # get_KV and KV_to_int
346 . /lib/udev/shell-compat-KV.sh
347
348 # FIXME
349 # Instead of this script testing kernel version, udev itself should
350 # Maybe something like udevd --test || exit $?
351 check_kernel()
352 {
353 if [ $(get_KV) -lt $(KV_to_int '%KV_MIN%') ]; then
354 eerror "Your kernel is too old to work with this version of udev."
355 eerror "Current udev only supports Linux kernel %KV_MIN% and newer."
356 return 1
357 fi
358
359 yesno "${unreliable_kernel_warning:-yes}" || return 0
360
361 if [ $(get_KV) -lt $(KV_to_int '%KV_MIN_RELIABLE%') ]; then
362 ewarn "You need at least Linux kernel %KV_MIN_RELIABLE% for reliable operation of udev."
363 fi
364 return 0
365 }
366
367
368 mount_dev_directory()
369 {
370 if mountinfo -q /dev; then
371 einfo "/dev is already mounted"
372 return 0
373 fi
374
375 # No options are processed here as they should all be in /etc/fstab
376 ebegin "Mounting /dev"
377 if ! fstabinfo --mount /dev; then
378 # we mount devtmpfs if supported
379 local fs=tmpfs
380 grep -qs devtmpfs /proc/filesystems && fs=devtmpfs
381
382 # Some devices require exec, Bug #92921
383 mount -n -t "$fs" -o "exec,nosuid,mode=0755,size=10M" udev /dev
384 fi
385 eend $?
386 }
387
388 seed_dev()
389 {
390 # Seed /dev with some things that we know we need
391
392 # creating /dev/console, /dev/tty and /dev/tty1 to be able to write
393 # to $CONSOLE with/without bootsplash before udevd creates it
394 [ -c /dev/console ] || mknod -m 600 /dev/console c 5 1
395 [ -c /dev/tty1 ] || mknod -m 620 /dev/tty1 c 4 1
396 [ -c /dev/tty ] || mknod -m 666 /dev/tty c 5 0
397
398 # udevd will dup its stdin/stdout/stderr to /dev/null
399 # and we do not want a file which gets buffered in ram
400 [ -c /dev/null ] || mknod -m 666 /dev/null c 1 3
401 ${HAVE_SELINUX} && restorecon /dev/null
402
403 # so udev can add its start-message to dmesg
404 [ -c /dev/kmsg ] || mknod -m 660 /dev/kmsg c 1 11
405
406 # copy over any persistant things
407 if [ -d /lib/udev/devices ]; then
408 cp -RPp /lib/udev/devices/* /dev 2>/dev/null
409 fi
410
411 # Not provided by sysfs but needed
412 ln -snf /proc/self/fd /dev/fd
413 ln -snf fd/0 /dev/stdin
414 ln -snf fd/1 /dev/stdout
415 ln -snf fd/2 /dev/stderr
416 [ -e /proc/kcore ] && ln -snf /proc/kcore /dev/core
417
418 # Create problematic directories
419 mkdir -p /dev/pts /dev/shm
420 ${HAVE_SELINUX} && restorecon -R /dev >/dev/null
421 return 0
422 }
423
424
425 start()
426 {
427 # do not run this on too old baselayout - udev-addon is already loaded!
428 if [ ! -f /etc/init.d/sysfs ]; then
429 eerror "The $SVCNAME init-script is written for baselayout-2!"
430 eerror "Please do not use it with baselayout-1!".
431 return 1
432 fi
433
434 _start
435 }
436
437 _start()
438 {
439 check_kernel || return 1
440 mount_dev_directory || return 1
441
442 # Selinux lovin; /selinux should be mounted by selinux-patched init
443 if [ -x /sbin/restorecon -a -c /selinux/null ]; then
444 HAVE_SELINUX=true
445 restorecon /dev > /selinux/null
446 else
447 HAVE_SELINUX=false
448 fi
449
450 # make sure it exists
451 mkdir -p /dev/.udev /dev/.udev/rules.d
452
453 seed_dev
454
455 return 0
456 }
457
458
459
460 1.1 sys-fs/udev/files/151/udev.confd
461
462 file : http://sources.gentoo.org/viewcvs.py/gentoo-x86/sys-fs/udev/files/151/udev.confd?rev=1.1&view=markup
463 plain: http://sources.gentoo.org/viewcvs.py/gentoo-x86/sys-fs/udev/files/151/udev.confd?rev=1.1&content-type=text/plain
464
465 Index: udev.confd
466 ===================================================================
467 # /etc/conf.d/udev: config file for udev
468
469 # We discourage to disable persistent-net!!
470 # this may lead to random interface naming
471
472 # Disable adding new rules for persistent-net
473 persistent_net_disable="no"
474
475 # Disable adding new rules for persistent-cd
476 # Disabling this will stop new cdrom devices to appear
477 # as /dev/{cdrom,cdrw,dvd,dvdrw}
478 persistent_cd_disable="no"
479
480 # Set to "yes" if you want to save /dev to a tarball on shutdown
481 # and restore it on startup. This is useful if you have a lot of
482 # custom device nodes that udev does not handle/know about.
483 #
484 # As this option is fragile, we recommend you
485 # to create your devices in /lib/udev/devices.
486 # These will be copied to /dev on boot.
487 #rc_device_tarball="NO"
488
489 # udev can trigger coldplug events which cause services to start and
490 # kernel modules to be loaded.
491 # Services are deferred to start in the boot runlevel.
492 # Set rc_coldplug="NO" if you don't want this.
493 # If you want module coldplugging but not coldplugging of services then you
494 # can disable service coldplugging in baselayout/openrc config files.
495 # The setting is named different in different versions.
496 # in /etc/rc.conf: rc_hotplug="!*" or
497 # in /etc/conf.d/rc: rc_plug_services="!*"
498 #rc_coldplug="YES"
499
500
501
502
503 # Expert options:
504
505 # Disable warning about unreliable kernel/udev combination
506 #unreliable_kernel_warning="no"
507
508 # Timeout in seconds to wait for processing of uevents at boot.
509 # There should be no need to change this.
510 #udev_settle_timeout="60"
511
512 # Run udevadmin monitor to get a log of all events
513 # in /dev/.udev/udevmonitor.log
514 #udev_monitor="YES"
515
516 # Keep udevmonitor running after populating /dev.
517 #udev_monitor_keep_running="no"
518
519 # Set cmdline options for udevmonitor.
520 # could be some of --env --kernel --udev
521 #udev_monitor_opts="--env"
522
523
524
525
526 1.1 sys-fs/udev/files/151/shell-compat-KV.sh
527
528 file : http://sources.gentoo.org/viewcvs.py/gentoo-x86/sys-fs/udev/files/151/shell-compat-KV.sh?rev=1.1&view=markup
529 plain: http://sources.gentoo.org/viewcvs.py/gentoo-x86/sys-fs/udev/files/151/shell-compat-KV.sh?rev=1.1&content-type=text/plain
530
531 Index: shell-compat-KV.sh
532 ===================================================================
533 # Copyright 1999-2008 Gentoo Foundation
534 # Distributed under the terms of the GNU General Public License v2
535
536 # provides get_KV and KV_to_int as not all openrc-versions installed via ebuild have these
537
538 cmd_exist()
539 {
540 type "$1" >/dev/null 2>&1
541 }
542
543 # does exist in baselayout-1
544 # does not exist in openrc, but is added by openrc-ebuild since some time
545 if ! cmd_exist KV_to_int; then
546 KV_to_int() {
547 [ -z $1 ] && return 1
548
549 local x=${1%%-*}
550 local KV_MAJOR=${x%%.*}
551 x=${x#*.}
552 local KV_MINOR=${x%%.*}
553 x=${x#*.}
554 local KV_MICRO=${x%%.*}
555 local KV_int=$((${KV_MAJOR} * 65536 + ${KV_MINOR} * 256 + ${KV_MICRO} ))
556
557 # We make version 2.2.0 the minimum version we will handle as
558 # a sanity check ... if its less, we fail ...
559 [ "${KV_int}" -lt 131584 ] && return 1
560
561 echo "${KV_int}"
562 }
563 fi
564
565 # same as KV_to_int
566 if ! cmd_exist get_KV; then
567 _RC_GET_KV_CACHE=""
568 get_KV() {
569 [ -z "${_RC_GET_KV_CACHE}" ] \
570 && _RC_GET_KV_CACHE="$(uname -r)"
571
572 echo "$(KV_to_int "${_RC_GET_KV_CACHE}")"
573
574 return $?
575 }
576 fi
577
578
579
580
581 1.1 sys-fs/udev/files/151/udev.initd
582
583 file : http://sources.gentoo.org/viewcvs.py/gentoo-x86/sys-fs/udev/files/151/udev.initd?rev=1.1&view=markup
584 plain: http://sources.gentoo.org/viewcvs.py/gentoo-x86/sys-fs/udev/files/151/udev.initd?rev=1.1&content-type=text/plain
585
586 Index: udev.initd
587 ===================================================================
588 #!/sbin/runscript
589 # Copyright 1999-2008 Gentoo Foundation
590 # Distributed under the terms of the GNU General Public License v2
591
592 description="Run udevd and create the device-nodes"
593
594 [ -e /etc/udev/udev.conf ] && . /etc/udev/udev.conf
595
596 rc_coldplug=${rc_coldplug:-${RC_COLDPLUG:-YES}}
597
598 depend()
599 {
600 if [ -f /etc/init.d/sysfs ]; then
601 # require new enough openrc with sysinit being extra runlevel
602 # on linux we just check if sysfs init-script exists
603 # this is to silence out ugly warnings about not-existing sysfs script
604 provide dev
605 if yesno "${rc_device_tarball:-no}"; then
606 need sysfs udev-mount udev-dev-tarball
607 else
608 need sysfs udev-mount
609 fi
610 before checkfs fsck
611
612 # udev does not work inside vservers
613 keyword novserver
614 fi
615 }
616
617 cleanup()
618 {
619 # fail more gracely and not leave udevd running
620 start-stop-daemon --stop --exec /sbin/udevd
621 exit 1
622 }
623
624 disable_hotplug_agent()
625 {
626 if [ -e /proc/sys/kernel/hotplug ]; then
627 echo "" >/proc/sys/kernel/hotplug
628 fi
629 }
630
631 root_link()
632 {
633 /lib/udev/write_root_link_rule
634 }
635
636 rules_disable_switch()
637 {
638 # this function disables rules files
639 # by creating new files with the same name
640 # in a temp rules directory with higher priority
641 local f=/dev/.udev/rules.d/"$1" bname="$1" onoff="$2"
642
643 if yesno "${onoff}"; then
644 echo "# This file disables ${bname} due to /etc/conf.d/udev" \
645 > "${f}"
646 else
647 rm -f "${f}"
648 fi
649 }
650
651 # only called on openrc
652 is_service_enabled() {
653 local svc="$1"
654
655 [ ! -e "/etc/init.d/${svc}" ] && return 1
656
657 [ -e "/etc/runlevels/${RC_BOOTLEVEL}/${svc}" ] && return 0
658 [ -e "/etc/runlevels/${RC_DEFAULTLEVEL}/${svc}" ] && return 0
659 return 1
660 }
661
662 check_openrc_net()
663 {
664 local f=/dev/.udev/rules.d/90-network.rules
665 is_service_enabled network || return 0
666
667 # disable network hotplugging
668 echo "# This file disables network hotplug events calling old-style openrc net scripts" >> "${f}"
669 echo "# as we use new-style network init script /etc/init.d/network" >> "${f}"
670 }
671
672 start_udevd()
673 {
674 # load unix domain sockets if built as module, Bug #221253
675 if [ -e /proc/modules ] ; then
676 modprobe -q unix 2>/dev/null
677 fi
678 ebegin "Starting udevd"
679 start-stop-daemon --start --exec /sbin/udevd -- --daemon
680 eend $?
681 }
682
683 # populate /dev with devices already found by the kernel
684 populate_dev()
685 {
686 if get_bootparam "nocoldplug" ; then
687 rc_coldplug="NO"
688 ewarn "Skipping udev coldplug as requested in kernel cmdline"
689 fi
690
691 ebegin "Populating /dev with existing devices through uevents"
692 if yesno "${rc_coldplug}"; then
693 udevadm trigger
694 else
695 # Do not run any init-scripts, Bug #206518
696 udevadm control --env do_not_run_plug_service=1
697
698 # only create device nodes
699 udevadm trigger --attr-match=dev
700
701 # run persistent-net stuff, bug 191466
702 udevadm trigger --subsystem-match=net
703 fi
704 eend $?
705
706 # we can speed up booting under these conditions:
707 # * using devtmpfs so kernel creates device nodes for us
708 # * only using kernel created device nodes at boot (in /etc/fstab and elsewhere)
709 #
710 ebegin "Waiting for uevents to be processed"
711 udevadm settle --timeout=${udev_settle_timeout:-60}
712 eend $?
713
714 udevadm control --env do_not_run_plug_service=
715 return 0
716 }
717
718 # for debugging
719 start_udevmonitor()
720 {
721 yesno "${udev_monitor:-no}" || return 0
722
723 udevmonitor_log=/dev/.udev/udevmonitor.log
724 udevmonitor_pid=/dev/.udev/udevmonitor.pid
725
726 einfo "udev: Running udevadm monitor ${udev_monitor_opts} to get a log of all events"
727 start-stop-daemon --start --stdout "${udevmonitor_log}" \
728 --make-pidfile --pidfile "${udevmonitor_pid}" \
729 --background --exec /sbin/udevadm -- monitor ${udev_monitor_opts}
730 }
731
732 stop_udevmonitor()
733 {
734 yesno "${udev_monitor:-no}" || return 0
735
736 if yesno "${udev_monitor_keep_running:-no}"; then
737 ewarn "udev: udevmonitor is still running and writing into ${udevmonitor_log}"
738 else
739 einfo "udev: Stopping udevmonitor: Log is in ${udevmonitor_log}"
740 start-stop-daemon --stop --pidfile "${udevmonitor_pid}" --exec /sbin/udevadm
741 fi
742 }
743
744 display_hotplugged_services() {
745 local svcfile= svc= services=
746 for svcfile in "${RC_SVCDIR}"/hotplugged/*; do
747 svc="${svcfile##*/}"
748 [ -x "${svcfile}" ] || continue
749
750 services="${services} ${svc}"
751 done
752 [ -n "${services}" ] && einfo "Device initiated services:${HILITE}${services}${NORMAL}"
753 }
754
755 check_persistent_net()
756 {
757 # check if there are problems with persistent-net
758 local syspath= devs= problem=false
759 for syspath in /sys/class/net/*_rename*; do
760 if [ -d "${syspath}" ]; then
761 devs="${devs} ${syspath##*/}"
762 problem=true
763 fi
764 done
765
766 ${problem} || return 0
767
768 eerror "UDEV: Your system has a problem assigning persistent names"
769 eerror "to these network interfaces: ${devs}"
770
771 einfo "Checking persistent-net rules:"
772 # the sed-expression lists all duplicate lines
773 # from the input, like "uniq -d" does, but uniq
774 # is installed into /usr/bin and not available at boot.
775 dups=$(
776 RULES_FILE='/etc/udev/rules.d/70-persistent-net.rules'
777 . /lib/udev/rule_generator.functions
778 find_all_rules 'NAME=' '.*' | \
779 tr ' ' '\n' | \
780 sort | \
781 sed '$!N; s/^\(.*\)\n\1$/\1/; t; D'
782 )
783 if [ -n "${dups}" ]; then
784 ewarn "The rules create multiple entries assigning these names:"
785 eindent
786 ewarn "${dups}"
787 eoutdent
788 else
789 ewarn "Found no duplicate names in persistent-net rules,"
790 ewarn "there must be some other problem!"
791 fi
792 return 1
793 }
794
795 check_udev_works()
796 {
797 # should exist on every system, else udev failed
798 if [ ! -e /dev/zero ]; then
799 eerror "Assuming udev failed somewhere, as /dev/zero does not exist."
800 return 1
801 fi
802 return 0
803 }
804
805 start()
806 {
807 # do not run this on old baselayout where udev-addon gets loaded
808 if [ ! -f /etc/init.d/sysfs ]; then
809 eerror "The $SVCNAME init-script is written for baselayout-2!"
810 eerror "Please do not use it with baselayout-1!".
811 return 1
812 fi
813
814 check_openrc_net
815 _start
816
817 display_hotplugged_services
818
819 return 0
820 }
821
822 _start()
823 {
824 if [ ! -e /etc/runlevels/${RC_DEFAULTLEVEL:-default}/udev-postmount ]; then
825 ewarn "You should add udev-postmount service to your default runlevel."
826 fi
827
828 root_link
829 rules_disable_switch 75-persistent-net-generator.rules "${persistent_net_disable:-no}"
830 rules_disable_switch 75-cd-aliases-generator.rules ${persistent_cd_disable:-no}
831
832 disable_hotplug_agent
833 start_udevd || cleanup
834 start_udevmonitor
835 populate_dev || cleanup
836
837 check_persistent_net
838
839 check_udev_works || cleanup
840 stop_udevmonitor
841
842 return 0
843 }
844
845 stop() {
846 ebegin "Stopping udevd"
847 start-stop-daemon --stop --exec /sbin/udevd
848 eend $?
849 }