From eb8320b2e924e22c20af49a0d37bee12417ede95 Mon Sep 17 00:00:00 2001 From: Jo¶rgen Karlsson Date: Tue, 10 Nov 2015 14:55:00 +0100 Subject: Add cleanup trap to yardstick-img-modify MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes a problem with loopback devices not beeing detached when the image build fails. Change-Id: I3e422be4fb0157289a032c14700e184f58d544d9 Signed-off-by: Jo¶rgen Karlsson --- tools/yardstick-img-modify | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/tools/yardstick-img-modify b/tools/yardstick-img-modify index ee9a45780..33065627f 100755 --- a/tools/yardstick-img-modify +++ b/tools/yardstick-img-modify @@ -25,6 +25,7 @@ # set -e +set -x die() { echo "error: $1" >&2 @@ -117,13 +118,34 @@ cleanup() { rm -rf $mountdir } -set -x +exitcode="" +error_trap() +{ + local rc=$? + + set +e + + if [ -z "$exitcode" ]; then + exitcode=$rc + fi + + cleanup + + echo "Image build failed with $exitcode" + + exit $exitcode +} main() { cleanup + + trap "error_trap" EXIT SIGTERM + download setup modify + + trap - EXIT SIGTERM cleanup echo "the modified image is found here: $imgfile" -- cgit 1.2.3-korg