[rtems commit] posix_devctl - Add support for SOCKCLOSE

Joel Sherrill joel at rtems.org
Fri Jan 17 22:13:41 UTC 2020


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

Author:    Joel Sherrill <joel at rtems.org>
Date:      Mon Oct  7 10:48:23 2019 -0500

posix_devctl - Add support for SOCKCLOSE

The FACE Technical Standard, Edition 3.0 and later require the definition
of the subcommand SOCKCLOSE in <devctl.h>.

Reference: ​https://www.opengroup.org/face

closes #3856.

---

 cpukit/libcsupport/src/posix_devctl.c           | 16 ++++++++++++++-
 testsuites/psxtests/psxdevctl01/main.c          |  2 ++
 testsuites/psxtests/psxdevctl01/psxdevctl01.doc |  8 +++++++-
 testsuites/psxtests/psxdevctl01/psxdevctl01.scn |  4 +++-
 testsuites/psxtests/psxdevctl01/test.c          | 26 +++++++++++++++++++++++++
 5 files changed, 53 insertions(+), 3 deletions(-)

diff --git a/cpukit/libcsupport/src/posix_devctl.c b/cpukit/libcsupport/src/posix_devctl.c
index 415b94e..0646ee4 100644
--- a/cpukit/libcsupport/src/posix_devctl.c
+++ b/cpukit/libcsupport/src/posix_devctl.c
@@ -1,5 +1,6 @@
 /*
- * Copyright (c) 2016 Joel Sherrill <joel at rtems.org>.  All rights reserved.
+ * Copyright (c) 2016, 2020 Joel Sherrill <joel at rtems.org>.
+ * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -33,6 +34,8 @@
 #include <sys/ioctl.h>
 #include <rtems/seterr.h>
 
+#include  <unistd.h>
+
 int posix_devctl(
   int              fd,
   int              dcmd,
@@ -68,5 +71,16 @@ int posix_devctl(
     *dev_info_ptr = 0;
   }
 
+  /*
+   * The FACE Technical Standard Edition 3.0 and newer requires the SOCKCLOSE
+   * ioctl command. This is because the Security Profile does not include
+   * close() and applications need a way to close sockets. Closing sockets is
+   * a minimum requirement so using close() in the implementation meets that
+   * requirement but also lets the application close other file types.
+   */
+  if (dcmd == SOCKCLOSE ) {
+    return close(fd);
+  }
+
   return ioctl(fd, dcmd, dev_data_ptr);
 }
diff --git a/testsuites/psxtests/psxdevctl01/main.c b/testsuites/psxtests/psxdevctl01/main.c
index d74fb6b..54776e2 100644
--- a/testsuites/psxtests/psxdevctl01/main.c
+++ b/testsuites/psxtests/psxdevctl01/main.c
@@ -39,6 +39,8 @@ rtems_task Init(
 
 #define CONFIGURE_MAXIMUM_TASKS 1
 
+#define CONFIGURE_MAXIMUM_FILE_DESCRIPTORS 4
+
 #define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
 
 #define CONFIGURE_RTEMS_INIT_TASKS_TABLE
diff --git a/testsuites/psxtests/psxdevctl01/psxdevctl01.doc b/testsuites/psxtests/psxdevctl01/psxdevctl01.doc
index fee22d2..51f295d 100644
--- a/testsuites/psxtests/psxdevctl01/psxdevctl01.doc
+++ b/testsuites/psxtests/psxdevctl01/psxdevctl01.doc
@@ -19,5 +19,11 @@ concepts:
 + Ensure that proper error values result when passing different combinations of
   arguments to posix_devctl().
 
-+ Ensure that a requestn is passed through the underlying ioctl() operation
++ Ensure that a request is passed through the underlying ioctl() operation
   to the console device driver and flagged as an error.
+
++ Ensure that the SOCKCLOSE subcommand is supported by posix_devctl()
+  and returns an error on invalid file descriptors.
+
++ Ensure that the SOCKCLOSE subcommand is supported by posix_devctl()
+  and will close a file descriptor.
diff --git a/testsuites/psxtests/psxdevctl01/psxdevctl01.scn b/testsuites/psxtests/psxdevctl01/psxdevctl01.scn
index 1df1d7e..4400463 100644
--- a/testsuites/psxtests/psxdevctl01/psxdevctl01.scn
+++ b/testsuites/psxtests/psxdevctl01/psxdevctl01.scn
@@ -1,4 +1,6 @@
 *** BEGIN OF TEST PSXDEVCTL 1 ***
 posix_devctl() FIONBIO on stdin return dev_info -- EBADF
-posix_devctl() FIONBIO on stdin return dev_info -- EBADF
+posix_devctl() FIONBIO on stdin NULL dev_info -- EBADF
+posix_devctl() SOCKCLOSE on invalid file descriptor -- EBADF
+posix_devctl() SOCKCLOSE on valid file descriptor -- OK
 *** END OF TEST PSXDEVCTL 1 ***
diff --git a/testsuites/psxtests/psxdevctl01/test.c b/testsuites/psxtests/psxdevctl01/test.c
index ed22ba8..b45725c 100644
--- a/testsuites/psxtests/psxdevctl01/test.c
+++ b/testsuites/psxtests/psxdevctl01/test.c
@@ -76,6 +76,32 @@ int main(
   rtems_test_assert( status == -1 );
   rtems_test_assert( errno == EBADF );
 
+  puts( "posix_devctl() SOCKCLOSE on invalid file descriptor -- EBADF" );
+  fd = 21;
+  dcmd = SOCKCLOSE;
+  dev_data_ptr = NULL;
+  nbyte = 0;
+  status = posix_devctl( fd, dcmd, dev_data_ptr, nbyte, NULL );
+  rtems_test_assert( status == -1 );
+  rtems_test_assert( errno == EBADF );
+
+  /*
+   * Create a file, open it, and close it via posix_devctl().
+   * Then verify it is really closed.
+   */
+  puts( "posix_devctl() SOCKCLOSE on valid file descriptor -- OK" );
+  fd = open("tmp_for_close", O_CREAT | O_RDWR, S_IRWXU );
+  rtems_test_assert( fd != -1 );
+
+  dcmd = SOCKCLOSE;
+  dev_data_ptr = NULL;
+  nbyte = 0;
+  status = posix_devctl( fd, dcmd, dev_data_ptr, nbyte, NULL );
+  rtems_test_assert( status == 0 );
+
+  status = close( fd );
+  rtems_test_assert( status == -1 );
+  rtems_test_assert( errno == EBADF );
   TEST_END();
   exit(0);
 }



More information about the vc mailing list