Module: xenomai-2.6
Branch: master
Commit: f4cfe2ceddc1cee4034d791cb9866451f385de03
URL:    
http://git.xenomai.org/?p=xenomai-2.6.git;a=commit;h=f4cfe2ceddc1cee4034d791cb9866451f385de03

Author: Jan Kiszka <jan.kis...@siemens.com>
Date:   Wed Feb 12 19:20:23 2014 +0100

posix: Flush print buffer on fclose

As we keep a reference to the stream that was written to via fwrite &
Co., we need to flush our buffers before closing streams. Otherwise, we
risk that print_buffers crashes while trying to use a stale FILE object.

Signed-off-by: Jan Kiszka <jan.kis...@siemens.com>

---

 include/posix/stdio.h          |    2 ++
 src/skins/posix/posix.wrappers |    1 +
 src/skins/posix/printf.c       |    6 ++++++
 src/skins/posix/wrappers.c     |    6 ++++++
 4 files changed, 15 insertions(+)

diff --git a/include/posix/stdio.h b/include/posix/stdio.h
index bbd3249..fb89590 100644
--- a/include/posix/stdio.h
+++ b/include/posix/stdio.h
@@ -55,6 +55,8 @@ int __real_putchar(int c);
 
 size_t __real_fwrite(const void *ptr, size_t sz, size_t nmemb, FILE *stream);
 
+int __real_fclose(FILE *stream);
+
 #ifdef __cplusplus
 }
 #endif /* __cplusplus */
diff --git a/src/skins/posix/posix.wrappers b/src/skins/posix/posix.wrappers
index db73a14..6db51ea 100644
--- a/src/skins/posix/posix.wrappers
+++ b/src/skins/posix/posix.wrappers
@@ -99,6 +99,7 @@
 --wrap fputc
 --wrap putchar
 --wrap fwrite
+--wrap fclose
 --wrap syslog
 --wrap vsyslog
 --wrap malloc
diff --git a/src/skins/posix/printf.c b/src/skins/posix/printf.c
index 379540e..6807a81 100644
--- a/src/skins/posix/printf.c
+++ b/src/skins/posix/printf.c
@@ -118,6 +118,12 @@ size_t __wrap_fwrite(void *ptr, size_t size, size_t nmemb, 
FILE *stream)
 
 }
 
+int __wrap_fclose(FILE *stream)
+{
+       rt_print_flush_buffers();
+       return __real_fclose(stream);
+}
+
 void __wrap_vsyslog(int priority, const char *fmt, va_list ap)
 {
        if (unlikely(xeno_get_current() != XN_NO_HANDLE &&
diff --git a/src/skins/posix/wrappers.c b/src/skins/posix/wrappers.c
index 3744eb7..687f2a8 100644
--- a/src/skins/posix/wrappers.c
+++ b/src/skins/posix/wrappers.c
@@ -398,6 +398,12 @@ size_t __real_fwrite(const void *ptr, size_t sz, size_t 
nmemb, FILE *stream)
 }
 
 __attribute__ ((weak))
+int __real_fclose(FILE *stream)
+{
+       return fclose(stream);
+}
+
+__attribute__ ((weak))
 void __real_syslog(int priority, const char *fmt, ...)
 {
        va_list args;


_______________________________________________
Xenomai-git mailing list
Xenomai-git@xenomai.org
http://www.xenomai.org/mailman/listinfo/xenomai-git

Reply via email to