From cc501868cafa8ec15515cbce50ccb4e7a7e25394 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Aleksey=20Kliger=20=28=CE=BBgeek=29?= Date: Wed, 28 Aug 2019 08:34:30 -0400 Subject: [PATCH] [merp] Initialize hang_watchdog_path earlier; be lax if it's missing (mono/mono#16298) * [merp] Initialize hang_watchdog_path earlier; be lax if it's missing Initialize hang_watchdog_path earlier - not just when ves_icall_Mono_Runtime_EnableCrashReportingLog is called. That function is only expected to be called by apps that explicitly want progress reports from MERP when it's collecting a crash report. But we want the mono-hang-watchdog to execute for all mono crashes (when crash reporting isn't ifdef'd out). Also if we try to exec mono-hang-watchdog and fail for some reason, print a nice message and then exit. We used to call g_assert_not_reached which would kick off another MERP of the _forked child process_ which would then get confused because it really can't run in the forked process at all. Commit migrated from https://github.com/mono/mono/commit/fc21168065af270d1e500fa6be618f8563d0c525 --- src/mono/mono/metadata/icall.c | 2 +- src/mono/mono/metadata/threads-types.h | 2 +- src/mono/mono/metadata/threads.c | 24 ++++++++++++++++++++---- src/mono/mono/mini/mini-posix.c | 1 + 4 files changed, 23 insertions(+), 6 deletions(-) diff --git a/src/mono/mono/metadata/icall.c b/src/mono/mono/metadata/icall.c index e9661ff..b0539aa 100644 --- a/src/mono/mono/metadata/icall.c +++ b/src/mono/mono/metadata/icall.c @@ -6383,7 +6383,7 @@ void ves_icall_Mono_Runtime_EnableCrashReportingLog (const char *directory, MonoError *error) { #ifndef DISABLE_CRASH_REPORTING - mono_threads_summarize_init (directory); + mono_summarize_set_timeline_dir (directory); #endif } diff --git a/src/mono/mono/metadata/threads-types.h b/src/mono/mono/metadata/threads-types.h index ca5be1c..09188fc 100644 --- a/src/mono/mono/metadata/threads-types.h +++ b/src/mono/mono/metadata/threads-types.h @@ -546,7 +546,7 @@ typedef struct { } MonoThreadSummary; void -mono_threads_summarize_init (const char *timeline_dir); +mono_threads_summarize_init (void); gboolean mono_threads_summarize (MonoContext *ctx, gchar **out, MonoStackHash *hashes, gboolean silent, gboolean signal_handler_controller, gchar *mem, size_t provided_size); diff --git a/src/mono/mono/metadata/threads.c b/src/mono/mono/metadata/threads.c index 2ddcccc..f83ceb1 100644 --- a/src/mono/mono/metadata/threads.c +++ b/src/mono/mono/metadata/threads.c @@ -6135,6 +6135,11 @@ mono_set_thread_dump_dir (gchar* dir) { } #ifdef DISABLE_CRASH_REPORTING +void +mono_threads_summarize_init (void) +{ +} + gboolean mono_threads_summarize (MonoContext *ctx, gchar **out, MonoStackHash *hashes, gboolean silent, gboolean signal_handler_controller, gchar *mem, size_t provided_size) { @@ -6201,6 +6206,9 @@ typedef struct { #define HAVE_MONO_SUMMARIZER_SUPERVISOR 1 #endif +static void +summarizer_supervisor_init (void); + typedef struct { MonoSemType supervisor; pid_t pid; @@ -6210,7 +6218,7 @@ typedef struct { #ifndef HAVE_MONO_SUMMARIZER_SUPERVISOR void -mono_threads_summarize_init (const char *timeline_dir) +summarizer_supervisor_init (void) { return; } @@ -6232,11 +6240,12 @@ summarizer_supervisor_end (SummarizerSupervisorState *state) static const char *hang_watchdog_path; void -mono_threads_summarize_init (const char *timeline_dir) +summarizer_supervisor_init (void) { hang_watchdog_path = g_build_filename (mono_get_config_dir (), "..", "bin", "mono-hang-watchdog", NULL); - mono_summarize_set_timeline_dir (timeline_dir); + g_assert (hang_watchdog_path); } + static pid_t summarizer_supervisor_start (SummarizerSupervisorState *state) { @@ -6268,7 +6277,8 @@ summarizer_supervisor_start (SummarizerSupervisorState *state) sprintf (pid_str, "%llu", (uint64_t)state->pid); const char *const args[] = { hang_watchdog_path, pid_str, NULL }; execve (args[0], (char * const*)args, NULL); // run 'mono-hang-watchdog [pid]' - g_assert_not_reached (); + g_async_safe_printf ("Could not exec mono-hang-watchdog, expected on path '%s' (errno %d)\n", hang_watchdog_path, errno); + exit (1); } return pid; @@ -6566,6 +6576,12 @@ mono_threads_summarize_execute_internal (MonoContext *ctx, gchar **out, MonoStac return TRUE; } +void +mono_threads_summarize_init (void) +{ + summarizer_supervisor_init (); +} + gboolean mono_threads_summarize_execute (MonoContext *ctx, gchar **out, MonoStackHash *hashes, gboolean silent, gchar *working_mem, size_t provided_size) { diff --git a/src/mono/mono/mini/mini-posix.c b/src/mono/mono/mini/mini-posix.c index cb61d3a..db13a4b 100644 --- a/src/mono/mono/mini/mini-posix.c +++ b/src/mono/mono/mini/mini-posix.c @@ -1144,6 +1144,7 @@ mono_init_native_crash_info (void) { gdb_path = g_find_program_in_path ("gdb"); lldb_path = g_find_program_in_path ("lldb"); + mono_threads_summarize_init (); } void -- 2.7.4