Skip to content

Commit 577db6b

Browse files
matttbekuba-moo
authored andcommitted
selftests: net: lib: do not set ns var as readonly
It sounds good to mark the global netns variable as 'readonly', but Bash doesn't allow the creation of local variables with the same name. Because it looks like 'readonly' is mainly used here to check if a netns with that name has already been set, it sounds fine to check if a variable with this name has already been set instead. By doing that, we avoid having to modify helpers from MPTCP selftests using the same variable name as the one used to store the created netns name. While at it, also avoid an unnecessary call to 'eval' to set a local variable. Reviewed-by: Geliang Tang <[email protected]> Signed-off-by: Matthieu Baerts (NGI0) <[email protected]> Link: https://lore.kernel.org/r/20240607-upstream-net-next-20240607-selftests-mptcp-net-lib-v1-3-e36986faac94@kernel.org Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 92fe567 commit 577db6b

File tree

1 file changed

+3
-3
lines changed
  • tools/testing/selftests/net

1 file changed

+3
-3
lines changed

tools/testing/selftests/net/lib.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -172,11 +172,11 @@ setup_ns()
172172
local ns_list=()
173173
for ns_name in "$@"; do
174174
# Some test may setup/remove same netns multi times
175-
if unset ${ns_name} 2> /dev/null; then
175+
if [ -z "${!ns_name}" ]; then
176176
ns="${ns_name,,}-$(mktemp -u XXXXXX)"
177-
eval readonly ${ns_name}="$ns"
177+
eval "${ns_name}=${ns}"
178178
else
179-
eval ns='$'${ns_name}
179+
ns="${!ns_name}"
180180
cleanup_ns "$ns"
181181
fi
182182

0 commit comments

Comments
 (0)