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.
This commit is contained in:
Yoshisato Yanagisawa 2015-11-18 15:40:12 +09:00
parent f46e0745a8
commit cda16b3443
4 changed files with 31 additions and 7 deletions

View File

@ -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) \

View File

@ -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.

View File

@ -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();

View File

@ -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) \