Commit 30b1d7f2 authored by osdaniellee's avatar osdaniellee

add SIGTERM handle for brpc controller

parent d28ae56f
...@@ -1374,27 +1374,46 @@ typedef sighandler_t SignalHandler; ...@@ -1374,27 +1374,46 @@ typedef sighandler_t SignalHandler;
#endif #endif
static volatile bool s_signal_quit = false; static volatile bool s_signal_quit = false;
static SignalHandler s_prev_handler = NULL; static SignalHandler s_prev_sigint_handler = NULL;
static SignalHandler s_prev_sigterm_handler = NULL;
static void quit_handler(int signo) { static void quit_handler(int signo) {
s_signal_quit = true; s_signal_quit = true;
if (s_prev_handler) { if (SIGINT == signo && s_prev_sigint_handler) {
s_prev_handler(signo); s_prev_sigint_handler(signo);
}
if (SIGTERM == signo && s_prev_sigterm_handler) {
s_prev_sigterm_handler(signo);
} }
} }
static pthread_once_t register_quit_signal_once = PTHREAD_ONCE_INIT; static pthread_once_t register_quit_signal_once = PTHREAD_ONCE_INIT;
static void RegisterQuitSignalOrDie() { static void RegisterQuitSignalOrDie() {
// Not thread-safe. // Not thread-safe.
const SignalHandler prev = signal(SIGINT, quit_handler); SignalHandler prev = signal(SIGINT, quit_handler);
if (prev != SIG_DFL && if (prev != SIG_DFL &&
prev != SIG_IGN) { // shell may install SIGINT of background jobs with SIG_IGN prev != SIG_IGN) { // shell may install SIGINT of background jobs with SIG_IGN
if (prev == SIG_ERR) { if (prev == SIG_ERR) {
LOG(ERROR) << "Fail to register SIGINT, abort"; LOG(ERROR) << "Fail to register SIGINT, abort";
abort(); abort();
} else { } else {
s_prev_handler = prev; s_prev_sigint_handler = prev;
LOG(WARNING) << "SIGINT was installed with " << prev; LOG(WARNING) << "SIGINT was installed with " << prev;
} }
} }
prev = signal(SIGTERM, quit_handler);
if (prev != SIG_DFL &&
prev != SIG_IGN) { // shell may install SIGTERM of background jobs with SIG_IGN
if (prev == SIG_ERR) {
LOG(ERROR) << "Fail to register SIGTERM, abort";
abort();
} else {
s_prev_sigterm_handler = prev;
LOG(WARNING) << "SIGTERM was installed with " << prev;
}
}
} }
bool IsAskedToQuit() { bool IsAskedToQuit() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment