diff options
author | José Fonseca <jfonseca@vmware.com> | 2013-05-10 12:27:26 +0100 |
---|---|---|
committer | José Fonseca <jfonseca@vmware.com> | 2013-05-10 12:27:26 +0100 |
commit | a880472a469e2acdc004176166161a6772c37f1f (patch) | |
tree | f1dfb9bce6d1fc6115fcc14dd17b401e6cfe6059 /common | |
parent | 2e0cc860b7002600281ff69bf08b7e502a5cc27f (diff) |
trace: Check process id also when the destructor is invoked.
Diffstat (limited to 'common')
-rw-r--r-- | common/trace_writer_local.cpp | 40 | ||||
-rw-r--r-- | common/trace_writer_local.hpp | 2 |
2 files changed, 24 insertions, 18 deletions
diff --git a/common/trace_writer_local.cpp b/common/trace_writer_local.cpp index a9981930..4d946f5c 100644 --- a/common/trace_writer_local.cpp +++ b/common/trace_writer_local.cpp @@ -71,6 +71,7 @@ LocalWriter::LocalWriter() : LocalWriter::~LocalWriter() { os::resetExceptionCallback(); + checkProcessId(); } void @@ -135,23 +136,27 @@ static uintptr_t next_thread_num = 1; static OS_THREAD_SPECIFIC_PTR(void) thread_num; +void LocalWriter::checkProcessId(void) { + if (m_file->isOpened() && + os::getCurrentProcessId() != pid) { + // We are a forked child process that inherited the trace file, so + // create a new file. We can't call any method of the current + // file, as it may cause it to flush and corrupt the parent's + // trace, so we effectively leak the old file object. + m_file = File::createSnappy(); + // Don't want to open the same file again + os::unsetEnvironment("TRACE_FILE"); + open(); + } +} + unsigned LocalWriter::beginEnter(const FunctionSig *sig) { mutex.lock(); ++acquired; + checkProcessId(); if (!m_file->isOpened()) { open(); - } else { - if (os::getCurrentProcessId() != pid) { - // We are a forked child process that inherited the trace file, so - // create a new file. We can't call any method of the current - // file, as it may cause it to flush and corrupt the parent's - // trace, so we effectively leak the old file object. - m_file = File::createSnappy(); - // Don't want to open the same file again - os::unsetEnvironment("TRACE_FILE"); - open(); - } } // Although thread_num is a void *, we actually use it as a uintptr_t @@ -186,11 +191,6 @@ void LocalWriter::endLeave(void) { } void LocalWriter::flush(void) { - if (os::getCurrentProcessId() != pid) { - os::log("apitrace: ignoring exception in child process\n"); - return; - } - /* * Do nothing if the mutex is already acquired (e.g., if a segfault happen * while writing the file) as state could be inconsistent, therefore yield @@ -203,8 +203,12 @@ void LocalWriter::flush(void) { } else { ++acquired; if (m_file->isOpened()) { - os::log("apitrace: flushing trace due to an exception\n"); - m_file->flush(); + if (os::getCurrentProcessId() != pid) { + os::log("apitrace: ignoring exception in child process\n"); + } else { + os::log("apitrace: flushing trace due to an exception\n"); + m_file->flush(); + } } --acquired; } diff --git a/common/trace_writer_local.hpp b/common/trace_writer_local.hpp index 6e4abc44..815e3c0f 100644 --- a/common/trace_writer_local.hpp +++ b/common/trace_writer_local.hpp @@ -76,6 +76,8 @@ namespace trace { */ os::ProcessId pid; + void checkProcessId(); + public: /** * Should never called directly -- use localWriter singleton below |