From: José Fonseca Date: Fri, 10 May 2013 12:16:18 +0000 (+0100) Subject: os: Prevent app from redirecting log messages. X-Git-Url: https://git.notmuchmail.org/git?a=commitdiff_plain;h=f917f612220b4e424ac7dfd05945460b2af5ed14;p=apitrace os: Prevent app from redirecting log messages. This happens e.g., with SurgeonSimulator2013 --- diff --git a/common/os_posix.cpp b/common/os_posix.cpp index bd15bba..5ec8b36 100644 --- a/common/os_posix.cpp +++ b/common/os_posix.cpp @@ -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; diff --git a/common/trace_writer_local.cpp b/common/trace_writer_local.cpp index 4d946f5..d2ff3b5 100644 --- a/common/trace_writer_local.cpp +++ b/common/trace_writer_local.cpp @@ -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);