Update Client.cpp, Log.cpp, and 4 more files...

This commit is contained in:
Andrea Cavalli 2020-10-12 19:50:17 +02:00
parent d3b2f81269
commit 85bf271fb8
6 changed files with 32 additions and 4 deletions

View File

@ -20,6 +20,10 @@
#include "td/utils/port/RwMutex.h"
#include "td/utils/port/thread.h"
#ifndef _WIN32
#include "td/utils/death_handler.h"
#endif
#include <algorithm>
#include <atomic>
#include <memory>
@ -616,6 +620,9 @@ Client::Client(Client &&other) = default;
Client &Client::operator=(Client &&other) = default;
ClientManager::ClientManager() : impl_(std::make_unique<Impl>()) {
#ifndef _WIN32
Debug::DeathHandler dh;
#endif
}
ClientManager::ClientId ClientManager::create_client() {

View File

@ -67,4 +67,9 @@ void Log::set_fatal_error_callback(FatalErrorCallbackPtr callback) {
}
}
void Log::set_disable_death_handler(bool disabled) {
std::lock_guard<std::mutex> lock(log_mutex);
set_log_disable_death_handler(disabled);
}
} // namespace td

View File

@ -80,6 +80,8 @@ class Log {
* Pass nullptr to remove the callback.
*/
static void set_fatal_error_callback(FatalErrorCallbackPtr callback);
static void set_disable_death_handler(bool disabled);
};
} // namespace td

View File

@ -278,10 +278,16 @@ LogInterface *log_interface = default_log_interface;
static OnFatalErrorCallback on_fatal_error_callback = nullptr;
static bool use_death_handler = true;
void set_log_fatal_error_callback(OnFatalErrorCallback callback) {
on_fatal_error_callback = callback;
}
void set_log_disable_death_handler(bool disabled) {
use_death_handler = !disabled;
}
void process_fatal_error(CSlice message) {
auto callback = on_fatal_error_callback;
if (callback) {
@ -292,7 +298,12 @@ void process_fatal_error(CSlice message) {
std::abort();
#else
struct sigaction sa{};
Debug::DeathHandler::HandleSignal(SIGABRT, &sa, nullptr);
if (use_death_handler) {
Debug::DeathHandler::HandleSignal(SIGABRT, &sa, nullptr);
} else {
std::abort();
}
#endif
#else
std::abort();

View File

@ -199,6 +199,7 @@ extern LogInterface *log_interface;
using OnFatalErrorCallback = void (*)(CSlice message);
void set_log_fatal_error_callback(OnFatalErrorCallback callback);
void set_log_disable_death_handler(bool disabled);
[[noreturn]] void process_fatal_error(CSlice message);

View File

@ -10,6 +10,7 @@
#include "td/utils/OptionParser.h"
#include "td/utils/Slice.h"
#include "td/utils/tests.h"
#include "td/telegram/Log.h"
#ifndef _WIN32
#include "td/utils/death_handler.h"
@ -20,9 +21,10 @@
#endif
int main(int argc, char **argv) {
#ifndef _WIN32
Debug::DeathHandler dh;
#endif
#ifndef _WIN32
td::Log::set_disable_death_handler(true);
Debug::DeathHandler dh;
#endif
td::init_openssl_threads();
td::TestsRunner &runner = td::TestsRunner::get_default();