diff options
-rw-r--r-- | src/crashhandler.cpp | 38 | ||||
-rw-r--r-- | src/crashhandler.h | 34 | ||||
-rw-r--r-- | src/main.cpp | 40 | ||||
-rw-r--r-- | src/meson.build | 2 |
4 files changed, 76 insertions, 38 deletions
diff --git a/src/crashhandler.cpp b/src/crashhandler.cpp new file mode 100644 index 0000000..194d04b --- /dev/null +++ b/src/crashhandler.cpp @@ -0,0 +1,38 @@ +/* + * 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" + +#ifdef BREAKPAD + +//#ifdef Q_OS_LINUX +#include <unistd.h> +//#endif // Q_OS_LINUX + + +bool CrashHandler::dumpCallback(const google_breakpad::MinidumpDescriptor &descriptor, void *context, bool succeeded) +{ + printf("Dump path: %s\n", descriptor.path()); + + auto *ctx = static_cast<BreakpadContext *>(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_Version, descriptor.path()); + execlp("/bin/sh", "/bin/sh", "-c", buffer, (char *)nullptr); + } + } + } + + return succeeded; +} +#endif diff --git a/src/crashhandler.h b/src/crashhandler.h new file mode 100644 index 0000000..e7f7fa1 --- /dev/null +++ b/src/crashhandler.h @@ -0,0 +1,34 @@ +/* + * 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 + */ + +#ifndef SMOLBOTE_CRASHHANDLER_H +#define SMOLBOTE_CRASHHANDLER_H + +#ifdef BREAKPAD +//#ifdef Q_OS_LINUX +#include <client/linux/handler/exception_handler.h> +#endif + +class CrashHandler +{ + +public: + struct BreakpadContext { + char *handler = nullptr; + }; + + // bool filter_callback (void*) + // --> true: continue processing and write a minidump + +#ifdef BREAKPAD + static bool dumpCallback(const google_breakpad::MinidumpDescriptor &descriptor, void *context, bool succeeded); +#endif + +}; // CrashHandler + +#endif // SMOLBOTE_CRASHHANDLER_H 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 <QFile> #include <QLibraryInfo> @@ -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 <client/linux/handler/exception_handler.h> -#include <unistd.h> - -// 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<BreakpadContext *>(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<std::string>("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<std::string>("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()); diff --git a/src/meson.build b/src/meson.build index ec5f873..367a7f9 100644 --- a/src/meson.build +++ b/src/meson.build @@ -25,7 +25,7 @@ poi = executable(get_option('poiName'), install: true, dependencies: [dep_qt5, dep_boost, dep_SingleApplication, dep_genheaders, optdepends, dep_about, dep_addressbar, dep_bookmarks, dep_configuration, dep_downloads, dep_urlfilter, dep_web], include_directories: [include], - sources: ['main.cpp', 'builtins.cpp', poi_moc, + sources: ['main.cpp', 'builtins.cpp', 'crashhandler.cpp', poi_moc, 'browser.cpp', 'util.cpp', 'util.h', |