From f264b82dd2c2bb8c58a042c4ca231488e8530440 Mon Sep 17 00:00:00 2001 From: Brian Harring Date: Sat, 1 Sep 2012 01:39:03 -0700 Subject: [PATCH] Force our umount w/in the chroot. Do this via ensuring that any common.sh invoker of raw umount (say a root script) sees our umount path. Additionally, inject into default profiles our override, and via an upgrade scriptlet. This is round two; originally appeared as CL:32088, was reverted due to: https://uberchromegw.corp.google.com/i/chromiumos/builders/chromiumos%20sdk/builds/2314/steps/BuildBoard/logs/stdio The fix however is just adding a single sudo mkdir. :/ BUG=chromium-os:23443 TEST=cros_sdk --replace --bootstrap TEST=cros_sdk --replace Change-Id: I0dc7522a9c623f40081d4f138cea0c2c45171fea Reviewed-on: https://gerrit.chromium.org/gerrit/32365 Commit-Ready: Brian Harring Tested-by: Brian Harring Reviewed-by: Chris Sosa --- chroot_version_hooks.d/47_path_overrides | 13 +++++++++++++ common.sh | 23 +++++++++++++++++++++-- sdk_lib/enter_chroot.sh | 6 +++++- sdk_lib/make_chroot.sh | 5 +++++ 4 files changed, 44 insertions(+), 3 deletions(-) create mode 100644 chroot_version_hooks.d/47_path_overrides diff --git a/chroot_version_hooks.d/47_path_overrides b/chroot_version_hooks.d/47_path_overrides new file mode 100644 index 0000000000..58f0dfbbe1 --- /dev/null +++ b/chroot_version_hooks.d/47_path_overrides @@ -0,0 +1,13 @@ +# Copyright (c) 2012 The Chromium OS Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +# Ensure that crosutils path overrides are in use; note that chroot +# creation also invokes this, thus why we check for CROS_CHROOT; for +# the normal upgrade pathway, it's non existant. For chroot creation, +# It points to the chroot base. +sudo mkdir -p "${CROS_CHROOT}/etc/profile.d/" +echo 'export PATH="/usr/local/path-overrides${PATH:+:${PATH}}"' | \ + sudo tee "${CROS_CHROOT}"/etc/profile.d/crosutils-path-overrides.sh \ + > /dev/null +sudo chmod 644 "${CROS_CHROOT}"/etc/profile.d/crosutils-path-overrides.sh diff --git a/common.sh b/common.sh index 839f421a5a..f4ff153fb0 100644 --- a/common.sh +++ b/common.sh @@ -466,12 +466,12 @@ assert_not_root_user() { # Usage: check_flags_only_and_allow_null_arg "$@" && set -- check_flags_only_and_allow_null_arg() { do_shift=1 - if [[ $# == 1 && -z "$@" ]]; then + if [ $# = 1 -a -z "$1" ]; then echo "$0: warning: ignoring null argument" >&2 shift do_shift=0 fi - if [[ $# -gt 0 ]]; then + if [ $# -gt 0 ]; then echo "error: invalid arguments: \"$@\"" >&2 flags_help exit 1 @@ -1071,3 +1071,22 @@ switch_to_strict_mode() { # TODO: Re-enable this once shflags is set -e safe. #switch_to_strict_mode + +# The following code is used to ensure our umount wrapper is in use. +# Shouldn't be invoked by anything other than common.sh +_enable_path_overrides(){ + # Ensure that our PATH overrides are in use. + local override_dir=$(readlink -f "${SCRIPT_ROOT}/path-overrides") + local IFS=: + local x + for x in ${PATH}; do + x=$(readlink -f "${x}") + if [ "${x}" = "${override_dir}" ]; then + # Already is in path; nothing more to do. + return + fi + done + export PATH="${override_dir}${PATH:+:${PATH}}" +} + +_enable_path_overrides diff --git a/sdk_lib/enter_chroot.sh b/sdk_lib/enter_chroot.sh index 77a25d4f4e..58cb0f5307 100755 --- a/sdk_lib/enter_chroot.sh +++ b/sdk_lib/enter_chroot.sh @@ -274,8 +274,12 @@ setup_env() { queue_mount /run/shm "--bind" /run/shm fi fi - queue_mount "${FLAGS_trunk}" "--bind" "${CHROOT_TRUNK_DIR}" + # Get path overrides for the chroot in place now- it's possible + # that they may be needed for early teardown. + queue_mount "${FLAGS_trunk}/src/scripts/path-overrides" "--bind" \ + "/usr/local/path-overrides" + queue_mount "${FLAGS_trunk}" "--bind" "${CHROOT_TRUNK_DIR}" debug "Setting up referenced repositories if required." REFERENCE_DIR=$(git config --file \ diff --git a/sdk_lib/make_chroot.sh b/sdk_lib/make_chroot.sh index f857f0f4a3..6f957c9f8b 100755 --- a/sdk_lib/make_chroot.sh +++ b/sdk_lib/make_chroot.sh @@ -177,6 +177,11 @@ init_setup () { sudo bash -e "${SCRIPT_ROOT}/chroot_version_hooks.d/45_rewrite_sudoers.d" \ "${FLAGS_chroot}" "${USER}" "${ENVIRONMENT_WHITELIST[@]}" + # Turn on the path overrides; subshelled to protect our env from whatever + # vars the scriptlet may bleed. + ( CROS_CHROOT="${FLAGS_chroot}" + . "${SCRIPT_ROOT}/chroot_version_hooks.d/47_path_overrides" ) + sudo find "${FLAGS_chroot}/etc/"sudoers* -type f -exec chmod 0440 {} + # Fix bad group for some. sudo chown -R root:root "${FLAGS_chroot}/etc/"sudoers*