From 3761bef513dbb6852cb6c69b76dc221775c30d7b Mon Sep 17 00:00:00 2001 From: Window Maker Date: Sun, 24 May 2026 18:01:43 +0200 Subject: [PATCH] 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. --- WPrefs.app/main.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/WPrefs.app/main.c b/WPrefs.app/main.c index 1ad2edb..fb0d745 100644 --- a/WPrefs.app/main.c +++ b/WPrefs.app/main.c @@ -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); }