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