aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/configuration/configuration.cpp3
-rw-r--r--lib/configuration/defaults.h.in1
-rw-r--r--src/main.cpp44
-rw-r--r--vendor.cmake2
4 files changed, 40 insertions, 10 deletions
diff --git a/lib/configuration/configuration.cpp b/lib/configuration/configuration.cpp
index 0898c09..48acecf 100644
--- a/lib/configuration/configuration.cpp
+++ b/lib/configuration/configuration.cpp
@@ -55,6 +55,9 @@ Configuration::Configuration(QObject *parent)
("browser.locale", po::value<std::string>(), "Set Qt localization.")
("browser.translation", po::value<std::string>(), "Set application localization.")
+ ("browser.crash.path", po::value<std::string>()->default_value(CrashdumpPath))
+ ("browser.crash.handler", po::value<std::string>())
+
// main window ui
("mainwindow.height", po::value<int>()->default_value(720))
("mainwindow.width", po::value<int>()->default_value(1280))
diff --git a/lib/configuration/defaults.h.in b/lib/configuration/defaults.h.in
index 8c4b334..f239b14 100644
--- a/lib/configuration/defaults.h.in
+++ b/lib/configuration/defaults.h.in
@@ -2,6 +2,7 @@
#define SMOLBOTE_DEFAULTS
#cmakedefine ConfigPath "@ConfigPath@"
+#cmakedefine CrashdumpPath "@CrashdumpPath@"
#cmakedefine FilterPath "@FilterPath@"
#cmakedefine PluginsPath "@PluginsPath@"
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
diff --git a/vendor.cmake b/vendor.cmake
index 27d9893..183dce9 100644
--- a/vendor.cmake
+++ b/vendor.cmake
@@ -12,6 +12,7 @@ set(poi_name "smolbote")
## Configuration paths, used in lib/configuration/defaults.h.in
if(${CMAKE_SYSTEM_NAME} MATCHES "Windows")
set(ConfigPath "smolbote.ini")
+ set(CrashdumpPath "crashes")
set(FilterPath "hosts")
set(PluginsPath "plugins")
@@ -21,6 +22,7 @@ if(${CMAKE_SYSTEM_NAME} MATCHES "Windows")
set(DownloadsPath "~/Downloads")
else()
set(ConfigPath "~/.config/smolbote/smolbote.cfg")
+ set(CrashdumpPath "~/.config/smolbote/crash.d")
set(FilterPath "~/.config/smolbote/hosts.d")
set(PluginsPath "~/.config/smolbote/plugins.d")