]> git.cworth.org Git - apitrace/blobdiff - common/os_posix.cpp
Merge branch 'fork-safe' (issue #110)
[apitrace] / common / os_posix.cpp
index bd15bbac43db16710075fff3afaa59bf11e3e15c..5ec8b363390792748e733a6d8d5e7a9b3afadb24 100644 (file)
@@ -173,8 +173,16 @@ log(const char *format, ...)
 #ifdef ANDROID
     __android_log_vprint(ANDROID_LOG_DEBUG, "apitrace", format, ap);
 #else
-    vfprintf(stderr, format, ap);
-    fflush(stderr);
+    static FILE *log = NULL;
+    if (!log) {
+        // Duplicate stderr file descriptor, to prevent applications from
+        // redirecting our debug messages to somewhere else.
+        //
+        // Another alternative would be to log to /dev/tty when available.
+        log = fdopen(dup(STDERR_FILENO), "at");
+    }
+    vfprintf(log, format, ap);
+    fflush(log);
 #endif
     va_end(ap);
     logging = false;