/* * This file is part of smolbote. It's copyrighted by the contributors recorded * in the version control history of the file, available from its original * location: https://neueland.iserlohn-fortress.net/gitea/aqua/smolbote * * SPDX-License-Identifier: GPL-3.0 */ #include "crashhandler.h" #include "version.h" #include #include #include // bool filter_callback (void*) // --> true: continue processing and write a minidump static bool minidumpCb(const google_breakpad::MinidumpDescriptor &descriptor, void *context, bool succeeded) { printf("Dump path: %s\n", descriptor.path()); auto *ctx = static_cast(context); if(ctx != nullptr) { if(!ctx->handler.empty()) { // fork and run 'handler master:commit path.dmp' pid_t pid = fork(); if(pid == 0) { // pathname program argument ... nullptr execlp(ctx->handler.c_str(), ctx->handler.c_str(), "--crashd", ctx->dumppath.c_str(), "-c", descriptor.path(), poi_Version, (char *)nullptr); } } } return succeeded; } bool CrashHandler::install_handler(CrashHandler::Context &ctx) { if(ctx.dumppath.empty()) return false; // Disable Chromium's crash handler so breakpad can capture crashes instead. // This has to be done before QtWebEngine gets initialized. const auto chromiumFlags = qgetenv("QTWEBENGINE_CHROMIUM_FLAGS"); if(!chromiumFlags.contains("disable-in-process-stack-traces")) { qputenv("QTWEBENGINE_CHROMIUM_FLAGS", chromiumFlags + " --disable-in-process-stack-traces"); } google_breakpad::MinidumpDescriptor descriptor(ctx.dumppath.c_str()); // minidump descriptor, filter callback, minidump callback, callback_context, install handler, server_fd new google_breakpad::ExceptionHandler(descriptor, nullptr, minidumpCb, &ctx, true, -1); return true; }