* [LTP] [PATCH] syscalls: close open files in cleanup
@ 2016-03-18 13:57 Alexey Kodanev
2016-03-21 13:04 ` Cyril Hrubis
0 siblings, 1 reply; 3+ messages in thread
From: Alexey Kodanev @ 2016-03-18 13:57 UTC (permalink / raw)
To: ltp
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.
Signed-off-by: Alexey Kodanev <alexey.kodanev@oracle.com>
---
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(-)
diff --git a/testcases/kernel/syscalls/faccessat/faccessat01.c b/testcases/kernel/syscalls/faccessat/faccessat01.c
index 72827ad..6f276fc 100644
--- a/testcases/kernel/syscalls/faccessat/faccessat01.c
+++ b/testcases/kernel/syscalls/faccessat/faccessat01.c
@@ -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();
}
diff --git a/testcases/kernel/syscalls/fchmodat/fchmodat01.c b/testcases/kernel/syscalls/fchmodat/fchmodat01.c
index ea08665..d4f7093 100644
--- a/testcases/kernel/syscalls/fchmodat/fchmodat01.c
+++ b/testcases/kernel/syscalls/fchmodat/fchmodat01.c
@@ -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();
}
diff --git a/testcases/kernel/syscalls/fstatat/fstatat01.c b/testcases/kernel/syscalls/fstatat/fstatat01.c
index 8b279fa..c210968 100644
--- a/testcases/kernel/syscalls/fstatat/fstatat01.c
+++ b/testcases/kernel/syscalls/fstatat/fstatat01.c
@@ -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();
}
-
diff --git a/testcases/kernel/syscalls/futimesat/futimesat01.c b/testcases/kernel/syscalls/futimesat/futimesat01.c
index 5c16dd8..f5e90b8 100644
--- a/testcases/kernel/syscalls/futimesat/futimesat01.c
+++ b/testcases/kernel/syscalls/futimesat/futimesat01.c
@@ -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();
}
diff --git a/testcases/kernel/syscalls/unlinkat/unlinkat01.c b/testcases/kernel/syscalls/unlinkat/unlinkat01.c
index 47cba25..0abede6 100644
--- a/testcases/kernel/syscalls/unlinkat/unlinkat01.c
+++ b/testcases/kernel/syscalls/unlinkat/unlinkat01.c
@@ -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();
}
--
1.7.1
^ permalink raw reply related [flat|nested] 3+ messages in thread* [LTP] [PATCH] syscalls: close open files in cleanup
2016-03-18 13:57 [LTP] [PATCH] syscalls: close open files in cleanup Alexey Kodanev
@ 2016-03-21 13:04 ` Cyril Hrubis
2016-03-22 9:11 ` Alexey Kodanev
0 siblings, 1 reply; 3+ messages in thread
From: Cyril Hrubis @ 2016-03-21 13:04 UTC (permalink / raw)
To: ltp
Hi!
> 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.
--
Cyril Hrubis
chrubis@suse.cz
^ permalink raw reply [flat|nested] 3+ messages in thread
* [LTP] [PATCH] syscalls: close open files in cleanup
2016-03-21 13:04 ` Cyril Hrubis
@ 2016-03-22 9:11 ` Alexey Kodanev
0 siblings, 0 replies; 3+ messages in thread
From: Alexey Kodanev @ 2016-03-22 9:11 UTC (permalink / raw)
To: ltp
Hi,
On 03/21/2016 04:04 PM, Cyril Hrubis wrote:
> Hi!
>> 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
> Otherwise it looks good.
>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2016-03-22 9:11 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-03-18 13:57 [LTP] [PATCH] syscalls: close open files in cleanup Alexey Kodanev
2016-03-21 13:04 ` Cyril Hrubis
2016-03-22 9:11 ` Alexey Kodanev
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox