diff options
| author | luqiuwen <[email protected]> | 2019-08-20 18:41:44 +0800 |
|---|---|---|
| committer | luqiuwen <[email protected]> | 2019-08-20 18:41:44 +0800 |
| commit | dbe9fba033f1df852a8d105448d7593cc2af1236 (patch) | |
| tree | 313f136fc46cd99d6ed6f2d082b0daa4df2a1ae8 /platform/src/proxy.cpp | |
| parent | 3a99ba9f13666d112fa6c165df3aacef8a01a9b0 (diff) | |
#159 集成Google Breakpad,用于生成minidump便于后期集中收集崩溃。
Diffstat (limited to 'platform/src/proxy.cpp')
| -rw-r--r-- | platform/src/proxy.cpp | 121 |
1 files changed, 116 insertions, 5 deletions
diff --git a/platform/src/proxy.cpp b/platform/src/proxy.cpp index 0406ed6..eca3270 100644 --- a/platform/src/proxy.cpp +++ b/platform/src/proxy.cpp @@ -7,6 +7,7 @@ #include <sys/prctl.h> #include <netinet/in.h> #include <sys/un.h> +#include <sys/stat.h> #include <assert.h> #include <signal.h> #include <stdlib.h> @@ -43,6 +44,11 @@ #include <acceptor_kni_v2.h> #include <watchdog_kni.h> +/* Breakpad */ +#include <client/linux/handler/exception_handler.h> +#include <common/linux/http_upload.h> + + extern struct ssl_policy_enforcer* ssl_policy_enforcer_create(void* logger); extern enum ssl_stream_action ssl_policy_enforce(struct ssl_stream *upstream, void* u_para); @@ -377,6 +383,110 @@ void tfe_proxy_acceptor_init(struct tfe_proxy * proxy, const char * profile) return; } +struct breakpad_instance +{ + unsigned int en_breakpad; + char minidump_dir_prefix[TFE_STRING_MAX]; + google_breakpad::ExceptionHandler * exceptionHandler; + + /* Upload to crash server */ + unsigned int en_breakpad_upload; + char minidump_sentry_upload_url[TFE_STRING_MAX]; + char minidump_sentry_upload_token[TFE_STRING_MAX]; +}; + +static bool tfe_breakpad_dump_callback(const google_breakpad::MinidumpDescriptor& descriptor, + void* context, bool succeeded) +{ + fprintf(stderr, "Crash happened, minidump path: %s\n", descriptor.path()); + return succeeded; +} + +/* COREDUMP GENERATE TEST */ +static void segv_generate() +{ + char * _NULLPTR = NULL; + (*_NULLPTR) = 0; +} + +static void _mkdir(const char *dir) +{ + char tmp[PATH_MAX]; + char * p = NULL; + size_t len; + + snprintf(tmp, sizeof(tmp), "%s", dir); + len = strlen(tmp); + if (tmp[len - 1] == '/') + tmp[len - 1] = 0; + for (p = tmp + 1; *p; p++) + { + if (*p == '/') + { + *p = 0; + mkdir(tmp, S_IRWXU); + *p = '/'; + } + } + mkdir(tmp, S_IRWXU); +} + +struct breakpad_instance * breakpad_init(const char * profile) +{ + struct breakpad_instance * instance = ALLOC(struct breakpad_instance, 1); + assert(instance != nullptr); + + int ret = 0; + MESA_load_profile_uint_def(profile, "system", "enable_breakpad", &instance->en_breakpad, 1); + if (instance->en_breakpad <= 0) + { + TFE_LOG_ERROR(g_default_logger, "Breakpad Crash Reporting System is disabled. "); + return instance; + } + + MESA_load_profile_string_def(profile, "system", "breakpad_minidump_dir", + instance->minidump_dir_prefix, sizeof(instance->minidump_dir_prefix), "/tmp/crashreport"); + + MESA_load_profile_uint_def(profile, "system", "enable_breakpad_upload", + &instance->en_breakpad_upload, 0); + + if (instance->en_breakpad_upload) + { + ret = MESA_load_profile_string_nodef(profile, "system", "breakpad_upload_url", + instance->minidump_sentry_upload_url, sizeof(instance->minidump_sentry_upload_url)); + + if (unlikely(ret < 0)) + { + TFE_LOG_ERROR(g_default_logger, "breakpad_upload_url is necessary, failed. "); + goto errout; + } + + ret = MESA_load_profile_string_nodef(profile, "system", "breakpad_upload_token", + instance->minidump_sentry_upload_token, sizeof(instance->minidump_sentry_upload_token)); + + if (unlikely(ret < 0)) + { + TFE_LOG_ERROR(g_default_logger, "breakpad_upload_token is necessary, failed. "); + goto errout; + } + } + + /* Create the minidump dir if it is not existed */ + _mkdir(instance->minidump_dir_prefix); + + instance->exceptionHandler = new google_breakpad::ExceptionHandler( + google_breakpad::MinidumpDescriptor(instance->minidump_dir_prefix), NULL, + tfe_breakpad_dump_callback, NULL,true, -1); + + TFE_LOG_INFO(g_default_logger, "Breakpad Crash Report is enable. "); + TFE_LOG_INFO(g_default_logger, "Minidump Dir: %s", instance->minidump_dir_prefix); + return instance; + +errout: + if (instance) free(instance); + return NULL; +} + int main(int argc, char * argv[]) { const char * main_profile = "./conf/tfe/tfe.conf"; @@ -398,7 +508,6 @@ int main(int argc, char * argv[]) /* adds locking, only required if accessed from separate threads */ evthread_use_pthreads(); - unsigned int __log_level = RLOG_LV_INFO; MESA_load_profile_uint_def(main_profile, "log", "level", &__log_level, RLOG_LV_INFO); @@ -412,14 +521,17 @@ int main(int argc, char * argv[]) exit(EXIT_FAILURE); } - future_promise_library_init(future_profile); - tango_cache_global_init(); - /* PROXY INSTANCE */ g_default_proxy = ALLOC(struct tfe_proxy, 1); assert(g_default_proxy); strcpy(g_default_proxy->name, "tfe3a"); + g_default_proxy->breakpad = breakpad_init(main_profile); + CHECK_OR_EXIT(g_default_proxy->breakpad, "Failed at starting breakpad. Exit."); + + future_promise_library_init(future_profile); + tango_cache_global_init(); + /* CONFIG */ ret = tfe_proxy_config(g_default_proxy, main_profile); CHECK_OR_EXIT(ret == 0, "Failed at loading profile %s, Exit.", main_profile); @@ -482,7 +594,6 @@ int main(int argc, char * argv[]) TFE_LOG_ERROR(g_default_logger, "Tango Frontend Engine initialized. "); event_base_dispatch(g_default_proxy->evbase); - return 0; } |
