From 08f0abebb4791018c3cfc4c30f9beb7a52c4eea6 Mon Sep 17 00:00:00 2001 From: Michal Berger Date: Mon, 4 May 2020 09:54:28 +0200 Subject: [PATCH] test/vhost: Use heredoc to create run.sh This is to make the code that's about to be written out more clear and drop the unecessary usage of a subshell. Signed-off-by: Michal Berger Change-Id: I024012b08fc3c29d3c37c59a42e64d8429929799 Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/2004 Community-CI: Mellanox Build Bot Tested-by: SPDK CI Jenkins Reviewed-by: Ben Walker Reviewed-by: Darek Stojaczyk Reviewed-by: Jim Harris --- test/vhost/common.sh | 49 ++++++++++++++++++++++---------------------- 1 file changed, 25 insertions(+), 24 deletions(-) diff --git a/test/vhost/common.sh b/test/vhost/common.sh index 59ad2ce81..c533b0ec6 100644 --- a/test/vhost/common.sh +++ b/test/vhost/common.sh @@ -774,30 +774,31 @@ function vm_setup() (( ${#qemu_args[@]} )) && cmd+=("${qemu_args[@]}") notice "Saving to $vm_dir/run.sh" - ( - echo '#!/bin/bash' - echo 'if [[ $EUID -ne 0 ]]; then ' - echo ' echo "Go away user come back as root"' - echo ' exit 1' - echo 'fi'; - echo - echo "qemu_cmd=($(printf '%s\n' "${cmd[@]}"))"; - echo - echo "echo 'Running VM in $vm_dir'" - echo "rm -f $qemu_pid_file" - echo '"${qemu_cmd[@]}"' - echo "echo 'Waiting for QEMU pid file'" - echo "sleep 1" - echo "[[ ! -f $qemu_pid_file ]] && sleep 1" - echo "[[ ! -f $qemu_pid_file ]] && echo 'ERROR: no qemu pid file found' && exit 1" - echo - echo "chmod +r $vm_dir/*" - echo - echo "echo '=== qemu.log ==='" - echo "cat $vm_dir/qemu.log" - echo "echo '=== qemu.log ==='" - echo '# EOF' - ) > $vm_dir/run.sh + cat <<-RUN >"$vm_dir/run.sh" + #!/bin/bash + + if [[ \$EUID -ne 0 ]]; then + echo "Go away user come back as root" + exit 1 + fi + + qemu_cmd=($(printf '%s\n' "${cmd[@]}")) + + echo "Running VM in $vm_dir" + rm -f $qemu_pid_file + "\${qemu_cmd[@]}" + echo "Waiting for QEMU pid file" + sleep 1 + [[ ! -f $qemu_pid_file ]] && sleep 1 + [[ ! -f $qemu_pid_file ]] && echo "ERROR: no qemu pid file found" && exit 1 + + chmod +r $vm_dir/* + + echo "=== qemu.log ===" + cat $vm_dir/qemu.log + echo "=== qemu.log ===" + # EOF + RUN chmod +x $vm_dir/run.sh # Save generated sockets redirection