diff options
Diffstat (limited to 'scripts/zloop.sh')
-rwxr-xr-x | scripts/zloop.sh | 45 |
1 files changed, 26 insertions, 19 deletions
diff --git a/scripts/zloop.sh b/scripts/zloop.sh index 580fcfe40..3a6db40cf 100755 --- a/scripts/zloop.sh +++ b/scripts/zloop.sh @@ -20,7 +20,7 @@ # Copyright (C) 2016 Lawrence Livermore National Security, LLC. # -basedir="$(dirname $0)" +basedir=$(dirname "$0") SCRIPT_COMMON=common.sh if [ -f "${basedir}/${SCRIPT_COMMON}" ]; then @@ -29,6 +29,7 @@ else echo "Missing helper script ${SCRIPT_COMMON}" && exit 1 fi +# shellcheck disable=SC2034 PROG=zloop.sh DEFAULTWORKDIR=/var/tmp @@ -56,8 +57,11 @@ function usage function or_die { + # shellcheck disable=SC2068 $@ + # shellcheck disable=SC2181 if [[ $? -ne 0 ]]; then + # shellcheck disable=SC2145 echo "Command failed: $@" exit 1 fi @@ -76,14 +80,16 @@ fi function core_file { + # shellcheck disable=SC2012 disable=2086 printf "%s" "$(ls -tr1 $coreglob 2> /dev/null | head -1)" } function core_prog { prog=$ZTEST - core_id=$($GDB --batch -c $1 | grep "Core was generated by" | \ + core_id=$($GDB --batch -c "$1" | grep "Core was generated by" | \ tr \' ' ') + # shellcheck disable=SC2076 if [[ "$core_id" =~ "zdb " ]]; then prog=$ZDB fi @@ -95,23 +101,23 @@ function store_core core="$(core_file)" if [[ $ztrc -ne 0 ]] || [[ -f "$core" ]]; then coreid=$(date "+zloop-%y%m%d-%H%M%S") - foundcrashes=$(($foundcrashes + 1)) + foundcrashes=$((foundcrashes + 1)) dest=$coredir/$coreid - or_die mkdir -p $dest - or_die mkdir -p $dest/vdev + or_die mkdir -p "$dest" + or_die mkdir -p "$dest/vdev" echo "*** ztest crash found - moving logs to $dest" - or_die mv ztest.history $dest/ - or_die mv ztest.ddt $dest/ - or_die mv ztest.out $dest/ - or_die mv $workdir/ztest* $dest/vdev/ - or_die mv $workdir/zpool.cache $dest/vdev/ + or_die mv ztest.history "$dest/" + or_die mv ztest.ddt "$dest/" + or_die mv ztest.out "$dest/" + or_die mv "$workdir/ztest*" "$dest/vdev/" + or_die mv "$workdir/zpool.cache" "$dest/vdev/" # check for core if [[ -f "$core" ]]; then - coreprog=$(core_prog $core) + coreprog=$(core_prog "$core") corestatus=$($GDB --batch --quiet \ -ex "set print thread-events off" \ -ex "printf \"*\n* Backtrace \n*\n\"" \ @@ -124,11 +130,11 @@ function store_core -ex "thread apply all bt" \ -ex "printf \"*\n* Backtraces (full) \n*\n\"" \ -ex "thread apply all bt full" \ - -ex "quit" $coreprog "$core" | grep -v "New LWP") + -ex "quit" "$coreprog" "$core" | grep -v "New LWP") # Dump core + logs to stored directory - echo "$corestatus" >>$dest/status - or_die mv "$core" $dest/ + echo "$corestatus" >>"$dest/status" + or_die mv "$core" "$dest/" # Record info in cores logfile echo "*** core @ $coredir/$coreid/$core:" | \ @@ -149,7 +155,7 @@ while getopts ":ht:c:f:" opt; do case $opt in t ) [[ $OPTARG -gt 0 ]] && timeout=$OPTARG ;; c ) [[ $OPTARG ]] && coredir=$OPTARG ;; - f ) [[ $OPTARG ]] && workdir=$(readlink -f $OPTARG) ;; + f ) [[ $OPTARG ]] && workdir=$(readlink -f "$OPTARG") ;; h ) usage exit 2 ;; @@ -166,13 +172,13 @@ ulimit -c unlimited if [[ -f "$(core_file)" ]]; then echo -n "There's a core dump here you might want to look at first... " - echo "$(core_file)" + core_file exit 1 fi if [[ ! -d $coredir ]]; then echo "core dump directory ($coredir) does not exist, creating it." - or_die mkdir -p $coredir + or_die mkdir -p "$coredir" fi if [[ ! -w $coredir ]]; then @@ -190,7 +196,7 @@ starttime=$(date +%s) curtime=$starttime # if no timeout was specified, loop forever. -while [[ $timeout -eq 0 ]] || [[ $curtime -le $(($starttime + $timeout)) ]]; do +while [[ $timeout -eq 0 ]] || [[ $curtime -le $((starttime + timeout)) ]]; do zopt="-VVVVV" # switch between common arrangements & fully randomized @@ -220,6 +226,7 @@ while [[ $timeout -eq 0 ]] || [[ $curtime -le $(($starttime + $timeout)) ]]; do zopt="$zopt -s $size" zopt="$zopt -f $workdir" + # shellcheck disable=SC2124 cmd="$ZTEST $zopt $@" desc="$(date '+%m/%d %T') $cmd" echo "$desc" | tee -a ztest.history @@ -227,7 +234,7 @@ while [[ $timeout -eq 0 ]] || [[ $curtime -le $(($starttime + $timeout)) ]]; do $cmd >>ztest.out 2>&1 ztrc=$? egrep '===|WARNING' ztest.out >>ztest.history - $ZDB -U $workdir/zpool.cache -DD ztest >>ztest.ddt + $ZDB -U "$workdir/zpool.cache" -DD ztest >>ztest.ddt store_core |