Broaden scope of gAborting. Fixes hang in HandleUnexpectedSignal.

Change-Id: I4c29cd7b67f07bb9f99c308feac5a3d6c236bc2b
diff --git a/src/logging.cc b/src/logging.cc
index 5680ed0..9dde963 100644
--- a/src/logging.cc
+++ b/src/logging.cc
@@ -25,6 +25,8 @@
 
 LogVerbosity gLogVerbosity;
 
+bool gAborting = false;
+
 static LogSeverity gMinimumLogSeverity = INFO;
 static std::string* gCmdLine;
 static std::string* gProgramInvocationName;
diff --git a/src/logging.h b/src/logging.h
index 75782d5..d0d35ea 100644
--- a/src/logging.h
+++ b/src/logging.h
@@ -318,6 +318,11 @@
 };
 
 extern LogVerbosity gLogVerbosity;
+
+// Used on fatal exit. Prevents recursive aborts. Allows us to disable
+// some error checking to ensure fatal shutdown makes forward progress.
+extern bool gAborting;
+
 extern void InitLogging(char* argv[]);
 
 extern const char* GetCmdLine();
diff --git a/src/mutex.h b/src/mutex.h
index 4af2ad7..d0c6369 100644
--- a/src/mutex.h
+++ b/src/mutex.h
@@ -107,7 +107,7 @@
 
   // Assert that the Mutex is exclusively held by the current thread.
   void AssertExclusiveHeld(const Thread* self) {
-    if (kDebugLocking) {
+    if (kDebugLocking && !gAborting) {
       CHECK(IsExclusiveHeld(self)) << *this;
     }
   }
diff --git a/src/runtime.cc b/src/runtime.cc
index 79d1fb2..afe0a42 100644
--- a/src/runtime.cc
+++ b/src/runtime.cc
@@ -153,8 +153,6 @@
   instance_ = NULL;
 }
 
-static bool gAborting = false;
-
 struct AbortState {
   void Dump(std::ostream& os) {
     if (gAborting) {
@@ -200,6 +198,8 @@
 };
 
 void Runtime::Abort() {
+  gAborting = true;  // set before taking any locks
+
   // Ensure that we don't have multiple threads trying to abort at once,
   // which would result in significantly worse diagnostics.
   MutexLock mu(Thread::Current(), *Locks::abort_lock_);
diff --git a/src/runtime_linux.cc b/src/runtime_linux.cc
index 01c08d3..430c70f 100644
--- a/src/runtime_linux.cc
+++ b/src/runtime_linux.cc
@@ -228,6 +228,7 @@
 };
 
 static void HandleUnexpectedSignal(int signal_number, siginfo_t* info, void* raw_context) {
+  gAborting = true;  // set before taking any locks
   MutexLock mu(Thread::Current(), *Locks::unexpected_signal_lock_);
 
   bool has_address = (signal_number == SIGILL || signal_number == SIGBUS ||