diff --git a/archive_hwqual b/archive_hwqual index 718bbdf742..c31b464dbc 100755 --- a/archive_hwqual +++ b/archive_hwqual @@ -34,7 +34,7 @@ function main() { # Parse command line FLAGS "$@" || exit 1 eval set -- "${FLAGS_ARGV}" - set -e + switch_to_strict_mode if [[ -z "${FLAGS_from}" ]]; then echo "Please specify --from directory" diff --git a/bin/cros_download_latest_image b/bin/cros_download_latest_image index 87d0f6470b..c0ac6e8790 100755 --- a/bin/cros_download_latest_image +++ b/bin/cros_download_latest_image @@ -42,7 +42,7 @@ eval set -- "$FLAGS_ARGV" # Check on the board that they are trying to set up. if [ -z "$FLAGS_board" ] ; then - die "Error: --board required." + die_notrace "Error: --board required." fi BUCKET="chromeos-image-archive" diff --git a/bin/cros_get_chrome_version b/bin/cros_get_chrome_version index 938b57a681..e5c9467909 100755 --- a/bin/cros_get_chrome_version +++ b/bin/cros_get_chrome_version @@ -31,7 +31,7 @@ find_common_sh FLAGS "$@" || exit 1 -set -e +switch_to_strict_mode # TMP necessary for remote_access_init. TMP=$(mktemp -d /tmp/cros_check_chrome_version.XXXX) diff --git a/bin/cros_make_image_bootable b/bin/cros_make_image_bootable index 3e5f1213f6..33ac51399d 100755 --- a/bin/cros_make_image_bootable +++ b/bin/cros_make_image_bootable @@ -36,7 +36,7 @@ assert_inside_chroot die "Unable to load /usr/lib/installer/chromeos-common.sh" . "${SCRIPTS_DIR}/build_library/build_image_util.sh" || die "No build_image_util" -set -e +switch_to_strict_mode if [ $# -lt 2 ]; then echo "Usage: ${0} /PATH/TO/IMAGE IMAGE.BIN [shflags overrides]" @@ -143,8 +143,8 @@ FLAGS "${@}" || exit 1 [ -z "${FLAGS_verity_salt}" ] && FLAGS_verity_salt=$(make_salt) # Only now can we die on error. shflags functions leak non-zero error codes, -# so will die prematurely if 'set -e' is specified before now. -set -e -u +# so will die prematurely if 'switch_to_strict_mode' is specified before now. +switch_to_strict_mode -u # $1 - Directory where developer rootfs is mounted. # $2 - Directory where developer stateful_partition is mounted. diff --git a/bin/cros_package_to_live b/bin/cros_package_to_live index 0414f6c905..711268230a 100755 --- a/bin/cros_package_to_live +++ b/bin/cros_package_to_live @@ -68,7 +68,7 @@ if [ -z "${FLAGS_board}" ]; then exit 1 fi -set -e +switch_to_strict_mode trap cleanup EXIT eval set -- "${FLAGS_ARGV}" diff --git a/bin/cros_resign_image.sh b/bin/cros_resign_image.sh index 3d5e6a85eb..21f76553fd 100755 --- a/bin/cros_resign_image.sh +++ b/bin/cros_resign_image.sh @@ -57,7 +57,7 @@ FLAGS "$@" || exit 1 eval set -- "${FLAGS_ARGV}" # Abort on error -set -e +switch_to_strict_mode if [ -z $FLAGS_from ] || [ ! -f $FLAGS_from ] ; then echo "Error: invalid flag --from" diff --git a/bin/cros_sign_to_ssd b/bin/cros_sign_to_ssd index 64960cef72..dfd9d7301d 100755 --- a/bin/cros_sign_to_ssd +++ b/bin/cros_sign_to_ssd @@ -50,7 +50,7 @@ failure() { } # Abort on error -set -e +switch_to_strict_mode trap "failure" EXIT @@ -68,18 +68,19 @@ fi VBOOT_DIR="${SRC_ROOT}/platform/vboot_reference" if [ ! -d "${VBOOT_DIR}" ]; then - die "VBOOT DIR NOT FOUND at \'${VBOOT_DIR}\' .." + die_notrace "VBOOT DIR NOT FOUND at \'${VBOOT_DIR}\' .." fi TMP_IMAGE=$(mktemp) VBOOT_KEYS="${VBOOT_DIR}/tests/devkeys" if [ ! -d "${VBOOT_KEYS}" ]; then - die "VBOOT KEYS NOT FOUND at \'${VBOOT_KEYS}\' .." + die_notrace "VBOOT KEYS NOT FOUND at \'${VBOOT_KEYS}\' .." fi VBOOT_SIGN="${VBOOT_DIR}/scripts/image_signing/sign_official_build.sh" if [ ! -x "${VBOOT_SIGN}" ]; then - die "VBOOT TOOL sign_official_build.sh NOT FOUND at \'${VBOOT_SIGN}\' .." + die_notrace \ + "VBOOT TOOL sign_official_build.sh NOT FOUND at \'${VBOOT_SIGN}\' .." fi cp "${FLAGS_from}" "${TMP_IMAGE}" diff --git a/bin/cros_workon_make b/bin/cros_workon_make index 639183035c..9bed17cd6f 100755 --- a/bin/cros_workon_make +++ b/bin/cros_workon_make @@ -28,4 +28,5 @@ find_common_sh . "${SCRIPT_ROOT}/common.sh" || (echo "Unable to load common.sh" && exit 1) # --- END COMMON.SH BOILERPLATE --- -die "error: Please run cros_workon_make from chroot:/usr/bin/cros_workon_make" +die_notrace \ + "error: Please run cros_workon_make from chroot:/usr/bin/cros_workon_make" diff --git a/build_image b/build_image index bf077bf4bc..3b67a9e059 100755 --- a/build_image +++ b/build_image @@ -87,8 +87,8 @@ FLAGS "$@" || exit 1 eval set -- "${FLAGS_ARGV}" # Only now can we die on error. shflags functions leak non-zero error codes, -# so will die prematurely if 'set -e' is specified before now. -set -e +# so will die prematurely if 'switch_to_strict_mode' is specified before now. +switch_to_strict_mode # Determine build version. OVERLAY_CHROMEOS_DIR="${SRC_ROOT}/third_party/chromiumos-overlay/chromeos" @@ -161,7 +161,7 @@ fi if [ $((FLAGS_rootfs_size + FLAGS_rootfs_hash_pad)) -gt \ ${FLAGS_rootfs_partition_size} ] ; then - die "rootfs ($((FLAGS_rootfs_size + FLAGS_rootfs_hash_pad)) MiB) is" \ + die_notrace "rootfs ($((FLAGS_rootfs_size + FLAGS_rootfs_hash_pad)) MiB) is" \ "bigger than partition (${FLAGS_rootfs_partition_size} MiB)." fi @@ -204,7 +204,8 @@ if [[ -e "${BUILD_DIR}" ]]; then else error "Directory ${BUILD_DIR} already exists." error "Use --build_attempt option to specify an unused attempt." - die "Or use --replace if you want to overwrite this directory." + error "Or use --replace if you want to overwrite this directory." + die "Unwilling to overwrite ${BUILD_DIR}." fi fi diff --git a/build_kernel_image.sh b/build_kernel_image.sh index dc111bc0d4..d151da1e33 100755 --- a/build_kernel_image.sh +++ b/build_kernel_image.sh @@ -58,7 +58,7 @@ FLAGS "$@" || exit 1 eval set -- "${FLAGS_ARGV}" # Die on error -set -e +switch_to_strict_mode verity_args= # Even with a rootfs_image, root= is not changed unless specified. diff --git a/build_library/base_image_util.sh b/build_library/base_image_util.sh index 1d9e515507..7286ecf5ae 100755 --- a/build_library/base_image_util.sh +++ b/build_library/base_image_util.sh @@ -73,7 +73,8 @@ create_base_image() { ROOT_LOOP_DEV=$(sudo losetup --show -f "${ROOT_FS_IMG}") if [ -z "${ROOT_LOOP_DEV}" ] ; then - die "No free loop device. Free up a loop device or reboot. exiting. " + die_notrace \ + "No free loop device. Free up a loop device or reboot. exiting. " fi # Specify a block size and block count to avoid using the hash pad. @@ -105,7 +106,8 @@ create_base_image() { DISK_LABEL="C-STATE" STATEFUL_LOOP_DEV=$(sudo losetup --show -f "${STATEFUL_FS_IMG}") if [ -z "${STATEFUL_LOOP_DEV}" ] ; then - die "No free loop device. Free up a loop device or reboot. exiting. " + die_notrace \ + "No free loop device. Free up a loop device or reboot. exiting. " fi sudo mkfs.ext4 "${STATEFUL_LOOP_DEV}" sudo tune2fs -L "${DISK_LABEL}" -U "${UUID}" -c 0 -i 0 "${STATEFUL_LOOP_DEV}" @@ -138,7 +140,8 @@ create_base_image() { LIBC_PATH="${PKGDIR}/cross-${CHOST}/${LIBC_TAR}" if ! [[ -e ${LIBC_PATH} ]]; then - die "${LIBC_PATH} does not exist. Try running ./setup_board" \ + die_notrace \ + "${LIBC_PATH} does not exist. Try running ./setup_board" \ "--board=${BOARD} to update the version of libc installed on that board." fi diff --git a/build_library/build_image_util.sh b/build_library/build_image_util.sh index d2cbfebee6..d355ad89e3 100755 --- a/build_library/build_image_util.sh +++ b/build_library/build_image_util.sh @@ -65,14 +65,15 @@ parse_build_image_args() { get_images_to_build ${FLAGS_ARGV} if should_build_image ${CHROMEOS_TEST_IMAGE_NAME}; then if should_build_image "${CHROMEOS_FACTORY_TEST_IMAGE_NAME}"; then - die "Cannot build both the test and factory_test images." + die_notrace "Cannot build both the test and factory_test images." fi fi if should_build_image ${CHROMEOS_BASE_IMAGE_NAME} \ ${CHROMEOS_DEVELOPER_IMAGE_NAME} ${CHROMEOS_TEST_IMAGE_NAME} \ ${CHROMEOS_FACTORY_TEST_IMAGE_NAME} && should_build_image ${CHROMEOS_FACTORY_INSTALL_SHIM_NAME}; then - die "Can't build ${CHROMEOS_FACTORY_INSTALL_SHIM_NAME} with any other" \ + die_notrace \ + "Can't build ${CHROMEOS_FACTORY_INSTALL_SHIM_NAME} with any other" \ "image." fi if should_build_image ${CHROMEOS_FACTORY_INSTALL_SHIM_NAME}; then diff --git a/build_library/create_legacy_bootloader_templates.sh b/build_library/create_legacy_bootloader_templates.sh index 663dadda37..bae387c4f4 100755 --- a/build_library/create_legacy_bootloader_templates.sh +++ b/build_library/create_legacy_bootloader_templates.sh @@ -33,7 +33,7 @@ DEFINE_integer verity_max_ios 1024 \ # Parse flags FLAGS "$@" || exit 1 eval set -- "${FLAGS_ARGV}" -set -e +switch_to_strict_mode # Only let dm-verity block if rootfs verification is configured. dev_wait=0 diff --git a/build_library/test_build_root b/build_library/test_build_root index eb593322e5..0409582275 100755 --- a/build_library/test_build_root +++ b/build_library/test_build_root @@ -19,14 +19,14 @@ FLAGS "$@" || exit 1 eval set -- "${FLAGS_ARGV}" # Die on any errors -set -e +switch_to_strict_mode # Check all parts of a pipe set -o pipefail ROOT="$FLAGS_root" if [[ ! -d "$ROOT" ]]; then - die "Root FS does not exist ($ROOT)" + die_notrace "Root FS does not exist ($ROOT)" fi BINARIES="$ROOT/usr/bin/Xorg diff --git a/build_packages b/build_packages index ed9f2d0ca8..3256d91390 100755 --- a/build_packages +++ b/build_packages @@ -70,7 +70,7 @@ eval set -- "${FLAGS_ARGV}" check_flags_only_and_allow_null_arg "$@" && set -- # Die on any errors. -set -e +switch_to_strict_mode # Right now build_packages has to be run from scripts/ . ${SRC_ROOT}/third_party/chromiumos-overlay/chromeos/config/chromeos_version.sh @@ -167,7 +167,7 @@ fi # backtracking. Only print the output if this step fails. if ! OUTPUT=$(emerge-${FLAGS_board} -pe --backtrack=0 ${PACKAGES} 2>&1); then printf "%s\n" "${OUTPUT}" - die "emerge detected broken ebuilds. See error message above." + die_notrace "emerge detected broken ebuilds. See error message above." fi for pkg in ${CROS_WORKON_PKGS}; do diff --git a/common.sh b/common.sh index 876739c882..f270dc09bb 100644 --- a/common.sh +++ b/common.sh @@ -7,8 +7,6 @@ # All scripts should die on error unless commands are specifically excepted # by prefixing with '!' or surrounded by 'set +e' / 'set -e'. -# TODO: Re-enable this once shflags is less prone to dying. -#set -e # The number of jobs to pass to tools that can run in parallel (such as make # and dpkg-buildpackage @@ -52,21 +50,115 @@ if tput colors >/dev/null 2>&1; then V_VIDOFF="$(tput sgr0)" fi +# Stubs for sh compatibility. +function _dump_trace() { :; } +function _escaped_echo() { + printf '%b\n' "$*" +} + +# Bash awareness, including stacktraces if possible. +if [ -n "${BASH_VERSION-}" ]; then + function _escaped_echo() { + echo -e "$@" + } + # Turn on bash debug support if available. + if shopt -s extdebug 2> /dev/null; then + # Pull the path relative to this lib; SCRIPT_ROOT should always be set, + # but has never been formally required. + if [ -n "${SOURCE_ROOT-}" ]; then + . "${SOURCE_ROOT}"/common_bash_backtraces.sh + else + x=$(readlink -f "${BASH_SOURCE[0]}") + . "${x%/*}"/common_bash_backtraces.sh + unset x + fi + fi +fi + # Declare these asap so that code below can safely assume they exist. +function _message { + local prefix="${1}" + shift + if [ $# -eq 0 ]; then + _escaped_echo >&2 "${prefix}${CROS_LOG_PREFIX:-""}:${V_VIDOFF}" + return + fi + ( + # Handle newlines in the message, prefixing each chunk correctly. + # Do this in a subshell to avoid having to track IFS/set -f state. + IFS=" +" + set +f + set -- $* + IFS=' ' + if [ $# -eq 0 ]; then + # Empty line was requested. + set -- '' + fi + for line in "$@"; do + _escaped_echo >&2 "${prefix}${CROS_LOG_PREFIX:-}: ${line}${V_VIDOFF}" + done + ) +} + function info { - echo -e >&2 "${V_BOLD_GREEN}INFO ${CROS_LOG_PREFIX:-""}: $@${V_VIDOFF}" + _message "${V_BOLD_GREEN}INFO " "$*" } function warn { - echo -e >&2 "${V_BOLD_YELLOW}WARNING ${CROS_LOG_PREFIX:-""}: $@${V_VIDOFF}" + _message "${V_BOLD_YELLOW}WARNING " "$*" } function error { - echo -e >&2 "${V_BOLD_RED}ERROR ${CROS_LOG_PREFIX:-""}: $@${V_VIDOFF}" + _message "${V_BOLD_RED}ERROR " "$*" } + +# For all die functions, they must explicitly force set +eu; +# no reason to have them cause their own crash if we're inthe middle +# of reporting an error condition then exiting. + +function die_err_trap { + local command="$1" result="$2" + set +e +u + + # Per the message, bash misreports 127 as 1 during err trap sometimes. + # Note this fact to ensure users don't place too much faith in the + # exit code in that case. + set -- "Command '${command}' exited with nonzero code: ${result}" + if [ -n "${BASH_VERSION-}" ]; then + if [ "$result" = 1 ] && [ -z "$(type -t $command)" ]; then + set -- "$@" \ + '(Note bash sometimes misreports "command not found" as exit code 1 '\ +'instead of 127)' + fi + fi + _dump_trace + error + error "Command failed:" + DIE_PREFIX=' ' + die_notrace "$@" +} + +# Exit this script due to a failure, outputting a backtrace in the process. function die { - error "$@" + set +e +u + _dump_trace + error + error "Error was:" + DIE_PREFIX=' ' + die_notrace "$@" +} + +# Exit this script w/out a backtrace. +function die_notrace { + set +e +u + if [ $# -eq 0 ]; then + set -- '(no error message given)' + fi + for line in "$@"; do + error "${DIE_PREFIX}$line" + done exit 1 } @@ -137,7 +229,7 @@ CHROMEOS_DEV_SETTINGS="${CHROMEOS_DEV_SETTINGS:-$SCRIPTS_DIR/.chromeos_dev}" if [ -f "$CHROMEOS_DEV_SETTINGS" ]; then # Turn on exit-on-error during custom settings processing SAVE_OPTS=$(set +o) - set -e + switch_to_strict_mode # Read settings . "$CHROMEOS_DEV_SETTINGS" @@ -863,3 +955,16 @@ function show_help_if_requested() { fi done } + +function switch_to_strict_mode() { + # Set up strict execution mode; note that the trap + # must follow switch_to_strict_mode, else it will have no effect. + set -e + trap 'die_err_trap "${BASH_COMMAND:-command unknown}" "$?"' ERR + if [ $# -ne 0 ]; then + set "$@" + fi +} + +# TODO: Re-enable this once shflags is set -e safe. +#switch_to_strict_mode diff --git a/common_bash_backtraces.sh b/common_bash_backtraces.sh new file mode 100644 index 0000000000..adfc26d48a --- /dev/null +++ b/common_bash_backtraces.sh @@ -0,0 +1,35 @@ +# 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. + +# Code used for bash stack dumps included by common.sh when we're in +# bash mode. + +# Output a backtrace all the way back to the raw invocation, suppressing +# only the _dump_trace frame itself. + +function _dump_trace { + local j n p func src line args + p=${#BASH_ARGV[@]} + for (( n = ${#FUNCNAME[@]}; n > 1; n-- )); do + func=${FUNCNAME[${n} - 1]} + src=${BASH_SOURCE[${n}]##*/} + line=${BASH_LINENO[${n} - 1]} + args= + if [[ -z ${BASH_ARGC[${n} -1]} ]]; then + args='(args unknown, no debug available)' + else + for (( j = 0 ; j < ${BASH_ARGC[${n} -1]} ; ++j )); do + args="${args:+${args} }'${BASH_ARGV[$(( p - j - 1 ))]}'" + done + ! (( p -= ${BASH_ARGC[${n} - 1]} )) + fi + if [[ $n == ${#FUNCNAME[@]} ]]; then + error "script called: ${0##/*} ${args}" + error "Backtrace: (most recent call is last)" + else + error "$(printf ' file %s, line %s, called: %s %s' \ + "${src}" "${line}" "${func}" "${args}")" + fi + done +} diff --git a/cros_generate_breakpad_symbols b/cros_generate_breakpad_symbols index 6b89e04620..6dfd87d237 100755 --- a/cros_generate_breakpad_symbols +++ b/cros_generate_breakpad_symbols @@ -159,9 +159,9 @@ function main() { FLAGS "$@" || exit 1 eval set -- "${FLAGS_ARGV}" - set -e + switch_to_strict_mode - [ -n "$FLAGS_board" ] || die "--board is required." + [ -n "$FLAGS_board" ] || die_notrace "--board is required." SYSROOT="/build/${FLAGS_board}" diff --git a/cros_generate_stacks_bvt b/cros_generate_stacks_bvt index 15b7206311..6beabe8839 100755 --- a/cros_generate_stacks_bvt +++ b/cros_generate_stacks_bvt @@ -16,16 +16,16 @@ function usage() { if [ -z "$1" ] ; then usage - die "The URL or path to symbols tarball (debug.tgz) is required" + die_notrace "The URL or path to symbols tarball (debug.tgz) is required" fi if [ -z "$2" ] ; then usage - die "The URL to BVT test results is required" + die_notrace "The URL to BVT test results is required" fi # Die on any errors. -set -e +switch_to_strict_mode BREAKPAD_DIR="debug/breakpad" STACKS_GENERATED="" diff --git a/cros_show_stacks b/cros_show_stacks index b06a16e04c..c4ea71334c 100755 --- a/cros_show_stacks +++ b/cros_show_stacks @@ -133,7 +133,7 @@ function main() { fi else [ -n "${FLAGS_ARGV}" ] || usage - [ -n "${FLAGS_board}" ] || die "--board is required." + [ -n "${FLAGS_board}" ] || die_notrace "--board is required." fi local modules_file="${TMP}/modules" diff --git a/get_latest_image.sh b/get_latest_image.sh index 884ab15cc6..7829a1f201 100755 --- a/get_latest_image.sh +++ b/get_latest_image.sh @@ -20,7 +20,7 @@ eval set -- "${FLAGS_ARGV}" # Check on the board that they are trying to set up. if [ -z "$FLAGS_board" ] ; then - die "Error: --board required." + die_notrace "Error: --board required." fi IMAGES_DIR="${DEFAULT_BUILD_ROOT}/images/${FLAGS_board}" @@ -28,13 +28,14 @@ IMAGES_DIR="${DEFAULT_BUILD_ROOT}/images/${FLAGS_board}" # If there are no images, error out since presumably the # caller isn't doing this for fun. if [[ ! -d ${IMAGES_DIR} ]] ; then - die "${IMAGES_DIR} does not exist; have you run ./build_image?" + die_notrace \ + "${IMAGES_DIR} does not exist; have you run ./build_image?" fi # Use latest link if it exists, otherwise most recently changed dir if [ -L ${IMAGES_DIR}/latest ] ; then if ! dst=$(readlink "${IMAGES_DIR}"/latest) ; then - die "Could not read ${IMAGES_DIR}/latest; have you run ./build_image?" + die_notrace "Could not read ${IMAGES_DIR}/latest; have you run ./build_image?" fi DEFAULT_FROM="${IMAGES_DIR}/${dst}" else diff --git a/get_package_list b/get_package_list index d5bafa8696..d5d48cfbe7 100755 --- a/get_package_list +++ b/get_package_list @@ -23,11 +23,11 @@ DEFINE_string board "$DEFAULT_BOARD" \ FLAGS "$@" || exit 1 eval set -- "${FLAGS_ARGV}" -[[ -z "${FLAGS_board}" ]] && die "A board must be specified." +[[ -z "${FLAGS_board}" ]] && die_notrace "A board must be specified." if [[ -z "${FLAGS_ARGV}" ]]; then - warn "Please specify package." - die "Usage: ./get_package_list.sh chromeos-base/chromeos > package.list" + warn "Usage: ./get_package_list.sh chromeos-base/chromeos > package.list" + die_notrace "Please specify a package." fi emerge-$FLAGS_board --emptytree --usepkgonly -p -v --columns \ diff --git a/image_to_usb.sh b/image_to_usb.sh index a9bd42bd35..bbdb02988e 100755 --- a/image_to_usb.sh +++ b/image_to_usb.sh @@ -59,7 +59,7 @@ FLAGS "$@" || exit 1 eval set -- "${FLAGS_ARGV}" if [ $# -gt 0 ]; then - die "Arguments aren't currently supported in image_to_usb." + die_notrace "Arguments aren't currently supported in image_to_usb." fi # Generates a descriptive string of a removable device. Includes the @@ -92,7 +92,7 @@ function are_you_sure() { # Prohibit mutually exclusive factory/install flags. if [ ${FLAGS_factory} -eq ${FLAGS_TRUE} -a \ ${FLAGS_factory_install} -eq ${FLAGS_TRUE} ] ; then - die "Factory test image is incompatible with factory install shim" + die_notrace "Factory test image is incompatible with factory install shim" fi # Allow --from /foo/file.bin @@ -117,7 +117,7 @@ fi # Die on any errors. -set -e +switch_to_strict_mode # No board, no default and no image set then we can't find the image if [ -z ${FLAGS_from} ] && [ -z ${FLAGS_board} ] ; then @@ -137,7 +137,7 @@ if [ -z "${FLAGS_from}" ]; then fi if [ ! -d "${FLAGS_from}" ] ; then - die "Cannot find image directory ${FLAGS_from}" + die_notrace "Cannot find image directory ${FLAGS_from}" fi # No target provided, attempt autodetection. @@ -192,7 +192,7 @@ if [ "${FLAGS_to}" == "/dev/sdX" ]; then FLAGS_to="${disk_string%%:*}" elif [ -n "${FLAGS_to_product}" ]; then - die "Cannot specify both --to and --to_product" + die_notrace "Cannot specify both --to and --to_product" fi # Guess ARCH if it's unset @@ -217,7 +217,7 @@ if [ -b "${FLAGS_to}" ]; then disk_string=$(get_disk_string ${FLAGS_to}) elif [ ${FLAGS_force_non_usb} -ne ${FLAGS_TRUE} ]; then # Safeguard against writing to a real non-USB disk or non-SD disk - die "${FLAGS_to} does not appear to be a USB/MMC disk," \ + die_notrace "${FLAGS_to} does not appear to be a USB/MMC disk," \ "use --force_non_usb to override" fi fi @@ -295,7 +295,7 @@ fi # Make sure that the selected image exists. if [ ! -f "${SRC_IMAGE}" ]; then - die "Image not found: ${SRC_IMAGE}" + die_notrace "Image not found: ${SRC_IMAGE}" fi # Let's do it. diff --git a/image_to_vm.sh b/image_to_vm.sh index 695111f52c..ab5466e733 100755 --- a/image_to_vm.sh +++ b/image_to_vm.sh @@ -67,10 +67,10 @@ FLAGS "$@" || exit 1 eval set -- "${FLAGS_ARGV}" # Die on any errors. -set -e +switch_to_strict_mode if [ -z "${FLAGS_board}" ] ; then - die "--board is required." + die_notrace "--board is required." fi if [ "${FLAGS_full}" -eq "${FLAGS_TRUE}" ] && \ @@ -213,7 +213,7 @@ elif [ "${FLAGS_format}" = "vmware" ]; then qemu-img convert -f raw "${TEMP_IMG}" \ -O vmdk "${FLAGS_to}/${FLAGS_vmdk}" else - die "Invalid format: ${FLAGS_format}" + die_notrace "Invalid format: ${FLAGS_format}" fi rm -rf "${TEMP_DIR}" "${TEMP_IMG}" diff --git a/make_netboot.sh b/make_netboot.sh index b8d97f196d..324b0232f3 100755 --- a/make_netboot.sh +++ b/make_netboot.sh @@ -28,7 +28,7 @@ DEFINE_string image "" "Path to the image to use" FLAGS "$@" || exit 1 eval set -- "${FLAGS_ARGV}" -set -e +switch_to_strict_mode # build_packages artifact output. SYSROOT="${GCLIENT_ROOT}/chroot/build/${FLAGS_board}" # build_image artifact output. diff --git a/mod_image_for_recovery.sh b/mod_image_for_recovery.sh index 973d5fa376..fd6c74c866 100755 --- a/mod_image_for_recovery.sh +++ b/mod_image_for_recovery.sh @@ -51,8 +51,8 @@ FLAGS "$@" || exit 1 eval set -- "${FLAGS_ARGV}" # Only now can we die on error. shflags functions leak non-zero error codes, -# so will die prematurely if 'set -e' is specified before now. -set -e +# so will die prematurely if 'switch_to_strict_mode' is specified before now. +switch_to_strict_mode if [ $FLAGS_verbose -eq $FLAGS_TRUE ]; then # Make debugging with -v easy. @@ -79,7 +79,7 @@ get_install_vblock() { sudo umount "$stateful_mnt" rmdir "$stateful_mnt" - set -e + switch_to_strict_mode echo "$out" } @@ -245,7 +245,7 @@ install_recovery_kernel() { sudo cp "$vmlinuz" "$esp_mnt/syslinux/vmlinuz.A" || failed=1 sudo umount "$esp_mnt" rmdir "$esp_mnt" - set -e + switch_to_strict_mode fi if [ $failed -eq 1 ]; then @@ -325,7 +325,7 @@ maybe_resize_stateful() { sudo mkdir "$new_stateful_mnt/var" sudo umount "$new_stateful_mnt" rmdir "$new_stateful_mnt" - set -e + switch_to_strict_mode # Create a recovery image of the right size # TODO(wad) Make the developer script case create a custom GPT with @@ -358,7 +358,7 @@ FLAGS_image=$(readlink -f "$FLAGS_image") # Abort early if we can't find the image. if [ ! -f "$FLAGS_image" ]; then - die "Image not found: $FLAGS_image" + die_notrace "Image not found: $FLAGS_image" fi IMAGE_DIR="$(dirname "$FLAGS_image")" @@ -380,12 +380,12 @@ SCRIPTS_DIR=${SCRIPT_ROOT} if [ $FLAGS_kernel_image_only -eq $FLAGS_TRUE -a \ -n "$FLAGS_kernel_image" ]; then - die "Cannot use --kernel_image_only with --kernel_image" + die_notrace "Cannot use --kernel_image_only with --kernel_image" fi if [ $FLAGS_modify_in_place -eq $FLAGS_TRUE ]; then if [ $FLAGS_minimize_image -eq $FLAGS_TRUE ]; then - die "Cannot use --modify_in_place and --minimize_image together." + die_notrace "Cannot use --modify_in_place and --minimize_image together." fi RECOVERY_IMAGE="${FLAGS_image}" fi diff --git a/mod_image_for_test.sh b/mod_image_for_test.sh index 5124b1dc80..1a6114c5a4 100755 --- a/mod_image_for_test.sh +++ b/mod_image_for_test.sh @@ -42,8 +42,8 @@ FLAGS "$@" || exit 1 eval set -- "$FLAGS_ARGV" # Only now can we die on error. shflags functions leak non-zero error codes, -# so will die prematurely if 'set -e' is specified before now. -set -e +# so will die prematurely if 'switch_to_strict_mode' is specified before now. +switch_to_strict_mode . "${BUILD_LIBRARY_DIR}/board_options.sh" || exit 1 . "${BUILD_LIBRARY_DIR}/mount_gpt_util.sh" || exit 1 diff --git a/mod_test_image_for_dbusspy.sh b/mod_test_image_for_dbusspy.sh index aaa4dcb7a9..80a9cc75b2 100755 --- a/mod_test_image_for_dbusspy.sh +++ b/mod_test_image_for_dbusspy.sh @@ -42,7 +42,8 @@ cleanup() { } if [ ! -d "$VBOOT_DIR" ]; then - die "The required path: $VBOOT_DIR does not exist. This directory needs"\ + die_notrace \ + "The required path: $VBOOT_DIR does not exist. This directory needs"\ "to be sync'd into your chroot.\n $ cros_workon start vboot_reference" fi diff --git a/mod_test_image_for_pyauto.sh b/mod_test_image_for_pyauto.sh index facd095f4e..446a65418a 100644 --- a/mod_test_image_for_pyauto.sh +++ b/mod_test_image_for_pyauto.sh @@ -47,19 +47,19 @@ VBOOT_DIR="${CHROOT_TRUNK_DIR}/src/platform/vboot_reference/scripts/"\ "image_signing" if [ ! -d $PYAUTO_DEP ]; then - die "The required path: $PYAUTO_DEP does not exist. Did you mean to pass \ ---build_root and the path to the autotest bundle?" + die_notrace "The required path: $PYAUTO_DEP does not exist. Did you mean \ +to pass --build_root and the path to the autotest bundle?" fi if [ ! -d $CHROME_DEP ]; then - die "The required path: $CHROME_DEP does not exist. Did you mean to pass \ ---build_root and the path to the autotest bundle?" + die_notrace "The required path: $CHROME_DEP does not exist. Did you mean \ +to pass --build_root and the path to the autotest bundle?" fi if [ ! -d $VBOOT_DIR ]; then - die "The required path: $VBOOT_DIR does not exist. This directory needs to \ -be sync'd into your chroot.\n $ cros_workon start vboot_reference --board \ -${FLAGS_board}" + die_notrace "The required path: $VBOOT_DIR does not exist. This directory \ +needs to be sync'd into your chroot.\n $ cros_workon start vboot_reference \ +--board ${FLAGS_board}" fi if [ ! -d "${FLAGS_build_root}/client/cros" ]; then diff --git a/mount_gpt_image.sh b/mount_gpt_image.sh index 7621d7f55e..2185636f9f 100755 --- a/mount_gpt_image.sh +++ b/mount_gpt_image.sh @@ -49,7 +49,7 @@ FLAGS "$@" || exit 1 eval set -- "${FLAGS_ARGV}" # Die on error -set -e +switch_to_strict_mode # Find the last image built on the board. if [ ${FLAGS_most_recent} -eq ${FLAGS_TRUE} ] ; then @@ -60,7 +60,7 @@ fi # If --from is a block device, --image can't also be specified. if [ -b "${FLAGS_from}" ]; then if [ "${FLAGS_image}" != "chromiumos_image.bin" ]; then - die "-i ${FLAGS_image} can't be used with block device ${FLAGS_from}" + die_notrace "-i ${FLAGS_image} can't be used with block device ${FLAGS_from}" fi fi @@ -68,7 +68,7 @@ fi if [ -f "${FLAGS_from}" ]; then # If --from is specified as a file, --image cannot be also specified. if [ "${FLAGS_image}" != "chromiumos_image.bin" ]; then - die "-i ${FLAGS_image} can't be used with --from file ${FLAGS_from}" + die_notrace "-i ${FLAGS_image} can't be used with --from file ${FLAGS_from}" fi pathname=$(dirname "${FLAGS_from}") filename=$(basename "${FLAGS_from}") @@ -95,7 +95,7 @@ function unmount_image() { fi sudo umount "${FLAGS_stateful_mountpt}" sudo umount "${FLAGS_rootfs_mountpt}" - set -e + switch_to_strict_mode } function get_usb_partitions() { diff --git a/sdk_lib/enter_chroot.sh b/sdk_lib/enter_chroot.sh index 3e49230b3b..0d27870290 100755 --- a/sdk_lib/enter_chroot.sh +++ b/sdk_lib/enter_chroot.sh @@ -75,9 +75,9 @@ fi FLAGS_distfiles="${FLAGS_trunk}/distfiles" # Only now can we die on error. shflags functions leak non-zero error codes, -# so will die prematurely if 'set -e' is specified before now. +# so will die prematurely if 'switch_to_strict_mode' is specified before now. # TODO: replace shflags with something less error-prone, or contribute a fix. -set -e +switch_to_strict_mode INNER_CHROME_ROOT=$FLAGS_chrome_root_mount # inside chroot CHROME_ROOT_CONFIG="/var/cache/chrome_root" # inside chroot diff --git a/sdk_lib/make_chroot.sh b/sdk_lib/make_chroot.sh index 4aaeb33c1c..6d5014eea1 100755 --- a/sdk_lib/make_chroot.sh +++ b/sdk_lib/make_chroot.sh @@ -54,9 +54,9 @@ assert_not_root_user umask 022 # Only now can we die on error. shflags functions leak non-zero error codes, -# so will die prematurely if 'set -e' is specified before now. +# so will die prematurely if 'switch_to_strict_mode' is specified before now. # TODO: replace shflags with something less error-prone, or contribute a fix. -set -e +switch_to_strict_mode . "${SCRIPT_ROOT}"/sdk_lib/make_conf_util.sh diff --git a/set_shared_user_password.sh b/set_shared_user_password.sh index b252eb495e..8df7dc7c59 100755 --- a/set_shared_user_password.sh +++ b/set_shared_user_password.sh @@ -11,7 +11,7 @@ . "/usr/lib/crosutils/common.sh" || exit 1 # Die on any errors. -set -e +switch_to_strict_mode SHARED_USER_PASSWD_FILE="/etc/shared_user_passwd.txt" diff --git a/setup_board b/setup_board index 38b2765ea1..bd7631f50a 100755 --- a/setup_board +++ b/setup_board @@ -471,8 +471,8 @@ FLAGS "$@" || exit 1 eval set -- "${FLAGS_ARGV}" # Only now can we die on error. shflags functions leak non-zero error codes, -# so will die prematurely if 'set -e' is specified before now. -set -e +# so will die prematurely if 'switch_to_strict_mode' is specified before now. +switch_to_strict_mode if [ -z "$FLAGS_board" ] ; then error "--board required." @@ -516,7 +516,7 @@ ARCH=$(get_board_arch "${BOARD}") || exit 1 case "$BOARD" in *-host) if [[ $FLAGS_usepkg -eq $FLAGS_TRUE ]]; then - die "host boards only support --nousepkg" + die_notrace "host boards only support --nousepkg" fi HOST_BOARD=true ;; diff --git a/ssh_test.sh b/ssh_test.sh index 6c1d2de9ba..ddc6dfa112 100755 --- a/ssh_test.sh +++ b/ssh_test.sh @@ -23,7 +23,7 @@ function main() { FLAGS "$@" || exit 1 eval set -- "${FLAGS_ARGV}" - set -e + switch_to_strict_mode trap cleanup EXIT diff --git a/update_bootloaders.sh b/update_bootloaders.sh index 163b281992..1f6bbd9ec1 100755 --- a/update_bootloaders.sh +++ b/update_bootloaders.sh @@ -51,7 +51,7 @@ DEFINE_string usb_disk /dev/sdb3 \ # Parse flags FLAGS "$@" || exit 1 eval set -- "${FLAGS_ARGV}" -set -e +switch_to_strict_mode part_index_to_uuid() { local image="$1" diff --git a/update_chroot b/update_chroot index a1cf213887..f2b40c7d52 100755 --- a/update_chroot +++ b/update_chroot @@ -35,8 +35,8 @@ FLAGS "$@" || exit 1 eval set -- "${FLAGS_ARGV}" # Only now can we die on error. shflags functions leak non-zero error codes, -# so will die prematurely if 'set -e' is specified before now. -set -e +# so will die prematurely if 'switch_to_strict_mode' is specified before now. +switch_to_strict_mode . ${SCRIPTS_DIR}/sdk_lib/make_conf_util.sh diff --git a/update_kernel.sh b/update_kernel.sh index 6d0156154a..231f67be40 100755 --- a/update_kernel.sh +++ b/update_kernel.sh @@ -24,8 +24,8 @@ FLAGS "$@" || exit 1 eval set -- "${FLAGS_ARGV}" # Only now can we die on error. shflags functions leak non-zero error codes, -# so will die prematurely if 'set -e' is specified before now. -set -e +# so will die prematurely if 'switch_to_strict_mode' is specified before now. +switch_to_strict_mode function cleanup { cleanup_remote_access diff --git a/upload_symbols b/upload_symbols index 39111bb61e..292155d656 100755 --- a/upload_symbols +++ b/upload_symbols @@ -185,7 +185,9 @@ function main() { MAX_TOTAL_ERRORS_FOR_RETRY=${TEST_MAX_TOTAL_ERRORS_FOR_RETRY} fi - [ -n "$FLAGS_board" ] || die "--board is required." + switch_to_strict_mode + + [ -n "$FLAGS_board" ] || die_notrace "--board is required." SYSROOT="/build/${FLAGS_board}" diff --git a/verify_rootfs_chksum.sh b/verify_rootfs_chksum.sh index 83b60a1f3d..5efbb73f80 100755 --- a/verify_rootfs_chksum.sh +++ b/verify_rootfs_chksum.sh @@ -30,7 +30,7 @@ FLAGS "$@" || exit 1 eval set -- "${FLAGS_ARGV}" if [ -z $FLAGS_image ] ; then - die "Use --image to specify a device or an image file." + die_notrace "Use --image to specify a device or an image file." fi # Turn path into an absolute path. @@ -38,10 +38,10 @@ FLAGS_image=$(eval readlink -f ${FLAGS_image}) # Abort early if we can't find the image if [ ! -b ${FLAGS_image} ] && [ ! -f $FLAGS_image ] ; then - die "No image found at $FLAGS_image" + die_notrace "No image found at $FLAGS_image" fi -set -e +switch_to_strict_mode function get_partitions() { if [ -b ${FLAGS_image} ] ; then @@ -99,7 +99,7 @@ cleanup if [ "${expected_hash}" != "${generated_hash}" ]; then warn "expected hash = ${expected_hash}" warn "actual hash = ${generated_hash}" - die "Root filesystem has been modified unexpectedly!" + die_notrace "Root filesystem has been modified unexpectedly!" else info "Root filesystem checksum match!" fi