Fix write() return value warnings using compiler pragmas in signal_handler
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user