[merp] Initialize hang_watchdog_path earlier; be lax if it's missing (mono/mono#16298)
authorAleksey Kliger (λgeek) <alklig@microsoft.com>
Wed, 28 Aug 2019 12:34:30 +0000 (08:34 -0400)
committerGitHub <noreply@github.com>
Wed, 28 Aug 2019 12:34:30 +0000 (08:34 -0400)
* [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
src/mono/mono/metadata/threads-types.h
src/mono/mono/metadata/threads.c
src/mono/mono/mini/mini-posix.c

index e9661ff..b0539aa 100644 (file)
@@ -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
 }
 
index ca5be1c..09188fc 100644 (file)
@@ -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);
index 2ddcccc..f83ceb1 100644 (file)
@@ -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)
 {
index cb61d3a..db13a4b 100644 (file)
@@ -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