From 1107d483a26a5735de7d740fd3182d2e58960f63 Mon Sep 17 00:00:00 2001 From: Zdenek Kabelac Date: Tue, 9 May 2017 20:52:15 +0200 Subject: [PATCH] fsadm: fix test of subshell return value Subshell is not returning error code value upward thus error results in this case were actually ignored. Also add dots to moved error messages. --- WHATS_NEW | 1 + scripts/fsadm.sh | 18 ++++++++++++------ 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/WHATS_NEW b/WHATS_NEW index 0b9fab96d..79b6c678d 100644 --- a/WHATS_NEW +++ b/WHATS_NEW @@ -1,5 +1,6 @@ Version 2.02.172 - =============================== + Properly handle subshell return codes in fsadm. Disallow cachepool creation with policy cleaner and mode writeback. Version 2.02.171 - 3rd May 2017 diff --git a/scripts/fsadm.sh b/scripts/fsadm.sh index 26be1025c..0d6c5032b 100755 --- a/scripts/fsadm.sh +++ b/scripts/fsadm.sh @@ -183,7 +183,8 @@ decode_size() { detect_fs() { VOLUME_ORIG=$1 VOLUME=${1/#"${DM_DEV_DIR}/"/} - VOLUME=$("$READLINK" $READLINK_E "$DM_DEV_DIR/$VOLUME") || error "Cannot get readlink \"$1\"" + VOLUME=$("$READLINK" $READLINK_E "$DM_DEV_DIR/$VOLUME") + test -n "$VOLUME" || error "Cannot get readlink \"$1\"." RVOLUME=$VOLUME case "$RVOLUME" in # hardcoded /dev since udev does not create these entries elsewhere @@ -192,7 +193,8 @@ detect_fs() { read &1 || error "Cannot get major:minor for \"$VOLUME\"" ;; *) - STAT=$(stat --format "MAJOR=%t MINOR=%T" ${RVOLUME}) || error "Cannot get major:minor for \"$VOLUME\"" + STAT=$(stat --format "MAJOR=%t MINOR=%T" ${RVOLUME}) + test -n "$STAT" || error "Cannot get major:minor for \"$VOLUME\"." eval $STAT MAJOR=$((0x${MAJOR})) MINOR=$((0x${MINOR})) @@ -201,7 +203,8 @@ detect_fs() { esac # use null device as cache file to be sure about the result # not using option '-o value' to be compatible with older version of blkid - FSTYPE=$("$BLKID" -c "$NULL" -s TYPE "$VOLUME") || error "Cannot get FSTYPE of \"$VOLUME\"" + FSTYPE=$("$BLKID" -c "$NULL" -s TYPE "$VOLUME") + test -n "$FSTYPE" || error "Cannot get FSTYPE of \"$VOLUME\"." FSTYPE=${FSTYPE##*TYPE=\"} # cut quotation marks FSTYPE=${FSTYPE%%\"*} verbose "\"$FSTYPE\" filesystem found on \"$VOLUME\"" @@ -257,10 +260,13 @@ detect_device_size() { # check if blockdev supports getsize64 "$BLOCKDEV" 2>&1 | "$GREP" getsize64 >"$NULL" if test $? -eq 0; then - DEVSIZE=$("$BLOCKDEV" --getsize64 "$VOLUME") || error "Cannot read size of device \"$VOLUME\"" + DEVSIZE=$("$BLOCKDEV" --getsize64 "$VOLUME") + test -n "$DEVSIZE" || error "Cannot read size of device \"$VOLUME\"." else - DEVSIZE=$("$BLOCKDEV" --getsize "$VOLUME") || error "Cannot read size of device \"$VOLUME\"" - SSSIZE=$("$BLOCKDEV" --getss "$VOLUME") || error "Cannot block size read device \"$VOLUME\"" + DEVSIZE=$("$BLOCKDEV" --getsize "$VOLUME") + test -n "$DEVSIZE" || error "Cannot read size of device \"$VOLUME\"." + SSSIZE=$("$BLOCKDEV" --getss "$VOLUME") + test -n "$SSSIZE" || error "Cannot read sector size of device \"$VOLUME\"." DEVSIZE=$(($DEVSIZE * $SSSIZE)) fi }