From ffc4a9dc143bc66d2e1fd883e1395a3397a68e9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Ho=C5=99e=C5=88ovsk=C3=BD?= Date: Sat, 14 Jan 2017 15:21:44 +0100 Subject: [PATCH] If we receive a signal, we re-register ALL previous signal handlers. This fixes the case when we pass signal to previously registered handler, and it needs to transform the signal into different one. Still problematic: What if the signal handler we replaced does not terminate the application? We can end up in a weird state and loop forever. Possible solution: Deregister our signal handlers, CALL the previous signal handler explicitly and if control returns, abort. This would however complicate our code quite a bit, as we would have to parse the sigaction we delegate to, decide whether to use signal handler or signal action, etc... --- include/internal/catch_fatal_condition.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/internal/catch_fatal_condition.hpp b/include/internal/catch_fatal_condition.hpp index 895b662d..f99c8f26 100644 --- a/include/internal/catch_fatal_condition.hpp +++ b/include/internal/catch_fatal_condition.hpp @@ -118,10 +118,10 @@ namespace Catch { SignalDefs &def = signalDefs[i]; if (sig == def.id) { name = def.name; - sigaction(def.id, &oldSigActions[i], CATCH_NULL); break; } } + reset(); reportFatal(name, -sig); raise( sig ); } @@ -146,7 +146,7 @@ namespace Catch { ~FatalConditionHandler() { reset(); } - void reset() { + static void reset() { if( isSet ) { // Set signals back to previous values -- hopefully nobody overwrote them in the meantime for( std::size_t i = 0; i < sizeof(signalDefs)/sizeof(SignalDefs); ++i ) {