From 1a2ff3eb3bc8ca4f980dc54f15dc0cea1ba7eb2e Mon Sep 17 00:00:00 2001 From: ThoNohT Date: Wed, 17 Jun 2026 17:34:07 +0200 Subject: [PATCH] Handle sigterm so application reacts to docker stopping --- src/server.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/server.c b/src/server.c index d94e71d..970e91e 100644 --- a/src/server.c +++ b/src/server.c @@ -158,6 +158,13 @@ void show_usage(char *program_name, char *error) { exit(1); } +// SIGTERM handler. +static volatile sig_atomic_t got_term = 0; +void on_term(int sig) { + (void)sig; + got_term = 1; +} + int main(int argc, char **argv) { // Parse input parameters. @@ -197,7 +204,10 @@ int main(int argc, char **argv) noh_log(NOH_INFO, "Server is running on http://0.0.0.0:%d", port); - // Keep the server running + // Keep the server running, but handle SIGTERM. + struct sigaction sa = {0}; + sa.sa_handler = on_term; + sigaction(SIGTERM, &sa, NULL); getchar(); noh_log(NOH_INFO, "Shutting down.", port);