2
3
4
5
6
7
8
11
12
13
14
15
16
17
18
36
37
38
39
40
41
45 sa.sa_handler = SIG_DFL;
46 sigemptyset(&sa.sa_mask);
47 sa.sa_flags = SA_RESTART;
48 sigaction(SIGINT, &sa,
nullptr);
49 sigaction(SIGTERM, &sa,
nullptr);
50 sigaction(SIGQUIT, &sa,
nullptr);
51 sigaction(SIGUSR1, &sa,
nullptr);
52 sa.sa_flags = SA_SIGINFO;
53 sigaction(SIGSEGV, &sa,
nullptr);
56
57
58
59
60
61
65 memset(&sa, 0,
sizeof(sa));
67 sigemptyset(&sa.sa_mask);
68 sa.sa_flags = SA_RESTART;
69 if (sigaction(SIGINT, &sa,
nullptr) == -1) {
70 abend(-1
, "sigaction SIGINT failed");
73 if (sigaction(SIGTERM, &sa,
nullptr) == -1) {
74 abend(-1
, "sigaction SIGTERM failed");
77 if (sigaction(SIGQUIT, &sa,
nullptr) == -1) {
78 abend(-1
, "sigaction SIGQUIT failed");
81 if (sigaction(SIGUSR1, &sa,
nullptr) == -1) {
82 abend(-1
, "sigaction SIGUSR1 failed");
85 sa.sa_flags = SA_SIGINFO;
86 if (sigaction(SIGSEGV, &sa,
nullptr) == -1) {
87 abend(-1
, "sigaction SIGSEGV failed");
92
93
94
108 char *msg1 =
"\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n";
109 write(STDERR_FILENO, msg1, strlen(msg1));
110 char *msg2 =
"SIGSEGV - Segmentation fault - Stack trace\n\n";
111 write(STDERR_FILENO, msg2, strlen(msg2));
116 symbols = backtrace_symbols(addrlist, frames);
118 abend(-1
, "backtrace_symbols failed");
121 for (
int i = 0; i < frames; i++) {
124 write(STDERR_FILENO, buf, strlen(buf));
127 msg2 =
"\nSIGSEGV Segmentation fault - Writing core to file\n\n";
128 write(STDERR_FILENO, msg2, strlen(msg2));
130 sa.sa_handler = SIG_DFL;
131 sigemptyset(&sa.sa_mask);
133 sigaction(SIGSEGV, &sa, NULL);
134 kill(getpid(), SIGSEGV);
144
145
146
volatile sig_atomic_t sig_received
bool handle_signal(sig_atomic_t)
struct termios shell_tioctl
void abend(int, char *)
Abnormal program termination.
size_t strnz__cpy(char *, const char *, size_t)
safer alternative to strncpy
size_t ssnprintf(char *, size_t, const char *,...)
ssnprintf was designed to be a safer alternative to snprintf.
bool set_sane_tioctl(struct termios *)
set_sane_tioctl() - set terminal to sane settings for C-MENU
bool restore_shell_tioctl()
restore_shell_tioctl() - restore shell terminal settings
void sig_dfl_mode()
Set signal handlers to default behavior.
void signal_handler(int)
Signal handler for interrupt signals.
void sig_prog_mode()
Set up signal handlers for interrupt signals.