From: Po-Hsu Lin <po-hsu.lin@canonical.com>
To: linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org,
netdev@vger.kernel.org
Cc: shuah@kernel.org, kuba@kernel.org, davem@davemloft.net,
skhan@linuxfoundation.org
Subject: [PATCHv2] selftests: xfrm: put cleanup code into an exit trap
Date: Wed, 12 May 2021 18:11:31 +0800 [thread overview]
Message-ID: <20210512101131.45306-1-po-hsu.lin@canonical.com> (raw)
If the xfrm_policy.sh script gets terminated by any reason, the netns
namespace files created by the test will be left alone.
In this case a second attempt to run this test will fail with:
# Cannot create namespace file "/run/netns/ns1": File exists
Move the netns cleanup code into an exit trap so that we can ensure
these files will be removed in the end.
Changes in V2:
- Update commit message and patch title.
Signed-off-by: Po-Hsu Lin <po-hsu.lin@canonical.com>
---
tools/testing/selftests/net/xfrm_policy.sh | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/tools/testing/selftests/net/xfrm_policy.sh b/tools/testing/selftests/net/xfrm_policy.sh
index bdf450e..bb4632b 100755
--- a/tools/testing/selftests/net/xfrm_policy.sh
+++ b/tools/testing/selftests/net/xfrm_policy.sh
@@ -28,6 +28,11 @@ KEY_AES=0x0123456789abcdef0123456789012345
SPI1=0x1
SPI2=0x2
+cleanup() {
+ for i in 1 2 3 4;do ip netns del ns$i 2>/dev/null ;done
+}
+trap cleanup EXIT
+
do_esp_policy() {
local ns=$1
local me=$2
@@ -481,6 +486,4 @@ check_hthresh_repeat "policies with repeated htresh change"
check_random_order ns3 "policies inserted in random order"
-for i in 1 2 3 4;do ip netns del ns$i;done
-
exit $ret
--
2.7.4
reply other threads:[~2021-05-12 10:12 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20210512101131.45306-1-po-hsu.lin@canonical.com \
--to=po-hsu.lin@canonical.com \
--cc=davem@davemloft.net \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=shuah@kernel.org \
--cc=skhan@linuxfoundation.org \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).