From 38259266018f49c23e6b72f58f740a2d423d9c62 Mon Sep 17 00:00:00 2001 From: Sebastian Huber Date: Thu, 18 Oct 2018 11:51:32 +0200 Subject: 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 dbdce86be8..129412d3ef 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. -- cgit v1.2.3