From e98bf93cbe4a714c6cb127e78fbd577bbab654c9 Mon Sep 17 00:00:00 2001 From: Trumeet Date: Fri, 22 Jul 2022 20:11:05 -0700 Subject: feat(acronc): set SIGINT and SIGTERM handlers on Unix Otherwise ASAN does not seem to run (if terminated). Signed-off-by: Trumeet --- client/libacron/acronc/main.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/client/libacron/acronc/main.c b/client/libacron/acronc/main.c index cbc359e..21612d8 100644 --- a/client/libacron/acronc/main.c +++ b/client/libacron/acronc/main.c @@ -8,6 +8,10 @@ #ifdef WIN32 #include #include +#else +#include +#include +#include #endif static const char *world_name(const enum ac_world world) { @@ -121,8 +125,28 @@ static void handle_response(const ac_response_t *response) { } } +#ifndef WIN32 +static void intr(int signum) {} +#endif + int main(int argc, char **argv) { int r; +#ifdef WIN32 + fprintf(stderr, "Warning: ^C handler on Windows is not yet available."); +#else + struct sigaction sa; + sa.sa_handler = intr; + sigemptyset(&sa.sa_mask); + sa.sa_flags = 0; + if (sigaction(SIGINT, &sa, NULL) || + sigaction(SIGTERM, &sa, NULL)) { + const int e = errno; + fprintf(stderr, "Cannot set SIGINT or SIGTERM handlers: %s (%d).\n", + strerror(e), + e); + return e; + } +#endif #ifdef WIN32 WORD wVersionRequested; WSADATA wsaData; -- cgit v1.2.3