From 51661c33a5ea4cfa68d39450cc1b96c3db36b037 Mon Sep 17 00:00:00 2001 From: Ian Wienand Date: Thu, 20 Oct 2016 13:30:41 +1100 Subject: [PATCH] Show tracing around sourcing environment.d files Sourcing of environment files is a bit different than running scripts, because they are imported into the current environment. That means that if they are fiddling with "set -x" you can get odd things in the output -- for example, if one environment file enables tracing then all proceeding sourcing will have it on, but all the files sourced before will not have output. This is super confusing. It's also very helpful to see how things are being expanded as they set environment variables. Thus I think the best idea is for environment files to leave tracing alone and dib-run-parts can a) give a useful output about what file it is sourcing and b) enable tracing around the import, then restore it to the previous state afterwards. Change-Id: I29f7df1514aeb988222d1094e8269eddb485c2a0 --- bin/dib-run-parts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/bin/dib-run-parts b/bin/dib-run-parts index 6207b10..0f81be1 100755 --- a/bin/dib-run-parts +++ b/bin/dib-run-parts @@ -57,13 +57,20 @@ source_environment() { local dir=$target_dir/../environment.d local env_files + local xtrace if [ -d ${dir} ] ; then env_files=$(find ${dir} -maxdepth 1 -xtype f | \ grep -E "/[0-9A-Za-z_\.-]+$" | \ LANG=C sort -n) for env_file in $env_files ; do + output "Sourcing environment file ${env_file}" + # Set tracing as we import these environment files; it's + # nice to see the definitions in the logs + xtrace=$(set +o | grep xtrace) + set -o xtrace source $env_file + $xtrace done fi }