syscalls: close open files in cleanup
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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
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 withsafe_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]
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 withsafe_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.