From f2a893b74c62f8989add7981edcbe466226ddfe9 Mon Sep 17 00:00:00 2001 From: Gregory Haynes Date: Tue, 28 Apr 2015 00:02:15 +0000 Subject: [PATCH] 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 --- lib/img-functions | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/lib/img-functions b/lib/img-functions index 75ff5560b..f0bf4794e 100644 --- a/lib/img-functions +++ b/lib/img-functions @@ -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 }