WPrefs: make crash handler async-signal-safe with write/fsync
Previous version used fprintf which buffers and may not flush before _exit if the crash happened mid-libc. Use write() + fsync() so the backtrace appears in the log even if the crash is deep in a library.
This commit is contained in:
parent
04e6b348b2
commit
3761bef513
|
|
@ -83,8 +83,13 @@ void AddDeadChildHandler(pid_t pid, void (*handler) (void *), void *data)
|
|||
static void crash_handler(int sig) {
|
||||
void *bt[32];
|
||||
int n = backtrace(bt, 32);
|
||||
fprintf(stderr, "\n=== WPrefs CRASH (signal %d) ===\n", sig);
|
||||
const char *msg = "\n=== WPrefs CRASH ===\n";
|
||||
write(STDERR_FILENO, msg, strlen(msg));
|
||||
char sigbuf[32];
|
||||
int slen = snprintf(sigbuf, sizeof(sigbuf), "signal %d\n", sig);
|
||||
write(STDERR_FILENO, sigbuf, slen);
|
||||
backtrace_symbols_fd(bt, n, STDERR_FILENO);
|
||||
fsync(STDERR_FILENO);
|
||||
_exit(1);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue