[rtems commit] Support O_CLOEXEC open() flag

Sebastian Huber sebh at rtems.org
Mon Oct 22 06:16:36 UTC 2018


Module:    rtems
Branch:    master
Commit:    38259266018f49c23e6b72f58f740a2d423d9c62
Changeset: http://git.rtems.org/rtems/commit/?id=38259266018f49c23e6b72f58f740a2d423d9c62

Author:    Sebastian Huber <sebastian.huber at embedded-brains.de>
Date:      Thu Oct 18 11:51:32 2018 +0200

Support O_CLOEXEC open() flag

Make sure this flag is ignored and does not prevent a successful open.

Close #3547.

---

 testsuites/psxtests/psxfile01/test.c | 32 ++++++++++++++++++++++++++++----
 1 file changed, 28 insertions(+), 4 deletions(-)

diff --git a/testsuites/psxtests/psxfile01/test.c b/testsuites/psxtests/psxfile01/test.c
index dbdce86..129412d 100644
--- a/testsuites/psxtests/psxfile01/test.c
+++ b/testsuites/psxtests/psxfile01/test.c
@@ -57,6 +57,8 @@ char test_write_buffer[ 1024 ];
 rtems_filesystem_operations_table  IMFS_ops_no_evalformake;
 rtems_filesystem_operations_table  IMFS_ops_no_rename;
 
+static const char somefile[] = "somefile";
+
 /*
  *  File test support routines.
  */
@@ -132,11 +134,10 @@ void stat_a_file(
 
 static void test_open_directory(void)
 {
-  static const char file[] = "somefile";
   int status;
   int fd;
 
-  fd = open( file, O_CREAT, S_IRWXU );
+  fd = open( somefile, O_CREAT, S_IRWXU );
   rtems_test_assert( fd >= 0 );
 
   status = close( fd );
@@ -144,12 +145,34 @@ static void test_open_directory(void)
 
 #ifdef O_DIRECTORY
   errno = 0;
-  fd = open( file, O_DIRECTORY, S_IRWXU );
+  fd = open( somefile, O_DIRECTORY, S_IRWXU );
   rtems_test_assert( fd == -1 );
   rtems_test_assert( errno == ENOTDIR );
 #endif
 
-  status = unlink( file );
+  status = unlink( somefile );
+  rtems_test_assert( status == 0 );
+}
+
+static void test_open_cloexec(void)
+{
+  int status;
+  int fd;
+  mode_t mode;
+
+  mode = O_CREAT;
+
+#ifdef O_CLOEXEC
+  mode |= O_CLOEXEC;
+#endif
+
+  fd = open( somefile, mode, S_IRWXU );
+  rtems_test_assert( fd >= 0 );
+
+  status = close( fd );
+  rtems_test_assert( status == 0 );
+
+  status = unlink( somefile );
   rtems_test_assert( status == 0 );
 }
 
@@ -185,6 +208,7 @@ int main(
   TEST_BEGIN();
 
   test_open_directory();
+  test_open_cloexec();
 
   /*
    *  Grab the maximum size of an in-memory file.



More information about the vc mailing list