Thread (6 messages) 6 messages, 5 authors, 2022-09-26
STALE1370d

[PATCH bpf-next v2] selftests/bpf: fix incorrect fcntl call (test_sockmap.c)

From: Qiao Ma <hidden>
Date: 2022-08-25 02:11:59
Also in: linux-kselftest, lkml
Subsystem: bpf [general] (safe dynamic programs and tools), bpf [selftests] (test runners & infrastructure), kernel selftest framework, the rest · Maintainers: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko, Eduard Zingerman, Kumar Kartikeya Dwivedi, Shuah Khan, Linus Torvalds

In test_sockmap.c, the testcase sets socket nonblock first, and then
calls select() and recvmsg() to receive data.
If some error occur, nonblock setting will make recvmsg() return
immediately, rather than blocking forever.

However, the way to call fcntl() to set nonblock is wrong.
To set socket noblock, we need to use
fcntl(fd, F_SETFL, O_NONBLOCK);
rather than:
fcntl(fd, O_NONBLOCK);
Signed-off-by: Qiao Ma <redacted>
---
 tools/testing/selftests/bpf/test_sockmap.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/tools/testing/selftests/bpf/test_sockmap.c b/tools/testing/selftests/bpf/test_sockmap.c
index 0fbaccdc8861..abb4102f33b0 100644
--- a/tools/testing/selftests/bpf/test_sockmap.c
+++ b/tools/testing/selftests/bpf/test_sockmap.c
@@ -598,7 +598,12 @@ static int msg_loop(int fd, int iov_count, int iov_length, int cnt,
 		struct timeval timeout;
 		fd_set w;
 
-		fcntl(fd, fd_flags);
+		err = fcntl(fd, F_SETFL, fd_flags);
+		if (err < 0) {
+			perror("fcntl failed");
+			goto out_errno;
+		}
+
 		/* Account for pop bytes noting each iteration of apply will
 		 * call msg_pop_data helper so we need to account for this
 		 * by calculating the number of apply iterations. Note user
-- 
1.8.3.1
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help