diff options
author | Dmitry Safonov <0x7f454c46@gmail.com> | 2024-08-23 23:04:55 +0100 |
---|---|---|
committer | Jakub Kicinski <kuba@kernel.org> | 2024-08-27 14:11:27 -0700 |
commit | a9e1693406f96f3739611dd08518c9eda3acecfd (patch) | |
tree | 80092f7b23d4e06074c6297146b8fdf5fd0e9605 /tools | |
parent | 8acb1806e8c2846ae619f500a3229a325c3304f5 (diff) | |
download | lwn-a9e1693406f96f3739611dd08518c9eda3acecfd.tar.gz lwn-a9e1693406f96f3739611dd08518c9eda3acecfd.zip |
selftests/net: Don't forget to close nsfd after switch_save_ns()
The switch_save_ns() helper suppose to help switching to another
namespace for some action and to return back to original namespace.
The fd should be closed.
Signed-off-by: Dmitry Safonov <0x7f454c46@gmail.com>
Link: https://patch.msgid.link/20240823-tcp-ao-selftests-upd-6-12-v4-5-05623636fe8c@gmail.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Diffstat (limited to 'tools')
-rw-r--r-- | tools/testing/selftests/net/tcp_ao/lib/setup.c | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/tools/testing/selftests/net/tcp_ao/lib/setup.c b/tools/testing/selftests/net/tcp_ao/lib/setup.c index d5212ffe9489..86a4f6e20450 100644 --- a/tools/testing/selftests/net/tcp_ao/lib/setup.c +++ b/tools/testing/selftests/net/tcp_ao/lib/setup.c @@ -142,6 +142,13 @@ int switch_save_ns(int new_ns) return ret; } +void switch_close_ns(int fd) +{ + if (setns(fd, CLONE_NEWNET)) + test_error("setns()"); + close(fd); +} + static int nsfd_outside = -1; static int nsfd_parent = -1; static int nsfd_child = -1; @@ -296,7 +303,7 @@ static bool is_optmem_namespaced(void) int old_ns = switch_save_ns(nsfd_child); optmem_ns = !access(optmem_file, F_OK); - switch_ns(old_ns); + switch_close_ns(old_ns); } return !!optmem_ns; } @@ -317,7 +324,7 @@ size_t test_get_optmem(void) test_error("can't read from %s", optmem_file); fclose(foptmem); if (!is_optmem_namespaced()) - switch_ns(old_ns); + switch_close_ns(old_ns); return ret; } @@ -339,7 +346,7 @@ static void __test_set_optmem(size_t new, size_t *old) test_error("can't write %zu to %s", new, optmem_file); fclose(foptmem); if (!is_optmem_namespaced()) - switch_ns(old_ns); + switch_close_ns(old_ns); } static void test_revert_optmem(void) |