diff --git a/scripts/Build-Target b/scripts/Build-Target index 0e5006c6b..c573ff7d3 100755 --- a/scripts/Build-Target +++ b/scripts/Build-Target @@ -355,6 +355,22 @@ pkgloop_action() { $cmd_buildpkg } +# Try to umount any directories mounted by Build-Pkg -chroot +# if we are the last process using them. +# +umount_chroot() { + exec 201> /dev/null + if [ -z "$( fuser "${build_logs}/*.log" )" ]; then + umount -d -f $build_rock/{loop,config,download} 2> /dev/null + umount -d -f -l $build_rock/{loop,config,download} 2> /dev/null + umount -d -f $build_root/proc 2> /dev/null + umount -d -f -l $build_root/proc 2> /dev/null + fi +} + +# must trap outside the group command +trap 'umount_chroot' EXIT + { ln -sf build_target_$$.log ${build_logs}/build_target.log ./scripts/Build-Tools -1 -cfg $config