From 88097e830fd96296776243278145614c70a4aa58 Mon Sep 17 00:00:00 2001 From: Ian Wienand Date: Tue, 17 May 2016 13:57:21 +1000 Subject: [PATCH] Source environment files in a subshell By sourcing the environment files directly into the running process, dib-run-parts can pollute its own environment. For example, if an environment script enables tracing (set -x) then that enables tracing for dib-run-parts; particularly annoying as it then spews a bunch of stuff relating to the profiling. Move to sourcing the environment files in a subshell with the scripts to be executed to keep things separate. Change-Id: I1e39822f218dc0322e2490a770f3dc867a55802c --- bin/dib-run-parts | 48 +++++++++++++++++++++++++++++------------------ 1 file changed, 30 insertions(+), 18 deletions(-) diff --git a/bin/dib-run-parts b/bin/dib-run-parts index 575e6fd..0f95373 100755 --- a/bin/dib-run-parts +++ b/bin/dib-run-parts @@ -38,6 +38,23 @@ output () { echo $name $(date) $* >&2 } +# source the environment files from environment.d +# arg : target_dir +source_environment() { + + local dir=$target_dir/../environment.d + local env_files + + 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 + source $env_file + done + fi +} + if [ $# -lt 1 ] ; then usage fi @@ -70,26 +87,21 @@ fi PROFILE_DIR=$(mktemp -d --tmpdir profiledir.XXXXXX) -ENVIRONMENT_D_DIR=$target_dir/../environment.d +# note, run this in a sub-shell so we don't pollute our +# own environment with source_environment +( + source_environment -if [ -d $ENVIRONMENT_D_DIR ] ; then - env_files=$(find $ENVIRONMENT_D_DIR -maxdepth 1 -xtype f | \ - grep -E "/[0-9A-Za-z_\.-]+$" | \ - LANG=C sort -n) - for env_file in $env_files ; do - source $env_file + for target in $targets ; do + output "Running $target_dir/$target" + target_tag=${target//\//_} + date +%s.%N > $PROFILE_DIR/start_$target_tag + $target_dir/$target + target_tag=${target//\//_} + date +%s.%N > $PROFILE_DIR/stop_$target_tag + output "$target completed" done -fi - -for target in $targets ; do - output "Running $target_dir/$target" - target_tag=${target//\//_} - date +%s.%N > $PROFILE_DIR/start_$target_tag - $target_dir/$target - target_tag=${target//\//_} - date +%s.%N > $PROFILE_DIR/stop_$target_tag - output "$target completed" -done +) echo "----------------------- PROFILING -----------------------" echo ""