Add main loop and signal handler

This commit is contained in:
Camden Dixie O'Brien 2022-10-13 11:57:29 +01:00
parent 948c3971ee
commit fffd1c3fff

26
main.c
View File

@ -16,12 +16,38 @@
* <https://www.gnu.org/licenses/>. * <https://www.gnu.org/licenses/>.
*/ */
#include <signal.h>
#include <stdbool.h>
#include <stdio.h> #include <stdio.h>
#include <unistd.h>
static bool exit_requested = false;
void handle_exit_signal(int signum)
{
(void)signum;
exit_requested = true;
}
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
(void)argc; (void)argc;
(void)argv; (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; return 0;
} }