From: =?UTF-8?q?Radim=20Kr=C4=8Dm=C3=A1=C5=99?= Subject: [PATCH kvm-unit-tests] scripts/mkstandalone: fix races on forced exits Date: Thu, 21 Jan 2016 16:10:16 +0100 Message-ID: <1453389016-9141-1-git-send-email-rkrcmar@redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: QUOTED-PRINTABLE Cc: Paolo Bonzini , Andrew Jones To: kvm@vger.kernel.org Return-path: Received: from mx1.redhat.com ([209.132.183.28]:49735 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752770AbcAUPLP (ORCPT ); Thu, 21 Jan 2016 10:11:15 -0500 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by mx1.redhat.com (Postfix) with ESMTPS id 8D9A9120498 for ; Thu, 21 Jan 2016 15:11:15 +0000 (UTC) Sender: kvm-owner@vger.kernel.org List-ID: There are two bugs that happen if we exit after the first line of following examples, 1) var=3D`mktemp` # we don't remove the temp file trap 'rm -f $var' EXIT 2) trap 'rm -f $cfg' EXIT # if $cfg is defined (=3D exported), we delete an unrelated file cfg=3D`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=C4=8Dm=C3=A1=C5=99 --- 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=3D"$1" local file=3D"$2" =20 + temp_file_vars+=3D" \$$var" + + echo "unset $var" + echo "trap 'rm -f $temp_file_vars' EXIT" echo "$var=3D\`mktemp\`" - echo "cleanup=3D\"\$$var \$cleanup\"" echo "base64 -d << 'BIN_EOF' | zcat > \$$var || exit 1" =20 gzip - < $file | base64 @@ -32,6 +35,7 @@ temp_file () generate_test () { local args=3D( $(escape "${@}") ) + local temp_file_vars =20 echo "#!/bin/bash" grep '^ARCH=3D' config.mak @@ -42,8 +46,6 @@ generate_test () return 1 fi =20 - echo "trap 'rm -f \$cleanup' EXIT" - temp_file bin "$kernel" args[3]=3D'$bin' =20 @@ -76,6 +78,7 @@ function mkstandalone() return 0 } =20 +unset cfg trap 'rm -f $cfg' EXIT cfg=3D$(mktemp) =20 --=20 2.7.0