mirror of
https://github.com/flatcar/scripts.git
synced 2025-08-08 05:26:58 +02:00
Currently, if set -e spots a nonzero exit we basically have no real debug information- it just stops immediately without stating where or why. This forces our scripts to be stupidly verbose so we can track roughly where they were, thus when they fail we can use that information to localize the rough exit point. Instead we should be traping that set -e induced exit and outputing necessary debug information to run it down. This includes outputing the relevant stack trace, or at least what we can get of it. The 'die' function is now enhanced to automatically dump the trace that lead to it. For most consumers this is desired- however for commandline parsing induced dies ("--board is missing" for example), the trace is noise. For those cases, a 'die_notrace' function was added that retains the original non-backtrace behaviour. Example output via instrumenting cros_generate_breakpad_symbols w/ the failing command '/bin/false' (nonzero exit code). Before: ./cros_generate_breakpad_symbols monkeys --board=x86-alex <no output at all, just exit code 1> With this CL: ./cros_generate_breakpad_symbols monkeys --board=x86-alex ERROR : script called: ./cros_generate_breakpad_symbols 'monkeys' '--board=x86-alex' ERROR : Backtrace: (most recent call is last) ERROR : file cros_generate_breakpad_symbols, line 207, called: main 'monkeys' '--board=x86-alex' ERROR : file cros_generate_breakpad_symbols, line 163, called: die_err_trap '/bin/false' '1' ERROR : ERROR : Command failed: ERROR : Command '/bin/false' exited with nonzero code: 1 BUG=chromium-os:30598 TEST=inject a failing command into a script, verify the output. TEST=inject a 'command not found', verify the output TEST=cbuildbot x86-generic-full --remote TEST=cbuildbot arm-tegra2-full --remote TEST=cbuildbot chromiumos-sdk --remote Change-Id: I517ffde4d1bb7e2310a74f5a6455b53ba2dea86c Reviewed-on: https://gerrit.chromium.org/gerrit/17225 Reviewed-by: Brian Harring <ferringb@chromium.org> Tested-by: Brian Harring <ferringb@chromium.org> Commit-Ready: Brian Harring <ferringb@chromium.org>
74 lines
2.9 KiB
Bash
Executable File
74 lines
2.9 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# 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.
|
|
|
|
# Script to modify a keyfob-based chromeos test image to log all dbus
|
|
# activity from boot-time forward in a machine-readable replay format.
|
|
# This is not part of the main "mod-for-test" for several reasons:
|
|
# * it is overly invasive to the boot sequence,
|
|
# * it has major run-time performance downsides,
|
|
# * it consumes potentially huge amounts of disk space over time.
|
|
# Any one of these are too-great of a depature from "normal" Chrome OS
|
|
# to be appropriate for a "faithful" test-system. Note that dbus-monitor(1)
|
|
# is available for casual/interactive use in normal mod-for-test systems.
|
|
# Dbusspy-instrumented systems are only intended for narrow use cases, like
|
|
# corpus collection for fuzzing, where the above trade-offs are acceptable.
|
|
|
|
. "/usr/lib/crosutils/common.sh" || { echo "Unable to load common.sh"; exit 1; }
|
|
|
|
assert_inside_chroot
|
|
|
|
DEFINE_string image "$FLAGS_image" "Location of the test image file" i
|
|
|
|
# Parse command line
|
|
FLAGS "$@" || exit 1
|
|
eval set -- "$FLAGS_ARGV"
|
|
|
|
FLAGS_image=$(eval readlink -f "${FLAGS_image}")
|
|
|
|
IMAGE_DIR=$(dirname "${FLAGS_image}")
|
|
IMAGE_NAME=$(basename "${FLAGS_image}")
|
|
ROOT_FS_DIR="${IMAGE_DIR}/rootfs"
|
|
DBUS_CONF="$(dirname "$0")/mod_for_dbusspy/dbus.conf"
|
|
SYSTEM_LOCAL_CONF="$(dirname "$0")/mod_for_dbusspy/system-local.conf"
|
|
DEVKEYS_DIR="/usr/share/vboot/devkeys"
|
|
VBOOT_DIR="${CHROOT_TRUNK_DIR}/src/platform/vboot_reference/scripts/"\
|
|
"image_signing"
|
|
|
|
cleanup() {
|
|
"${SCRIPTS_DIR}/mount_gpt_image.sh" -u -r "$ROOT_FS_DIR"
|
|
}
|
|
|
|
if [ ! -d "$VBOOT_DIR" ]; then
|
|
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
|
|
|
|
trap cleanup EXIT
|
|
|
|
# Mounts gpt image and sets up var, /usr/local and symlinks.
|
|
"$SCRIPTS_DIR/mount_gpt_image.sh" --image="$IMAGE_NAME" --from="$IMAGE_DIR" \
|
|
--rootfs_mountpt="$ROOT_FS_DIR"
|
|
|
|
# A bunch of existing stuff is set to start up as soon as dbus is considered
|
|
# to have started. Instead of modifying all of those things to instead
|
|
# wait for dbus-spy to be started, drop dbus-spy in as "dbus" which,
|
|
# in turn, waits on "realdbus." This way we don't race other services
|
|
# and are guaranteed to capture all dbus events from boot onward.
|
|
sudo cp -a "${ROOT_FS_DIR}/etc/init/dbus.conf" \
|
|
"${ROOT_FS_DIR}/etc/init/realdbus.conf"
|
|
sudo cp "${DBUS_CONF}" "${ROOT_FS_DIR}/etc/init/dbus.conf"
|
|
sudo cp "${SYSTEM_LOCAL_CONF}" "${ROOT_FS_DIR}/etc/dbus-1/system-local.conf"
|
|
|
|
# Unmount and re-sign. See crosbug.com/18709 for why this isn't using
|
|
# cros_make_image_bootable.
|
|
cleanup
|
|
TMP_BIN_PATH="${FLAGS_image}.new"
|
|
"${VBOOT_DIR}/sign_official_build.sh" usb "${FLAGS_image}" \
|
|
"${DEVKEYS_DIR}" \
|
|
"${TMP_BIN_PATH}"
|
|
mv "${TMP_BIN_PATH}" "${FLAGS_image}"
|