forked from funkey/util
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SignalHandler.cpp
41 lines (28 loc) · 931 Bytes
/
SignalHandler.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include "SignalHandler.h"
namespace util {
logger::LogChannel signalhandlerlog("signalhandlerlog", "[SignalHandler] ");
void
SignalHandler::init() {
struct sigaction sa;
sa.sa_handler = handle_signal;
sa.sa_flags = SA_ONESHOT | SA_ONSTACK;
sigemptyset(&sa.sa_mask);
sigaddset(&sa.sa_mask, SIGSEGV);
sigaddset(&sa.sa_mask, SIGABRT);
sigaction(SIGSEGV, &sa, 0);
sigaction(SIGUSR1, &sa, 0);
sigaction(SIGTERM, &sa, 0);
sigaction(SIGABRT, &sa, 0);
}
void
SignalHandler::handle_signal(int signal) {
if (signal == SIGSEGV) {
LOG_ERROR(signalhandlerlog) << "got segfault at:" << std::endl;
LOG_ERROR(signalhandlerlog) << stack_trace_() << std::endl;
BOOST_THROW_EXCEPTION(Segfault() << error_message("segfault") << STACK_TRACE);
} else {
LOG_USER(signalhandlerlog) << "got signal " << signal << " at:" << std::endl;
LOG_USER(signalhandlerlog) << stack_trace_() << std::endl;
}
}
} // namespace util