From 55187c33509ec71549eb756720d8bf042a9dfb0d Mon Sep 17 00:00:00 2001 From: dehnert Date: Sat, 25 Jan 2014 10:34:52 +0100 Subject: [PATCH] Moved to new sigaction API to more reliably catch signals. Former-commit-id: 3ebe52109e307200dcfd7564b7636a2e3ebaf8c2 --- src/storm.cpp | 4 ++-- src/utility/ErrorHandling.h | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/storm.cpp b/src/storm.cpp index 6614172b5..207415e31 100644 --- a/src/storm.cpp +++ b/src/storm.cpp @@ -385,9 +385,9 @@ void checkPrctlFormulae(storm::modelchecker::prctl::AbstractModelChecker * Main entry point. */ int main(const int argc, const char* argv[]) { - // Register a signal handler to catch segfaults and display a backtrace. + // Register a signal handler to catch signals and display a backtrace. installSignalHandler(); - + // Print an information header. printHeader(argc, argv); diff --git a/src/utility/ErrorHandling.h b/src/utility/ErrorHandling.h index 4c87f4d0a..eb06b0afd 100644 --- a/src/utility/ErrorHandling.h +++ b/src/utility/ErrorHandling.h @@ -121,10 +121,30 @@ void signalHandler(int sig) { * Registers some signal handlers so that we can display a backtrace upon erroneuous termination. */ void installSignalHandler() { +#ifndef WINDOWS + struct sigaction sa; + sa.sa_handler = signalHandler; + sigemptyset(&sa.sa_mask); + sa.sa_flags = SA_RESTART; + + if (sigaction(SIGSEGV, &sa, nullptr) == -1) { + std::cerr << "FATAL: Installing a signal handler failed." << std::endl; + } + if (sigaction(SIGABRT, &sa, nullptr) == -1) { + std::cerr << "FATAL: Installing a signal handler failed." << std::endl; + } + if (sigaction(SIGINT, &sa, nullptr) == -1) { + std::cerr << "FATAL: Installing a signal handler failed." << std::endl; + } + if (sigaction(SIGTERM, &sa, nullptr) == -1) { + std::cerr << "FATAL: Installing a signal handler failed." << std::endl; + } +#else signal(SIGSEGV, signalHandler); signal(SIGABRT, signalHandler); signal(SIGINT, signalHandler); signal(SIGTERM, signalHandler); +#endif } #endif /* ERRORHANDLING_H */