32 lines
625 B
C
32 lines
625 B
C
#include "interrupt.h"
|
|
|
|
volatile sig_atomic_t exit_flag = 0;
|
|
|
|
void interrupt_register_sighandler() {
|
|
struct sigaction action;
|
|
memset( &action, 0, sizeof(action) );
|
|
action.sa_handler = interrupt_onsignal;
|
|
sigfillset(&action.sa_mask);
|
|
sigaction(SIGINT, &action, NULL);
|
|
}
|
|
|
|
void interrupt_onsignal(int) {
|
|
exit_flag = 1;
|
|
}
|
|
|
|
int interrupt_return_value() {
|
|
if (exit_flag == 1) {
|
|
// print message if we exited through sigint
|
|
fprintf(stderr, "\nExiting\n");
|
|
}
|
|
return exit_flag >= 0 ? 0 : exit_flag;
|
|
}
|
|
|
|
int interrupt_should_exit() {
|
|
return exit_flag;
|
|
}
|
|
|
|
void interrupt_set_exit_flag() {
|
|
exit_flag = -1;
|
|
}
|