]> git.cworth.org Git - apitrace/blobdiff - common/os_posix.cpp
Merge branch 'fork-safe' (issue #110)
[apitrace] / common / os_posix.cpp
index 0d93b31bcafa6e56604fa639a7656d20128835ca..5ec8b363390792748e733a6d8d5e7a9b3afadb24 100644 (file)
@@ -173,7 +173,16 @@ log(const char *format, ...)
 #ifdef ANDROID
     __android_log_vprint(ANDROID_LOG_DEBUG, "apitrace", format, ap);
 #else
-    vfprintf(stderr, format, ap);
+    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;
@@ -186,7 +195,7 @@ long long timeFrequency = 0LL;
 void
 abort(void)
 {
-    exit(0);
+    _exit(1);
 }