From a03e59cadd3fa03e341582cf398c0214b606b846 Mon Sep 17 00:00:00 2001 From: liuxueli Date: Fri, 22 May 2020 09:51:28 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E8=8E=B7=E5=8F=96device=5Fid?= =?UTF-8?q?,=E5=9C=A8=E5=8F=91=E9=80=81=E6=97=A5=E5=BF=97=E6=97=B6?= =?UTF-8?q?=E9=99=84=E5=B8=A6common=5Fdevice=5Fid=E5=AD=97=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/tsg_entry.cpp | 48 +++++++++++++++++++++++++++++++++++++++++--- src/tsg_entry.h | 1 + src/tsg_send_log.cpp | 3 ++- 3 files changed, 48 insertions(+), 4 deletions(-) diff --git a/src/tsg_entry.cpp b/src/tsg_entry.cpp index 32ae0f7..6af0f0f 100644 --- a/src/tsg_entry.cpp +++ b/src/tsg_entry.cpp @@ -41,7 +41,7 @@ static __attribute__((__used__)) const char * GIT_VERSION_UNKNOWN = NULL; #endif -char TSG_MASTER_VERSION_20200430=0; +char TSG_MASTER_VERSION_20200522=0; const char *tsg_conffile="tsgconf/main.conf"; g_tsg_para_t g_tsg_para; @@ -54,6 +54,40 @@ id2field_t g_tsg_fs2_field[TSG_FS2_MAX]={{TLD_TYPE_UNKNOWN, TSG_FS2_LINKS, "link {TLD_TYPE_UNKNOWN, TSG_FS2_DENY, "deny"} }; + +static int tsg_get_sn(char *filename, char *device_sn, int device_sn_len) +{ + int ret=0,flags=0; + char buff[4096]={0}; + cJSON *object=NULL; + + FILE *fp=fopen(filename, "rb"); + if(fp) + { + ret=fread(buff, sizeof(buff), 1, fp); + if(ret<(int)sizeof(buff)) + { + object=cJSON_Parse(buff); + if(object) + { + cJSON *item=cJSON_GetObjectItem(object, "sn"); + if(item && device_sn_len>(int)strlen(item->valuestring)) + { + flags=1; + memcpy(device_sn, item->valuestring, strlen(item->valuestring)); + } + cJSON_Delete(object); + object=NULL; + } + } + + fclose(fp); + fp=NULL; + } + + return flags; +} + static void free_policy_label(int thread_seq, void *project_req_value) { dictator_free(thread_seq, project_req_value); @@ -822,7 +856,8 @@ extern "C" int TSG_MASTER_INIT() char label_buff[MAX_STRING_LEN*4]={0}; char fs_server_ip[MAX_IPV4_LEN]={0}; char fs_output_path[MAX_STRING_LEN*4]={0}; - + char device_sn_filename[MAX_STRING_LEN]={0}; + memset(&g_tsg_para, 0, sizeof(g_tsg_para)); MESA_load_profile_int_def(tsg_conffile, "SYSTEM","LOG_LEVEL", &level, 30); @@ -837,7 +872,14 @@ extern "C" int TSG_MASTER_INIT() MESA_load_profile_int_def(tsg_conffile, "SYSTEM", "DEVICE_ID", &g_tsg_para.device_id, 0); MESA_load_profile_short_def(tsg_conffile, "SYSTEM", "TIMEOUT", (short *)&g_tsg_para.timeout, 300); - + + MESA_load_profile_string_def(tsg_conffile, "SYSTEM", "DEVICE_SN_FILENAME", device_sn_filename, sizeof(device_sn_filename), "/opt/tsg/etc/tsg_sn.json"); + ret=tsg_get_sn(device_sn_filename, g_tsg_para.device_sn, sizeof(g_tsg_para.device_sn)); + if(ret==0) + { + MESA_handle_runtime_log(g_tsg_para.logger, RLOG_LV_FATAL, "GET_DEVICE_SN", "Get device SN failed; please check :%s", device_sn_filename); + } + MESA_load_profile_string_def(tsg_conffile, "SYSTEM", "POLICY_PRIORITY_LABEL", label_buff, sizeof(label_buff), "POLICY_PRIORITY"); g_tsg_para.priority_project_id=project_producer_register(label_buff, PROJECT_VAL_TYPE_STRUCT, free_policy_label); if(g_tsg_para.priority_project_id<0) diff --git a/src/tsg_entry.h b/src/tsg_entry.h index c0e6ff8..f150253 100644 --- a/src/tsg_entry.h +++ b/src/tsg_entry.h @@ -69,6 +69,7 @@ typedef struct _tsg_para int priority_project_id; int establish_latency_project_id; int fs2_field_id[TSG_FS2_MAX]; + char device_sn[MAX_DOAMIN_LEN/8]; char table_name[TABLE_MAX][_MAX_TABLE_NAME_LEN]; void *logger; screen_stat_handle_t fs2_handle; diff --git a/src/tsg_send_log.cpp b/src/tsg_send_log.cpp index 58f24e4..5ec343c 100644 --- a/src/tsg_send_log.cpp +++ b/src/tsg_send_log.cpp @@ -19,7 +19,7 @@ #include "tsg_send_log.h" #include "tsg_send_log_internal.h" -char TSG_SEND_LOG_VERSION_20200427=0; +char TSG_SEND_LOG_VERSION_20200522=0; struct tsg_log_instance_t *g_tsg_log_instance; @@ -488,6 +488,7 @@ int tsg_send_log(struct tsg_log_instance_t *instance, struct TLD_handle_t *handl TLD_append_streaminfo(instance, handle, log_msg->a_stream); TLD_append(_handle, _instance->id2field[LOG_COMMON_SLED_IP].name, (void *)(_instance->local_ip_str), TLD_TYPE_STRING); + TLD_append(_handle, _instance->id2field[LOG_COMMON_DEVICE_ID].name, (void *)(g_tsg_para.device_sn), TLD_TYPE_STRING); for(i=0;iresult_num; i++) {