Logging: Disable logging after fork()
authorPavel Labath <labath@google.com>
Mon, 23 Oct 2017 19:41:17 +0000 (19:41 +0000)
committerPavel Labath <labath@google.com>
Mon, 23 Oct 2017 19:41:17 +0000 (19:41 +0000)
commitd813309e034cb32436eb804f70d94da7bdb406cd
treea226dcb93a66651509b88713fec41f153a1ba653
parent6f06b6edff4eb63703875e2785c18eea5d83e55c
Logging: Disable logging after fork()

Summary:
We had a bug where if we had forked (in the ProcessLauncherPosixFork)
while another thread was writing a log message, we would deadlock. This
happened because the fork child inherited the locked log rwmutex, which
would never get unlocked. This meant the child got stuck trying to
disable all log channels.

The bug existed for a while but only started being apparent after
D37930, which started using ThreadLauncher (which uses logging) instead
of std::thread (which does not) for launching TaskPool threads.

The fix is to use pthread_atfork to disable logging in the forked child.

Reviewers: zturner, eugene, clayborg

Subscribers: lldb-commits

Differential Revision: https://reviews.llvm.org/D38938

llvm-svn: 316368
lldb/include/lldb/Utility/Log.h
lldb/include/lldb/Utility/Logging.h
lldb/source/Host/posix/ProcessLauncherPosixFork.cpp
lldb/source/Initialization/SystemInitializerCommon.cpp
lldb/source/Utility/Log.cpp
lldb/source/Utility/Logging.cpp