14
static void sigsegv(int, siginfo_t *info, void*)
19
"\nArmory has crashed. Please provide the following "
20
"in your bug report:\n"
21
"Failed to dereference address ";
22
::write(stderr, e1, sizeof(e1)-1);
27
int num = snprintf(addr, sizeof(addr), "%p", info->si_addr);
28
::write(stderr, addr, num);
29
::write(stderr, "\n", 1);
33
int n = backtrace(bt_buffer, sizeof(bt_buffer)/sizeof(bt_buffer[0]));
35
backtrace_symbols_fd(bt_buffer, n, stderr);
37
// allow crash again, so that the user sees the pretty "Segmentation fault"
40
// now try to write that same error to the log file
41
// since Log::filename accesses what might be corrupt memory,
42
// we have to repeat some of the stuff above. So it can crash
43
// here and we still get a log on stderr
44
int log = open(Log::filename().c_str(), O_APPEND, O_WRONLY);
50
"Failed to dereference address ";
51
::write(log, e1, sizeof(e1)-1);
55
int num = snprintf(addr, sizeof(addr), "%p", info->si_addr);
56
::write(log, addr, num);
57
::write(log, "\n", 1);
59
backtrace_symbols_fd(bt_buffer, n, log);
63
// now actually crash again so the user sees the error
69
static void installSignalHandler()
71
static bool installed=false;
76
struct sigaction action;
77
action.sa_sigaction = sigsegv;
78
action.sa_flags = SA_SIGINFO | SA_NODEFER;
80
sigaction(SIGSEGV, &action, 0);
90
installSignalHandler();
97
// kate: indent-width 3; replace-tabs on;