From 19e48a66a47c2cc422629457d2de7e3b6af7385c Mon Sep 17 00:00:00 2001 From: Maciej Wawryk Date: Tue, 10 Dec 2019 07:58:35 +0100 Subject: [PATCH] test: Shellcheck - correct rule: Iterating over ls Correct shellcheck rule SC2045: Iterating over ls output is fragile. Use globs. Signed-off-by: Maciej Wawryk Change-Id: I436878774d6f86c23b1c5cf5220da297053f03e2 Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/477397 Tested-by: SPDK CI Jenkins Reviewed-by: Paul Luse Reviewed-by: Jim Harris Reviewed-by: Shuhei Matsumoto --- scripts/check_format.sh | 2 +- test/common/config/vm_setup.sh | 2 +- test/nvme/spdk_nvme_cli_cuse.sh | 4 ++-- test/nvmf/common.sh | 8 +++++--- test/vhost/common.sh | 2 +- 5 files changed, 10 insertions(+), 8 deletions(-) diff --git a/scripts/check_format.sh b/scripts/check_format.sh index 6fc1896028..5c85c3d2f6 100755 --- a/scripts/check_format.sh +++ b/scripts/check_format.sh @@ -240,7 +240,7 @@ if hash shellcheck 2>/dev/null; then # go to: https://trello.com/c/29Z90j1W # Error descriptions can also be found at: https://github.com/koalaman/shellcheck/wiki # This SHCK_EXCLUDE list is out "to do" and we work to fix all of this errors. - SHCK_EXCLUDE="SC2002,SC2010,SC2034,SC2045" + SHCK_EXCLUDE="SC2002,SC2010,SC2034" # SPDK fails some error checks which have been deprecated in later versions of shellcheck. # We will not try to fix these error checks, but instead just leave the error types here # so that we can still run with older versions of shellcheck. diff --git a/test/common/config/vm_setup.sh b/test/common/config/vm_setup.sh index 592b1c14f2..3e68057ba5 100755 --- a/test/common/config/vm_setup.sh +++ b/test/common/config/vm_setup.sh @@ -76,7 +76,7 @@ function install_iscsi_adm() git -C open-iscsi-install/open-iscsi config user.email none git -C open-iscsi-install/open-iscsi checkout 86e8892 - for patch in $(ls open-iscsi-install/patches); do + for patch in open-iscsi-install/patches/*; do git -C open-iscsi-install/open-iscsi am ../patches/$patch done sed -i '427s/.*/-1);/' open-iscsi-install/open-iscsi/usr/session_info.c diff --git a/test/nvme/spdk_nvme_cli_cuse.sh b/test/nvme/spdk_nvme_cli_cuse.sh index 621ec3fbeb..b0aed1eead 100755 --- a/test/nvme/spdk_nvme_cli_cuse.sh +++ b/test/nvme/spdk_nvme_cli_cuse.sh @@ -28,13 +28,13 @@ fi $rpc_py bdev_get_bdevs $rpc_py bdev_nvme_get_controllers -for ns in $(ls /dev/spdk/nvme?n?); do +for ns in /dev/spdk/nvme?n?; do ${NVME_CMD} get-ns-id $ns ${NVME_CMD} id-ns $ns ${NVME_CMD} list-ns $ns done -for ctrlr in $(ls /dev/spdk/nvme?); do +for ctrlr in /dev/spdk/nvme?; do ${NVME_CMD} id-ctrl $ctrlr ${NVME_CMD} list-ctrl $ctrlr ${NVME_CMD} fw-log $ctrlr diff --git a/test/nvmf/common.sh b/test/nvmf/common.sh index 3159baa3fb..cfdb120104 100644 --- a/test/nvmf/common.sh +++ b/test/nvmf/common.sh @@ -131,9 +131,11 @@ function get_available_rdma_ips() function get_rdma_if_list() { - for nic_type in $(ls /sys/class/infiniband); do - for nic_name in $(ls /sys/class/infiniband/${nic_type}/device/net); do - echo "$nic_name" + for nic_type in /sys/class/infiniband/*; do + [[ -e "$nic_type" ]] || break + for nic_name in /sys/class/infiniband/"$(basename ${nic_type})"/device/net/*; do + [[ -e "$nic_name" ]] || break + basename "$nic_name" done done } diff --git a/test/vhost/common.sh b/test/vhost/common.sh index 503f79ab48..4a880e5656 100644 --- a/test/vhost/common.sh +++ b/test/vhost/common.sh @@ -1123,7 +1123,7 @@ function at_app_exit() # Kill vhost application notice "killing vhost app" - for vhost_name in $(ls $TARGET_DIR); do + for vhost_name in "$TARGET_DIR"/*; do vhost_kill $vhost_name done