From 0d1d6bec7c58b2f52e6e1932f58767a02c86068b Mon Sep 17 00:00:00 2001 From: Gregory Haynes Date: Sun, 20 Dec 2015 05:38:36 +0000 Subject: [PATCH] Properly fail/trap in eval_run_d In phases which are called from eval_run_d (block-device.d) we do not listen to exit 1's nor do we allow break=after-error. This is because the run_d function is called in a subshell in order to grab its output. This also turns on pipefail in the main disk-image-create script. Change-Id: I88ab2e7104148437eabfe6880e3a1e5ebbb2c15d --- lib/common-functions | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/lib/common-functions b/lib/common-functions index 0f1b2565..541f5796 100644 --- a/lib/common-functions +++ b/lib/common-functions @@ -113,12 +113,15 @@ function check_element () { # $1 is the hook to run # $2 is the regex to look for function eval_run_d () { - local TEMP=`run_d $1` - echo "$TEMP" - if [ `echo "$TEMP" | grep -s "$2"` ]; then - TEMP=`echo "$TEMP" | grep "$2"` - eval "$TEMP" - fi + local run_output=$(mktemp) + trap "rm -f $run_output; check_break after-error ${break_cmd:-bash}" ERR + run_d $1 $run_output + if grep -q "$2" $run_output; then + local temp=$(grep "$2" $run_output) + eval "$temp" + fi + rm $run_output + trap - ERR } # Usage: map_nbd $image @@ -194,9 +197,16 @@ function cleanup_image_dir () { # Run a directory of hooks outside the target (that is, no chrooting). function run_d() { check_element - check_break before-$1 bash + check_break before-$1 ${break_cmd:-bash} if [ -d ${TMP_HOOKS_PATH}/$1.d ] ; then - dib-run-parts ${TMP_HOOKS_PATH}/$1.d + if [ -n "$2" ]; then + dib-run-parts ${TMP_HOOKS_PATH}/$1.d | tee $2 + if [[ $PIPESTATUS[0] != 0 ]]; then + return 1 + fi + else + dib-run-parts ${TMP_HOOKS_PATH}/$1.d + fi fi check_break after-$1 bash }