mirror of
https://github.com/KjellKod/g3log.git
synced 2024-12-12 10:23:50 +01:00
Avoid pending of containerized applications in case of aborting (#481)
Improvement for Docker run C++ applications with g3log * This addresses the case when a PID1 process crashes and the signal handling, goes into multiple or even infinite loops due to subsequent crashes. The PR makes sure to restore all signal handlers to the original signal handling after the first crash is detected. For
This commit is contained in:
parent
4f1224b9d5
commit
5323480780
@ -62,15 +62,16 @@ namespace {
|
|||||||
// ALL thanks to this thread at StackOverflow. Pretty much borrowed from:
|
// ALL thanks to this thread at StackOverflow. Pretty much borrowed from:
|
||||||
// Ref: http://stackoverflow.com/questions/77005/how-to-generate-a-stacktrace-when-my-gcc-c-app-crashes
|
// Ref: http://stackoverflow.com/questions/77005/how-to-generate-a-stacktrace-when-my-gcc-c-app-crashes
|
||||||
void signalHandler(int signal_number, siginfo_t* /*info*/, void* /*unused_context*/) {
|
void signalHandler(int signal_number, siginfo_t* /*info*/, void* /*unused_context*/) {
|
||||||
|
|
||||||
|
using namespace g3::internal;
|
||||||
|
|
||||||
// Only one signal will be allowed past this point
|
// Only one signal will be allowed past this point
|
||||||
if (false == shouldDoExit()) {
|
if (false == shouldDoExit()) {
|
||||||
while (true) {
|
while (shouldBlockForFatalHandling()) {
|
||||||
std::this_thread::sleep_for(std::chrono::seconds(1));
|
std::this_thread::sleep_for(std::chrono::seconds(1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
using namespace g3::internal;
|
|
||||||
{
|
{
|
||||||
const auto dump = stackdump();
|
const auto dump = stackdump();
|
||||||
std::ostringstream fatal_stream;
|
std::ostringstream fatal_stream;
|
||||||
@ -233,7 +234,13 @@ namespace g3 {
|
|||||||
// --- If LOG(FATAL) or CHECK(false) the signal_number will be SIGABRT
|
// --- If LOG(FATAL) or CHECK(false) the signal_number will be SIGABRT
|
||||||
void exitWithDefaultSignalHandler(const LEVELS& level, g3::SignalType fatal_signal_id) {
|
void exitWithDefaultSignalHandler(const LEVELS& level, g3::SignalType fatal_signal_id) {
|
||||||
const int signal_number = static_cast<int>(fatal_signal_id);
|
const int signal_number = static_cast<int>(fatal_signal_id);
|
||||||
restoreSignalHandler(signal_number);
|
|
||||||
|
// Restore all saved signal handlers. If handling a signal which causes exiting
|
||||||
|
// than let the original signal handlers to handle other signals.
|
||||||
|
for (const auto& sig : gSignals) {
|
||||||
|
restoreSignalHandler(sig.first);
|
||||||
|
}
|
||||||
|
|
||||||
std::cerr << "\n\n" << __FUNCTION__ << ":" << __LINE__ << ". Exiting due to " << level.text << ", " << signal_number << " \n\n" << std::flush;
|
std::cerr << "\n\n" << __FUNCTION__ << ":" << __LINE__ << ". Exiting due to " << level.text << ", " << signal_number << " \n\n" << std::flush;
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user