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

Geliang Tang posted 4 patches 4 months, 3 weeks ago
[PATCH mptcp-next 3/4] selftests: mptcp: diag: add ns name empty check in cleanup
Posted by Geliang Tang 4 months, 3 weeks ago
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(+)

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}"
-- 
2.43.0
Re: [PATCH mptcp-next 3/4] selftests: mptcp: diag: add ns name empty check in cleanup
Posted by Matthieu Baerts 4 months, 3 weeks ago
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
-- 
Sponsored by the NGI0 Core fund.