[PATCH 8/8] libcsupport: Delete libc_wrapup()

Sebastian Huber sebastian.huber at embedded-brains.de
Thu Apr 25 09:20:01 UTC 2013


Add and use rtems_libio_exit_helper.  Add rtems_libio_exit().

The fclose(stdin) etc. makes no sense during exit.  This would use the
_REENT structure of the thread calling _exit().
---
 cpukit/libcsupport/Makefile.am           |    1 +
 cpukit/libcsupport/include/rtems/libio.h |    4 +++
 cpukit/libcsupport/src/libio_exit.c      |   34 ++++++++++++++++++++++++++++++
 cpukit/libcsupport/src/newlibc_exit.c    |   27 +----------------------
 cpukit/sapi/include/confdefs.h           |    7 ++++++
 5 files changed, 48 insertions(+), 25 deletions(-)
 create mode 100644 cpukit/libcsupport/src/libio_exit.c

diff --git a/cpukit/libcsupport/Makefile.am b/cpukit/libcsupport/Makefile.am
index 42de63c..25e18c6 100644
--- a/cpukit/libcsupport/Makefile.am
+++ b/cpukit/libcsupport/Makefile.am
@@ -56,6 +56,7 @@ BASE_FS_C_FILES = src/base_fs.c src/mount.c src/unmount.c src/libio.c \
     src/mount-mgr.c src/mount-mktgt.c src/libio_init.c \
     src/privateenv.c \
     src/libio_helper_null.c \
+    src/libio_exit.c \
     src/open_dev_console.c src/__usrenv.c src/rtems_mkdir.c
 
 TERMIOS_C_FILES = src/cfgetispeed.c src/cfgetospeed.c src/cfsetispeed.c \
diff --git a/cpukit/libcsupport/include/rtems/libio.h b/cpukit/libcsupport/include/rtems/libio.h
index ec2ced3..23853f9 100644
--- a/cpukit/libcsupport/include/rtems/libio.h
+++ b/cpukit/libcsupport/include/rtems/libio.h
@@ -1392,12 +1392,16 @@ extern const rtems_libio_helper rtems_libio_init_helper;
 
 extern const rtems_libio_helper rtems_libio_post_driver_helper;
 
+extern const rtems_libio_helper rtems_libio_exit_helper;
+
 extern const rtems_libio_helper rtems_fs_init_helper;
 
 void rtems_libio_helper_null(void);
 
 void rtems_libio_post_driver(void);
 
+void rtems_libio_exit(void);
+
 /**
  * @brief Creates a directory and all its parent directories according to
  * @a path.
diff --git a/cpukit/libcsupport/src/libio_exit.c b/cpukit/libcsupport/src/libio_exit.c
new file mode 100644
index 0000000..443e576
--- /dev/null
+++ b/cpukit/libcsupport/src/libio_exit.c
@@ -0,0 +1,34 @@
+/**
+ * @file
+ *
+ * @ingroup LibIO
+ */
+
+/*
+ * Copyright (c) 2013 embedded brains GmbH.  All rights reserved.
+ *
+ *  embedded brains GmbH
+ *  Obere Lagerstr. 30
+ *  82178 Puchheim
+ *  Germany
+ *  <rtems at embedded-brains.de>
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ */
+
+#if HAVE_CONFIG_H
+  #include "config.h"
+#endif
+
+#include <unistd.h>
+
+#include <rtems/libio.h>
+
+void rtems_libio_exit(void)
+{
+  (void)close(0);
+  (void)close(1);
+  (void)close(2);
+}
diff --git a/cpukit/libcsupport/src/newlibc_exit.c b/cpukit/libcsupport/src/newlibc_exit.c
index 8dbbfce..f0c7b42 100644
--- a/cpukit/libcsupport/src/newlibc_exit.c
+++ b/cpukit/libcsupport/src/newlibc_exit.c
@@ -11,37 +11,14 @@
 #include "config.h"
 #endif
 
-#define __RTEMS_VIOLATE_KERNEL_VISIBILITY__
 #include <rtems.h>
 
 #if defined(RTEMS_NEWLIB)
-#include <rtems/libcsupport.h>
+#include <rtems/libio.h>
 
 #include <stdio.h>
 #include <unistd.h>
 
-static void libc_wrapup(void)
-{
-  /*
-   *  In case RTEMS is already down, don't do this.  It could be
-   *  dangerous.
-   */
-
-  if (!_System_state_Is_up(_System_state_Get()))
-     return;
-
-  /*
-   * Try to drain output buffers.
-   *
-   * Should this be changed to do *all* file streams?
-   *    _fwalk (_REENT, fclose);
-   */
-
-  fclose (stdin);
-  fclose (stdout);
-  fclose (stderr);
-}
-
 /* FIXME: These defines are a blatant hack */
 
   #if defined(__USE_INIT_FINI__)
@@ -66,7 +43,7 @@ void _exit(int status)
     FINI_SYMBOL();
   #endif
 
-  libc_wrapup();
+  (*rtems_libio_exit_helper)();
   rtems_shutdown_executive(status);
   for (;;) ; /* to avoid warnings */
 }
diff --git a/cpukit/sapi/include/confdefs.h b/cpukit/sapi/include/confdefs.h
index 0d8c99b..c15c8a3 100644
--- a/cpukit/sapi/include/confdefs.h
+++ b/cpukit/sapi/include/confdefs.h
@@ -106,6 +106,13 @@ const rtems_libio_helper rtems_libio_post_driver_helper =
     rtems_libio_post_driver;
   #endif
 
+const rtems_libio_helper rtems_libio_exit_helper =
+  #ifdef CONFIGURE_APPLICATION_DISABLE_FILESYSTEM
+    rtems_libio_helper_null;
+  #else
+    rtems_libio_exit;
+  #endif
+
 const rtems_libio_helper rtems_fs_init_helper =
   #ifdef CONFIGURE_APPLICATION_DISABLE_FILESYSTEM
     rtems_libio_helper_null;
-- 
1.7.7




More information about the devel mailing list