Skip to contentSkip to conversation

syscalls: close open files in cleanup

PATCH New Alexey Kodanev 2 participants 3 messages Mar 18, 2016 – Mar 22, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 syscalls: close open files in cleanup

NFS creates special .nfs* files when test file was removed and left open. In that case, tst_rmdir() fails to remove test dirs.

Close left open files in cleanup and replace some of safe_open() calls with safe_file_printf() ones for test files which fd won't be used in a test.

---
 testcases/kernel/syscalls/faccessat/faccessat01.c |    8 +++++---
 testcases/kernel/syscalls/fchmodat/fchmodat01.c   |    7 +++++--
 testcases/kernel/syscalls/fstatat/fstatat01.c     |    8 +++++---
 testcases/kernel/syscalls/futimesat/futimesat01.c |    7 +++++--
 testcases/kernel/syscalls/unlinkat/unlinkat01.c   |    8 +++++---
 5 files changed, 25 insertions(+), 13 deletions(-)
testcases/kernel/syscalls/faccessat/faccessat01.c +5 -3
index 72827ad..6f276fc 100644
@@ -130,9 +130,8 @@ void setup(void)
 	fds[0] = SAFE_OPEN(cleanup, pathname, O_DIRECTORY);
 	fds[1] = fds[4] = fds[0];
 
-
-	SAFE_OPEN(cleanup, testfile, O_CREAT | O_RDWR, 0600);
-	SAFE_OPEN(cleanup, testfile2, O_CREAT | O_RDWR, 0600);
+	SAFE_FILE_PRINTF(cleanup, testfile, testfile);
+	SAFE_FILE_PRINTF(cleanup, testfile2, testfile2);
 
 	fds[2] = SAFE_OPEN(cleanup, testfile3, O_CREAT | O_RDWR, 0600);
 
@@ -148,5 +147,8 @@ void setup(void)
 
 void cleanup(void)
 {
+	close(fds[0]);
+	close(fds[2]);
+
 	tst_rmdir();
 }
testcases/kernel/syscalls/fchmodat/fchmodat01.c +5 -2
index ea08665..d4f7093 100644
@@ -128,8 +128,8 @@ void setup(void)
 	fds[0] = SAFE_OPEN(cleanup, pathname, O_DIRECTORY);
 	fds[1] = fds[4] = fds[0];
 
-	SAFE_OPEN(cleanup, testfile, O_CREAT | O_RDWR, 0600);
-	SAFE_OPEN(cleanup, testfile2, O_CREAT | O_RDWR, 0600);
+	SAFE_FILE_PRINTF(cleanup, testfile, testfile);
+	SAFE_FILE_PRINTF(cleanup, testfile2, testfile2);
 
 	fds[2] = SAFE_OPEN(cleanup, testfile3, O_CREAT | O_RDWR, 0600);
 	fds[3] = 100;
@@ -144,5 +144,8 @@ void setup(void)
 
 void cleanup(void)
 {
+	close(fds[0]);
+	close(fds[2]);
+
 	tst_rmdir();
 }
testcases/kernel/syscalls/fstatat/fstatat01.c +5 -3
index 8b279fa..c210968 100644
@@ -129,8 +129,8 @@ void setup(void)
 	fds[0] = SAFE_OPEN(cleanup, pathname, O_DIRECTORY);
 	fds[1] = fds[4] = fds[0];
 
-	SAFE_OPEN(cleanup, testfile, O_CREAT | O_RDWR, 0600);
-	SAFE_OPEN(cleanup, testfile2, O_CREAT | O_RDWR, 0600);
+	SAFE_FILE_PRINTF(cleanup, testfile, testfile);
+	SAFE_FILE_PRINTF(cleanup, testfile2, testfile2);
 
 	fds[2] =  SAFE_OPEN(cleanup, testfile3, O_CREAT | O_RDWR, 0600);
 
@@ -146,7 +146,9 @@ void setup(void)
 
 void cleanup(void)
 {
+	close(fds[0]);
+	close(fds[2]);
+
 	free(testfile3);
 	tst_rmdir();
 }
-
testcases/kernel/syscalls/futimesat/futimesat01.c +5 -2
index 5c16dd8..f5e90b8 100644
@@ -112,8 +112,8 @@ void setup(void)
 	fds[0] = SAFE_OPEN(cleanup, pathname, O_DIRECTORY);
 	fds[1] = fds[0];
 
-	SAFE_OPEN(cleanup, testfile, O_CREAT | O_RDWR, 0600);
-	SAFE_OPEN(cleanup, testfile2, O_CREAT | O_RDWR, 0600);
+	SAFE_FILE_PRINTF(cleanup, testfile, testfile);
+	SAFE_FILE_PRINTF(cleanup, testfile2, testfile2);
 
 	fds[2] = SAFE_OPEN(cleanup, testfile3, O_CREAT | O_RDWR, 0600);
 
@@ -128,6 +128,9 @@ void setup(void)
 
 void cleanup(void)
 {
+	close(fds[0]);
+	close(fds[2]);
+
 	free(testfile3);
 	tst_rmdir();
 }
testcases/kernel/syscalls/unlinkat/unlinkat01.c +5 -3
index 47cba25..0abede6 100644
@@ -119,9 +119,8 @@ void setup(void)
 	fds[0] = SAFE_OPEN(cleanup, pathname, O_DIRECTORY);
 	fds[1] = fds[4] = fds[6] = fds[0];
 
-	SAFE_OPEN(cleanup, testfile, O_CREAT | O_RDWR, 0600);
-
-	SAFE_OPEN(cleanup, testfile2, O_CREAT | O_RDWR, 0600);
+	SAFE_FILE_PRINTF(cleanup, testfile, testfile);
+	SAFE_FILE_PRINTF(cleanup, testfile2, testfile2);
 
 	fds[2] = SAFE_OPEN(cleanup, testfile3, O_CREAT | O_RDWR, 0600);
 
@@ -138,6 +137,9 @@ void setup(void)
 
 void cleanup(void)
 {
+	close(fds[0]);
+	close(fds[2]);
+
 	free(testfile3);
 	tst_rmdir();
 }
Signature · 1 line
1.7.1
#1 lore raw

PATCH 1/1 syscalls: close open files in cleanup

Hi!

Quoted 6 lines

NFS creates special .nfs* files when test file was removed and left open. In that case, tst_rmdir() fails to remove test dirs.

Close left open files in cleanup and replace some of safe_open() calls with safe_file_printf() ones for test files which fd won't be used in a test.

I would be closing the file descriptors only if they were initialized with value > 0, since otherwise there would be misleading failing close in the strace in case that some setup step prior to the SAFE_OPEN() failed.

Otherwise it looks good.

Signature · 2 lines
Cyril Hrubis
[email protected]
#2 lore raw

PATCH 1/1 syscalls: close open files in cleanup

Hi,

Quoted 11 lines · Cyril Hrubis

Hi!

Quoted 6 lines

NFS creates special .nfs* files when test file was removed and left open. In that case, tst_rmdir() fails to remove test dirs.

Close left open files in cleanup and replace some of safe_open() calls with safe_file_printf() ones for test files which fd won't be used in a test.

I would be closing the file descriptors only if they were initialized with value > 0, since otherwise there would be misleading failing close in the strace in case that some setup step prior to the SAFE_OPEN() failed.

Added checks and applied.

Thanks,
Alexey

Quoted 2 lines

Otherwise it looks good.