Module: xenomai-3
Branch: wip/rtnet-fixes
Commit: 9da7bde25afaf5d6fb7f91a44bc2e96019cd4acb
URL:    
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=9da7bde25afaf5d6fb7f91a44bc2e96019cd4acb

Author: Wolfgang Hartmann <wolfgang.hartm...@siemens.com>
Date:   Mon Feb 26 18:45:00 2018 +0100

lib/boilerplate: Prevent migration to secondary mode for __printout

Use the __RT versions of the stdio function calls to avoid migration to
secondary mode. In case of ___panic, flush the printer before exiting to
avoid losing messages.

Signed-off-by: Wolfgang Hartmann <wolfgang.hartm...@siemens.com>
Signed-off-by: Jan Kiszka <jan.kis...@siemens.com>

---

 lib/boilerplate/ancillaries.c |   29 +++++++++++++++++++++++------
 1 file changed, 23 insertions(+), 6 deletions(-)

diff --git a/lib/boilerplate/ancillaries.c b/lib/boilerplate/ancillaries.c
index 13d7faf..7e98141 100644
--- a/lib/boilerplate/ancillaries.c
+++ b/lib/boilerplate/ancillaries.c
@@ -52,14 +52,30 @@ static void __do_printout(const char *name, const char 
*header,
 {
        FILE *fp = stderr;
 
-       fprintf(fp, "%4u\"%.3u.%.3u| ", ms / 1000, ms % 1000, us);
+       __RT(fprintf(fp, "%4u\"%.3u.%.3u| ", ms / 1000, ms % 1000, us));
 
        if (header)
-               fputs(header, fp);
+               __RT(fputs(header, fp));
 
-       fprintf(fp, "[%s] ", name ?: "main");
-       vfprintf(fp, fmt, ap);
-       fputc('\n', fp);
+       __RT(fprintf(fp, "[%s] ", name ?: "main"));
+       __RT(vfprintf(fp, fmt, ap));
+       __RT(fputc('\n', fp));
+}
+
+static void __do_early_printout(const char *name, const char *header,
+                         unsigned int ms, unsigned int us,
+                         const char *fmt, va_list ap)
+{
+       FILE *fp = stderr;
+
+       __STD(fprintf(fp, "%4u\"%.3u.%.3u| ", ms / 1000, ms % 1000, us));
+
+       if (header)
+               __STD(fputs(header, fp));
+
+       __STD(fprintf(fp, "[%s] ", name ?: "main"));
+       __STD(vfprintf(fp, fmt, ap));
+       __STD(fputc('\n', fp));
        fflush(fp);
 }
 
@@ -77,7 +93,7 @@ void __printout(const char *name, const char *header,
         * uncontended.
         */
        if (!init_done) {
-               __do_printout(name, header, 0, 0, fmt, ap);
+               __do_early_printout(name, header, 0, 0, fmt, ap);
                return;
        }
        
@@ -110,6 +126,7 @@ void ___panic(const char *fn, const char *name,
        if (asprintf(&p, "BUG in %s(): ", fn) < 0)
                p = "BUG: ";
        __printout(name, p, fmt, ap);
+       rt_print_flush_buffers();
        exit(1);
 }
 


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

Reply via email to