All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Radim Krčmář" <rkrcmar@redhat.com>
To: kvm@vger.kernel.org
Cc: Paolo Bonzini <pbonzini@redhat.com>, Andrew Jones <drjones@redhat.com>
Subject: [PATCH kvm-unit-tests 01/12] scripts/mkstandalone: simplify redirection
Date: Tue, 19 Jan 2016 14:24:00 +0100	[thread overview]
Message-ID: <1453209851-27760-2-git-send-email-rkrcmar@redhat.com> (raw)
In-Reply-To: <1453209851-27760-1-git-send-email-rkrcmar@redhat.com>

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

Signed-off-by: Radim Krčmář <rkrcmar@redhat.com>
---
 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


  reply	other threads:[~2016-01-19 13:24 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-01-19 13:23 [PATCH kvm-unit-tests 00/12] scripts/mkstandalone: rewrite Radim Krčmář
2016-01-19 13:24 ` Radim Krčmář [this message]
2016-01-19 13:24 ` [PATCH kvm-unit-tests 02/12] scripts/mkstandalone: fix ARCH Radim Krčmář
2016-01-19 14:32   ` Paolo Bonzini
2016-01-19 13:24 ` [PATCH kvm-unit-tests 03/12] scripts/mkstandalone: refactor temp file creation Radim Krčmář
2016-01-19 14:46   ` Paolo Bonzini
2016-01-19 14:53     ` Radim Krčmář
2016-01-19 13:24 ` [PATCH kvm-unit-tests 04/12] scripts/mkstandalone: use bash in standalone test Radim Krčmář
2016-01-19 13:24 ` [PATCH kvm-unit-tests 05/12] scripts/mkstandalone: reuse $TEST_DIR/run Radim Krčmář
2016-01-19 13:24 ` [PATCH kvm-unit-tests 06/12] run_tests: move reusable code to scripts/runtime Radim Krčmář
2016-01-19 13:24 ` [PATCH kvm-unit-tests 07/12] scripts/runtime: change callsite of $TEST_DIR/run Radim Krčmář
2016-01-19 14:38   ` Paolo Bonzini
2016-01-19 14:55     ` Radim Krčmář
2016-01-19 13:24 ` [PATCH kvm-unit-tests 08/12] scripts/mkstandalone: refactor check for test kernel Radim Krčmář
2016-01-19 13:24 ` [PATCH kvm-unit-tests 09/12] scripts/mkstandalone: use scripts/runtime Radim Krčmář
2016-01-19 13:24 ` [PATCH kvm-unit-tests 10/12] scripts/mkstandalone: simplifiy redirection, again Radim Krčmář
2016-01-19 13:24 ` [PATCH kvm-unit-tests 11/12] scripts/mkstandalone: sanitize one_kernel handling Radim Krčmář
2016-01-19 13:24 ` [PATCH kvm-unit-tests 12/12] scripts/mkstandalone: return the exit value of a test Radim Krčmář
2016-01-19 14:49 ` [PATCH kvm-unit-tests 00/12] scripts/mkstandalone: rewrite Paolo Bonzini
2016-01-19 14:56   ` Radim Krčmář
2016-01-19 15:20 ` Andrew Jones

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1453209851-27760-2-git-send-email-rkrcmar@redhat.com \
    --to=rkrcmar@redhat.com \
    --cc=drjones@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=pbonzini@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.