diff mbox series

unlinkat01: Add SAFE_CLOSE before test return

Message ID 20220325073333.255193-1-zhaogongyi@huawei.com
State Accepted
Headers show
Series unlinkat01: Add SAFE_CLOSE before test return | expand

Commit Message

Zhao Gongyi March 25, 2022, 7:33 a.m. UTC
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(-)

--
2.17.1

Comments

Petr Vorel March 25, 2022, 9:07 a.m. UTC | #1
Hi Zhao,

I rewritten the commit message and 
s/fd_testfile3/fd3/

Merged, thanks!

Kind regards,
Petr
diff mbox series

Patch

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)