Handle sigterm so application reacts to docker stopping

This commit is contained in:
2026-06-17 17:34:07 +02:00
parent 1c5afe4092
commit 1a2ff3eb3b

View File

@@ -158,6 +158,13 @@ void show_usage(char *program_name, char *error) {
exit(1); 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) int main(int argc, char **argv)
{ {
// Parse input parameters. // 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); 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(); getchar();
noh_log(NOH_INFO, "Shutting down.", port); noh_log(NOH_INFO, "Shutting down.", port);