]> git.cworth.org Git - apitrace/commitdiff
os: Prevent app from redirecting log messages.
authorJosé Fonseca <jfonseca@vmware.com>
Fri, 10 May 2013 12:16:18 +0000 (13:16 +0100)
committerJosé Fonseca <jfonseca@vmware.com>
Fri, 10 May 2013 12:16:56 +0000 (13:16 +0100)
This happens e.g., with SurgeonSimulator2013

common/os_posix.cpp
common/trace_writer_local.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;
index 4d946f5c0a53a50aa5b9ba91d323ffa4d76101a6..d2ff3b5f73f2a41c5ea9c1413f98260a56941b20 100644 (file)
@@ -63,6 +63,8 @@ static void exceptionCallback(void)
 LocalWriter::LocalWriter() :
     acquired(0)
 {
+    os::log("apitrace: loaded\n");
+
     // Install the signal handlers as early as possible, to prevent
     // interfering with the application's signal handling.
     os::setExceptionCallback(exceptionCallback);