diff mbox series

[mptcp-next,3/4] selftests: mptcp: diag: add ns name empty check in cleanup

Message ID eb0532a18d2d520268dc2ba0f1e414b25aaafb04.1716641976.git.tanggeliang@kylinos.cn (mailing list archive)
State Rejected, archived
Headers show
Series Squash to "use helpers in lib.sh" v5 | expand

Checks

Context Check Description
matttbe/build success Build and static analysis OK
matttbe/checkpatch success total: 0 errors, 0 warnings, 0 checks, 7 lines checked
matttbe/shellcheck success No ShellCheck issues
matttbe/KVM_Validation__normal success Success! ✅
matttbe/KVM_Validation__debug success Success! ✅
matttbe/KVM_Validation__btf__only_bpftest_all_ success Success! ✅

Commit Message

Geliang Tang May 25, 2024, 1:01 p.m. UTC
From: Geliang Tang <tanggeliang@kylinos.cn>

mptcp_lib_ns_init may fail sometimes, then ns isn't setup correctly. In
that case, cleanup is invoked, and ns is used in cleanup. So an "Invalid
netns name ''" error occurs.

For example, these errors occur when invalid name is set to setup_ns:

    Failed to setup namespace 'ns_temp': invalid name
    Invalid netns name ""

The patch adds an ns name empty check before using it in cleanup.

Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn>
---
 tools/testing/selftests/net/mptcp/diag.sh | 1 +
 1 file changed, 1 insertion(+)

Comments

Matthieu Baerts (NGI0) May 27, 2024, 10:15 a.m. UTC | #1
Hi Geliang,

On 25/05/2024 15:01, Geliang Tang wrote:
> From: Geliang Tang <tanggeliang@kylinos.cn>
> 
> mptcp_lib_ns_init may fail sometimes, then ns isn't setup correctly. In
> that case, cleanup is invoked, and ns is used in cleanup. So an "Invalid
> netns name ''" error occurs.
> 
> For example, these errors occur when invalid name is set to setup_ns:
> 
>     Failed to setup namespace 'ns_temp': invalid name
>     Invalid netns name ""

Mmh, I don't think this is needed: here, you explicitly caused the issue
by picking an invalid name. That's the only case where the 'ns' variable
will be not set. It should not fail with this error then.

Cheers,
Matt
diff mbox series

Patch

diff --git a/tools/testing/selftests/net/mptcp/diag.sh b/tools/testing/selftests/net/mptcp/diag.sh
index 776d43a6922d..7ee43c35e0e9 100755
--- a/tools/testing/selftests/net/mptcp/diag.sh
+++ b/tools/testing/selftests/net/mptcp/diag.sh
@@ -31,6 +31,7 @@  flush_pids()
 #shellcheck disable=SC2317
 cleanup()
 {
+	[ -n "${ns}" ] &&
 	ip netns pids "${ns}" | xargs --no-run-if-empty kill -SIGKILL &>/dev/null
 
 	mptcp_lib_ns_exit "${ns}"