From 613bec4884b25b4829b58b54de57806d882186d5 Mon Sep 17 00:00:00 2001 From: Tudor Bosman Date: Tue, 10 Dec 2013 14:41:28 -0800 Subject: [PATCH] Separate installFatalSignalCallbacks Summary: We want to install the signal handler first and then give users an opportunity to add their callbacks. Test Plan: built Reviewed By: lucian@fb.com FB internal diff: D1092083 @override-unit-failures --- folly/experimental/symbolizer/SignalHandler.cpp | 8 +++++--- folly/experimental/symbolizer/SignalHandler.h | 9 +++++++-- folly/experimental/symbolizer/Symbolizer.cpp | 4 ++-- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/folly/experimental/symbolizer/SignalHandler.cpp b/folly/experimental/symbolizer/SignalHandler.cpp index dc34c235..5eb01405 100644 --- a/folly/experimental/symbolizer/SignalHandler.cpp +++ b/folly/experimental/symbolizer/SignalHandler.cpp @@ -77,7 +77,7 @@ void FatalSignalCallbackRegistry::markInstalled() { void FatalSignalCallbackRegistry::run() { if (!installed_) { - return; // Shouldn't happen + return; } for (auto& fn : handlers_) { @@ -251,6 +251,10 @@ void addFatalSignalCallback(SignalCallback cb) { gFatalSignalCallbackRegistry->add(cb); } +void installFatalSignalCallbacks() { + gFatalSignalCallbackRegistry->markInstalled(); +} + namespace { std::atomic gAlreadyInstalled; @@ -263,8 +267,6 @@ void installFatalSignalHandler() { return; } - gFatalSignalCallbackRegistry->markInstalled(); - struct sigaction sa; memset(&sa, 0, sizeof(sa)); sigemptyset(&sa.sa_mask); diff --git a/folly/experimental/symbolizer/SignalHandler.h b/folly/experimental/symbolizer/SignalHandler.h index febe6e66..65cab866 100644 --- a/folly/experimental/symbolizer/SignalHandler.h +++ b/folly/experimental/symbolizer/SignalHandler.h @@ -30,7 +30,6 @@ namespace folly { namespace symbolizer { */ void installFatalSignalHandler(); - /** * Add a callback to be run when receiving a fatal signal. They will also * be called by LOG(FATAL) and abort() (as those raise SIGABRT internally). @@ -39,11 +38,17 @@ void installFatalSignalHandler(); * LOG(...) or printf or malloc / new or doing anything even remotely fun. * * All these fatal callback must be added before calling - * installFatalSignalHandler(). + * installFatalSignalCallbacks(), below. */ typedef void (*SignalCallback)(void); void addFatalSignalCallback(SignalCallback callback); +/** + * Install the fatal signal callbacks; fatal signals will call these + * callbacks in the order in which they were added. + */ +void installFatalSignalCallbacks(); + }} // namespaces diff --git a/folly/experimental/symbolizer/Symbolizer.cpp b/folly/experimental/symbolizer/Symbolizer.cpp index 2719caaa..d0f0c165 100644 --- a/folly/experimental/symbolizer/Symbolizer.cpp +++ b/folly/experimental/symbolizer/Symbolizer.cpp @@ -269,12 +269,12 @@ void SymbolizePrinter::print(uintptr_t address, const SymbolizedFrame& frame) { char mangledBuf[1024]; if (!frame.found) { - doPrint(" (not found)\n"); + doPrint(" (not found)"); return; } if (frame.name.empty()) { - doPrint(" (unknown)\n"); + doPrint(" (unknown)"); } else if (frame.name.size() >= sizeof(mangledBuf)) { doPrint(" "); doPrint(frame.name); -- 2.34.1