diff --git a/frontend/src/main.c b/frontend/src/main.c index fca9987..770a796 100644 --- a/frontend/src/main.c +++ b/frontend/src/main.c @@ -157,7 +157,6 @@ static void sigint_handler(const int sig) if (sig == SIGINT) { g_slunkcrypt_abort_flag = 1; - signal(SIGINT, sigint_handler); } } @@ -557,7 +556,7 @@ static int run_self_test(void) int MAIN(const int argc, CHR *const argv[]) { init_terminal(); - signal(SIGINT, sigint_handler); + setup_signal_handler(SIGINT, sigint_handler); int result = -1; FPRINTF(stderr, T("SlunkCrypt Utility (%") T(PRIstr) T("-%") T(PRIstr) T("), by LoRd_MuldeR \n"), OS_TYPE, CPU_ARCH); diff --git a/frontend/src/utils.c b/frontend/src/utils.c index feab263..c5ffea2 100644 --- a/frontend/src/utils.c +++ b/frontend/src/utils.c @@ -13,6 +13,7 @@ #include "utils.h" #include #include +#include #ifdef _WIN32 #include @@ -48,6 +49,19 @@ void init_terminal(void) #endif } +void setup_signal_handler(const int signo, signal_handler_t* const handler) +{ +#ifdef _WIN32 + signal(signo, handler); +#else + struct sigaction act; + act.sa_handler = handler; + sigemptyset(&act.sa_mask); + act.sa_flags = 0; + sigaction(signo, &act, NULL); +#endif +} + char* CHR_to_utf8(const CHR*const input) { #ifdef _WIN32 diff --git a/frontend/src/utils.h b/frontend/src/utils.h index de0bef7..8f50bf3 100644 --- a/frontend/src/utils.h +++ b/frontend/src/utils.h @@ -9,7 +9,10 @@ #include "platform.h" #include +typedef void (signal_handler_t)(int); + void init_terminal(void); +void setup_signal_handler(const int signo, signal_handler_t* const handler); char* CHR_to_utf8(const CHR *const input); uint64_t get_file_size(FILE* const file); const CHR *get_file_name(const CHR *path);