Skip to contentSkip to conversation

syscalls/accept02: Fix TST_GET_UNUSED_PORT() usage

PATCH New Cyril Hrubis 1 participant 2 messages Jul 30, 2019

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 syscalls/accept02: Fix TST_GET_UNUSED_PORT() usage

The value returned from TST_GET_UNUSED_PORT() is in network byte order already so we must not use htons() when passing the value in the sockaddr structure.

Also when printing the value we have to do the inverse conversion.

---
 testcases/kernel/syscalls/accept/accept02.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
testcases/kernel/syscalls/accept/accept02.c +2 -2
index 662ae4346..3db0f33bc 100644
@@ -92,7 +92,7 @@ static void run(void)
 {
 	pthread_t server_thr, client_thr;
 
-	server_addr.sin_port = htons(server_port);
+	server_addr.sin_port = server_port;
 	client_addr.sin_port = htons(0);
 
 	SAFE_PTHREAD_CREATE(&server_thr, NULL, server_thread, NULL);
@@ -121,7 +121,7 @@ static void setup(void)
 	addr_len = sizeof(struct sockaddr_in);
 
 	server_port = TST_GET_UNUSED_PORT(AF_INET, SOCK_STREAM);
-	tst_res(TINFO, "Starting listener on port: %d", server_port);
+	tst_res(TINFO, "Starting listener on port: %d", ntohs(server_port));
 }
 
 static void cleanup(void)
Signature · 1 line
2.21.0
#1 lore raw

PATCH 2/2 syscalls/accept02: Remove .needs_root

This was a workaround for bug fixed in:

commit af4e42cf022b4f3d016892ed8257e0ec205ec2f0 (HEAD -> master)

Author: Cyril Hrubis <[email protected]>
Date:   Tue Jul 30 17:31:33 2019 +0200

syscalls/accept02: Fix TST_GET_UNUSED_PORT() usage

The test was failing randomly with EACCESS when the wrongly converted port number was < 1024.

---
 testcases/kernel/syscalls/accept/accept02.c | 1 -
 1 file changed, 1 deletion(-)
testcases/kernel/syscalls/accept/accept02.c +0 -1
index 3db0f33bc..df048ede4 100644
@@ -139,5 +139,4 @@ static struct tst_test test = {
 	.setup = setup,
 	.cleanup = cleanup,
 	.needs_checkpoints = 1,
-	.needs_root = 1,
 };
Signature · 1 line
2.21.0