Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stack trace on SIGABRT to catch assertion failures #22097

Merged
merged 1 commit into from
Feb 3, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
35 changes: 24 additions & 11 deletions FWCore/Services/plugins/InitRootHandlers.cc
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ namespace edm {
std::shared_ptr<const void> sigSegvHandler_;
std::shared_ptr<const void> sigIllHandler_;
std::shared_ptr<const void> sigTermHandler_;
std::shared_ptr<const void> sigAbrtHandler_;
};

inline
Expand Down Expand Up @@ -290,6 +291,13 @@ namespace {
}

extern "C" {
void set_default_signals() {
signal(SIGILL, SIG_DFL);
signal(SIGSEGV, SIG_DFL);
signal(SIGBUS, SIG_DFL);
signal(SIGTERM, SIG_DFL);
signal(SIGABRT, SIG_DFL);
}

static int full_write(int fd, const char *text)
{
Expand Down Expand Up @@ -498,6 +506,11 @@ namespace {
signalname = "external termination request";
break;
}
case SIGABRT:
{
signalname = "abort signal";
break;
}
default:
break;
}
Expand Down Expand Up @@ -561,15 +574,16 @@ namespace {
full_cerr_write(signalname);
full_cerr_write("\n");

// For these four known cases, re-raise the signal so get the correct
// For these five known cases, re-raise the signal to get the correct
// exit code.
if ((sig == SIGILL) || (sig == SIGSEGV) || (sig == SIGBUS) || (sig == SIGTERM))
if ((sig == SIGILL) || (sig == SIGSEGV) || (sig == SIGBUS) || (sig == SIGTERM) || (sig == SIGABRT))
{
signal(sig, SIG_DFL);
raise(sig);
}
else
{
set_default_signals();
::abort();
}
}
Expand All @@ -582,18 +596,11 @@ namespace {
raise(sig);

// shouldn't get here
set_default_signals();
::sleep(10);
::abort();
}
}

void set_default_signals() {
signal(SIGILL, SIG_DFL);
signal(SIGSEGV, SIG_DFL);
signal(SIGBUS, SIG_DFL);
signal(SIGTERM, SIG_DFL);
}

} // end of unnamed namespace

namespace edm {
Expand Down Expand Up @@ -700,7 +707,7 @@ namespace edm {
#else
fork();
if (child_stack_ptr) {} // Suppress 'unused variable' warning on non-Linux
if (pid == 0) {edm::service::cmssw_stacktrace(nullptr); ::abort();}
if (pid == 0) { edm::service::cmssw_stacktrace(nullptr); }
#endif
if (pid == -1)
{
Expand All @@ -722,6 +729,8 @@ namespace edm {

int cmssw_stacktrace(void * /*arg*/)
{
set_default_signals();

char *const *argv = edm::service::InitRootHandlers::getPstackArgv();
// NOTE: this is NOT async-signal-safe at CERN's lxplus service.
// CERN uses LD_PRELOAD to replace execv with a function from libsnoopy which
Expand Down Expand Up @@ -793,6 +802,10 @@ namespace edm {
sigTermHandler_ = std::shared_ptr<const void>(nullptr,[](void*) {
installCustomHandler(SIGTERM,sig_abort);
});
installCustomHandler(SIGABRT,sig_dostack_then_abort);
sigAbrtHandler_ = std::shared_ptr<const void>(nullptr,[](void*) {
signal(SIGABRT,SIG_DFL); // release SIGABRT to default
});
}

iReg.watchPreallocate([](edm::service::SystemBounds const& iBounds){
Expand Down