From 93e24f87750fe6189519d1531012b95a62c77605 Mon Sep 17 00:00:00 2001 From: Joseph Hickey Date: Tue, 30 Sep 2025 09:49:11 -0400 Subject: [PATCH] Fix #461, set stdout to unbuffered on pc-linux --- fsw/pc-linux/src/cfe_psp_start.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/fsw/pc-linux/src/cfe_psp_start.c b/fsw/pc-linux/src/cfe_psp_start.c index 2141aa9d..b281a4cf 100644 --- a/fsw/pc-linux/src/cfe_psp_start.c +++ b/fsw/pc-linux/src/cfe_psp_start.c @@ -235,6 +235,24 @@ void OS_Application_Startup(void) */ memset(&(CommandData), 0, sizeof(CFE_PSP_CommandData_t)); + /* + * Set console output to unbuffered + * + * This PSP uses "printf()" calls before OSAL is initialized, + * then changes to OS_printf(). Lines in OS_printf() are buffered + * by OSAL and then directly written to the STDOUT_FILENO. + * + * This can cause unexpected behavior where the early calls to + * printf() are seen after the OS_printf() calls, because they + * are being buffered in stdio. This is especially true if the + * output is directed to a log file or pipe, where block buffering + * is the default, as opposed to line buffering. + * + * As the only usage of stdout is in the early log messages, + * turning off buffering should not have any real downside. + */ + setbuf(stdout, NULL); + /* ** Process the arguments with getopt_long(), then ** start the cFE