From 07b70bc388369f843fb07e721ec6b3790144dcc8 Mon Sep 17 00:00:00 2001 From: Nuno Luz Date: Tue, 20 Apr 2021 11:23:30 +0100 Subject: [PATCH] STAFF-120395: add app relaunch on crash (#4) * STAFF-120395: add app relaunch on crash * STAFF-120395: update to td version of crashpad * STAFF-120395: add ability to pass argv to crashpad relaunch * STAFF-120395: add ability to pass argv to crashpad relaunch 2 * STAFF-120395: update crashpad * STAFF-120395: update crashpad * STAFF-120395: fix relaunch annotation * STAFF-120395: update crashpad * STAFF-120395: update crashpad * update crashpad * update crashpad * update crashpad --- .gitmodules | 4 ++-- external/breakpad | 2 +- external/crashpad | 2 +- external/libunwindstack-ndk | 2 +- external/third_party/lss | 2 +- include/sentry.h | 13 +++++++++++++ src/backends/sentry_backend_crashpad.cpp | 24 ++++++++++++++++++++++++ src/sentry_options.c | 15 +++++++++++++++ src/sentry_options.h | 1 + 9 files changed, 59 insertions(+), 6 deletions(-) diff --git a/.gitmodules b/.gitmodules index f8c2d9e87..fd6a68c45 100644 --- a/.gitmodules +++ b/.gitmodules @@ -9,5 +9,5 @@ url = https://chromium.googlesource.com/linux-syscall-support [submodule "external/crashpad"] path = external/crashpad - url = https://github.com/getsentry/crashpad.git - branch = getsentry + url = https://github.com/mystaff/crashpad.git + branch = timedoctor diff --git a/external/breakpad b/external/breakpad index 78180df60..77bf06f4d 160000 --- a/external/breakpad +++ b/external/breakpad @@ -1 +1 @@ -Subproject commit 78180df608bf0d0181fd1b096ec98d1354b640d0 +Subproject commit 77bf06f4dee17f3b9021875a0647752c62452aaf diff --git a/external/crashpad b/external/crashpad index fba97d0d5..d11e19648 160000 --- a/external/crashpad +++ b/external/crashpad @@ -1 +1 @@ -Subproject commit fba97d0d5556ebd2dc94d183304ff990d2462820 +Subproject commit d11e196480ef5ab4a521e7996fe855626dee120c diff --git a/external/libunwindstack-ndk b/external/libunwindstack-ndk index 1cc38e715..abcfef9e7 160000 --- a/external/libunwindstack-ndk +++ b/external/libunwindstack-ndk @@ -1 +1 @@ -Subproject commit 1cc38e71516f353c947d0cb0d69e10e15400c937 +Subproject commit abcfef9e77ec6c8b0fe179591e354b8509727686 diff --git a/external/third_party/lss b/external/third_party/lss index 171a36a8e..29f7c7e01 160000 --- a/external/third_party/lss +++ b/external/third_party/lss @@ -1 +1 @@ -Subproject commit 171a36a8e0d1e456f63d342a09f811f9273a64af +Subproject commit 29f7c7e018f4ce706a709f0b0afbf8bacf869480 diff --git a/include/sentry.h b/include/sentry.h index 6b2af7f94..eff88e790 100644 --- a/include/sentry.h +++ b/include/sentry.h @@ -708,6 +708,19 @@ SENTRY_API void sentry_options_set_release( */ SENTRY_API const char *sentry_options_get_release(const sentry_options_t *opts); +/** + * Sets the args passed to the process when relaunching after a crash. + * Args must be in 1 single string separated by | + */ +SENTRY_API void sentry_options_set_relaunch_argv( + sentry_options_t *opts, const char *relaunch_argv); + +/** + * Gets the args passsed to the process when relaunching after a crash. + */ +SENTRY_API const char *sentry_options_get_relaunch_argv( + const sentry_options_t *opts); + /** * Sets the environment. */ diff --git a/src/backends/sentry_backend_crashpad.cpp b/src/backends/sentry_backend_crashpad.cpp index 04f71b6bd..6ec8b3ab6 100644 --- a/src/backends/sentry_backend_crashpad.cpp +++ b/src/backends/sentry_backend_crashpad.cpp @@ -39,6 +39,22 @@ extern "C" { # pragma warning(pop) #endif +#if defined(SENTRY_PLATFORM_WINDOWS) +# include +static int +td__getpid() +{ + return _getpid(); +} +#else +# include +static int +td__getpid() +{ + return getpid(); +} +#endif + extern "C" { #ifdef SENTRY_PLATFORM_LINUX @@ -192,6 +208,14 @@ sentry__crashpad_backend_startup( std::map annotations; std::vector attachments; + sentry_path_t *current_exe = sentry__path_current_exe(); + if (current_exe && options->relaunch_argv) { + annotations["__td-crashed-pid"] = std::to_string(td__getpid()); + annotations["__td-relaunch-path"] = std::string(current_exe->path); + annotations["__td-relaunch-argv"] = std::string(options->relaunch_argv); + sentry__path_free(current_exe); + } + // register attachments for (sentry_attachment_t *attachment = options->attachments; attachment; attachment = attachment->next) { diff --git a/src/sentry_options.c b/src/sentry_options.c index 8468c2c58..13f3de6f4 100644 --- a/src/sentry_options.c +++ b/src/sentry_options.c @@ -74,6 +74,7 @@ sentry_options_free(sentry_options_t *opts) } sentry__dsn_decref(opts->dsn); sentry_free(opts->release); + sentry_free(opts->relaunch_argv); sentry_free(opts->environment); sentry_free(opts->dist); sentry_free(opts->http_proxy); @@ -155,6 +156,20 @@ sentry_options_get_release(const sentry_options_t *opts) return opts->release; } +void +sentry_options_set_relaunch_argv( + sentry_options_t *opts, const char *relaunch_argv) +{ + sentry_free(opts->relaunch_argv); + opts->relaunch_argv = sentry__string_clone(relaunch_argv); +} + +const char * +sentry_options_get_relaunch_argv(const sentry_options_t *opts) +{ + return opts->relaunch_argv; +} + void sentry_options_set_environment(sentry_options_t *opts, const char *environment) { diff --git a/src/sentry_options.h b/src/sentry_options.h index 09b727522..d86e55111 100644 --- a/src/sentry_options.h +++ b/src/sentry_options.h @@ -37,6 +37,7 @@ typedef struct sentry_options_s { char *http_proxy; char *ca_certs; char *transport_thread_name; + char *relaunch_argv; sentry_path_t *database_path; sentry_path_t *handler_path; sentry_logger_t logger;