]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
logging: allow reopening stderr
authorMiroslav Lichvar <mlichvar@redhat.com>
Tue, 28 Aug 2018 12:10:21 +0000 (14:10 +0200)
committerMiroslav Lichvar <mlichvar@redhat.com>
Tue, 28 Aug 2018 16:18:07 +0000 (18:18 +0200)
LOG_OpenFileLog(NULL) can be now used to reopen stderr.

logging.c
logging.h

index 0f73a457c9d4c4652ce9003d9013578349381afd..828ae3071addc06752449860bdeb6bb0af01d994 100644 (file)
--- 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);
index 5bb46f5aa4eb31f32b2b3e196e2b815494fb5f63..67931dc735cbf9b69836b6ee2b7ec616b0208e38 100644 (file)
--- 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 */