[LTP] [PATCH] ioctl/ioctl_ns*: Move the SAFE_CLOSE to the suitable location

Zhao Gongyi zhaogongyi@huawei.com
Tue Mar 22 07:37:56 CET 2022


If we run the test with the option -i 10000, and the ulimit
of open files little than 10000, the test would fail and report
error of EMFILE.

Signed-off-by: Zhao Gongyi <zhaogongyi@huawei.com>
---
 testcases/kernel/syscalls/ioctl/ioctl_ns01.c | 2 +-
 testcases/kernel/syscalls/ioctl/ioctl_ns02.c | 2 +-
 testcases/kernel/syscalls/ioctl/ioctl_ns03.c | 2 +-
 testcases/kernel/syscalls/ioctl/ioctl_ns04.c | 2 +-
 4 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/testcases/kernel/syscalls/ioctl/ioctl_ns01.c b/testcases/kernel/syscalls/ioctl/ioctl_ns01.c
index 36d2b3b67..f01dd020f 100644
--- a/testcases/kernel/syscalls/ioctl/ioctl_ns01.c
+++ b/testcases/kernel/syscalls/ioctl/ioctl_ns01.c
@@ -58,9 +58,9 @@ static void test_ns_get_parent(void)
 		else
 			tst_res(TFAIL | TERRNO, "unexpected ioctl error");
 	} else {
-		SAFE_CLOSE(fd);
 		tst_res(TFAIL, "call to ioctl succeded");
 	}
+	SAFE_CLOSE(fd);
 }

 static int child(void *arg LTP_ATTRIBUTE_UNUSED)
diff --git a/testcases/kernel/syscalls/ioctl/ioctl_ns02.c b/testcases/kernel/syscalls/ioctl/ioctl_ns02.c
index 33ef757a8..e63b56859 100644
--- a/testcases/kernel/syscalls/ioctl/ioctl_ns02.c
+++ b/testcases/kernel/syscalls/ioctl/ioctl_ns02.c
@@ -40,9 +40,9 @@ static void run(void)
 		else
 			tst_res(TFAIL | TERRNO, "unexpected ioctl error");
 	} else {
-		SAFE_CLOSE(fd);
 		tst_res(TFAIL, "call to ioctl succeded");
 	}
+	SAFE_CLOSE(fd);
 }

 static struct tst_test test = {
diff --git a/testcases/kernel/syscalls/ioctl/ioctl_ns03.c b/testcases/kernel/syscalls/ioctl/ioctl_ns03.c
index 279032d20..8464bcd07 100644
--- a/testcases/kernel/syscalls/ioctl/ioctl_ns03.c
+++ b/testcases/kernel/syscalls/ioctl/ioctl_ns03.c
@@ -43,9 +43,9 @@ static void run(void)
 		else
 			tst_res(TFAIL | TERRNO, "unexpected ioctl error");
 	} else {
-		SAFE_CLOSE(fd);
 		tst_res(TFAIL, "call to ioctl succeded");
 	}
+	SAFE_CLOSE(fd);
 }

 static struct tst_test test = {
diff --git a/testcases/kernel/syscalls/ioctl/ioctl_ns04.c b/testcases/kernel/syscalls/ioctl/ioctl_ns04.c
index 90035cbeb..a3923f485 100644
--- a/testcases/kernel/syscalls/ioctl/ioctl_ns04.c
+++ b/testcases/kernel/syscalls/ioctl/ioctl_ns04.c
@@ -39,9 +39,9 @@ static void run(void)
 		else
 			tst_res(TFAIL | TERRNO, "unexpected ioctl error");
 	} else {
-		SAFE_CLOSE(fd);
 		tst_res(TFAIL, "call to ioctl succeded");
 	}
+	SAFE_CLOSE(fd);
 }

 static struct tst_test test = {
--
2.17.1



More information about the ltp mailing list