[PATCH kvm-unit-tests 01/12] scripts/mkstandalone: simplify redirection

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Use exec to redirect stdout to a file, and start the cleanup.

Signed-off-by: Radim Krčmář <rkrcmar@xxxxxxxxxx>
---
 scripts/mkstandalone.sh | 25 ++++++++++++++-----------
 1 file changed, 14 insertions(+), 11 deletions(-)

diff --git a/scripts/mkstandalone.sh b/scripts/mkstandalone.sh
index 3ce244aff67b..5f9ef146208e 100755
--- a/scripts/mkstandalone.sh
+++ b/scripts/mkstandalone.sh
@@ -48,12 +48,13 @@ function mkstandalone()
 	qemu=$(cut -d' ' -f1 <<< "$cmdline")
 	cmdline=$(cut -d' ' -f2- <<< "$cmdline")
 
-	cat <<EOF > $standalone
-#!/bin/sh
+	exec {tmpfd}<&1
+	exec > $standalone
+
+	echo "#!/bin/sh"
 
-EOF
 if [ "$arch" ]; then
-	cat <<EOF >> $standalone
+	cat <<EOF
 ARCH=\`uname -m | sed -e s/i.86/i386/ | sed -e 's/arm.*/arm/'\`
 [ "\$ARCH" = "aarch64" ] && ARCH="arm64"
 if [ "\$ARCH" != "$arch" ]; then
@@ -64,7 +65,7 @@ fi
 EOF
 fi
 if [ "$check" ]; then
-	cat <<EOF >> $standalone
+	cat <<EOF
 for param in $check; do
 	path=\`echo \$param | cut -d= -f1\`
 	value=\`echo \$param | cut -d= -f2\`
@@ -77,18 +78,18 @@ done
 EOF
 fi
 if [ ! -f $kernel ]; then
-	cat <<EOF >> $standalone
+	cat <<EOF
 echo "skip $testname (test kernel not present)" 1>&2
 exit 1
 EOF
 else
-	cat <<EOF >> $standalone
+	cat <<EOF
 trap 'rm -f \$bin; exit 1' HUP INT TERM
 bin=\`mktemp\`
 base64 -d << 'BIN_EOF' | zcat > \$bin &&
 EOF
-gzip - < $kernel | base64 >> $standalone
-	cat <<EOF >> $standalone
+gzip - < $kernel | base64
+	cat <<EOF
 BIN_EOF
 
 qemu="$qemu"
@@ -122,8 +123,10 @@ rm -f \$bin
 exit 0
 EOF
 fi
-chmod +x $standalone
-return 0
+	exec 1<&$tmpfd {tmpfd}<&-
+	chmod +x $standalone
+
+	return 0
 }
 
 trap 'rm -f $cfg; exit 1' HUP INT TERM
-- 
2.7.0

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]
  Powered by Linux