C Everything
This is a C repository containing a curated set of generic data structures and algorithm.
fault_manager.c
Go to the documentation of this file.
1 
6 #include "common.h"
7 #include <execinfo.h>
8 
9 static struct sigaction action = {0};
10 
12 {
13 
14  void *array[10];
15  size_t size;
16 
17  //get void*'s for all entries on the stack
18  size = backtrace(array, 10);
19 
20  // print out all the frames to stderr
21  backtrace_symbols_fd(array, size, STDERR_FILENO);
22  // gracefulexit
23  // closing_logger_manager
24 
25  // closing_memory_manager
26  mem_finit();
27 
28  printf("gracefullexit\n");
29 }
30 
38 void default_fault_handler(int signo, siginfo_t *info, void *extra)
39 {
40  printf("Signal %d received\n", signo);
42  abort();
43 }
44 
45 
53 {
54  // If no fault handler define use default
55  if (handler == NULL) {
56  printf("fault_handler_undefined using deafult_fault_handler\n");
57  handler = default_fault_handler;
58 
59  }
60 
61  // Add signals to be handle
62  action.sa_flags = SA_SIGINFO;
63  action.sa_sigaction = handler;
64 
65  // Handle fatal arithmetic error such as floating pt exception
66  if (sigaction(SIGFPE, &action, NULL) == -1) {
67  perror("sigfpe: sigaction");
68  exit(1);
69  }
70  // Handle segmentation fault
71  if (sigaction(SIGSEGV, &action, NULL) == -1) {
72  perror("sigsegv: sigaction");
73  exit(1);
74  }
75  // Handles corrupted executable or stack overflow
76  if (sigaction(SIGILL, &action, NULL) == -1) {
77  perror("sigill: sigaction");
78  exit(1);
79  }
80  // Handles interpts
81  if (sigaction(SIGINT, &action, NULL) == -1) {
82  perror("sigint: sigaction");
83  exit(1);
84  }
85  // handles termination signal
86  if (sigaction(SIGTERM, &action, NULL) == -1) {
87  perror("sigterm: sigaction");
88  exit(1);
89  }
90 }
91 
92 /* TODO enchancment:
93 - mechanism for handling multiple signals
94 - mechanism mutiple handlers for multiple signals
95 - create fault_manager close
96 - module to register routine to be called when fault
97 -
98 
99 */
100 
101 
102 
Top level include containg common headers.
void dummy_fault_handler()
Definition: fault_manager.c:11
void fault_manager_init(f_fault_handle handler)
Handles signals and faults depending on type of fault/signal occured
Definition: fault_manager.c:52
void default_fault_handler(int signo, siginfo_t *info, void *extra)
Defaul fault handler called on any of the signals initialised to be handled
Definition: fault_manager.c:38
void(* f_fault_handle)(int, siginfo_t *, void *)
Function pointer for fault handler.
Definition: fault_manager.h:11
void mem_finit(void)
Close memory module by checking and destroying if any tagged memory