diff --git a/common.sh b/common.sh index 340eddf694..58187de883 100644 --- a/common.sh +++ b/common.sh @@ -765,3 +765,14 @@ function emerge_custom_kernel() { sudo -E PKGDIR="${tmp_pkgdir}" $EMERGE_BOARD_CMD --usepkgonly \ --root=${install_root} ${kernel} || die "Cannot emerge kernel to root" } + +function enable_strict_sudo { + if [ -z "$CROS_SUDO_KEEP_ALIVE" ]; then + echo "$0 was somehow invoked in a way that the sudo keep alive could" + echo "not be found. Failing due to this. See crosbug.com/18393." + exit 126 + fi + function sudo { + `type -P sudo` -n "$@" + } +} diff --git a/sdk_lib/enter_chroot.sh b/sdk_lib/enter_chroot.sh index 0339a761fe..de484afe48 100755 --- a/sdk_lib/enter_chroot.sh +++ b/sdk_lib/enter_chroot.sh @@ -9,6 +9,8 @@ SCRIPT_ROOT=$(readlink -f $(dirname "$0")/..) . "${SCRIPT_ROOT}/common.sh" || exit 1 +enable_strict_sudo + # Script must be run outside the chroot and as a regular user. assert_outside_chroot assert_not_root_user diff --git a/sdk_lib/make_chroot.sh b/sdk_lib/make_chroot.sh index 5479a0fc33..56f37e5cc8 100755 --- a/sdk_lib/make_chroot.sh +++ b/sdk_lib/make_chroot.sh @@ -14,6 +14,8 @@ SCRIPT_ROOT=$(readlink -f $(dirname "$0")/..) ENTER_CHROOT=$(readlink -f $(dirname "$0")/enter_chroot.sh) +enable_strict_sudo + # Check if the host machine architecture is supported. ARCHITECTURE="$(uname -m)" if [[ "$ARCHITECTURE" != "x86_64" ]]; then