summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastian Huber <sebastian.huber@embedded-brains.de>2018-10-18 12:38:58 +0200
committerSebastian Huber <sebastian.huber@embedded-brains.de>2018-10-22 08:06:05 +0200
commit1ad26cdcf7eae323feda4c1030c057c52126af3b (patch)
tree1470970a2ab7faa010077e88f06b4b72d89d5f7e
parent38259266018f49c23e6b72f58f740a2d423d9c62 (diff)
Support O_NOFOLLOW open() flag
Close #3546.
-rw-r--r--cpukit/libcsupport/src/open.c7
-rw-r--r--testsuites/psxtests/psxfile01/test.c67
2 files changed, 73 insertions, 1 deletions
diff --git a/cpukit/libcsupport/src/open.c b/cpukit/libcsupport/src/open.c
index 554311c5aa..86d0bbeab9 100644
--- a/cpukit/libcsupport/src/open.c
+++ b/cpukit/libcsupport/src/open.c
@@ -74,7 +74,12 @@ static int do_open(
bool exclusive = (oflag & (O_CREAT | O_EXCL)) == (O_CREAT | O_EXCL);
bool truncate = (oflag & O_TRUNC) == O_TRUNC;
bool open_dir;
- int eval_flags = RTEMS_FS_FOLLOW_LINK
+#ifdef O_NOFOLLOW
+ int follow = (oflag & O_NOFOLLOW) == O_NOFOLLOW ? 0 : RTEMS_FS_FOLLOW_LINK;
+#else
+ int follow = RTEMS_FS_FOLLOW_LINK;
+#endif
+ int eval_flags = follow
| (read_access ? RTEMS_FS_PERMS_READ : 0)
| (write_access ? RTEMS_FS_PERMS_WRITE : 0)
| (make ? RTEMS_FS_MAKE : 0)
diff --git a/testsuites/psxtests/psxfile01/test.c b/testsuites/psxtests/psxfile01/test.c
index 129412d3ef..1ea3dad503 100644
--- a/testsuites/psxtests/psxfile01/test.c
+++ b/testsuites/psxtests/psxfile01/test.c
@@ -59,6 +59,8 @@ rtems_filesystem_operations_table IMFS_ops_no_rename;
static const char somefile[] = "somefile";
+static const char somelink[] = "somelink";
+
/*
* File test support routines.
*/
@@ -152,6 +154,11 @@ static void test_open_directory(void)
status = unlink( somefile );
rtems_test_assert( status == 0 );
+
+ errno = 0;
+ fd = open( somefile, O_RDONLY );
+ rtems_test_assert( fd == -1 );
+ rtems_test_assert( errno == ENOENT );
}
static void test_open_cloexec(void)
@@ -174,6 +181,65 @@ static void test_open_cloexec(void)
status = unlink( somefile );
rtems_test_assert( status == 0 );
+
+ errno = 0;
+ fd = open( somefile, O_RDONLY );
+ rtems_test_assert( fd == -1 );
+ rtems_test_assert( errno == ENOENT );
+}
+
+static void test_open_nofollow(void)
+{
+ int status;
+ int fd;
+ struct stat st;
+
+ fd = open( somefile, O_CREAT, S_IRWXU );
+ rtems_test_assert( fd >= 0 );
+
+ status = close( fd );
+ rtems_test_assert( status == 0 );
+
+ status = symlink( somefile, somelink );
+ rtems_test_assert( status == 0 );
+
+ fd = open( somelink, O_RDONLY );
+ rtems_test_assert( fd >= 0 );
+
+ status = fstat( fd, &st );
+ rtems_test_assert( status == 0 );
+ rtems_test_assert( S_ISREG( st.st_mode ) );
+
+ status = close( fd );
+ rtems_test_assert( status == 0 );
+
+#ifdef O_NOFOLLOW
+ fd = open( somelink, O_RDONLY | O_NOFOLLOW );
+ rtems_test_assert( fd >= 0 );
+
+ status = fstat( fd, &st );
+ rtems_test_assert( status == 0 );
+ rtems_test_assert( S_ISLNK( st.st_mode ) );
+
+ status = close( fd );
+ rtems_test_assert( status == 0 );
+#endif
+
+ status = unlink( somelink );
+ rtems_test_assert( status == 0 );
+
+ errno = 0;
+ fd = open( somelink, O_RDONLY );
+ rtems_test_assert( fd == -1 );
+ rtems_test_assert( errno == ENOENT );
+
+ status = unlink( somefile );
+ rtems_test_assert( status == 0 );
+
+ errno = 0;
+ fd = open( somefile, O_RDONLY );
+ rtems_test_assert( fd == -1 );
+ rtems_test_assert( errno == ENOENT );
}
/*
@@ -209,6 +275,7 @@ int main(
test_open_directory();
test_open_cloexec();
+ test_open_nofollow();
/*
* Grab the maximum size of an in-memory file.