[PATCH] termios: Replace rtems_termios_isig_status_code

Sebastian Huber sebastian.huber at embedded-brains.de
Thu May 7 06:52:24 UTC 2020


Merge the rtems_termios_isig_status_code and
rtems_termios_iproc_status_code enums into a single
rtems_termios_iproc_status_code which is now a part of the API.

Simplify rtems_termios_posix_isig_handler() to avoid unreachable code.

Close #3800.
---
 cpukit/include/rtems/libio.h                       | 47 +++++++++++++---------
 cpukit/libcsupport/src/termios.c                   | 34 ++--------------
 .../libcsupport/src/termios_posix_isig_handler.c   | 18 ++++-----
 3 files changed, 40 insertions(+), 59 deletions(-)

diff --git a/cpukit/include/rtems/libio.h b/cpukit/include/rtems/libio.h
index b3c0e975cd..f1c9eea51b 100644
--- a/cpukit/include/rtems/libio.h
+++ b/cpukit/include/rtems/libio.h
@@ -1904,28 +1904,37 @@ rtems_status_code rtems_termios_bufsize (
 );
 
 /**
- * @brief Type returned by all input processing (isig) methods
- */ 
+ * @brief The status code returned by all Termios input processing (iproc)
+ * functions and input signal (isig) handlers.
+ */
 typedef enum {
   /**
-   * This indicates that the input character was processed
-   * and possibly placed into the buffer.
+   * @brief This status indicates that the input processing can continue.
+   *
+   * Input signal handlers shall return this status if no signal was raised and
+   * the input processing can continue.
    */
-  RTEMS_TERMIOS_ISIG_WAS_PROCESSED,
+  RTEMS_TERMIOS_IPROC_CONTINUE,
+
   /**
-   * This indicates that the input character was not processed and
-   * subsequent processing is required.
+   * @brief This status indicates that the input processing should stop due to
+   * a signal.
+   *
+   * This indicates that the character was processed and determined to be one
+   * that requires a signal to be raised (e.g. VINTR or VKILL).  The tty must
+   * be in the right Termios mode for this to occur.  There is no further
+   * processing of this character required and the pending read() operation
+   * should be interrupted.
    */
-  RTEMS_TERMIOS_ISIG_WAS_NOT_PROCESSED,
+  RTEMS_TERMIOS_IPROC_INTERRUPT,
+
   /**
-   * This indicates that the character was processed and determined
-   * to be one that requires a signal to be raised (e.g. VINTR or
-   * VKILL). The tty must be in the right termios mode for this to
-   * occur. There is no further processing of this character required and
-   * the pending read() operation should be interrupted.
+   * @brief This status indicates that the input processing is done.
+   *
+   * This status shall not be returned by input processing signal handlers.
    */
-  RTEMS_TERMIOS_ISIG_INTERRUPT_READ
-} rtems_termios_isig_status_code;
+  RTEMS_TERMIOS_IPROC_DONE
+} rtems_termios_iproc_status_code;
 
 /**
  * @brief Type for ISIG (VINTR/VKILL) handler
@@ -1941,9 +1950,9 @@ typedef enum {
  * @param tty   termios structure pointer for this input tty
  *
  * @return The value returned is according to that documented
- *         for @ref rtems_termios_isig_status_code.
+ *         for @ref rtems_termios_iproc_status_code.
  */
-typedef rtems_termios_isig_status_code (*rtems_termios_isig_handler)(
+typedef rtems_termios_iproc_status_code (*rtems_termios_isig_handler)(
   unsigned char             c,
   struct rtems_termios_tty *tty
 );
@@ -1966,7 +1975,7 @@ typedef rtems_termios_isig_status_code (*rtems_termios_isig_handler)(
  * @return The value returned is according to that documented
  *         for all methods adhering to @ref rtems_termios_isig_handler.
  */
-rtems_termios_isig_status_code rtems_termios_default_isig_handler(
+rtems_termios_iproc_status_code rtems_termios_default_isig_handler(
   unsigned char             c,
   struct rtems_termios_tty *tty
 );
@@ -1984,7 +1993,7 @@ rtems_termios_isig_status_code rtems_termios_default_isig_handler(
  * @return The value returned is according to that documented
  *         for all methods adhering to @ref rtems_termios_isig_handler.
  */
-rtems_termios_isig_status_code rtems_termios_posix_isig_handler(
+rtems_termios_iproc_status_code rtems_termios_posix_isig_handler(
   unsigned char             c,
   struct rtems_termios_tty *tty
 );
diff --git a/cpukit/libcsupport/src/termios.c b/cpukit/libcsupport/src/termios.c
index 3690ee3fc3..75925cf8ec 100644
--- a/cpukit/libcsupport/src/termios.c
+++ b/cpukit/libcsupport/src/termios.c
@@ -1311,12 +1311,12 @@ static rtems_termios_isig_handler termios_isig_handler =
  * This is the default method to process VKILL or VQUIT characters if
  * ISIG processing is enabled. Note that it does nothing.
  */
-rtems_termios_isig_status_code rtems_termios_default_isig_handler(
+rtems_termios_iproc_status_code rtems_termios_default_isig_handler(
   unsigned char c,
   struct rtems_termios_tty *tty
 )
 {
-  return RTEMS_TERMIOS_ISIG_WAS_NOT_PROCESSED;
+  return RTEMS_TERMIOS_IPROC_CONTINUE;
 }
 
 /*
@@ -1335,28 +1335,6 @@ rtems_status_code rtems_termios_register_isig_handler(
   return RTEMS_SUCCESSFUL;
 }
 
-/**
- * @brief Type returned by all input processing (iproc) methods
- */
-typedef enum {
-  /**
-   * This indicates that the input processing can continue.
-   */
-  RTEMS_TERMIOS_IPROC_CONTINUE,
-  /**
-   * This indicates that the input processing is done.
-   */
-  RTEMS_TERMIOS_IPROC_DONE,
-  /**
-   * This indicates that the character was processed and determined
-   * to be one that requires a signal to be raised (e.g. VINTR or
-   * VKILL). The tty must be in the right termios mode for this to
-   * occur. There is no further processing of this character required and
-   * the pending read() operation should be interrupted.
-   */
-  RTEMS_TERMIOS_IPROC_INTERRUPT
-} rtems_termios_iproc_status_code;
-
 /*
  * Process a single input character
  */
@@ -1369,13 +1347,7 @@ iproc (unsigned char c, struct rtems_termios_tty *tty)
    */
   if ((tty->termios.c_lflag & ISIG)) {
     if ((c == tty->termios.c_cc[VINTR]) || (c == tty->termios.c_cc[VQUIT])) {
-      rtems_termios_isig_status_code rc;
-      rc = (*termios_isig_handler)(c, tty);
-      if (rc == RTEMS_TERMIOS_ISIG_INTERRUPT_READ) {
-         return RTEMS_TERMIOS_IPROC_INTERRUPT;
-      }
-
-      return RTEMS_TERMIOS_IPROC_CONTINUE;
+      return (*termios_isig_handler)(c, tty);
     }
   }
 
diff --git a/cpukit/libcsupport/src/termios_posix_isig_handler.c b/cpukit/libcsupport/src/termios_posix_isig_handler.c
index 5be2d10aa2..5f505fecb4 100644
--- a/cpukit/libcsupport/src/termios_posix_isig_handler.c
+++ b/cpukit/libcsupport/src/termios_posix_isig_handler.c
@@ -20,20 +20,20 @@
 
 #include <signal.h>
 
-rtems_termios_isig_status_code rtems_termios_posix_isig_handler(
+rtems_termios_iproc_status_code rtems_termios_posix_isig_handler(
   unsigned char             c,
   struct rtems_termios_tty *tty
 )
 {
-  if (c == tty->termios.c_cc[VINTR]) {
-    raise(SIGINT);
-    return RTEMS_TERMIOS_ISIG_INTERRUPT_READ;
-  }
+  int sig;
 
-  if (c == tty->termios.c_cc[VQUIT]) {
-    raise(SIGQUIT);
-    return RTEMS_TERMIOS_ISIG_INTERRUPT_READ;
+  if ( c == tty->termios.c_cc[ VQUIT ] ) {
+    sig = SIGQUIT;
+  } else {
+    sig = SIGINT;
   }
 
-  return RTEMS_TERMIOS_ISIG_WAS_NOT_PROCESSED;
+  (void) raise( sig );
+
+  return RTEMS_TERMIOS_IPROC_INTERRUPT;
 }
-- 
2.16.4



More information about the devel mailing list