Improved signal handling on Linux/BSD.

This commit is contained in:
LoRd_MuldeR 2020-10-20 19:13:11 +02:00
parent aeb7d1af4a
commit 64fa094b9f
Signed by: mulder
GPG Key ID: 2B5913365F57E03F
3 changed files with 18 additions and 2 deletions

View File

@ -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 <MuldeR2@GMX.de>\n"), OS_TYPE, CPU_ARCH);

View File

@ -13,6 +13,7 @@
#include "utils.h"
#include <sys/stat.h>
#include <sys/types.h>
#include <signal.h>
#ifdef _WIN32
#include <Windows.h>
@ -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

View File

@ -9,7 +9,10 @@
#include "platform.h"
#include <stdint.h>
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);