public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
From: Andrew Chen <yanpai.chen@gmail.com>
To: ltp-list@lists.sourceforge.net
Cc: ypchen@faraday-tech.com
Subject: [LTP] [PATCH 7/7] testcases: syscalls: close file descriptors before unlinking
Date: Thu, 30 Jun 2011 14:19:47 +0800	[thread overview]
Message-ID: <1309414787-2022-7-git-send-email-yanpai.chen@gmail.com> (raw)
In-Reply-To: <1309414787-2022-1-git-send-email-yanpai.chen@gmail.com>

From: Andrew Chen <ypchen@faraday-tech.com>

Ensure file descriptors are closed before unlinking them, or we cannot
remove the generated directories after these tests. The leftover
directories may cause tests failed in latter runs once the directory
names are hit.

Signed-off-by: Andrew Chen <ypchen@faraday-tech.com>
---
 .../testcases/kernel/syscalls/fstatat/fstatat01.c  |    4 +++-
 .../kernel/syscalls/futimesat/futimesat01.c        |    4 +++-
 .../testcases/kernel/syscalls/openat/openat01.c    |   11 ++++++++++-
 .../kernel/syscalls/readlinkat/readlinkat01.c      |    4 +++-
 .../kernel/syscalls/renameat/renameat01.c          |    4 +++-
 .../kernel/syscalls/unlinkat/unlinkat01.c          |    5 ++++-
 6 files changed, 26 insertions(+), 6 deletions(-)

diff --git a/ltp-full-20101031/testcases/kernel/syscalls/fstatat/fstatat01.c b/ltp-full-20101031/testcases/kernel/syscalls/fstatat/fstatat01.c
index 5f81dac..f5938eb 100644
--- a/ltp-full-20101031/testcases/kernel/syscalls/fstatat/fstatat01.c
+++ b/ltp-full-20101031/testcases/kernel/syscalls/fstatat/fstatat01.c
@@ -73,6 +73,7 @@ char testfile[256];
 char testfile2[256];
 char testfile3[256];
 int dirfd, fd, ret;
+int innerfd;
 int fds[TEST_CASES];
 char *filenames[TEST_CASES];
 int expected_errno[TEST_CASES] = { 0, 0, ENOTDIR, EBADF, EINVAL, 0 };
@@ -217,7 +218,7 @@ void setup_every_copy()
 		exit(-1);
 	}
 
-	fd = open(testfile2, O_CREAT | O_RDWR, 0600);
+	innerfd = open(testfile2, O_CREAT | O_RDWR, 0600);
 	if (fd < 0) {
 		perror("open: ");
 		exit(-1);
@@ -258,6 +259,7 @@ void setup()
 void cleanup()
 {
 	/* Remove them */
+	close(innerfd);
 	unlink(testfile2);
 	unlink(testfile3);
 	unlink(testfile);
diff --git a/ltp-full-20101031/testcases/kernel/syscalls/futimesat/futimesat01.c b/ltp-full-20101031/testcases/kernel/syscalls/futimesat/futimesat01.c
index d82a2c4..6729941 100644
--- a/ltp-full-20101031/testcases/kernel/syscalls/futimesat/futimesat01.c
+++ b/ltp-full-20101031/testcases/kernel/syscalls/futimesat/futimesat01.c
@@ -73,6 +73,7 @@ char testfile[256];
 char testfile2[256];
 char testfile3[256];
 int dirfd, fd, ret;
+int innerfd;
 int fds[TEST_CASES];
 char *filenames[TEST_CASES];
 int expected_errno[TEST_CASES] = { 0, 0, ENOTDIR, EBADF, 0 };
@@ -184,7 +185,7 @@ void setup_every_copy()
 		exit(-1);
 	}
 
-	fd = open(testfile2, O_CREAT | O_RDWR, 0600);
+	innerfd = open(testfile2, O_CREAT | O_RDWR, 0600);
 	if (fd < 0) {
 		perror("open: ");
 		exit(-1);
@@ -224,6 +225,7 @@ void setup()
 void cleanup()
 {
 	/* Remove them */
+	close(innerfd);
 	unlink(testfile2);
 	unlink(testfile3);
 	unlink(testfile);
diff --git a/ltp-full-20101031/testcases/kernel/syscalls/openat/openat01.c b/ltp-full-20101031/testcases/kernel/syscalls/openat/openat01.c
index be40c63..38f2014 100644
--- a/ltp-full-20101031/testcases/kernel/syscalls/openat/openat01.c
+++ b/ltp-full-20101031/testcases/kernel/syscalls/openat/openat01.c
@@ -72,6 +72,7 @@ char testfile[256];
 char testfile2[256];
 char testfile3[256];
 int dirfd, fd, ret;
+int innerfds[2];
 int fds[TEST_CASES];
 char *filenames[TEST_CASES];
 int expected_errno[TEST_CASES] = { 0, 0, ENOTDIR, EBADF, 0 };
@@ -118,9 +119,12 @@ int main(int ac, char **av)
 		 * Call openat
 		 */
 		for (i = 0; i < TST_TOTAL; i++) {
-			TEST(myopenat
+			TEST(fd = myopenat
 			     (fds[i], filenames[i], O_CREAT | O_WRONLY, 0600));
 
+			if (i < 2)
+				innerfds[i] = fd;
+
 			/* check return code */
 			if (TEST_ERRNO == expected_errno[i]) {
 
@@ -206,7 +210,12 @@ void setup()
 void cleanup()
 {
 	/* Remove them */
+	int i;
 	char tmppathname[256];
+
+	for (i = 0; i < 2; ++i)
+		close(innerfds[i]);
+
 	strcpy(tmppathname, pathname);
 	unlink(strcat(strcat(tmppathname, "/"), testfile));
 	unlink(testfile);
diff --git a/ltp-full-20101031/testcases/kernel/syscalls/readlinkat/readlinkat01.c b/ltp-full-20101031/testcases/kernel/syscalls/readlinkat/readlinkat01.c
index a6963f1..78768fb 100644
--- a/ltp-full-20101031/testcases/kernel/syscalls/readlinkat/readlinkat01.c
+++ b/ltp-full-20101031/testcases/kernel/syscalls/readlinkat/readlinkat01.c
@@ -83,6 +83,7 @@ char dtestfile2[256];
 char testfile3[256];
 char dtestfile3[256];
 int dirfd, fd, ret;
+int innerfd;
 int fds[TEST_CASES];
 char *filenames[TEST_CASES];
 int expected_errno[TEST_CASES] = { 0, 0, ENOTDIR, EBADF, 0 };
@@ -222,7 +223,7 @@ void setup_every_copy()
 		exit(-1);
 	}
 
-	fd = open(testfile2, O_CREAT | O_RDWR, 0600);
+	innerfd = open(testfile2, O_CREAT | O_RDWR, 0600);
 	if (fd < 0) {
 		perror("open: ");
 		exit(-1);
@@ -285,6 +286,7 @@ void setup()
 void cleanup()
 {
 	/* Remove them */
+	close(innerfd);
 	unlink(testfile2);
 	unlink(dtestfile2);
 	unlink(testfile3);
diff --git a/ltp-full-20101031/testcases/kernel/syscalls/renameat/renameat01.c b/ltp-full-20101031/testcases/kernel/syscalls/renameat/renameat01.c
index 3f27c95..5eff504 100644
--- a/ltp-full-20101031/testcases/kernel/syscalls/renameat/renameat01.c
+++ b/ltp-full-20101031/testcases/kernel/syscalls/renameat/renameat01.c
@@ -81,6 +81,7 @@ char dtestfile2[256];
 char testfile3[256];
 char dtestfile3[256];
 int olddirfd, newdirfd, fd, ret;
+int innerfd;
 int oldfds[TEST_CASES], newfds[TEST_CASES];
 char *oldfilenames[TEST_CASES], *newfilenames[TEST_CASES];
 int expected_errno[TEST_CASES] = { 0, 0, ENOTDIR, EBADF, 0 };
@@ -208,7 +209,7 @@ void setup_every_copy()
 		exit(-1);
 	}
 
-	fd = open(testfile2, O_CREAT | O_RDWR, 0600);
+	innerfd = open(testfile2, O_CREAT | O_RDWR, 0600);
 	if (fd < 0) {
 		perror("open: ");
 		exit(-1);
@@ -258,6 +259,7 @@ void setup()
 void cleanup()
 {
 	/* Remove them */
+	close(innerfd);
 	unlink(testfile2);
 	unlink(dtestfile2);
 	unlink(testfile3);
diff --git a/ltp-full-20101031/testcases/kernel/syscalls/unlinkat/unlinkat01.c b/ltp-full-20101031/testcases/kernel/syscalls/unlinkat/unlinkat01.c
index f8977f5..a20c085 100644
--- a/ltp-full-20101031/testcases/kernel/syscalls/unlinkat/unlinkat01.c
+++ b/ltp-full-20101031/testcases/kernel/syscalls/unlinkat/unlinkat01.c
@@ -78,6 +78,7 @@ char testfile[256];
 char testfile2[256];
 char testfile3[256];
 int dirfd, fd, ret;
+int innerfd;
 int fds[TEST_CASES];
 char *filenames[TEST_CASES];
 int expected_errno[TEST_CASES] = { 0, 0, ENOTDIR, EBADF, EINVAL, 0, 0 };
@@ -196,7 +197,7 @@ void setup_every_copy()
 		exit(-1);
 	}
 
-	fd = open(testfile2, O_CREAT | O_RDWR, 0600);
+	innerfd = open(testfile2, O_CREAT | O_RDWR, 0600);
 	if (fd < 0) {
 		perror("open: ");
 		exit(-1);
@@ -239,6 +240,8 @@ void cleanup()
 {
 	/* Remove them */
 	char tmppathname[256] = "";
+
+	close(innerfd);
 	strcat(strcat(strcat(tmppathname, pathname), "/"), subpathname);
 	rmdir(tmppathname);
 	unlink(testfile2);
-- 
1.6.5


------------------------------------------------------------------------------
All of the data generated in your IT infrastructure is seriously valuable.
Why? It contains a definitive record of application performance, security 
threats, fraudulent activity, and more. Splunk takes this data and makes 
sense of it. IT sense. And common sense.
http://p.sf.net/sfu/splunk-d2d-c2
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

  parent reply	other threads:[~2011-06-30  6:21 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-06-30  6:19 [LTP] [PATCH 1/7] testcases: fs_bind: fix hanging of testscript Andrew Chen
2011-06-30  6:19 ` [LTP] [PATCH 2/7] testcases: cgroup: correct wrong variable used in the testscript Andrew Chen
2011-07-11 14:45   ` Cyril Hrubis
2011-07-11 16:07     ` Cyril Hrubis
2011-06-30  6:19 ` [LTP] [PATCH 3/7] testcases: controllers: fix wrong cpu number calculated Andrew Chen
2011-07-21 16:57   ` Cyril Hrubis
2011-06-30  6:19 ` [LTP] [PATCH 4/7] testcases: memcg_function: set hugepage size to zero when no hugepage support Andrew Chen
2011-06-30  6:19 ` [LTP] [PATCH 5/7] runltp: precise pattern matching for skipped testcases Andrew Chen
2011-06-30  6:19 ` [LTP] [PATCH 6/7] runtest/fs: change parameters of growfiles Andrew Chen
2011-07-29 11:45   ` Cyril Hrubis
     [not found]     ` <CANj_sbC3+eO+6=_S4MO8Wr1o6b7Oo9mbX=EehBFaQb6dj=xOww@mail.gmail.com>
     [not found]       ` <CAGH67wROk8oOO85TVCZxfNofy2M1NdQXPTkuEHezgUJy8Jx-zw@mail.gmail.com>
2011-08-10 12:12         ` Cyril Hrubis
2011-08-10 12:16       ` Cyril Hrubis
2011-09-08 12:09         ` Cyril Hrubis
     [not found]           ` <1316411646-1886-1-git-send-email-yanpai.chen@gmail.com>
     [not found]             ` <CANj_sbD=c+R4YVwqh1tSw-4LanVimNos5rFc0tU872ouCLf-8g@mail.gmail.com>
2011-10-13 14:00               ` [LTP] [PATCH 6/7 V2] " Cyril Hrubis
2011-06-30  6:19 ` Andrew Chen [this message]
2011-07-11 16:45   ` [LTP] [PATCH 7/7] testcases: syscalls: close file descriptors before unlinking Cyril Hrubis
2011-07-21 17:01   ` Cyril Hrubis
     [not found]     ` <CANj_sbBZGdHond=dOHRKtgBrEHYiK8-iQD=hM-iv3ZU1J5_aYQ@mail.gmail.com>
     [not found]       ` <CANj_sbB1KoHxDCBEnGGX66LihMY-00N+mj+rv-4zPYA7XpkssQ@mail.gmail.com>
     [not found]         ` <20110727121238.GB20610@saboteur.suse.cz>
     [not found]           ` <20110728180131.GA3307@saboteur.suse.cz>
     [not found]             ` <CANj_sbCv=TKkRuaPmfWOBz4qArC1eKEuCoDiMb2oLrWCOf_GWQ@mail.gmail.com>
2011-08-10 12:10               ` Cyril Hrubis
     [not found]                 ` <1316411928-1941-1-git-send-email-yanpai.chen@gmail.com>
2011-10-13 13:45                   ` [LTP] [PATCH] testcases: syscalls: use tst_tmpdir() interface Cyril Hrubis
2011-07-21 16:55 ` [LTP] [PATCH 1/7] testcases: fs_bind: fix hanging of testscript Cyril Hrubis

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1309414787-2022-7-git-send-email-yanpai.chen@gmail.com \
    --to=yanpai.chen@gmail.com \
    --cc=ltp-list@lists.sourceforge.net \
    --cc=ypchen@faraday-tech.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox