lib/boilerplate: Prevent migration to secondary mode for __printout
PATCH 1/1 lib/boilerplate: Prevent migration to secondary mode for __printout
From: Wolfgang Hartmann <[email protected]>
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.
--- lib/boilerplate/ancillaries.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
lib/boilerplate/ancillaries.c +6 -6
@@ -52,15 +52,14 @@ 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); -fflush (fp); +__RT (fprintf (fp,"[%s] " , name ?:"main" )); +__RT (vfprintf (fp, fmt, ap)); +__RT (fputc ('\n' , fp)); } void __printout(const char *name, const char *header,
@@ -110,6 +109,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 ); }
Signature · 1 line
2.13.6
Quoted 26 lines · Jan Kiszka
From: Wolfgang Hartmann <[email protected]>
Use the
__RTversions 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 <[email protected]>Signed-off-by Jan Kiszka <[email protected]>--- lib/boilerplate/ancillaries.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)lib/boilerplate/ancillaries.c +2
-2@@ -52,15 +52,14 @@ 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));
lib/boilerplate/ancillaries.c static void __do_printout(const char *name, const char *header, · line 64
Quoted 10 lines
lib/boilerplate/ancillaries.c +3
-4-fprintf (fp,"[%s] " , name ?:"main" ); -vfprintf (fp, fmt, ap); -fputc ('\n' , fp); -fflush (fp); +__RT (fprintf (fp,"[%s] " , name ?:"main" )); +__RT (vfprintf (fp, fmt, ap)); +__RT (fputc ('\n' , fp)); }
This would not work as intended during the early init phase. We may not invoke any wrapped call until init_done is set by __boilerplate_init(). In addition to the above patch, you would also need something like:
lib/boilerplate/ancillaries.c +8 -1
@@ -46,6 +46,13 @@ static struct timespec init_date;static int init_done; +static void __do_early_printout (const char *name,const char *header, +unsigned int ms,unsigned int us, +const char *fmt,va_list ap) +{ +/* ... should use __STD() POSIX calls only ... */ +} +static void __do_printout (const char *name,const char *header,unsigned int ms,unsigned int us,const char *fmt,va_list ap)
@@ -77,7 +84,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 ; }
Signature · 1 line
Philippe.
PATCH v2 1/1 lib/boilerplate: Prevent migration to secondary mode for __printout
From: Wolfgang Hartmann <[email protected]>
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.
---
Changes in v2:
- handle early print via standard calls
lib/boilerplate/ancillaries.c | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-)
lib/boilerplate/ancillaries.c +23 -6
@@ -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 ); }
Philippe Gerum
AppliedQuoted 8 lines · Jan Kiszka
From: Wolfgang Hartmann <[email protected]>
Use the
__RTversions 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 <[email protected]>Signed-off-by Jan Kiszka <[email protected]>
Quoted 8 lines
---
Changes in v2:
- handle early print via standard callslib/boilerplate/ancillaries.c | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-)
Merged, thanks.
Signature · 1 line
Philippe.