From 5b98fd0dabd5e8b38b9764a474bd2fec33020ced Mon Sep 17 00:00:00 2001 From: Lorenz Stechauner Date: Mon, 23 Jan 2023 10:07:58 +0100 Subject: [PATCH] Catching error of async_thread() in main --- src/server.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/server.c b/src/server.c index c3418c6..8d066f0 100644 --- a/src/server.c +++ b/src/server.c @@ -185,7 +185,7 @@ static void terminate_forcefully(int sig) { } static void terminate_gracefully(int sig) { - fprintf(stderr, "\n"); + if (sig != 0) fprintf(stderr, "\n"); notice("Terminating gracefully..."); struct sigaction act = {0}; @@ -410,7 +410,13 @@ int main(int argc, char *const argv[]) { notice("Ready to accept connections"); + int error = 0; async_thread(); + if (errno != 0) { + errno = 0; + error = 2; + terminate_gracefully(0); + } notice("Goodbye!"); @@ -424,5 +430,6 @@ int main(int argc, char *const argv[]) { async_free(); logger_stop(); logger_join(); - return 0; + + return error; }