From f06493bcd63f433e1553d7a0b4447d1a447f88e5 Mon Sep 17 00:00:00 2001 From: Gregory Haynes Date: Fri, 10 Oct 2014 17:01:37 -0700 Subject: [PATCH] Preserve exit value when leaving cleanup trap If we entered the cleanup trap due to exit with an error code we should exit dib with an error code. Change-Id: Iee1a05668b3239113fb91a2da0d9a66d7de4db6b --- lib/common-functions | 2 +- lib/img-functions | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/common-functions b/lib/common-functions index 9ac62bd3..6681dc78 100644 --- a/lib/common-functions +++ b/lib/common-functions @@ -36,7 +36,7 @@ function mk_build_dir () { sudo mount -t tmpfs tmpfs $TMP_IMAGE_DIR fi sudo chown $(id -u):$(id -g) $TMP_BUILD_DIR $TMP_IMAGE_DIR - trap cleanup EXIT + trap trap_cleanup EXIT echo Building in $TMP_BUILD_DIR export TMP_IMAGE_PATH=$TMP_IMAGE_DIR/image.raw export TMP_HOOKS_PATH=$TMP_BUILD_DIR/hooks diff --git a/lib/img-functions b/lib/img-functions index d973f29e..b2838604 100644 --- a/lib/img-functions +++ b/lib/img-functions @@ -28,6 +28,12 @@ function unmount_image () { fi } +function trap_cleanup() { + exitval=$? + cleanup + exit $exitval +} + function cleanup () { unmount_image cleanup_dirs