Add explicit return statement for every function 79/280079/2 tizen
authorSangYoun Kwak <sy.kwak@samsung.com>
Tue, 23 Aug 2022 08:19:09 +0000 (17:19 +0900)
committerSangYoun Kwak <sy.kwak@samsung.com>
Tue, 23 Aug 2022 08:45:04 +0000 (17:45 +0900)
Change-Id: I9d68c19cad5a4783877937511427f8ea126ba5ea
Signed-off-by: SangYoun Kwak <sy.kwak@samsung.com>
scripts/fota-init.sh
scripts/fus_rw-init.sh
scripts/progress_restart.sh

index 9eb2f6f1e92bdd5659feef0e99bb359305cd6c11..75e7fb92a2d754a662d419b6add82e7ace1a6f89 100755 (executable)
@@ -116,6 +116,8 @@ get_partition_id() {
     fi
 
     PART_USER=$("$BLKID" --match-token PARTLABEL=user -o device -l || "$BLKID" --match-token LABEL=user -o device -l)
+
+    return 0
 }
 
 mount_bow_partition() {
@@ -141,6 +143,8 @@ mount_bow_partition() {
        DM_NUMBER=$(($("${STAT}" -c "0x%T" $(readlink -f "${BOWDEV_PATH}"))))
        echo 1 > /sys/block/dm-${DM_NUMBER}/bow/state
        log "[Debug] Mounted ${PARTITION} as DM-BOW" "${INT_LOG_FILE}"
+
+       return 0
 }
 
 mount_f2fs_partition() {
@@ -152,6 +156,8 @@ mount_f2fs_partition() {
                return 1
        fi
        log "[Debug] Mounted ${PARTITION} as F2FS checkpoint=disable" "${INT_LOG_FILE}"
+
+       return 0
 }
 
 mount_checkpoint_partition() {
@@ -172,6 +178,8 @@ mount_checkpoint_partition() {
                "${MOUNT}" "${PARTITION}" "${DIRECTORY}"
                log "[Info] Unsupported filesystem ${FSTYPE} on ${PARTITION}" "${INT_LOG_FILE}"
        fi
+
+       return 0
 }
 
 commit_bow_partition()
@@ -183,6 +191,8 @@ commit_bow_partition()
        DM_NUMBER=$(($("${STAT}" -c "0x%T" $(readlink -f "${BOWDEV_PATH}"))))
        echo 2 > /sys/block/dm-${DM_NUMBER}/bow/state
        log "[Info] Changes on partition ${LABEL} commited (dm-bow)" "${INT_LOG_FILE}"
+
+       return 0
 }
 
 commit_f2fs_partition()
@@ -191,6 +201,8 @@ commit_f2fs_partition()
        PART_SYSTEM_DATA=$(blkid --match-token PARTLABEL="${LABEL}" -o device -l || blkid --match-token LABEL="${LABEL}" -o device -l)
        "${MOUNT}" -o remount,checkpoint=enable "${PART_SYSTEM_DATA}"
        log "[Info] Changes on partition ${LABEL} commited (f2fs)" "${INT_LOG_FILE}"
+
+       return 0
 }
 
 commit_partition()
@@ -199,12 +211,18 @@ commit_partition()
        MNT_POINT=${2}
        TYPE=$(blkid --match-token PARTLABEL="${LABEL}" -o value -s TYPE || blkid --match-token LABEL="${LABEL}" -o value -s TYPE | tail -n 1)
        if [ "${TYPE}" = "ext4" ]; then
-               commit_bow_partition "${LABEL}"
+               if ! commit_bow_partition "${LABEL}"; then
+                       return 1
+               fi
        elif [ "${TYPE}" = "f2fs" ]; then
-               commit_f2fs_partition "${LABEL}"
+               if ! commit_f2fs_partition "${LABEL}"; then
+                       return 1
+               fi
        else
                log "[Info] Cannot commit ${LABEL}: Unsupported filesystem ${TYPE}" "${INT_LOG_FILE}"
        fi
+
+       return 0
 }
 
 mount_rootfs()
@@ -228,7 +246,12 @@ mount_rootfs()
                 echo "verifyboot: disabling"
                 ;;
         esac
-       "$MOUNT" -o ro "${PART_ROOTFS}" "${FAKE_ROOT}"
+
+       if ! "$MOUNT" -o ro "${PART_ROOTFS}" "${FAKE_ROOT}"; then
+               return 1
+       fi
+
+       return 0
 }
 
 #------------------------------------------------
@@ -242,7 +265,9 @@ mount_partitions() {
                # Therefore rootfs should be mounted as RO.
                # We cannot mount rootfs as RW because mount timestamp would
                # change and dmverity data would become incorrect
-               mount_rootfs
+               if ! mount_rootfs; then
+                       return 1
+               fi
        else
                if ! mount_checkpoint_partition rootfs "${PART_ROOTFS}" "${FAKE_ROOT}"; then
                        return 1
@@ -264,14 +289,22 @@ mount_partitions() {
                                return 1
                        fi
                else
-                       "$MOUNT" -o ro "${PART_HAL}" "${FAKE_ROOT}/${HAL_MNT}"
+                       if ! "$MOUNT" -o ro "${PART_HAL}" "${FAKE_ROOT}/${HAL_MNT}"; then
+                               return 1
+                       fi
                fi
        fi
 
-       "$MOUNT" -t proc none "${FAKE_ROOT}/proc"
-       "$MOUNT" -t sysfs none "${FAKE_ROOT}/sys"
-       "$MOUNT" -t devtmpfs devtmpfs "${FAKE_ROOT}/dev"
+       "$MOUNT" -t proc none "${FAKE_ROOT}/proc" &&
+       "$MOUNT" -t sysfs none "${FAKE_ROOT}/sys" &&
+       "$MOUNT" -t devtmpfs devtmpfs "${FAKE_ROOT}/dev" &&
        "$MOUNT" -t devpts devpts "${FAKE_ROOT}/dev/pts"
+
+       if [ $? -ne 0 ]; then
+               return 1
+       fi
+
+       return 0
 }
 
 umount_bow_partition()
@@ -279,10 +312,16 @@ umount_bow_partition()
        LABEL=${1}
        PART=${2}
 
-       "$UMOUNT" "${PART}"
+       if ! "$UMOUNT" "${PART}"; then
+               return 1
+       fi
 
        BOWDEV_NAME=bowdev_${LABEL}
-       "${DMSETUP}" remove ${BOWDEV_NAME}
+       if ! "${DMSETUP}" remove ${BOWDEV_NAME}; then
+               return 1
+       fi
+
+       return 0
 }
 
 umount_partition()
@@ -292,10 +331,16 @@ umount_partition()
 
        TYPE=$(blkid --match-token PARTLABEL="${LABEL}" -o value -s TYPE || blkid --match-token LABEL="${LABEL}" -o value -s TYPE | tail -n 1)
        if [ "${TYPE}" = "ext4" ]; then
-               umount_bow_partition "${LABEL}" "${DIRECTORY}"
+               if ! umount_bow_partition "${LABEL}" "${DIRECTORY}"; then
+                       return 1
+               fi
        else
-               "$UMOUNT" "${DIRECTORY}"
+               if ! "$UMOUNT" "${DIRECTORY}"; then
+                       return 1
+               fi
        fi
+
+       return 0
 }
 
 #------------------------------------------------
@@ -311,38 +356,62 @@ umount_partitions() {
        if [ "${P_SUFFIX}" == "" ]; then
                if [ ! "z${PART_HAL}" = "z" ]; then
                        if [ "${UPGRADE_SUCCESS}" = "1" ]; then
-                                       commit_partition hal "${FAKE_ROOT}/${HAL_MNT}"
+                                       if ! commit_partition hal "${FAKE_ROOT}/${HAL_MNT}"; then
+                                               return 1
+                                       fi
+                       fi
+                       if ! umount_partition hal "${FAKE_ROOT}/${HAL_MNT}"; then
+                               return 1
                        fi
-                       umount_partition hal "${FAKE_ROOT}/${HAL_MNT}"
                fi
        else
-               "$UMOUNT" "${FAKE_ROOT}/${HAL_MNT}"
+               if ! "$UMOUNT" "${FAKE_ROOT}/${HAL_MNT}"; then
+                       return 1
+               fi
        fi
 
        if [ ! "z${PART_USER}" = "z" ]; then
                if [ "${UPGRADE_SUCCESS}" = "1" ]; then
-                       commit_partition user "${FAKE_ROOT}/${USER_MNT}"
+                       if ! commit_partition user "${FAKE_ROOT}/${USER_MNT}"; then
+                               return 1
+                       fi
+               fi
+               if ! umount_partition user "${FAKE_ROOT}/${USER_MNT}"; then
+                       return 1
                fi
-               umount_partition user "${FAKE_ROOT}/${USER_MNT}"
        fi
 
        if [ "${UPGRADE_SUCCESS}" = "1" ]; then
-               commit_partition system-data "${FAKE_ROOT}/${SYSTEM_DATA_MNT}"
+               if ! commit_partition system-data "${FAKE_ROOT}/${SYSTEM_DATA_MNT}"; then
+                       return 1
+               fi
+       fi
+       if ! umount_partition system-data "${FAKE_ROOT}/${SYSTEM_DATA_MNT}"; then
+               return 1
        fi
-       umount_partition system-data "${FAKE_ROOT}/${SYSTEM_DATA_MNT}"
 
        if [[ "${P_SLOT}" != "" ]]
        then
-               "$UMOUNT" "${FAKE_ROOT}"
+               if ! "$UMOUNT" "${FAKE_ROOT}"; then
+                       return 1
+               fi
        else
                if [ "${UPGRADE_SUCCESS}" = "1" ]; then
-                       commit_partition rootfs "${FAKE_ROOT}"
+                       if ! commit_partition rootfs "${FAKE_ROOT}"; then
+                               return 1
+                       fi
+               fi
+               if ! umount_partition rootfs "${FAKE_ROOT}"; then
+                       return 1
                fi
-               umount_partition rootfs "${FAKE_ROOT}"
        fi
 
        # close dm-verity
-       /usr/bin/verityctl close rootfs
+       if ! /usr/bin/verityctl close rootfs; then
+               return 1
+       fi
+
+       return 0
 }
 
 #------------------------------------------------
@@ -350,8 +419,9 @@ umount_partitions() {
 #------------------------------------------------
 handle_no_delta() {
        log "[Error] delta does not exist ..." "${INT_LOG_FILE}"
-
        echo "${UPI_NO_DELTA_ERROR}" > "${RESULT_FILE}"
+
+       return 0
 }
 
 #------------------------------------------------
@@ -359,8 +429,9 @@ handle_no_delta() {
 #------------------------------------------------
 handle_no_ua() {
        log "[Error] ua does not exist ..." "${INT_LOG_FILE}"
-
        echo "${UPI_NO_UA_ERROR}" > "${RESULT_FILE}"
+
+       return 0
 }
 
 #------------------------------------------------
@@ -379,6 +450,8 @@ do_create_part_table() {
        echo "$PART_NUM" > "${PART_TBL_PATH}"
        echo "$PART_LIST" >> "${PART_TBL_PATH}"
        "$SYNC"
+
+       return 0
 }
 
 #------------------------------------------------
@@ -449,6 +522,8 @@ clear_internal_log() {
        if [ -e "${INT_LOG_FILE}" ]; then
                /bin/rm -fr "${INT_LOG_FILE}"
        fi
+
+       return 0
 }
 
 
@@ -467,6 +542,8 @@ init_fota_dir() {
                        fi
                fi
        done
+
+       return 0
 }
 
 #------------------------------------------------
@@ -482,6 +559,8 @@ check_for_rw_power_fail() {
                umount_partitions
                exec /sbin/fus_rw-init
        fi
+
+       return 1
 }
 
 #------------------------------------------------
@@ -492,6 +571,8 @@ check_for_fota_gui() {
                log "[Info] GUI Enabled" "${INT_LOG_FILE}"
                FOTA_GUI_ENABLE=1
        fi
+
+       return 0
 }
 
 #------------------------------------------------
@@ -513,6 +594,8 @@ check_debug_mode() {
                        log "[Info] Warning: somebody made non-root debug mode file... ignore it"
                fi
        fi
+
+       return 0
 }
 
 #------------------------------------------------
@@ -545,6 +628,7 @@ remake_hash_table() {
 #------------------------------------------------
 mark_rw_update() {
        echo "start" > ${STATUS_FILE}
+       return 0
 }
 
 #------------------------------------------------
@@ -573,6 +657,7 @@ jump_to_ramdisk() {
 #------------------------------------------------
 prepare_fakeroot() {
     mkdir -p ${FAKE_ROOT}
+    return 0
 }
 
 #------------------------------------------------
@@ -583,6 +668,7 @@ function log_boot_info() {
     CMDLINE_PARTITION_AB=$([[ $(</proc/cmdline) =~ (partition_ab=[ab]) ]]; echo ${BASH_REMATCH[1]})
     CMDLINE_BOOTMODE=$([[ $(</proc/cmdline) =~ (bootmode=[^ ]*) ]]; echo ${BASH_REMATCH[1]})
     log "[Info] Initrd-fota booting (/proc/cmdline $CMDLINE_BOOTMODE $CMDLINE_PARTITION_AB $CMDLINE_ROOT)"
+    return 0
 }
 
 #------------------------------------------------
index fdf6b0f526b9a6c8d700b8486d08b29966eaed1e..49543349c6e16b1e05a597293196cefeff172b84 100755 (executable)
@@ -68,6 +68,8 @@ get_partition_id() {
     fi
 
     PART_USER=$("$BLKID" --match-token PARTLABEL=user -o device -l || "$BLKID" --match-token LABEL=user -o device -l)
+
+    return 0
 }
 
 #------------------------------------------------
@@ -94,7 +96,12 @@ mount_rootfs()
                 echo "verifyboot: disabling"
                 ;;
         esac
-       "$MOUNT" -o ro "${PART_ROOTFS}" "${FAKE_ROOT}"
+
+       if ! "$MOUNT" -o ro "${PART_ROOTFS}" "${FAKE_ROOT}"; then
+               return 1
+       fi
+
+       return 0
 }
 
 
@@ -104,25 +111,34 @@ mount_rootfs()
 mount_hal() {
     if [ "z${PART_HAL}" = "z" ]; then
         # No hal partition
-        return
+        return 2
     fi
 
-    "$MOUNT" -o ro "${PART_HAL}" "${FAKE_ROOT}/${HAL_MNT}"
+    if ! "$MOUNT" -o ro "${PART_HAL}" "${FAKE_ROOT}/${HAL_MNT}"; then
+           return 1
+    fi
+
+    return 0
 }
 
 #------------------------------------------------
 #       mount_partitions
 #------------------------------------------------
 mount_partitions() {
-    get_partition_id
-
-    mount_rootfs
-    mount_hal
-    "$MOUNT" -t proc none ${FAKE_ROOT}/proc
-    "$MOUNT" -t sysfs none ${FAKE_ROOT}/sys
-    "$MOUNT" -t devtmpfs devtmpfs ${FAKE_ROOT}/dev
-    "$MOUNT" -t devpts devpts ${FAKE_ROOT}/dev/pts
+    get_partition_id &&
+    mount_rootfs &&
+    mount_hal &&
+    "$MOUNT" -t proc none ${FAKE_ROOT}/proc &&
+    "$MOUNT" -t sysfs none ${FAKE_ROOT}/sys &&
+    "$MOUNT" -t devtmpfs devtmpfs ${FAKE_ROOT}/dev &&
+    "$MOUNT" -t devpts devpts ${FAKE_ROOT}/dev/pts &&
     "$MOUNT" -t tmpfs tmpfs ${FAKE_ROOT}/tmp
+
+    if [ $? -ne 0 ]; then
+           return 1
+    fi
+
+    return 0
 }
 
 #------------------------------------------------
@@ -144,6 +160,7 @@ do_rw_update() {
 #------------------------------------------------
 prepare_fakeroot() {
     mkdir -p ${FAKE_ROOT}
+    return 0
 }
 
 #------------------------------------------------
index 68395968777695781af7357d64401ff41aef799b..5138f24705c6e39703122fae43709a76b2ebb567 100755 (executable)
@@ -30,10 +30,12 @@ function log {
 
 function info {
        log "[INFO] ${1}"
+       return 0
 }
 
 function error {
        log "[ERROR] ${1}"
+       return 0
 }
 
 
@@ -48,6 +50,7 @@ function init_ro {
        RESTART_PROGRESS_FILE="/mnt/inform/restart-progress-ro"
        PROGRESS_FILE="/tmp/upgrade/ro_progress"
        DELAY=2
+       return 0
 }
 
 function init_rw {
@@ -58,15 +61,18 @@ function init_rw {
        FAKE_ROOT=/run/upgrade-sysroot
        PROGRESS_FILE="${FAKE_ROOT}/tmp/upgrade/progress"
        DELAY=0.1
+       return 0
 }
 
 function cleanup {
        info "[RESTART_TEST] Cleanup"
        rm -rf "${RESTART_PROGRESS_FILE}"
+       return 0
 }
 
 function init_progress_file {
        echo ${INIT_PROGRES} > "${RESTART_PROGRESS_FILE}"
+       return 0
 }
 
 function update_progress {
@@ -75,6 +81,7 @@ function update_progress {
        if [[ "${MODE}" == "RW" ]]; then
                MAX_PROGRESS=$(cat "${FAKE_ROOT}/tmp/upgrade/total")
        fi
+       return 0
 }