From: Jo¶rgen Karlsson Date: Tue, 10 Nov 2015 13:55:00 +0000 (+0100) Subject: Add cleanup trap to yardstick-img-modify X-Git-Tag: brahmaputra.1.0~153 X-Git-Url: https://gerrit.opnfv.org/gerrit/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F79%2F3179%2F1;p=yardstick.git Add cleanup trap to yardstick-img-modify Fixes a problem with loopback devices not beeing detached when the image build fails. Change-Id: I3e422be4fb0157289a032c14700e184f58d544d9 Signed-off-by: Jo¶rgen Karlsson --- 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"