Fix write() return value warnings using compiler pragmas in signal_handler

This commit is contained in:
Your Name
2025-08-17 12:22:24 -04:00
parent 44c7737fa7
commit 46977c882c
2 changed files with 13 additions and 7 deletions

View File

@@ -1 +1 @@
0.1.31
0.1.32

View File

@@ -321,14 +321,18 @@ static void signal_handler(int sig) {
// Log the signal (async-signal-safe functions only)
const char* sig_name = get_signal_name(sig);
// Write to stderr using async-signal-safe functions (ignore return values in signal handler)
(void)write(STDERR_FILENO, "\n[SIGNAL] Received ", 19);
(void)write(STDERR_FILENO, sig_name, strlen(sig_name));
(void)write(STDERR_FILENO, "\n", 1);
// Disable warn_unused_result for signal handler write() calls
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-result"
// Write to stderr using async-signal-safe functions
write(STDERR_FILENO, "\n[SIGNAL] Received ", 19);
write(STDERR_FILENO, sig_name, strlen(sig_name));
write(STDERR_FILENO, "\n", 1);
// For fatal signals, try emergency shutdown
if (sig == SIGSEGV || sig == SIGABRT || sig == SIGFPE || sig == SIGBUS) {
(void)write(STDERR_FILENO, "[SIGNAL] Attempting emergency shutdown...\n", 42);
write(STDERR_FILENO, "[SIGNAL] Attempting emergency shutdown...\n", 42);
emergency_shutdown();
// Reset signal handler to default and re-raise
@@ -336,10 +340,12 @@ static void signal_handler(int sig) {
raise(sig);
} else if (sig == SIGINT || sig == SIGTERM) {
// Graceful shutdown for interrupt signals
(void)write(STDERR_FILENO, "[SIGNAL] Initiating graceful shutdown...\n", 41);
write(STDERR_FILENO, "[SIGNAL] Initiating graceful shutdown...\n", 41);
emergency_shutdown();
}
#pragma GCC diagnostic pop
in_signal_handler = 0;
}