diff options
Diffstat (limited to 'meta/recipes-core/udev/eudev/udev-cache')
-rw-r--r-- | meta/recipes-core/udev/eudev/udev-cache | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/meta/recipes-core/udev/eudev/udev-cache b/meta/recipes-core/udev/eudev/udev-cache new file mode 100644 index 0000000000..dcfff1cb45 --- /dev/null +++ b/meta/recipes-core/udev/eudev/udev-cache | |||
@@ -0,0 +1,75 @@ | |||
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 | |||
12 | export 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 | DEVCACHE_TMP="/dev/shm/udev-cache-tmp.tar" | ||
20 | SYSCONF_CACHED="/etc/udev/cache.data" | ||
21 | SYSCONF_TMP="/dev/shm/udev.cache" | ||
22 | DEVCACHE_REGEN="/dev/shm/udev-regen" # create to request cache regen | ||
23 | |||
24 | # A list of files which are used as a criteria to judge whether the udev cache could be reused. | ||
25 | CMP_FILE_LIST="/proc/version /proc/cmdline /proc/devices" | ||
26 | [ -f /proc/atags ] && CMP_FILE_LIST="$CMP_FILE_LIST /proc/atags" | ||
27 | |||
28 | # List of files whose metadata (size/mtime/name) will be included in cached | ||
29 | # system state. | ||
30 | META_FILE_LIST="lib/udev/rules.d/* etc/udev/rules.d/*" | ||
31 | |||
32 | # Command to compute system configuration. | ||
33 | sysconf_cmd () { | ||
34 | cat -- $CMP_FILE_LIST | ||
35 | stat -c '%s %Y %n' -- $META_FILE_LIST | awk -F/ '{print $1 " " $NF;}' | ||
36 | } | ||
37 | |||
38 | [ -f /etc/default/udev-cache ] && . /etc/default/udev-cache | ||
39 | |||
40 | if [ "$ROOTFS_READ_ONLY" = "yes" ]; then | ||
41 | [ "$VERBOSE" != "no" ] && echo "udev-cache: read-only rootfs, skip generating udev-cache" | ||
42 | exit 0 | ||
43 | fi | ||
44 | |||
45 | [ "$DEVCACHE" != "" ] || exit 0 | ||
46 | [ "${VERBOSE}" == "no" ] || echo -n "udev-cache: checking for ${DEVCACHE_REGEN}... " | ||
47 | if ! [ -e "$DEVCACHE_REGEN" ]; then | ||
48 | [ "${VERBOSE}" == "no" ] || echo "not found." | ||
49 | exit 0 | ||
50 | fi | ||
51 | [ "${VERBOSE}" == "no" ] || echo "found." | ||
52 | echo "Populating dev cache" | ||
53 | |||
54 | err_cleanup () { | ||
55 | echo "udev-cache: update failed!" | ||
56 | udevadm control --start-exec-queue | ||
57 | rm -f -- "$SYSCONF_TMP" "$DEVCACHE_TMP" "$DEVCACHE" "$SYSCONF_CACHED" | ||
58 | } | ||
59 | |||
60 | ( | ||
61 | set -e | ||
62 | trap 'err_cleanup' EXIT | ||
63 | udevadm control --stop-exec-queue | ||
64 | sysconf_cmd > "$SYSCONF_TMP" | ||
65 | find /dev -xdev \( -type b -o -type c -o -type l \) | cut -c 2- \ | ||
66 | | xargs tar cf "${DEVCACHE_TMP}" | ||
67 | gzip < "${DEVCACHE_TMP}" > "$DEVCACHE" | ||
68 | rm -f "${DEVCACHE_TMP}" | ||
69 | mv "$SYSCONF_TMP" "$SYSCONF_CACHED" | ||
70 | udevadm control --start-exec-queue | ||
71 | rm -f "$DEVCACHE_REGEN" | ||
72 | trap - EXIT | ||
73 | ) & | ||
74 | |||
75 | exit 0 | ||