[LTP] [PATCH] unlinkat01: Add SAFE_CLOSE before test return

Zhao Gongyi zhaogongyi@huawei.com
Fri Mar 25 08:33:33 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/unlinkat/unlinkat01.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/testcases/kernel/syscalls/unlinkat/unlinkat01.c b/testcases/kernel/syscalls/unlinkat/unlinkat01.c
index 9e9a5d7db..4f5a6da1e 100644
--- a/testcases/kernel/syscalls/unlinkat/unlinkat01.c
+++ b/testcases/kernel/syscalls/unlinkat/unlinkat01.c
@@ -52,13 +52,14 @@ static struct tcase {

 static void run(unsigned int i)
 {
+	int fd_testfile3 = -1;
 	/* tesfile2 will be unlinked by test0. */
 	if (access(testfile2, F_OK))
 		SAFE_FILE_PRINTF(testfile2, testfile2);

 	/* testfile3 will be unlined by test1. */
 	if (access(testfile3, F_OK))
-		SAFE_OPEN(testfile3, O_CREAT | O_RDWR, 0600);
+		fd_testfile3 = SAFE_OPEN(testfile3, O_CREAT | O_RDWR, 0600);

 	/* subpathdir will be unlinked by test6. */
 	if (access(subpathdir, F_OK))
@@ -80,6 +81,8 @@ static void run(unsigned int i)

 	if (!tc[i].fd)
 		SAFE_CLOSE(fd);
+	if (fd_testfile3 > 0)
+		SAFE_CLOSE(fd_testfile3);
 }

 static void setup(void)
--
2.17.1



More information about the ltp mailing list