diff mbox

[kvm-unit-tests,03/12] scripts/mkstandalone: refactor temp file creation

Message ID 1453209851-27760-4-git-send-email-rkrcmar@redhat.com (mailing list archive)
State New, archived
Headers show

Commit Message

Radim Krčmář Jan. 19, 2016, 1:24 p.m. UTC
Using the cleanup variable is ugly, but I couldn't come up with a better
idea.

Signed-off-by: Radim Kr?má? <rkrcmar@redhat.com>
---
 scripts/mkstandalone.sh | 26 +++++++++++++++++++-------
 1 file changed, 19 insertions(+), 7 deletions(-)

Comments

Paolo Bonzini Jan. 19, 2016, 2:46 p.m. UTC | #1
On 19/01/2016 14:24, Radim Kr?má? wrote:
> +
> +	echo "cleanup=\"\$$var \$cleanup\""
> +	echo "$var=\`mktemp\`"

$var is not yet defined when you update cleanup.

Paolo
--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Radim Krčmář Jan. 19, 2016, 2:53 p.m. UTC | #2
2016-01-19 15:46+0100, Paolo Bonzini:
> On 19/01/2016 14:24, Radim Kr?má? wrote:
>> +
>> +	echo "cleanup=\"\$$var \$cleanup\""
>> +	echo "$var=\`mktemp\`"
> 
> $var is not yet defined when you update cleanup.

Ah, I missed that bug.
I'll add `unset var`, so we don't accidentaly delete something.
--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/scripts/mkstandalone.sh b/scripts/mkstandalone.sh
index 47d6e279d212..a187adc856b7 100755
--- a/scripts/mkstandalone.sh
+++ b/scripts/mkstandalone.sh
@@ -20,6 +20,21 @@  fi
 unittests=$TEST_DIR/unittests.cfg
 mkdir -p tests
 
+temp_file ()
+{
+	local var="$1"
+	local file="$2"
+
+	echo "cleanup=\"\$$var \$cleanup\""
+	echo "$var=\`mktemp\`"
+	echo "base64 -d << 'BIN_EOF' | zcat > \$$var || exit 1"
+
+	gzip - < $file | base64
+
+	echo "BIN_EOF"
+	echo "chmod +x \$$var"
+}
+
 function mkstandalone()
 {
 	local testname="$1"
@@ -74,14 +89,11 @@  echo "skip $testname (test kernel not present)" 1>&2
 exit 1
 EOF
 else
+	echo "trap 'rm -f \$cleanup; exit 1' HUP INT TERM"
+
+	temp_file bin "$kernel"
+
 	cat <<EOF
-trap 'rm -f \$bin; exit 1' HUP INT TERM
-bin=\`mktemp\`
-base64 -d << 'BIN_EOF' | zcat > \$bin &&
-EOF
-gzip - < $kernel | base64
-	cat <<EOF
-BIN_EOF
 
 qemu="$qemu"
 if [ "\$QEMU" ]; then