From 4058e117ca775756f6e99c25c4f2e5bec8cf8175 Mon Sep 17 00:00:00 2001 From: fredzio Date: Sat, 17 Apr 2021 09:12:03 +0200 Subject: [PATCH] Don't clobber game log file when we collect a stack trace. When the crash catcher catch a signal it forks to collect data about its parent. In the process the child reinitialize the log file, which ends up empty. --- components/crashcatcher/crashcatcher.cpp | 2 +- components/crashcatcher/crashcatcher.hpp | 2 ++ components/debug/debugging.cpp | 7 ++++++- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/components/crashcatcher/crashcatcher.cpp b/components/crashcatcher/crashcatcher.cpp index e0a5c964fa..86571e1e3a 100644 --- a/components/crashcatcher/crashcatcher.cpp +++ b/components/crashcatcher/crashcatcher.cpp @@ -43,7 +43,7 @@ namespace bfs = boost::filesystem; #include #endif -static const char crash_switch[] = "--cc-handle-crash"; +#include "crashcatcher.hpp" static const char fatal_err[] = "\n\n*** Fatal Error ***\n"; static const char pipe_err[] = "!!! Failed to create pipe\n"; diff --git a/components/crashcatcher/crashcatcher.hpp b/components/crashcatcher/crashcatcher.hpp index fd8f0d1542..b693ccae43 100644 --- a/components/crashcatcher/crashcatcher.hpp +++ b/components/crashcatcher/crashcatcher.hpp @@ -9,6 +9,8 @@ #define USE_CRASH_CATCHER 0 #endif +constexpr char crash_switch[] = "--cc-handle-crash"; + #if USE_CRASH_CATCHER extern void crashCatcherInstall(int argc, char **argv, const std::string &crashLogPath); #else diff --git a/components/debug/debugging.cpp b/components/debug/debugging.cpp index e9bcf8ad75..0e372942f2 100644 --- a/components/debug/debugging.cpp +++ b/components/debug/debugging.cpp @@ -179,7 +179,12 @@ int wrapApplication(int (*innerApplication)(int argc, char *argv[]), int argc, c std::cerr.rdbuf (&sb); #else // Redirect cout and cerr to the log file - logfile.open (boost::filesystem::path(cfgMgr.getLogPath() / logName)); + // If we are collecting a stack trace, append to existing log file + std::ios_base::openmode mode = std::ios::out; + if(argc == 2 && strcmp(argv[1], crash_switch) == 0) + mode |= std::ios::app; + + logfile.open (boost::filesystem::path(cfgMgr.getLogPath() / logName), mode); coutsb.open (Debug::Tee(logfile, oldcout)); cerrsb.open (Debug::Tee(logfile, oldcerr));