summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoe MacDonald <joe@deserted.net>2013-09-27 15:09:06 -0400
committerJoe MacDonald <joe@deserted.net>2013-10-02 13:24:45 -0400
commitc7fc09794c20db9e3b32d326abb627985d2b5b65 (patch)
tree3519562a6192659686c770da2d059e5cf2d0e940
parenta43e03a87c4d69c2554621394127d50f197d9eaf (diff)
downloadmeta-selinux-c7fc09794c20db9e3b32d326abb627985d2b5b65.tar.gz
udev/init: work around dev-cache restore problems
Restoring from the dev-cache with selinux enforcing causes various failures as devices are lacking, at a minimum, reasonable types and attributes. If, on the other hand, we at least create the cache with selinux and xattrs preserved and restored, we get significantly fewer errors and warnings on boot and we can successfully restore the context further down in init anyway. It still leaves some devices mislabeled, though, and still produces warnings on boot. Previous versions of the initscript removed all use of the dev-cache, if need be, we fall back to that. It is possible to get the middle-ground behaviour by defining use_udev_cache at the top of the udev initscript. Signed-off-by: Joe MacDonald <joe@deserted.net>
-rw-r--r--recipes-core/udev/udev/init63
-rw-r--r--recipes-core/udev/udev/udev-cache32
2 files changed, 66 insertions, 29 deletions
diff --git a/recipes-core/udev/udev/init b/recipes-core/udev/udev/init
index e88bddf..a96638f 100644
--- a/recipes-core/udev/udev/init
+++ b/recipes-core/udev/udev/init
@@ -14,7 +14,9 @@ export TZ=/etc/localtime
14[ -d /sys/class ] || exit 1 14[ -d /sys/class ] || exit 1
15[ -r /proc/mounts ] || exit 1 15[ -r /proc/mounts ] || exit 1
16[ -x @UDEVD@ ] || exit 1 16[ -x @UDEVD@ ] || exit 1
17[ -f /etc/default/udev-cache ] && . /etc/default/udev-cache 17if [ "$use_udev_cache" != "" ]; then
18 [ -f /etc/default/udev-cache ] && . /etc/default/udev-cache
19fi
18[ -f /etc/udev/udev.conf ] && . /etc/udev/udev.conf 20[ -f /etc/udev/udev.conf ] && . /etc/udev/udev.conf
19[ -f /etc/default/rcS ] && . /etc/default/rcS 21[ -f /etc/default/rcS ] && . /etc/default/rcS
20 22
@@ -60,35 +62,38 @@ case "$1" in
60 # Cache handling. 62 # Cache handling.
61 # A list of files which are used as a criteria to judge whether the udev cache could be reused. 63 # A list of files which are used as a criteria to judge whether the udev cache could be reused.
62 CMP_FILE_LIST="/proc/version /proc/cmdline /proc/devices /proc/atags" 64 CMP_FILE_LIST="/proc/version /proc/cmdline /proc/devices /proc/atags"
63 if [ "$DEVCACHE" != "" ]; then 65 if [ "$use_udev_cache" != "" ]; then
64 if [ -e $DEVCACHE ]; then 66 if [ "$DEVCACHE" != "" ]; then
65 readfiles $CMP_FILE_LIST 67 if [ -e $DEVCACHE ]; then
66 NEWDATA="$READDATA"
67 readfiles /etc/udev/cache.data
68 OLDDATA="$READDATA"
69 if [ "$OLDDATA" = "$NEWDATA" ]; then
70 (cd /; tar xf $DEVCACHE > /dev/null 2>&1)
71 not_first_boot=1
72 [ "$VERBOSE" != "no" ] && echo "udev: using cache file $DEVCACHE"
73 [ -e /dev/shm/udev.cache ] && rm -f /dev/shm/udev.cache
74 else
75 # Output detailed reason why the cached /dev is not used
76 if [ "$VERBOSE" != "no" ]; then
77 echo "udev: udev cache not used"
78 echo "udev: we use $CMP_FILE_LIST as criteria to judge whether the cache /dev could be resued"
79 echo "udev: olddata: $OLDDATA"
80 echo "udev: newdata: $NEWDATA"
81 fi
82 echo "$NEWDATA" > /dev/shm/udev.cache
83 fi
84 else
85 if [ "$ROOTFS_READ_ONLY" != "yes" ]; then
86 # If rootfs is not read-only, it's possible that a new udev cache would be generated;
87 # otherwise, we do not bother to read files.
88 readfiles $CMP_FILE_LIST 68 readfiles $CMP_FILE_LIST
89 echo "$READDATA" > /dev/shm/udev.cache 69 NEWDATA="$READDATA"
70 readfiles /etc/udev/cache.data
71 OLDDATA="$READDATA"
72 if [ "$OLDDATA" = "$NEWDATA" ]; then
73 tar --directory=/ -xf $DEVCACHE > /dev/null 2>&1
74 not_first_boot=1
75 [ "$VERBOSE" != "no" ] && echo "udev: using cache file $DEVCACHE"
76 [ -e /dev/shm/udev.cache ] && rm -f /dev/shm/udev.cache
77 else
78 # Output detailed reason why the cached /dev is not used
79 if [ "$VERBOSE" != "no" ]; then
80 echo "udev: udev cache not used"
81 echo "udev: we use $CMP_FILE_LIST as criteria to judge whether the cache /dev could be resued"
82 echo "udev: olddata: $OLDDATA"
83 echo "udev: newdata: $NEWDATA"
84 fi
85 echo "$NEWDATA" > /dev/shm/udev.cache
86 fi
87 /usr/sbin/setenforce 1
88 else
89 if [ "$ROOTFS_READ_ONLY" != "yes" ]; then
90 # If rootfs is not read-only, it's possible that a new udev cache would be generated;
91 # otherwise, we do not bother to read files.
92 readfiles $CMP_FILE_LIST
93 echo "$READDATA" > /dev/shm/udev.cache
94 fi
90 fi 95 fi
91 fi 96 fi
92 fi 97 fi
93 98
94 # make_extra_nodes 99 # make_extra_nodes
@@ -101,7 +106,7 @@ case "$1" in
101 /usr/bin/udevadm control --env=STARTUP=1 106 /usr/bin/udevadm control --env=STARTUP=1
102 if [ "$not_first_boot" != "" ];then 107 if [ "$not_first_boot" != "" ];then
103 /usr/bin/udevadm trigger --action=add --subsystem-nomatch=tty --subsystem-nomatch=mem --subsystem-nomatch=vc --subsystem-nomatch=vtconsole --subsystem-nomatch=misc --subsystem-nomatch=dcon --subsystem-nomatch=pci_bus --subsystem-nomatch=graphics --subsystem-nomatch=backlight --subsystem-nomatch=video4linux --subsystem-nomatch=platform 108 /usr/bin/udevadm trigger --action=add --subsystem-nomatch=tty --subsystem-nomatch=mem --subsystem-nomatch=vc --subsystem-nomatch=vtconsole --subsystem-nomatch=misc --subsystem-nomatch=dcon --subsystem-nomatch=pci_bus --subsystem-nomatch=graphics --subsystem-nomatch=backlight --subsystem-nomatch=video4linux --subsystem-nomatch=platform
104 (/usr/bin/udevadm settle --timeout=3; /usr/bin/udevadm control --env=STARTUP=)& 109 (/usr/bin/udevadm settle --timeout=10; /usr/bin/udevadm control --env=STARTUP=)&
105 else 110 else
106 /usr/bin/udevadm trigger --action=add 111 /usr/bin/udevadm trigger --action=add
107 /usr/bin/udevadm settle 112 /usr/bin/udevadm settle
diff --git a/recipes-core/udev/udev/udev-cache b/recipes-core/udev/udev/udev-cache
new file mode 100644
index 0000000..6898577
--- /dev/null
+++ b/recipes-core/udev/udev/udev-cache
@@ -0,0 +1,32 @@
1#!/bin/sh -e
2
3### BEGIN INIT INFO
4# Provides: udev-cache
5# Required-Start: mountall
6# Required-Stop:
7# Default-Start: S
8# Default-Stop:
9# Short-Description: cache /dev to speedup the udev next boot
10### END INIT INFO
11
12export TZ=/etc/localtime
13
14[ -r /proc/mounts ] || exit 1
15[ -x @UDEVD@ ] || exit 1
16[ -d /sys/class ] || exit 1
17
18[ -f /etc/default/rcS ] && . /etc/default/rcS
19[ -f /etc/default/udev-cache ] && . /etc/default/udev-cache
20
21if [ "$ROOTFS_READ_ONLY" = "yes" ]; then
22 [ "$VERBOSE" != "no" ] && echo "udev-cache: read-only rootfs, skip generating udev-cache"
23 exit 0
24fi
25
26if [ "$DEVCACHE" != "" -a -e /dev/shm/udev.cache ]; then
27 echo "Populating dev cache"
28 tar --directory=/ --selinux --xattrs -cf "$DEVCACHE" dev
29 mv /dev/shm/udev.cache /etc/udev/cache.data
30fi
31
32exit 0