-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsignal_handler.cpp
50 lines (36 loc) · 963 Bytes
/
signal_handler.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
42
43
44
45
46
47
48
49
50
#include "signal_handler.hpp"
namespace numerator {
static sigset_t set;
using namespace apache::thrift::server;
void
init_signals()
{
sigemptyset(&set);
sigaddset(&set, SIGTERM);
sigaddset(&set, SIGINT);
sigaddset(&set, SIGHUP);
pthread_sigmask(SIG_BLOCK, &set, NULL);
}
void*
sigwaiter(void *arg)
{
if (arg == NULL) {
LOG(FATAL) << "Invalid argument";
}
int status, signum;
TThreadPoolServer *server = static_cast<TThreadPoolServer*>(arg);
LOG(INFO) << "started signal handling thread";
while (true) {
status = sigwait(&set, &signum);
if (status == 0) {
if (signum == SIGINT || signum == SIGTERM || signum == SIGHUP) {
LOG(WARNING) << "received " << signum << " signal, exiting";
server->stop();
break;
}
}
}
LOG(INFO) << "finished signal handling thread";
return NULL;
}
} // namespace