Patchwork [v2,12/12] udev-cache: refactor; improve verbosity and error handling

login
register
mail settings
Submitter Richard Tollerton
Date Aug. 22, 2014, 9:30 p.m.
Message ID <fda8933d3d23815d7eee6a2e4398e00bb97947b5.1408742574.git.rich.tollerton@ni.com>
Download mbox | patch
Permalink /patch/78853/
State New
Headers show

Comments

Richard Tollerton - Aug. 22, 2014, 9:30 p.m.
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@ni.com>
---
 meta/recipes-core/udev/udev/udev-cache | 33 ++++++++++++++++++++-------------
 1 file changed, 20 insertions(+), 13 deletions(-)

Patch

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