From d7e4d0b62a08366d65c266f91fe0b6ea6e38aa37 Mon Sep 17 00:00:00 2001 From: liuxueli Date: Wed, 23 Feb 2022 18:43:00 +0800 Subject: [PATCH] =?UTF-8?q?TSG-9700:=20=E6=94=AF=E6=8C=81=E4=BC=98?= =?UTF-8?q?=E9=9B=85=E9=80=80=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/tsg_entry.cpp | 12 ++++++++--- src/tsg_entry.h | 4 ++++ src/tsg_rule.cpp | 2 +- src/tsg_send_log.cpp | 42 +++++++++++++++++++++++++++++++++++++ src/tsg_send_log_internal.h | 1 + src/tsg_statistic.cpp | 18 ++++++++++++---- 6 files changed, 71 insertions(+), 8 deletions(-) diff --git a/src/tsg_entry.cpp b/src/tsg_entry.cpp index 76ce0b9..b4da0e8 100644 --- a/src/tsg_entry.cpp +++ b/src/tsg_entry.cpp @@ -2317,10 +2317,11 @@ extern "C" int TSG_MASTER_INIT() return 0; } - - extern "C" int TSG_MASTER_UNLOAD() { + tsg_sendlog_destroy(g_tsg_log_instance); + tsg_statistic_destroy(); + Maat_burn_feather(g_tsg_maat_feather); g_tsg_maat_feather=NULL; @@ -2329,6 +2330,11 @@ extern "C" int TSG_MASTER_UNLOAD() Maat_burn_feather(g_tsg_dynamic_maat_feather); g_tsg_dynamic_maat_feather=NULL; } - + + FS_stop(&(g_tsg_para.fs2_handle)); + + MESA_destroy_runtime_log_handle(g_tsg_para.logger); + g_tsg_para.logger=NULL; + return 0; } diff --git a/src/tsg_entry.h b/src/tsg_entry.h index 2c7c4e3..f344ba9 100644 --- a/src/tsg_entry.h +++ b/src/tsg_entry.h @@ -382,6 +382,8 @@ typedef struct tsg_statistic { int cycle; int fs_line_id; + int thread_alive; + pthread_t stat_thread_id; int fs_field_id[STATIS_MAX]; long long statistic_opt[_OPT_TYPE_MAX]; struct _traffic_info *traffic_info[TSG_ACTION_MAX+1]; @@ -390,6 +392,8 @@ typedef struct tsg_statistic }tsg_statis_para_t; int tsg_statistic_init(const char *conffile, void *logger); +void tsg_statistic_destroy(void); + int tsg_gtp_signaling_hash_init(const char* conffile, void *logger); int set_struct_project(const struct streaminfo *a_stream, int project_id, void *data); diff --git a/src/tsg_rule.cpp b/src/tsg_rule.cpp index 7c64cc8..ee5855b 100644 --- a/src/tsg_rule.cpp +++ b/src/tsg_rule.cpp @@ -820,7 +820,7 @@ static int parse_answer_records(struct dns_user_region *user_region_records, cJS } answer_type=get_dns_qtype(a_item->valuestring, strlen(a_item->valuestring)); - switch(answer_type==-1) + if(answer_type==-1) { continue; } diff --git a/src/tsg_send_log.cpp b/src/tsg_send_log.cpp index a7f7b32..7bdfd30 100644 --- a/src/tsg_send_log.cpp +++ b/src/tsg_send_log.cpp @@ -1648,6 +1648,48 @@ struct tsg_log_instance_t *tsg_sendlog_init(const char *conffile) return _instance; } +void tsg_sendlog_destroy(struct tsg_log_instance_t * instance) +{ + for(int i=0; imax_service; i++) + { + if(instance->topic_rkt[i]==NULL) + { + continue; + } + + rd_kafka_topic_destroy(instance->topic_rkt[i]); + } + + rd_kafka_destroy_flags(instance->kafka_handle, 4); + rd_kafka_destroy(instance->kafka_handle); + + MESA_destroy_runtime_log_handle(instance->logger); + instance->logger=NULL; + + free(instance->topic_rkt); + instance->topic_rkt=NULL; + + free(instance->service2topic); + instance->service2topic=NULL; + + free(instance); + instance=NULL; +/* + int ret=0,count=0; + + while(1) + { + ret=rd_kafka_wait_destroyed(1000); + if(ret==0) + { + break; + } + count++; + } +*/ + + return ; +} int tsg_send_log(struct tsg_log_instance_t *instance, struct TLD_handle_t *handle, tsg_log_t *log_msg, int thread_id) { diff --git a/src/tsg_send_log_internal.h b/src/tsg_send_log_internal.h index 822da67..bcb5b8c 100644 --- a/src/tsg_send_log_internal.h +++ b/src/tsg_send_log_internal.h @@ -176,6 +176,7 @@ struct tsg_log_instance_t char *log_field_id2name(struct tsg_log_instance_t *instance, tsg_log_field_id_t id); struct tsg_log_instance_t *tsg_sendlog_init(const char *filename); +void tsg_sendlog_destroy(struct tsg_log_instance_t * instance); #endif diff --git a/src/tsg_statistic.cpp b/src/tsg_statistic.cpp index 39ba745..6abfc6b 100644 --- a/src/tsg_statistic.cpp +++ b/src/tsg_statistic.cpp @@ -213,7 +213,7 @@ static void *tsg_statistic_thread(void *arg) FS_start(g_tsg_statis_para.fs2_handle); - while(1) + while(g_tsg_statis_para.thread_alive) { memset(&policy_traffic_info, 0, sizeof(policy_traffic_info)); memset(&total_traffic_info, 0, sizeof(total_traffic_info)); @@ -370,6 +370,7 @@ int tsg_statistic_init(const char *conffile, void *logger) MESA_load_profile_int_def(conffile, "STATISTIC", "PROMETHEUS", &output_prometheus, 1); g_tsg_statis_para.fs2_handle=FS_create_handle(); + g_tsg_statis_para.thread_alive=1; value=1;//Rewrite FS_set_para(g_tsg_statis_para.fs2_handle, PRINT_MODE, &value, sizeof(value)); @@ -460,9 +461,18 @@ int tsg_statistic_init(const char *conffile, void *logger) g_tsg_statis_para.fs_line_id=FS_register(g_tsg_statis_para.fs2_handle, FS_STYLE_LINE, FS_CALC_CURRENT, (const char *)"TRAFFIC"); - pthread_t stat_thread_t; - pthread_create(&stat_thread_t, NULL, tsg_statistic_thread, NULL); + pthread_create(&g_tsg_statis_para.stat_thread_id, NULL, tsg_statistic_thread, NULL); - return 0; } + +void tsg_statistic_destroy(void) +{ + pthread_cancel(g_tsg_statis_para.stat_thread_id); + g_tsg_statis_para.thread_alive=0; + sleep(g_tsg_statis_para.cycle); + FS_stop(&(g_tsg_statis_para.fs2_handle)); + + return ; +} +