From: Miroslav Lichvar Date: Tue, 28 Aug 2018 12:10:21 +0000 (+0200) Subject: logging: allow reopening stderr X-Git-Tag: 3.4-pre1~16 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=eb8c9ad601531d79b253b1f17cc7bca9fc7cc3c9;p=thirdparty%2Fchrony.git logging: allow reopening stderr LOG_OpenFileLog(NULL) can be now used to reopen stderr. --- diff --git a/logging.c b/logging.c index 0f73a457..828ae307 100644 --- a/logging.c +++ b/logging.c @@ -184,9 +184,13 @@ LOG_OpenFileLog(const char *log_file) { FILE *f; - f = fopen(log_file, "a"); - if (!f) - LOG_FATAL("Could not open log file %s", log_file); + if (log_file) { + f = fopen(log_file, "a"); + if (!f) + LOG_FATAL("Could not open log file %s", log_file); + } else { + f = stderr; + } /* Enable line buffering */ setvbuf(f, NULL, _IOLBF, BUFSIZ); diff --git a/logging.h b/logging.h index 5bb46f5a..67931dc7 100644 --- a/logging.h +++ b/logging.h @@ -99,7 +99,7 @@ extern void LOG_Message(LOG_Severity severity, const char *format, ...); */ extern void LOG_SetDebugLevel(int level); -/* Log messages to a file instead of stderr */ +/* Log messages to a file instead of stderr, or stderr again if NULL */ extern void LOG_OpenFileLog(const char *log_file); /* Log messages to syslog instead of stderr */