From a118a7b6de720906e383d52aee056fbe55eb680d Mon Sep 17 00:00:00 2001 From: Aqua-sama Date: Sat, 8 Dec 2018 12:41:18 +0100 Subject: Split crash handler code off main --- src/main.cpp | 40 +++------------------------------------- 1 file changed, 3 insertions(+), 37 deletions(-) (limited to 'src/main.cpp') diff --git a/src/main.cpp b/src/main.cpp index 2a0d355..e718722 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -13,6 +13,7 @@ #include "session/session.h" #include "session/sessiondialog.h" #include "util.h" +#include "crashhandler.h" #include "version.h" #include #include @@ -34,41 +35,6 @@ #error "You have enabled Breakpad integration, but Breakpad was not found." #endif -#ifdef CONFIG_USEBREAKPAD - -struct BreakpadContext { - char *handler = nullptr; -}; - -#ifdef Q_OS_LINUX -#include -#include - -// bool filter_callback (void*) -// --> true: continue processing and write a minidump - -static bool dumpCallback(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 != nullptr) { - // fork and run 'handler master:commit path.dmp' - pid_t pid = fork(); - if(pid == 0) { - char buffer[256]; - snprintf(buffer, 256, "%s %s %s", ctx->handler, poi_Build, descriptor.path()); - execlp("/bin/sh", "/bin/sh", "-c", buffer, (char *)nullptr); - } - } - } - - return succeeded; -} -#endif // Q_OS_LINUX -#endif // CONFIG_USEBREAKPAD - int main(int argc, char **argv) { // a beautiful hack to be able to write to stdout on Windows @@ -140,7 +106,7 @@ int main(int argc, char **argv) const std::string crashpath = config->value("browser.crash.path").value_or("/tmp"); assert(!crashpath.empty()); - BreakpadContext ctx; + CrashHandler::BreakpadContext ctx; google_breakpad::MinidumpDescriptor descriptor(crashpath.c_str()); const auto crashHandler = config->value("browser.crash.handler"); @@ -152,7 +118,7 @@ int main(int argc, char **argv) } // minidump descriptor, filter callback, minidump callback, callback_context, install handler, server_fd - google_breakpad::ExceptionHandler eh(descriptor, nullptr, dumpCallback, &ctx, true, -1); + google_breakpad::ExceptionHandler eh(descriptor, nullptr, CrashHandler::dumpCallback, &ctx, true, -1); #ifdef QT_DEBUG qDebug("Installed breakpad exception handler (path=%s)", crashpath.c_str()); -- cgit v1.2.1