Commit cda16b34 authored by Yoshisato Yanagisawa's avatar Yoshisato Yanagisawa

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.
parent f46e0745
...@@ -923,6 +923,9 @@ template <bool> ...@@ -923,6 +923,9 @@ template <bool>
struct CompileAssert { struct CompileAssert {
}; };
struct CrashReason; struct CrashReason;
// Returns true if FailureSignalHandler is installed.
bool IsFailureSignalHandlerInstalled();
} // namespace glog_internal_namespace_ } // namespace glog_internal_namespace_
#define GOOGLE_GLOG_COMPILE_ASSERT(expr, msg) \ #define GOOGLE_GLOG_COMPILE_ASSERT(expr, msg) \
......
...@@ -335,6 +335,22 @@ void FailureSignalHandler(int signal_number, ...@@ -335,6 +335,22 @@ void FailureSignalHandler(int signal_number,
#endif // HAVE_SIGACTION #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() { void InstallFailureSignalHandler() {
#ifdef HAVE_SIGACTION #ifdef HAVE_SIGACTION
// Build the sigaction struct. // Build the sigaction struct.
......
...@@ -138,13 +138,15 @@ static void DumpStackTraceAndExit() { ...@@ -138,13 +138,15 @@ static void DumpStackTraceAndExit() {
// TOOD(hamaji): Use signal instead of sigaction? // TOOD(hamaji): Use signal instead of sigaction?
#ifdef HAVE_SIGACTION #ifdef HAVE_SIGACTION
// Set the default signal handler for SIGABRT, to avoid invoking our if (IsFailureSignalHandlerInstalled()) {
// own signal handler installed by InstallFailedSignalHandler(). // Set the default signal handler for SIGABRT, to avoid invoking our
struct sigaction sig_action; // own signal handler installed by InstallFailureSignalHandler().
memset(&sig_action, 0, sizeof(sig_action)); struct sigaction sig_action;
sigemptyset(&sig_action.sa_mask); memset(&sig_action, 0, sizeof(sig_action));
sig_action.sa_handler = SIG_DFL; sigemptyset(&sig_action.sa_mask);
sigaction(SIGABRT, &sig_action, NULL); sig_action.sa_handler = SIG_DFL;
sigaction(SIGABRT, &sig_action, NULL);
}
#endif // HAVE_SIGACTION #endif // HAVE_SIGACTION
abort(); abort();
......
...@@ -910,6 +910,9 @@ template <bool> ...@@ -910,6 +910,9 @@ template <bool>
struct CompileAssert { struct CompileAssert {
}; };
struct CrashReason; struct CrashReason;
// Returns true if FailureSignalHandler is installed.
bool IsFailureSignalHandlerInstalled();
} // namespace glog_internal_namespace_ } // namespace glog_internal_namespace_
#define GOOGLE_GLOG_COMPILE_ASSERT(expr, msg) \ #define GOOGLE_GLOG_COMPILE_ASSERT(expr, msg) \
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment