hermes

HTTP GET/HEAD-only web server for static content.
git clone https://git.francescosaccone.com/hermes
Log | Files | Refs | README | LICENSE

commit 769bf130db0a1f3664f6c976cda0f491b07ffb6b
parent fc42549f6f6ec411a54771d45fb6901da399dcbf
Author: Francesco Saccone <francesco@francescosaccone.com>
Date:   Tue,  1 Apr 2025 11:09:04 +0200

feat: create register signal handler

I know that should have been one of the first things to write,
but I just learned about it ;).

Signed-off-by: Francesco Saccone <francesco@francescosaccone.com>

Diffstat:
Mmain.c | 20++++++++++++++++++++
1 file changed, 20 insertions(+), 0 deletions(-)

diff --git a/main.c b/main.c @@ -1,5 +1,6 @@ #include <grp.h> #include <pwd.h> +#include <signal.h> #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -25,6 +26,19 @@ print_usage(char *program_name) { program_name); } +void handle_signal(int signal) { + printf("\nTerminating Hermes...\n"); + + switch (signal) { + case SIGINT: + case SIGTERM: + exit(0); + break; + default: + exit(1); + } +} + int main(int argc, char *argv[]) { char *program_name = argv[0], @@ -38,6 +52,12 @@ main(int argc, char *argv[]) { struct passwd *user; struct group *group; + signal(SIGINT, handle_signal); + signal(SIGTERM, handle_signal); + signal(SIGSEGV, handle_signal); + signal(SIGABRT, handle_signal); + signal(SIGFPE, handle_signal); + for (i = 1; i < argc; i++) { char *argument = argv[i];