Use sigaction, _exit if anything fails

This commit is contained in:
Andrew Noyes 2020-03-20 12:50:31 -07:00
parent bed5d4733a
commit c0bae64105

View File

@ -2787,8 +2787,25 @@ void crashHandler(int sig) {
fprintf(stderr, "SIGNAL: %s (%d)\n", strsignal(sig), sig);
fprintf(stderr, "Trace: %s\n", backtrace.c_str());
signal(sig, SIG_DFL);
kill(getpid(), sig);
struct sigaction sa;
sa.sa_handler = SIG_DFL;
if (sigemptyset(&sa.sa_mask)) {
int err = errno;
fprintf(stderr, "sigemptyset failed: %s\n", strerror(err));
_exit(sig + 128);
}
sa.sa_flags = 0;
if (sigaction(sig, &sa, NULL)) {
int err = errno;
fprintf(stderr, "sigaction failed: %s\n", strerror(err));
_exit(sig + 128);
}
if (kill(getpid(), sig)) {
int err = errno;
fprintf(stderr, "kill failed: %s\n", strerror(err));
_exit(sig + 128);
}
// Rely on kill to end the process
#else
// No crash handler for other platforms!
#endif