enter_chroot should only modify things within a lock.

enter_chroot is often called from multiple processes and we expect that
it doesn't modify anything unless it's within a lock. This CL moves
chroot modifications up to occur during the lock so that we don't have
multiple modifications to .gitconfig occurring at the same time.

This prevents the following warning:
  error: could not lock config file
/b/cbuild/chroot/home/chrome-bot/.gitconfig: File exists

See http://chromeos-botmaster.mtv.corp.google.com:8026/builders/TOT%20Pre-Flight%20Queue/builds/3771/steps/Test/logs/stdio

BUG=chromium-os:17661
TEST=Run enter_chroot.sh and verify gitconfig is still setup.

Change-Id: I73a7755d62cce895c76b8e0f35838b3874e5db33
Reviewed-on: http://gerrit.chromium.org/gerrit/4208
Reviewed-by: Chris Sosa <sosa@chromium.org>
Tested-by: David James <davidjames@chromium.org>
This commit is contained in:
David James 2011-07-15 15:21:18 -07:00
parent d6ae1ec95e
commit 342f156c35

View File

@ -277,6 +277,20 @@ function setup_env {
fi
fi
if [ -d "$HOME/.subversion" ]; then
TARGET="/home/${USER}/.subversion"
mkdir -p "${FLAGS_chroot}${TARGET}"
ensure_mounted "${HOME}/.subversion" "--bind" "${TARGET}"
fi
# Configure committer username and email in chroot .gitconfig
git config -f ${FLAGS_chroot}/home/${USER}/.gitconfig --replace-all \
user.name "$(cd /tmp; git var GIT_COMMITTER_IDENT | \
sed -e 's/ *<.*//')" || true
git config -f ${FLAGS_chroot}/home/${USER}/.gitconfig --replace-all \
user.email "$(cd /tmp; git var GIT_COMMITTER_IDENT | \
sed -e 's/.*<\([^>]*\)>.*/\1/')" || true
# Fix permissions on shared memory to allow non-root users access to POSIX
# semaphores.
sudo chmod -R 777 "${FLAGS_chroot}/dev/shm"
@ -377,21 +391,6 @@ for type in http_proxy ftp_proxy all_proxy GIT_PROXY_COMMAND GIT_SSH; do
fi
done
if [ -d "$HOME/.subversion" ]; then
TARGET="/home/${USER}/.subversion"
mkdir -p "${FLAGS_chroot}${TARGET}"
ensure_mounted "${HOME}/.subversion" "--bind" "${TARGET}"
fi
# Configure committer username and email in chroot .gitconfig
git config -f ${FLAGS_chroot}/home/${USER}/.gitconfig --replace-all \
user.name "$(cd /tmp; git var GIT_COMMITTER_IDENT | sed -e 's/ *<.*//')" ||
true
git config -f ${FLAGS_chroot}/home/${USER}/.gitconfig --replace-all \
user.email "$(cd /tmp; git var GIT_COMMITTER_IDENT | \
sed -e 's/.*<\([^>]*\)>.*/\1/')" ||
true
# Run command or interactive shell. Also include the non-chrooted path to
# the source trunk for scripts that may need to print it (e.g.
# build_image.sh).