Skip to content

Commit 96d5d62

Browse files
srjsrinijar3m
andauthored
Fault manager (#11)
* Commit Logs - Created New branch for fault handling - Make file rule def for .out files clean up (come up with a better name) * commit logs - makefile clean up - change executable name to foo.out - updated os.h * Commit logs fault manager handels common header files Makefile modified Co-authored-by: jar3m <[email protected]>
1 parent 32ac3d6 commit 96d5d62

5 files changed

Lines changed: 85 additions & 2 deletions

File tree

common/Makefile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,24 @@ common_ARCHIVE=$(PROJ_PATH)/common/bin/common.a
77
logger_SRC=src/logger.c
88
logger_OBJ=bin/logger.o
99

10+
fault_SRC=src/fault_manager.c
11+
fault_OBJ=bin/fault_manager.o
12+
1013
common_ARCHIVE=$(PROJ_PATH)/common/bin/common.a
1114

1215
OBJS=$(common_OBJ)
1316
OBJS+=$(logger_OBJ)
17+
OBJS+=$(fault_OBJ)
1418

1519
$(common_OBJ): $(common_SRC)
1620
$(CC) $(INCLUDES) -c $^ -o $@ $(CFLAGS)
1721

1822
$(logger_OBJ): $(logger_SRC)
1923
$(CC) $(INCLUDES) -c $^ -o $@ $(CFLAGS)
2024

25+
$(fault_OBJ): $(fault_SRC)
26+
$(CC) $(INCLUDES) -c $^ -o $@ $(CFLAGS)
27+
2128
all: $(OBJS)
2229
@echo "building common"
2330
ar rcs $(common_ARCHIVE) $(OBJS)

common/inc/common.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
#include "os.h"
22
#include "typedefs.h"
33
#include "logger.h"
4-
4+
#include "fault_manager.h"

common/inc/fault_manager.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#pragma once
2+
#include <os.h>
3+
4+
typedef void (*f_fault_handle)(int,siginfo_t *,void *);
5+
6+
7+
void fault_manager_init(f_fault_handle h);

common/src/fault_manager.c

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
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+

test/src/test.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
#include "common.h"
22

3-
43
int main(int argc, char *argv[])
54
{
65
printf("Hello World\n");
6+
77
logger_init();
8+
fault_manager_init(NULL);
9+
810
return 0;
11+
912
}

0 commit comments

Comments
 (0)