|
| 1 | +#include <fault_manager.h> |
| 2 | +static struct sigaction action = {0}; |
| 3 | + |
| 4 | +void dummy_fault_handler() |
| 5 | +{ |
| 6 | + |
| 7 | + // closing_logger_manager |
| 8 | + // closing_memory_manager |
| 9 | + // gracefulexit |
| 10 | + printf("gracefullexit\n"); |
| 11 | +} |
| 12 | + |
| 13 | +void default_fault_handler(int signo, siginfo_t *info, void *extra) |
| 14 | +{ |
| 15 | + printf("Signal %d received\n", signo); |
| 16 | + dummy_fault_handler(); |
| 17 | + abort(); |
| 18 | +} |
| 19 | + |
| 20 | + |
| 21 | + |
| 22 | +void fault_manager_init(f_fault_handle handler) |
| 23 | +{ |
| 24 | + |
| 25 | + if (handler == NULL) { |
| 26 | + printf("fault_handler_undefined using deafult_fault_handler\n"); |
| 27 | + handler = default_fault_handler; |
| 28 | + |
| 29 | + } |
| 30 | + |
| 31 | + action.sa_flags = SA_SIGINFO; |
| 32 | + action.sa_sigaction = handler; |
| 33 | + |
| 34 | + if (sigaction(SIGFPE, &action, NULL) == -1) { |
| 35 | + perror("sigfpe: sigaction"); |
| 36 | + exit(1); |
| 37 | + } |
| 38 | + if (sigaction(SIGSEGV, &action, NULL) == -1) { |
| 39 | + perror("sigsegv: sigaction"); |
| 40 | + exit(1); |
| 41 | + } |
| 42 | + if (sigaction(SIGILL, &action, NULL) == -1) { |
| 43 | + perror("sigill: sigaction"); |
| 44 | + exit(1); |
| 45 | + } |
| 46 | + if (sigaction(SIGINT, &action, NULL) == -1) { |
| 47 | + perror("sigint: sigaction"); |
| 48 | + exit(1); |
| 49 | + } |
| 50 | + if (sigaction(SIGTERM, &action, NULL) == -1) { |
| 51 | + perror("sigterm: sigaction"); |
| 52 | + exit(1); |
| 53 | + } |
| 54 | +} |
| 55 | + |
| 56 | +/* TODO enchancment: |
| 57 | +- mechanism for handling multiple signals |
| 58 | +- mechanism mutiple handlers for multiple signals |
| 59 | +- create fault_manager close |
| 60 | +- module to register routine to be called when fault |
| 61 | +- |
| 62 | +
|
| 63 | +*/ |
| 64 | + |
| 65 | + |
| 66 | + |
0 commit comments