From 13a8c9ef63cbae666f05888cfcd412cc4010be9d Mon Sep 17 00:00:00 2001 From: Sergey Fedorov Date: Mon, 27 Jul 2026 14:58:13 +0000 Subject: [PATCH 6/6] fdm: use NSIG instead of SIGRTMAX for signal array sizing SIGRTMAX is undeclared on Darwin, which has no POSIX real-time signal range at all. It was only ever used here as an upper bound for signal-number array indices, not for its real-time-signal semantics -- foot only ever registers standard signals (SIGINT, SIGTERM, SIGUSR1, SIGUSR2, SIGCHLD). NSIG is the correct constant for that purpose on every platform, and is also strictly better on Linux too: unlike SIGRTMAX (glibc's public SIGRTMAX macro is a disguised call to __libc_current_sigrtmax(), not a compile-time constant), NSIG is a plain preprocessor integer everywhere. Co-Authored-By: Claude Sonnet 5 Claude-Session: https://claude.ai/code/session_01U6fuL1PtRJHhr97gAGyS1h --- fdm.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/fdm.c b/fdm.c index 4822cd97..a3883e87 100644 --- a/fdm.c +++ b/fdm.c @@ -83,7 +83,7 @@ fdm_init(void) } xassert(received_signals == NULL); /* Only one FDM instance supported */ - received_signals = xcalloc(SIGRTMAX, sizeof(received_signals[0])); + received_signals = xcalloc(NSIG, sizeof(received_signals[0])); got_signal = false; struct fdm *fdm = malloc(sizeof(*fdm)); @@ -92,7 +92,7 @@ fdm_init(void) return NULL; } - struct sig_handler *sig_handlers = calloc(SIGRTMAX, sizeof(sig_handlers[0])); + struct sig_handler *sig_handlers = calloc(NSIG, sizeof(sig_handlers[0])); if (sig_handlers == NULL) { LOG_ERRNO("failed to allocate signal handler array"); @@ -123,7 +123,7 @@ fdm_destroy(struct fdm *fdm) if (tll_length(fdm->fds) > 0) LOG_WARN("FD list not empty"); - for (int i = 0; i < SIGRTMAX; i++) { + for (int i = 0; i < NSIG; i++) { if (fdm->signal_handlers[i].callback != NULL) LOG_WARN("handler for signal %d (SIG%s) not removed", i, sigabbrev_np(i)); @@ -452,7 +452,7 @@ fdm_poll(struct fdm *fdm) if (unlikely(got_signal)) { got_signal = false; - for (int i = 0; i < SIGRTMAX; i++) { + for (int i = 0; i < NSIG; i++) { if (received_signals[i]) { received_signals[i] = false; struct sig_handler *handler = &fdm->signal_handlers[i]; -- 2.43.0