From cc7ba5bb5aac8c61fb38eb5f89651791d9151293 Mon Sep 17 00:00:00 2001 From: SangYoun Kwak Date: Tue, 24 May 2022 10:34:32 +0900 Subject: [PATCH] Change critical error logs to be logged as critical_logs Change-Id: If1edd58b6c493c5f29959cc52bc52fbe617ab89b Signed-off-by: SangYoun Kwak --- clone_partitions/clone_partitions.sh | 33 ++++++++++++++++++++++++++++++--- scripts/upgrade-common.inc | 17 +++++++++++++++++ scripts/upgrade-fota.sh | 8 ++++---- scripts/upgrade-full.sh | 4 ++-- scripts/upgrade-legacy.sh | 4 ++-- scripts/upgrade-partial.sh | 6 +++--- 6 files changed, 58 insertions(+), 14 deletions(-) diff --git a/clone_partitions/clone_partitions.sh b/clone_partitions/clone_partitions.sh index 939324f..ee21340 100644 --- a/clone_partitions/clone_partitions.sh +++ b/clone_partitions/clone_partitions.sh @@ -1,6 +1,33 @@ #!/bin/bash PATH=/bin:/usr/bin:/sbin:/usr/sbin +SCRIPT_NAME="clone_partitions.sh" + +#------------------------------------------------ +# critical_log msg [file] +#------------------------------------------------ +critical_log() { + # log format: [script_name][tag]actual_log + LOG="[${SCRIPT_NAME}]$1" + dlogsend -k "$LOG" + if [ "$2" != "" ]; then + echo "$LOG" >> "$2" + fi + echo "$LOG" +} + +#------------------------------------------------ +# log msg [file] +#------------------------------------------------ +log() { + # log format: [script_name][tag]actual_log + LOG="[${SCRIPT_NAME}]$1" + if [ "$2" != "" ]; then + echo "$LOG" >> "$2" + fi + echo "$LOG" +} + set -o errexit trap 'echo "Aborting due to errexit on ${0##*/}:$LINENO. Exit code: $?" >&2' ERR set -o errtrace -e -o pipefail @@ -10,13 +37,13 @@ if [ ! -z "${UPGRADE_DEBUG}" ]; then fi if [ "$(device_board_get_partition_ab_cloned)" -eq "1" ]; then - echo "[Info] Partitions already cloned" + log "[Info] Partitions already cloned" exit 0 fi if /usr/libexec/upgrade-support/upgrade-prepare-partitions.sh; then - echo "[Info] Partitions have been cloned" + log "[Info] Partitions have been cloned" device_board_set_partition_ab_cloned else - echo "[Error] Partitions have not been cloned" + critical_log "[Error] Partitions have not been cloned" fi diff --git a/scripts/upgrade-common.inc b/scripts/upgrade-common.inc index bf1ff93..c313ad8 100644 --- a/scripts/upgrade-common.inc +++ b/scripts/upgrade-common.inc @@ -7,6 +7,23 @@ CONFIG_FILE="update.cfg" SET_UPGRADE_STATUS="/usr/bin/device_board_set_upgrade_status" #------------------------------------------------ +# critical_log msg [file] +#------------------------------------------------ +critical_log() { + # log format: [script_name][tag]actual_log + LOG="[${SCRIPT_NAME}]$1" + dlogsend -k "$LOG" + if [ "$2" != "" ]; then + echo "$LOG" >> "$2" + fi + echo "$LOG" +} + +critical_flog() { + critical_log "$1" "$LOG_FILE" +} + +#------------------------------------------------ # log msg [file] #------------------------------------------------ log() { diff --git a/scripts/upgrade-fota.sh b/scripts/upgrade-fota.sh index 41581ab..0067b5c 100755 --- a/scripts/upgrade-fota.sh +++ b/scripts/upgrade-fota.sh @@ -78,14 +78,14 @@ should_mount_rootfs() { mount() { if should_mount_rootfs; then if ! mount_partition rootfs "$FOTA_UPDATE_PREFIX" "rw"; then - flog "[Error] Unable to mount rootfs" + critical_flog "[Error] Unable to mount rootfs" return 1 fi else mkdir -p "$FOTA_UPDATE_PREFIX/opt" fi if ! mount_partition system-data "$FOTA_UPDATE_PREFIX/opt" "rw"; then - flog "[Error] Unable to mount opt" + critical_flog "[Error] Unable to mount opt" return 1 fi untrap @@ -103,13 +103,13 @@ reboot_to_fota() { flog "[Info] Switching board partition from $CURRENT_AB, to $NEXT_AB" if ! device_board_switch_partition $NEXT_AB; then - flog "[Error] Failed to switch board slot to $NEXT_AB" + critical_flog "[Error] Failed to switch board slot to $NEXT_AB" exit 1 fi /bin/sync flog "[Info] Rebooting to fota" if ! /sbin/reboot fota; then - flog "[Error] Failed to reboot fota" + critical_flog "[Error] Failed to reboot fota" exit 1 fi } diff --git a/scripts/upgrade-full.sh b/scripts/upgrade-full.sh index 12126c7..85dd3e5 100755 --- a/scripts/upgrade-full.sh +++ b/scripts/upgrade-full.sh @@ -40,13 +40,13 @@ reboot_to_fota() { flog "[Info] Switching board partition from $CURRENT_AB, to $NEXT_AB" if ! device_board_switch_partition $NEXT_AB; then - flog "[Error] Failed to switch board slot to $NEXT_AB" + critical_flog "[Error] Failed to switch board slot to $NEXT_AB" exit 1 fi /bin/sync flog "[Info] Rebooting to fota" if ! /sbin/reboot fota; then - flog "[Error] Failed to reboot fota" + critical_flog "[Error] Failed to reboot fota" exit 1 fi } diff --git a/scripts/upgrade-legacy.sh b/scripts/upgrade-legacy.sh index 823cd43..73fc85d 100644 --- a/scripts/upgrade-legacy.sh +++ b/scripts/upgrade-legacy.sh @@ -38,7 +38,7 @@ flash_pre_image() { /bin/tar xvfp "$DELTA_TAR" -C "$FOTA_DIR" "$CONFIG_FILE" if [ ! -e "$FOTA_DIR/$CONFIG_FILE" ]; then - log "[Error] There is no $CONFIG_FILE" "$LOG_FILE" + critical_log "[Error] There is no $CONFIG_FILE" "$LOG_FILE" return fi @@ -109,6 +109,6 @@ sync # go to fota mode log "[Info] Go TOTA update..." "$LOG_FILE" if ! /sbin/reboot fota; then - log "[Error] Failed to reboot fota" "$LOG_FILE" + critical_log "[Error] Failed to reboot fota" "$LOG_FILE" exit 100 fi diff --git a/scripts/upgrade-partial.sh b/scripts/upgrade-partial.sh index f6dd232..b1d6470 100755 --- a/scripts/upgrade-partial.sh +++ b/scripts/upgrade-partial.sh @@ -168,19 +168,19 @@ copy_delta unpack_file "$DELTA_TAR" "$CONFIG_FILE" upgrade_images "$DELTA_TAR" if ! prepare_for_ua; then - flog "[Error] Unable to prepare_for_ua" + critical_flog "[Error] Unable to prepare_for_ua" cleanup exit_error fi if ! run_setup_script "$DELTA_TAR"; then - flog "[Error] Unable to run_setup_script" + critical_flog "[Error] Unable to run_setup_script" cleanup exit_error fi if ! run_ro_update; then - flog "[Error] Unable to run_ro_update" + critical_flog "[Error] Unable to run_ro_update" cleanup exit_error fi -- 2.7.4