[LTP] [PATCH 3/4] syscalls/accept4: convert to new library

Cyril Hrubis chrubis@suse.cz
Tue Mar 26 16:33:56 CET 2019


Hi!
Pushed with small cleanup and simplification, thanks.

diff --git a/testcases/kernel/syscalls/accept4/accept4_01.c b/testcases/kernel/syscalls/accept4/accept4_01.c
index 036457571..c423b2a7d 100644
--- a/testcases/kernel/syscalls/accept4/accept4_01.c
+++ b/testcases/kernel/syscalls/accept4/accept4_01.c
@@ -25,18 +25,18 @@
 #define PORT_NUM 33333
 
 #ifndef SOCK_CLOEXEC
-#define SOCK_CLOEXEC    O_CLOEXEC
+# define SOCK_CLOEXEC    O_CLOEXEC
 #endif
 #ifndef SOCK_NONBLOCK
-#define SOCK_NONBLOCK   O_NONBLOCK
+# define SOCK_NONBLOCK   O_NONBLOCK
 #endif
 
 #if defined(SYS_ACCEPT4)	/* the socketcall() number */
 #define USE_SOCKETCALL 1
 #endif
 
-struct sockaddr_in conn_addr;
-int listening_fd;
+static struct sockaddr_in conn_addr;
+static int listening_fd;
 
 #if !(__GLIBC_PREREQ(2, 10))
 static int
@@ -78,7 +78,7 @@ static int create_listening_socket(void)
 	return lfd;
 }
 
-void setup(void)
+static void setup(void)
 {
 	memset(&conn_addr, 0, sizeof(struct sockaddr_in));
 	conn_addr.sin_family = AF_INET;
@@ -88,7 +88,7 @@ void setup(void)
 	listening_fd = create_listening_socket();
 }
 
-void cleanup(void)
+static void cleanup(void)
 {
 	SAFE_CLOSE(listening_fd);
 }
@@ -103,11 +103,11 @@ static struct test_case {
 	{ SOCK_CLOEXEC, SOCK_NONBLOCK },
 };
 
-void verify_accept4(unsigned int nr)
+static void verify_accept4(unsigned int nr)
 {
 	struct test_case *tcase = &tcases[nr];
 	int connfd, acceptfd;
-	int fdf, flf, fdf_pass, flf_pass;
+	int fdf, flf, fdf_pass, flf_pass, fd_cloexec, fd_nonblock;
 	struct sockaddr_in claddr;
 	socklen_t addrlen;
 
@@ -133,27 +133,29 @@ void verify_accept4(unsigned int nr)
 
 	/* Test to see if O_CLOEXEC is as expected */
 	fdf = SAFE_FCNTL(acceptfd, F_GETFD);
-	fdf_pass = !!(fdf & FD_CLOEXEC) == !!(tcase->cloexec & SOCK_CLOEXEC);
-	if (!fdf_pass)
-		tst_res(TFAIL,  "Close-on-exec flag mismatch, %d vs %d",
-			 !!(fdf & FD_CLOEXEC),
-			 !!(tcase->cloexec & SOCK_CLOEXEC));
+	fd_cloexec = !!(fdf & FD_CLOEXEC);
+	fdf_pass = fd_cloexec == !!tcase->cloexec;
+	if (!fdf_pass) {
+		tst_res(TFAIL, "Close-on-exec flag mismatch, %d vs %d",
+			fd_cloexec, !!tcase->cloexec);
+	}
 
 	/* Test to see if O_NONBLOCK is as expected */
 	flf = SAFE_FCNTL(acceptfd, F_GETFL);
-	flf_pass = !!(flf & O_NONBLOCK) == !!(tcase->nonblock & SOCK_NONBLOCK);
-	if (!flf_pass)
+	fd_nonblock = !!(flf & O_NONBLOCK);
+	flf_pass = fd_nonblock == !!tcase->nonblock;
+	if (!flf_pass) {
 		tst_res(TFAIL, "nonblock flag mismatch, %d vs %d",
-			 !!(fdf & O_NONBLOCK),
-			 !!(tcase->nonblock & SOCK_NONBLOCK));
+		        fd_nonblock, !!tcase->nonblock);
+	}
 
 	SAFE_CLOSE(acceptfd);
 	SAFE_CLOSE(connfd);
 
-	if (fdf_pass && flf_pass)
-		tst_res(TPASS, "Test passed: Close-on-exec %d, nonblock %d",
-				fdf_pass, flf_pass);
-
+	if (fdf_pass && flf_pass) {
+		tst_res(TPASS, "Close-on-exec %d, nonblock %d",
+				fd_cloexec, fd_nonblock);
+	}
 }
 
 static struct tst_test test = {

-- 
Cyril Hrubis
chrubis@suse.cz


More information about the ltp mailing list