On Wed 12-05-10 22:16:03, Subrata Modak wrote:
> On Wed, 2010-05-12 at 17:59 +0200, Jan Kara wrote:
> > Hi,
> >
> > On Tue 11-05-10 22:05:52, Subrata Modak wrote:
> > > It would be great if you can shoot it in the form of a patch, mentioning
> > >
> > > 1. The GPL Lincense,
> > > 2. The purpose of the test case,
> > > 3. Exact location it goes,
> > > 4. Which LTPROOT/runtest/<file> executes it
> > With a help of Cyril I've created the attached patch and verified that
> > the test fails on 2.6.33 but succeeds on 2.6.32...
>
> Great. Thanks for the patch. But, it falters on the latest git. Can you
> please rebase and resend:
Ah, OK. Sorry for that. Now a patch rediffed against latest git tree of
LTP. Hopefully this time I got it right.
Honza
--
Jan Kara <[email protected]>
SUSE Labs, CR
>From 02340e1c55f2b446a1706ee087559b6e70480990 Mon Sep 17 00:00:00 2001
From: Jan Kara <[email protected]>
Date: Thu, 13 May 2010 13:24:51 +0200
Subject: [PATCH] Add O_NOFOLLOW open test with trailing slash
In a situation where symlink (say 's') points to a directory,
open("s/", O_NOFOLLOW) should succeed. Check for this.
Signed-off-by: Jan Kara <[email protected]>
---
testcases/kernel/syscalls/open/open07.c | 98 ++++++++++++++++++++++---------
1 files changed, 71 insertions(+), 27 deletions(-)
diff --git a/testcases/kernel/syscalls/open/open07.c b/testcases/kernel/syscalls/open/open07.c
index 9d2fc04..2322e85 100644
--- a/testcases/kernel/syscalls/open/open07.c
+++ b/testcases/kernel/syscalls/open/open07.c
@@ -40,6 +40,9 @@
* 4. Create a symbolic link to a symbolically linked directory, and call
* open(O_NOFOLLOW). Check that it returns ELOOP.
*
+ * 5. Create a symbolic link to a directory, and call
+ * open("link/", O_NOFOLLOW). Check that it succeeds.
+ *
* USAGE: <for command-line>
* open07 [-c n] [-e] [-i n] [-I x] [-P x] [-t]
* where, -c n : Run n copies concurrently.
@@ -70,35 +73,35 @@ void setupfunc_test1();
void setupfunc_test2();
void setupfunc_test3();
void setupfunc_test4();
+void setupfunc_test5();
char *TCID = "open07";
-int TST_TOTAL = 4;
+int TST_TOTAL = 5;
extern int Tst_count;
int fd1, fd2;
-char file1[100], file2[100], file3[100];
-
int exp_enos[] = { ELOOP, 0 };
struct test_case_t {
char *desc;
- char *filename;
+ char filename[100];
int flags;
int mode;
void (*setupfunc) ();
int exp_errno;
- int fileHandle;
} TC[] = {
{
- "Test for ELOOP on f2: f1 -> f2", file2, O_NOFOLLOW, 00700,
- setupfunc_test1, ELOOP, 0}, {
- "Test for ELOOP on d2: d1 -> d2", file2, O_NOFOLLOW, 00700,
- setupfunc_test2, ELOOP, 0}, {
- "Test for ELOOP on f3: f1 -> f2 -> f3", file3, O_NOFOLLOW,
- 00700, setupfunc_test3, ELOOP, 0}, {
- "Test for ELOOP on d3: d1 -> d2 -> d3", file3, O_NOFOLLOW,
- 00700, setupfunc_test4, ELOOP, 0}, {
- NULL, NULL, 0, 0, NULL, 0, 0}
+ "Test for ELOOP on f2: f1 -> f2", {}, O_NOFOLLOW, 00700,
+ setupfunc_test1, ELOOP}, {
+ "Test for ELOOP on d2: d1 -> d2", {}, O_NOFOLLOW, 00700,
+ setupfunc_test2, ELOOP}, {
+ "Test for ELOOP on f3: f1 -> f2 -> f3", {}, O_NOFOLLOW,
+ 00700, setupfunc_test3, ELOOP}, {
+ "Test for ELOOP on d3: d1 -> d2 -> d3", {}, O_NOFOLLOW,
+ 00700, setupfunc_test4, ELOOP}, {
+ "Test for success on d2: d1 -> d2", {}, O_NOFOLLOW, 00700,
+ setupfunc_test5, 0}, {
+ NULL, {}, 0, 0, NULL, 0}
};
int main(int ac, char **av)
@@ -133,21 +136,34 @@ int main(int ac, char **av)
TEST(open(TC[i].filename, TC[i].flags, TC[i].mode));
- if (TEST_RETURN != -1) {
- tst_resm(TFAIL, "call succeeded unexpectedly");
- }
+ if (TC[i].exp_errno != 0) {
+ if (TEST_RETURN != -1) {
+ tst_resm(TFAIL, "open succeeded "
+ "unexpectedly");
+ }
+ TEST_ERROR_LOG(TEST_ERRNO);
- TEST_ERROR_LOG(TEST_ERRNO);
-
- if (TEST_ERRNO != TC[i].exp_errno) {
- tst_resm(TFAIL, "open returned unexpected "
- "errno, expected: %d, got: %d",
- TC[i].exp_errno, TEST_ERRNO);
+ if (TEST_ERRNO != TC[i].exp_errno) {
+ tst_resm(TFAIL, "open returned "
+ "unexpected errno, expected: "
+ "%d, got: %d",
+ TC[i].exp_errno, TEST_ERRNO);
+ } else {
+ tst_resm(TPASS, "open returned "
+ "expected ELOOP error");
+ }
} else {
- tst_resm(TPASS, "open returned expected "
- "ELOOP error");
- }
- close(TC[i].fileHandle);
+ if (TEST_RETURN == -1) {
+ tst_resm(TFAIL, "open failed "
+ "unexpectedly with errno %d",
+ TEST_ERRNO);
+ } else {
+ tst_resm(TPASS, "open succeeded as "
+ "expected");
+ }
+ }
+ if (TEST_RETURN != -1)
+ close(TEST_RETURN);
}
}
cleanup();
@@ -156,6 +172,8 @@ int main(int ac, char **av)
void setupfunc_test1()
{
+ char file1[100], file2[100];
+
sprintf(file1, "open03.1.%d", getpid());
sprintf(file2, "open03.2.%d", getpid());
if ((fd1 = creat(file1, 00700)) < 0) {
@@ -164,10 +182,13 @@ void setupfunc_test1()
if (symlink(file1, file2) < 0) {
tst_brkm(TBROK, cleanup, "symlink(2) failed: errno: %d", errno);
/*NOTREACHED*/}
+ strcpy(TC[0].filename, file2);
}
void setupfunc_test2()
{
+ char file1[100], file2[100];
+
sprintf(file1, "open03.3.%d", getpid());
sprintf(file2, "open03.4.%d", getpid());
if (mkdir(file1, 00700) < 0) {
@@ -176,10 +197,13 @@ void setupfunc_test2()
if (symlink(file1, file2) < 0) {
tst_brkm(TBROK, cleanup, "symlink(2) failed: errno: %d", errno);
/*NOTREACHED*/}
+ strcpy(TC[1].filename, file2);
}
void setupfunc_test3()
{
+ char file1[100], file2[100], file3[100];
+
sprintf(file1, "open03.5.%d", getpid());
sprintf(file2, "open03.6.%d", getpid());
sprintf(file3, "open03.7.%d", getpid());
@@ -192,10 +216,13 @@ void setupfunc_test3()
if (symlink(file2, file3) < 0) {
tst_brkm(TBROK, cleanup, "symlink(2) failed: errno: %d", errno);
/*NOTREACHED*/}
+ strcpy(TC[2].filename, file3);
}
void setupfunc_test4()
{
+ char file1[100], file2[100], file3[100];
+
sprintf(file1, "open03.8.%d", getpid());
sprintf(file2, "open03.9.%d", getpid());
sprintf(file3, "open03.10.%d", getpid());
@@ -208,6 +235,23 @@ void setupfunc_test4()
if (symlink(file2, file3) < 0) {
tst_brkm(TBROK, cleanup, "symlink(2) failed: errno: %d", errno);
/*NOTREACHED*/}
+ strcpy(TC[3].filename, file3);
+}
+
+void setupfunc_test5()
+{
+ char file1[100], file2[100];
+
+ sprintf(file1, "open11.3.%d", getpid());
+ sprintf(file2, "open12.4.%d", getpid());
+ if (mkdir(file1, 00700) < 0) {
+ tst_brkm(TBROK, cleanup, "mkdir(2) failed: errno: %d", errno);
+ /*NOTREACHED*/}
+ if (symlink(file1, file2) < 0) {
+ tst_brkm(TBROK, cleanup, "symlink(2) failed: errno: %d", errno);
+ /*NOTREACHED*/}
+ strcpy(TC[4].filename, file2);
+ strcat(TC[4].filename, "/");
}
/*
--
1.6.4.2
------------------------------------------------------------------------------
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list