From fffd1c3fff47c24ef4694eb9ce4aa31bccd6b42d Mon Sep 17 00:00:00 2001 From: Camden Dixie O'Brien Date: Thu, 13 Oct 2022 11:57:29 +0100 Subject: [PATCH] Add main loop and signal handler --- main.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/main.c b/main.c index 71543aa..6197e7f 100644 --- a/main.c +++ b/main.c @@ -16,12 +16,38 @@ * . */ +#include +#include #include +#include + +static bool exit_requested = false; + +void handle_exit_signal(int signum) +{ + (void)signum; + exit_requested = true; +} int main(int argc, char *argv[]) { (void)argc; (void)argv; + if (signal(SIGTERM, handle_exit_signal) == SIG_ERR) { + fprintf(stderr, "Failed to register SIGTERM signal handler\n"); + return 1; + } + if (signal(SIGINT, handle_exit_signal) == SIG_ERR) { + fprintf(stderr, "Failed to register SIGINT signal handler\n"); + return 1; + } + + while (!exit_requested) { + sleep(1); + } + + printf("After loop\n"); + return 0; }