From c9055d075fe0776b51299bf0e5502a5bc7ac8d6d Mon Sep 17 00:00:00 2001 From: Simo Piiroinen Date: Mon, 7 Nov 2016 10:07:18 +0200 Subject: [PATCH] [logging] Flush output streams relevant for logging Mixed use of syslog, stdout, stderr and differences in buffering of the streams causes the initial "starting up" message to end up as the final output in usb-moded journal when debug level logging is used (i.e. when freopen steps are skipped and stdout is not implicitly flushed). Use stderr and flush it before potentially switching to syslog logging. Signed-off-by: Simo Piiroinen --- src/usb_moded.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/usb_moded.c b/src/usb_moded.c index f5c0ef3..7942fe5 100644 --- a/src/usb_moded.c +++ b/src/usb_moded.c @@ -1162,13 +1162,16 @@ int main(int argc, char* argv[]) } } - printf("usb_moded %s starting\n", VERSION); + fprintf(stderr, "usb_moded %s starting\n", VERSION); + fflush(stderr); + /* silence system() calls */ if(log_type != LOG_TO_STDERR || log_level != LOG_DEBUG ) { freopen("/dev/null", "a", stdout); freopen("/dev/null", "a", stderr); } + #if !GLIB_CHECK_VERSION(2, 36, 0) g_type_init(); #endif