[OE-core] [PATCH v2 12/12] udev-cache: refactor; improve verbosity and error handling
Richard Tollerton
rich.tollerton at ni.com
Fri Aug 22 21:30:58 UTC 2014
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 improve handling of VERBOSE a bit.
Previously, errors encountered during find, tar, etc. were ignored,
which could mask some problems, or cause invalid cache files to get
created. To solve: abort the update process (and report an error) if any
command in the process fails; and write the system configuration to
$SYSCONF_TMP first -- only update $SYSCONF_CACHED when we are certain
that the cache tarball was successfully created.
Signed-off-by: Richard Tollerton <rich.tollerton at ni.com>
---
meta/recipes-core/udev/udev/udev-cache | 33 ++++++++++++++++++++-------------
1 file changed, 20 insertions(+), 13 deletions(-)
diff --git a/meta/recipes-core/udev/udev/udev-cache b/meta/recipes-core/udev/udev/udev-cache
index baeb125..dc97198 100644
--- a/meta/recipes-core/udev/udev/udev-cache
+++ b/meta/recipes-core/udev/udev/udev-cache
@@ -41,19 +41,26 @@ if [ "$ROOTFS_READ_ONLY" = "yes" ]; then
exit 0
fi
-if [ "$DEVCACHE" != "" -a -e "$DEVCACHE_REGEN" ]; then
- echo "Populating dev cache"
- (
- # Run sysconf_cmd before `tar`, not after, so that as little
- # time as possible elapses between creating $SYSCONF_CACHED and
- # $DEVCACHE.
- sysconf_cmd > "$SYSCONF_CACHED"
- 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}"
- 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; building cache."
+
+(
+ # Run sysconf_cmd before `tar`, not after, so that as little time as
+ # possible elapses between creating $SYSCONF_CACHED and $DEVCACHE.
+ if ! { 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" \
+ && mv "$SYSCONF_TMP" "$SYSCONF_CACHED" \
+ && rm -f "$DEVCACHE_REGEN" "${DEVCACHE_TMP}"; }
+ then
+ echo "udev-cache: update failed!"
+ fi
+) &
exit 0
--
2.0.4
More information about the Openembedded-core
mailing list