diff options
author | Aqua-sama <aqua@iserlohn-fortress.net> | 2018-10-08 13:34:34 +0200 |
---|---|---|
committer | Aqua-sama <aqua@iserlohn-fortress.net> | 2018-10-08 13:34:34 +0200 |
commit | f698922eeea11e4089d746d3529a819897defee4 (patch) | |
tree | 5e84a0193f79029a98f5ccab7c89b336ff4b8b91 /src | |
parent | Fix wiping current directory when deleting off-the-record profiles (diff) | |
download | smolbote-f698922eeea11e4089d746d3529a819897defee4.tar.xz |
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
Diffstat (limited to 'src')
-rw-r--r-- | src/main.cpp | 44 |
1 files changed, 34 insertions, 10 deletions
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 <unistd.h> #include <client/linux/handler/exception_handler.h> // 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<Browser *>(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<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, 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<Configuration> config = std::make_unique<Configuration>(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<std::string>("browser.crash.path").value_or("/tmp").c_str()); + + const auto crashHandler = config->value<std::string>("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 |