summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorYoshisato Yanagisawa <yyanagisawa@google.com>2015-11-18 06:40:12 (GMT)
committerYoshisato Yanagisawa <yyanagisawa@google.com>2015-11-26 07:19:22 (GMT)
commitcda16b3443e2d6ef88cdbbe10b9a11adea6f33fe (patch)
tree165a2163546d8a78bda5385431128f932d9a571b /src
parentf46e0745a842b2edc924b6d384acf01fd7034c62 (diff)
downloadglog-cda16b3443e2d6ef88cdbbe10b9a11adea6f33fe.zip
glog-cda16b3443e2d6ef88cdbbe10b9a11adea6f33fe.tar.gz
glog-cda16b3443e2d6ef88cdbbe10b9a11adea6f33fe.tar.bz2
Reset SIGABRT action only if FailureSignalHandler is installed.
When I set my own signal handler to SIGABRT, it did not executed with CHECK. That is because SIGABRT handler is reset to default just before glog calls abort. Let me make it reset only if the handler is what glog installed i.e. FailureSignalHandler.
Diffstat (limited to 'src')
-rw-r--r--src/glog/logging.h.in3
-rw-r--r--src/signalhandler.cc16
-rw-r--r--src/utilities.cc16
-rwxr-xr-xsrc/windows/glog/logging.h3
4 files changed, 31 insertions, 7 deletions
diff --git a/src/glog/logging.h.in b/src/glog/logging.h.in
index 455bd28..b1de2c9 100644
--- a/src/glog/logging.h.in
+++ b/src/glog/logging.h.in
@@ -923,6 +923,9 @@ template <bool>
struct CompileAssert {
};
struct CrashReason;
+
+// Returns true if FailureSignalHandler is installed.
+bool IsFailureSignalHandlerInstalled();
} // namespace glog_internal_namespace_
#define GOOGLE_GLOG_COMPILE_ASSERT(expr, msg) \
diff --git a/src/signalhandler.cc b/src/signalhandler.cc
index cccd800..a7aef8b 100644
--- a/src/signalhandler.cc
+++ b/src/signalhandler.cc
@@ -335,6 +335,22 @@ void FailureSignalHandler(int signal_number,
#endif // HAVE_SIGACTION
+namespace glog_internal_namespace_ {
+
+bool IsFailureSignalHandlerInstalled() {
+#ifdef HAVE_SIGACTION
+ struct sigaction sig_action;
+ memset(&sig_action, 0, sizeof(sig_action));
+ sigemptyset(&sig_action.sa_mask);
+ sigaction(SIGABRT, NULL, &sig_action);
+ if (sig_action.sa_sigaction == &FailureSignalHandler)
+ return true;
+#endif // HAVE_SIGACTION
+ return false;
+}
+
+} // namespace glog_internal_namespace_
+
void InstallFailureSignalHandler() {
#ifdef HAVE_SIGACTION
// Build the sigaction struct.
diff --git a/src/utilities.cc b/src/utilities.cc
index f31c7c7..5c88e58 100644
--- a/src/utilities.cc
+++ b/src/utilities.cc
@@ -138,13 +138,15 @@ static void DumpStackTraceAndExit() {
// TOOD(hamaji): Use signal instead of sigaction?
#ifdef HAVE_SIGACTION
- // Set the default signal handler for SIGABRT, to avoid invoking our
- // own signal handler installed by InstallFailedSignalHandler().
- struct sigaction sig_action;
- memset(&sig_action, 0, sizeof(sig_action));
- sigemptyset(&sig_action.sa_mask);
- sig_action.sa_handler = SIG_DFL;
- sigaction(SIGABRT, &sig_action, NULL);
+ if (IsFailureSignalHandlerInstalled()) {
+ // Set the default signal handler for SIGABRT, to avoid invoking our
+ // own signal handler installed by InstallFailureSignalHandler().
+ struct sigaction sig_action;
+ memset(&sig_action, 0, sizeof(sig_action));
+ sigemptyset(&sig_action.sa_mask);
+ sig_action.sa_handler = SIG_DFL;
+ sigaction(SIGABRT, &sig_action, NULL);
+ }
#endif // HAVE_SIGACTION
abort();
diff --git a/src/windows/glog/logging.h b/src/windows/glog/logging.h
index bab8c61..36107a6 100755
--- a/src/windows/glog/logging.h
+++ b/src/windows/glog/logging.h
@@ -910,6 +910,9 @@ template <bool>
struct CompileAssert {
};
struct CrashReason;
+
+// Returns true if FailureSignalHandler is installed.
+bool IsFailureSignalHandlerInstalled();
} // namespace glog_internal_namespace_
#define GOOGLE_GLOG_COMPILE_ASSERT(expr, msg) \