Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[merp] Use a separate process as the hang supervisor.
Fixes mono#15646 macOS does not like signals being sent from the forked supervisor process, possibly towards anywhere but definitely when sent to the parent process. The following message is currently spewed after the supervisor process attempting to send a SIGSEGV to a hanged Mono process: "The process has forked and you cannot use this CoreFoundation functionality safely. You MUST exec()." We follow that direction and introduce a new binary that, when available on the environment's PATH, is used to abort the parent process for us.
- Loading branch information
Showing
5 changed files
with
70 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
SUBDIRS = locale-builder sgen pedump | ||
SUBDIRS = locale-builder sgen pedump mono-hang-watchdog | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
|
||
AM_CPPFLAGS = $(SHARED_CFLAGS) | ||
|
||
if DISABLE_EXECUTABLES | ||
bin_PROGRAMS = | ||
else | ||
bin_PROGRAMS = mono-hang-watchdog | ||
endif | ||
|
||
CFLAGS = $(filter-out @CXX_REMOVE_CFLAGS@, @CFLAGS@) | ||
mono_hang_watchdog_CFLAGS = @CXX_ADD_CFLAGS@ | ||
|
||
mono_hang_watchdog_SOURCES = mono-hang-watchdog.c |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* Given a external process' id as argument, the program waits for a set timeout then attempts to abort that process */ | ||
/* Used by the Mono runtime's crash reporting. */ | ||
|
||
#include <stdlib.h> | ||
#include <stdio.h> | ||
#include <errno.h> | ||
#include <unistd.h> | ||
|
||
#include "config.h" | ||
|
||
#ifdef HAVE_SIGNAL_H | ||
#include <signal.h> | ||
#endif | ||
|
||
#ifndef HAVE_KILL | ||
#error "kill() is not supported by this platform. This tool won't be able to function." | ||
#endif | ||
|
||
#define TIMEOUT_CRASH_REPORTER_FATAL 30 | ||
|
||
static char* program_name; | ||
void program_exit (int exit_code, const char* message); | ||
|
||
void program_exit (int exit_code, const char* message) { | ||
if (message) | ||
printf ("%s\n", message); | ||
printf ("Usage: '%s [pid]'\t\t[pid]: The id for the Mono process\n", program_name); | ||
exit (exit_code); | ||
} | ||
|
||
int main (int argc, char* argv[]) | ||
{ | ||
program_name = argv[0]; | ||
if (argc < 2) | ||
program_exit (-1, "Please provide one argument (pid)"); | ||
errno = 0; | ||
pid_t pid = (pid_t)strtoul (argv[1], NULL, 10); | ||
if (errno) | ||
program_exit (-2, "Invalid pid"); | ||
|
||
sleep (TIMEOUT_CRASH_REPORTER_FATAL); | ||
|
||
/* Abort the process. This isn't suspect to 'pid' referring a wrong new process with the same id: | ||
this process is killed by Mono if Mono doesn't hang */ | ||
printf ("Mono hang watchdog timed out, sending SIGSEGV to %ul\n", pid); | ||
kill (pid, SIGSEGV); | ||
} |