You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@brpc.apache.org by jr...@apache.org on 2023/06/07 10:14:20 UTC
[brpc] branch graceful-quit-on-sighup created (now d1a2fcfd)
This is an automated email from the ASF dual-hosted git repository.
jrjbear pushed a change to branch graceful-quit-on-sighup
in repository https://gitbox.apache.org/repos/asf/brpc.git
at d1a2fcfd + Add graceful exit for SIGHUP
This branch includes the following new commits:
new d1a2fcfd + Add graceful exit for SIGHUP
The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For additional commands, e-mail: dev-help@brpc.apache.org
[brpc] 01/01: + Add graceful exit for SIGHUP
Posted by jr...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
jrjbear pushed a commit to branch graceful-quit-on-sighup
in repository https://gitbox.apache.org/repos/asf/brpc.git
commit d1a2fcfd0c3536b83ba20f5d61b1ae400949a061
Author: oldbear <jr...@gmail.com>
AuthorDate: Wed Jun 7 18:13:48 2023 +0800
+ Add graceful exit for SIGHUP
---
src/brpc/controller.cpp | 20 ++++++++++++++++++++
1 file changed, 20 insertions(+)
diff --git a/src/brpc/controller.cpp b/src/brpc/controller.cpp
index b6c8e750..823ca953 100644
--- a/src/brpc/controller.cpp
+++ b/src/brpc/controller.cpp
@@ -87,6 +87,8 @@ namespace brpc {
DEFINE_bool(graceful_quit_on_sigterm, false,
"Register SIGTERM handle func to quit graceful");
+DEFINE_bool(graceful_quit_on_sighup, false,
+ "Register SIGHUP handle func to quit graceful");
const IdlNames idl_single_req_single_res = { "req", "res" };
const IdlNames idl_single_req_multi_res = { "req", "" };
@@ -1461,6 +1463,7 @@ typedef sighandler_t SignalHandler;
static volatile bool s_signal_quit = false;
static SignalHandler s_prev_sigint_handler = NULL;
static SignalHandler s_prev_sigterm_handler = NULL;
+static SignalHandler s_prev_sighup_handler = NULL;
static void quit_handler(int signo) {
s_signal_quit = true;
@@ -1470,6 +1473,9 @@ static void quit_handler(int signo) {
if (SIGTERM == signo && s_prev_sigterm_handler) {
s_prev_sigterm_handler(signo);
}
+ if (SIGHUP == signo && s_prev_sighup_handler) {
+ s_prev_sighup_handler(signo);
+ }
}
static pthread_once_t register_quit_signal_once = PTHREAD_ONCE_INIT;
@@ -1501,6 +1507,20 @@ static void RegisterQuitSignalOrDie() {
}
}
}
+
+ if (FLAGS_graceful_quit_on_sighup) {
+ prev = signal(SIGHUP, quit_handler);
+ if (prev != SIG_DFL &&
+ prev != SIG_IGN) { // shell may install SIGHUP of background jobs with SIG_IGN
+ if (prev == SIG_ERR) {
+ LOG(ERROR) << "Fail to register SIGHUP, abort";
+ abort();
+ } else {
+ s_prev_sighup_handler = prev;
+ LOG(WARNING) << "SIGHUP was installed with " << prev;
+ }
+ }
+ }
}
bool IsAskedToQuit() {
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For additional commands, e-mail: dev-help@brpc.apache.org