From f698922eeea11e4089d746d3529a819897defee4 Mon Sep 17 00:00:00 2001 From: Aqua-sama Date: Mon, 8 Oct 2018 13:34:34 +0200 Subject: Disable Chromium crash handler Chromium's crash handler prevents breakpad from creating crashdumps. - add browser.crash.path: set minidump location - add browser.crash.handler: call this program after crashing --- src/main.cpp | 44 ++++++++++++++++++++++++++++++++++---------- 1 file changed, 34 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/main.cpp b/src/main.cpp index 9ae0dc1..6940856 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -23,7 +23,13 @@ #endif #ifdef BreakpadEnabled + +struct BreakpadContext { + char *handler = nullptr; +}; + #ifdef Q_OS_LINUX +#include #include // bool filter_callback (void*) @@ -33,14 +39,16 @@ static bool dumpCallback(const google_breakpad::MinidumpDescriptor &descriptor, { printf("Dump path: %s\n", descriptor.path()); - if(auto *app = static_cast(context); app != nullptr) { - auto session = app->session(); - QJsonDocument doc(session); - QFile sessionFile(QString("%1.json").arg(QString::fromStdString(descriptor.path()))); - if(sessionFile.open(QIODevice::WriteOnly | QIODevice::Text)) { - sessionFile.write(qUtf8Printable(doc.toJson())); - sessionFile.flush(); - sessionFile.close(); + 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, SMOLBOTE_BUILD, descriptor.path()); + execlp("/bin/sh", "/bin/sh", "-c", buffer, (char *)nullptr); + } } } @@ -59,6 +67,13 @@ int main(int argc, char **argv) } #endif + // 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"); + } + // create and load configuration std::unique_ptr config = std::make_unique(nullptr); #ifdef QT_DEBUG @@ -133,10 +148,19 @@ int main(int argc, char **argv) app.setAttribute(Qt::AA_DontCreateNativeWidgetSiblings, true); #ifdef BreakpadEnabled - google_breakpad::MinidumpDescriptor descriptor("/tmp"); + BreakpadContext ctx; + google_breakpad::MinidumpDescriptor descriptor(config->value("browser.crash.path").value_or("/tmp").c_str()); + + const auto crashHandler = config->value("browser.crash.handler"); + if(crashHandler) { + const int length = crashHandler.value().length() + 1; + ctx.handler = new char[length]; + crashHandler.value().copy(ctx.handler, length - 1); + ctx.handler[length - 1] = '\0'; + } // minidump descriptor, filter callback, minidump callback, callback_context, install handler, server_fd - google_breakpad::ExceptionHandler eh(descriptor, nullptr, dumpCallback, &app, true, -1); + google_breakpad::ExceptionHandler eh(descriptor, nullptr, dumpCallback, &ctx, true, -1); #endif // translator -- cgit v1.2.1