Actually set a sane PATH for inside chroot
In I084aff7e449f5de811a6169ec90e352ada7da439 we attemped to address a bug for systems which dont have a path that works well for inside a chroot. Turns out there were multiple issues: * The PATH we were setting was after we attempted to call sh. * PATH was being set in a sibling process to the command being run. * PATH was not being exported so it was not effecting child processes. Using env to set a sane path before we attempt to run our commands addresses these issues. Change-Id: I4285f8048465ee5c2490116447d32033007bd185
This commit is contained in:
parent
c1d7cb4d6c
commit
f2a893b74c
@ -56,18 +56,16 @@ function ensure_sudo () {
|
||||
|
||||
# Helper function to run a command inside the chroot
|
||||
function run_in_target () {
|
||||
# Force the inclusion of a typical set of dirs in PATH, this is needed for guest
|
||||
# distros that have path elements not in the host PATH.
|
||||
# Note that we're not expanding PATH during argument processing, the \$
|
||||
# will preserve the PATH syntax until after the sh command runs
|
||||
cmd="PATH=\$PATH:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin ; $@"
|
||||
cmd="$@"
|
||||
# -E to preserve http_proxy
|
||||
ORIG_HOME=$HOME
|
||||
export HOME=/root
|
||||
# Force an empty TMPDIR inside the chroot. There is no need to use an user
|
||||
# defined tmp dir which may not exist in the chroot.
|
||||
# Bug: #1330290
|
||||
sudo -E TMPDIR= chroot $TMP_MOUNT_PATH sh -c "$cmd"
|
||||
# Force the inclusion of a typical set of dirs in PATH, this is needed for guest
|
||||
# distros that have path elements not in the host PATH.
|
||||
sudo -E TMPDIR= chroot $TMP_MOUNT_PATH env PATH="\$PATH:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" sh -c "$cmd"
|
||||
export HOME=$ORIG_HOME
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user