diff mbox series

[mptcp-next,v2,1/2] selftests: mptcp: open cfg_input once in main_loop

Message ID 58fcd84cd7eae33eb7ff2d87415109c5324a0c4d.1742355162.git.tanggeliang@kylinos.cn (mailing list archive)
State Superseded, archived
Headers show
Series cleanups for main_loop | expand

Checks

Context Check Description
matttbe/build success Build and static analysis OK
matttbe/checkpatch success total: 0 errors, 0 warnings, 0 checks, 36 lines checked
matttbe/shellcheck success MPTCP selftests files have not been modified
matttbe/KVM_Validation__normal warning Unstable: 1 failed test(s): selftest_mptcp_connect
matttbe/KVM_Validation__debug warning Unstable: 1 failed test(s): selftest_mptcp_connect
matttbe/KVM_Validation__btf-normal__only_bpftest_all_ success Success! ✅
matttbe/KVM_Validation__btf-debug__only_bpftest_all_ success Success! ✅

Commit Message

Geliang Tang March 19, 2025, 3:39 a.m. UTC
From: Geliang Tang <tanggeliang@kylinos.cn>

cfg_input is opened twice regardless of whether cfg_sockopt_types.mptfo
is configured. This can be simplified to open it once at the beginning
of main_loop() and close it at the end, because no need to repeatedly
open and close cfg_input during cfg_repeat.

Co-developed-by: Cong Liu <liucong2@kylinos.cn>
Signed-off-by: Cong Liu <liucong2@kylinos.cn>
Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn>
---
 tools/testing/selftests/net/mptcp/mptcp_connect.c | 12 +++---------
 1 file changed, 3 insertions(+), 9 deletions(-)
diff mbox series

Patch

diff --git a/tools/testing/selftests/net/mptcp/mptcp_connect.c b/tools/testing/selftests/net/mptcp/mptcp_connect.c
index 893dc36b12f6..5301062a5f3b 100644
--- a/tools/testing/selftests/net/mptcp/mptcp_connect.c
+++ b/tools/testing/selftests/net/mptcp/mptcp_connect.c
@@ -1268,7 +1268,7 @@  int main_loop(void)
 	struct addrinfo *peer;
 	struct wstate winfo;
 
-	if (cfg_input && cfg_sockopt_types.mptfo) {
+	if (cfg_input) {
 		fd_in = open(cfg_input, O_RDONLY);
 		if (fd_in < 0)
 			xerror("can't open %s:%d", cfg_input, errno);
@@ -1291,12 +1291,6 @@  int main_loop(void)
 	if (cfg_cmsg_types.cmsg_enabled)
 		apply_cmsg_types(fd, &cfg_cmsg_types);
 
-	if (cfg_input && !cfg_sockopt_types.mptfo) {
-		fd_in = open(cfg_input, O_RDONLY);
-		if (fd_in < 0)
-			xerror("can't open %s:%d", cfg_input, errno);
-	}
-
 	ret = copyfd_io(fd_in, fd, 1, 0, &winfo);
 	if (ret)
 		return ret;
@@ -1312,14 +1306,14 @@  int main_loop(void)
 		set_nonblock(fd, false);
 		if (connect(fd, peer->ai_addr, peer->ai_addrlen))
 			xerror("can't reconnect: %d", errno);
-		if (cfg_input)
-			close(fd_in);
 		memset(&winfo, 0, sizeof(winfo));
 		goto again;
 	} else {
 		close(fd);
 	}
 
+	if (cfg_input)
+		close(fd_in);
 	return 0;
 }