All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH kvm-unit-tests] scripts/mkstandalone: fix races on forced exits
@ 2016-01-21 15:10 Radim Krčmář
  0 siblings, 0 replies; only message in thread
From: Radim Krčmář @ 2016-01-21 15:10 UTC (permalink / raw)
  To: kvm; +Cc: Paolo Bonzini, Andrew Jones

There are two bugs that happen if we exit after the first line of
following examples,

1) var=`mktemp`
   # we don't remove the temp file
   trap 'rm -f $var' EXIT

2) trap 'rm -f $cfg' EXIT
   # if $cfg is defined (= exported), we delete an unrelated file
   cfg=`mktemp`

Unit tests don't use cleanup variable anymore, but redefine EXIT trap
every time a new file is added.  This makes the standalone test slower,
but both scripts are less tangled now, IMO.  (Passing temp_file_vars as
an argument is nicer in theory, but doesn't look very good.)

Signed-off-by: Radim Krčmář <rkrcmar@redhat.com>
---
 I wanted to redefine the trap from the beginning, but it didn't pass
 sanity test before ... and Paolo also noticed a severe bug in the
 original series, so I probably wasn't testing in the right directory
 on both occasions :/

 scripts/mkstandalone.sh | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/scripts/mkstandalone.sh b/scripts/mkstandalone.sh
index 58910059a355..7d3455e66c99 100755
--- a/scripts/mkstandalone.sh
+++ b/scripts/mkstandalone.sh
@@ -19,8 +19,11 @@ temp_file ()
 	local var="$1"
 	local file="$2"
 
+	temp_file_vars+=" \$$var"
+
+	echo "unset $var"
+	echo "trap 'rm -f $temp_file_vars' EXIT"
 	echo "$var=\`mktemp\`"
-	echo "cleanup=\"\$$var \$cleanup\""
 	echo "base64 -d << 'BIN_EOF' | zcat > \$$var || exit 1"
 
 	gzip - < $file | base64
@@ -32,6 +35,7 @@ temp_file ()
 generate_test ()
 {
 	local args=( $(escape "${@}") )
+	local temp_file_vars
 
 	echo "#!/bin/bash"
 	grep '^ARCH=' config.mak
@@ -42,8 +46,6 @@ generate_test ()
 		return 1
 	fi
 
-	echo "trap 'rm -f \$cleanup' EXIT"
-
 	temp_file bin "$kernel"
 	args[3]='$bin'
 
@@ -76,6 +78,7 @@ function mkstandalone()
 	return 0
 }
 
+unset cfg
 trap 'rm -f $cfg' EXIT
 cfg=$(mktemp)
 
-- 
2.7.0


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2016-01-21 15:11 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-01-21 15:10 [PATCH kvm-unit-tests] scripts/mkstandalone: fix races on forced exits Radim Krčmář

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.