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
This commit is contained in:
parent
ec92ab4981
commit
88097e830f
|
@ -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 ""
|
||||
|
|
Loading…
Reference in New Issue