From 336703252c327d82f49d40f79b1d1e4e65a9281e Mon Sep 17 00:00:00 2001 From: jiangheng Date: Tue, 19 Apr 2022 19:49:06 +0800 Subject: [PATCH 02/18] exit lstack process after ltran instance logout close fd is to notify ltran to execute the lstack instance logout. 200ms is an empirical value of instance logout. --- src/lstack/api/lstack_signal.c | 4 +++- src/lstack/core/lstack_control_plane.c | 9 +++++++++ src/lstack/include/lstack_control_plane.h | 1 + 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/lstack/api/lstack_signal.c b/src/lstack/api/lstack_signal.c index f4763e8..87cbdda 100644 --- a/src/lstack/api/lstack_signal.c +++ b/src/lstack/api/lstack_signal.c @@ -19,8 +19,9 @@ #include #include "lstack_log.h" +#include "lstack_control_plane.h" -static int g_hijack_signal[] = { SIGTERM, SIGINT, SIGSEGV, SIGBUS, SIGFPE, SIGILL }; +static int g_hijack_signal[] = { SIGTERM, SIGINT, SIGSEGV, SIGBUS, SIGFPE, SIGILL, SIGKILL}; #define HIJACK_SIGNAL_COUNT (sizeof(g_hijack_signal) / sizeof(g_hijack_signal[0])) #define BACKTRACE_SIZE 64 static void dump_stack(void) @@ -54,6 +55,7 @@ static inline bool match_hijack_signal(int sig) static void lstack_sig_default_handler(int sig) { LSTACK_LOG(ERR, LSTACK, "lstack dumped,caught signal:%d\n", sig); + control_fd_close(); dump_stack(); lwip_exit(); (void)kill(getpid(), sig); diff --git a/src/lstack/core/lstack_control_plane.c b/src/lstack/core/lstack_control_plane.c index c782d51..01b2ff0 100644 --- a/src/lstack/core/lstack_control_plane.c +++ b/src/lstack/core/lstack_control_plane.c @@ -446,6 +446,15 @@ int32_t client_reg_thrd_ring(void) return 0; } +void control_fd_close(void) +{ + if (g_data_fd != 0) { + close(g_data_fd); + /* 200ms: wait ltran instance logout */ + rte_delay_ms(200); + } +} + int32_t control_init_client(bool is_reconnect) { int32_t ret; diff --git a/src/lstack/include/lstack_control_plane.h b/src/lstack/include/lstack_control_plane.h index 0af891a..1fa84e6 100644 --- a/src/lstack/include/lstack_control_plane.h +++ b/src/lstack/include/lstack_control_plane.h @@ -32,5 +32,6 @@ void control_server_thread(void *arg); bool get_register_state(void); void thread_register_phase1(struct rpc_msg *msg); void thread_register_phase2(struct rpc_msg *msg); +void control_fd_close(void); #endif /* GAZELLE_CONTROL_PLANE_H */ -- 2.23.0