Skip to content

Commit

Permalink
[logging] Flush output streams relevant for logging
Browse files Browse the repository at this point in the history
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 <simo.piiroinen@jollamobile.com>
  • Loading branch information
spiiroin committed Nov 7, 2016
1 parent 5579463 commit c9055d0
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/usb_moded.c
Expand Up @@ -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
Expand Down

0 comments on commit c9055d0

Please sign in to comment.