]> code.ossystems Code Review - openembedded-core.git/commitdiff
udev-cache: refactor conditionals and error handling
authorRichard Tollerton <rich.tollerton@ni.com>
Tue, 21 Jan 2014 19:46:46 +0000 (13:46 -0600)
committerRichard Purdie <richard.purdie@linuxfoundation.org>
Fri, 19 Dec 2014 17:54:15 +0000 (17:54 +0000)
Most of /etc/init.d/udev-cache is in a conditional block which can be
replaced by a `[ ... ] || exit 0` to reduce nesting.

This also provides an opportunity to add some additional messages
when VERBOSE is set.

Capture and report errors encountered in the cache generation process,
using set -e and trap EXIT. These errors were previously being ignored.

Signed-off-by: Richard Tollerton <rich.tollerton@ni.com>
meta/recipes-core/udev/udev/udev-cache

index 3c1806199113cead3b0f2f85620c4f0dccc6c3b0..895b1971c4f64223754305359d7323da4af5c96d 100644 (file)
@@ -42,19 +42,28 @@ if [ "$ROOTFS_READ_ONLY" = "yes" ]; then
     exit 0
 fi
 
-if [ "$DEVCACHE" != "" -a -e "$DEVCACHE_REGEN" ]; then
-       echo "Populating dev cache"
-       (
-               udevadm control --stop-exec-queue
-               sysconf_cmd > "$SYSCONF_TMP"
-               find /dev -xdev \( -type b -o -type c -o -type l \) | cut -c 2- \
-                       | xargs tar cf "${DEVCACHE_TMP}" -T-
-                       gzip < "${DEVCACHE_TMP}" > "$DEVCACHE"
-                       rm -f "${DEVCACHE_TMP}"
-                       mv "$SYSCONF_TMP" "$SYSCONF_CACHED"
-                       udevadm control --start-exec-queue
-                       rm -f "$DEVCACHE_REGEN"
-       ) &
+[ "$DEVCACHE" != "" ] || exit 0
+[ "${VERBOSE}" == "no" ] || echo -n "udev-cache: checking for ${DEVCACHE_REGEN}... "
+if ! [ -e "$DEVCACHE_REGEN" ]; then
+       [ "${VERBOSE}" == "no" ] || echo "not found."
+       exit 0
 fi
+[ "${VERBOSE}" == "no" ] || echo "found."
+echo "Populating dev cache"
+
+(
+       set -e
+       trap 'echo "udev-cache: update failed!"' EXIT
+       udevadm control --stop-exec-queue
+       sysconf_cmd > "$SYSCONF_TMP"
+       find /dev -xdev \( -type b -o -type c -o -type l \) | cut -c 2- \
+               | xargs tar cf "${DEVCACHE_TMP}" -T-
+       gzip < "${DEVCACHE_TMP}" > "$DEVCACHE"
+       rm -f "${DEVCACHE_TMP}"
+       mv "$SYSCONF_TMP" "$SYSCONF_CACHED"
+       udevadm control --start-exec-queue
+       rm -f "$DEVCACHE_REGEN"
+       trap - EXIT
+) &
 
 exit 0