diff --git a/osp/src/ospLog.c b/osp/src/ospLog.c index 6697e20..ed425b2 100644 --- a/osp/src/ospLog.c +++ b/osp/src/ospLog.c @@ -203,7 +203,7 @@ OSP_STATUS osp_update_log(uint32_t len, uint32_t logid, uint32_t msg_type) char msg_name[10] = {0}; int32_t file_idx = 0; uint32_t type = 0; - //uint32_t ulfreeram = 0; + uint32_t fd = 0; if (logid >= MAX_LOG_CFG_NUM || logid < 0) { @@ -221,15 +221,11 @@ OSP_STATUS osp_update_log(uint32_t len, uint32_t logid, uint32_t msg_type) //p_log_file_cfg = &log_file_cfg_table[0][0]; p_log_file_cfg[logid][type].cur_sum_len += len; - osp_get_current_time(); UCP_PRINT_LOG("osp_update_log logid:%d type:0x%x cur_sum_len:%u max_file_size_M:%u !\n", logid,type, p_log_file_cfg[logid][type].cur_sum_len, p_log_file_cfg[logid][type].max_file_size_M); /*判断当前系统是否还有足够空间*/ - //ulfreeram = osp_get_freeram(); if(1 == g_ucFflushEnable) { - //sprintf(name, "rm -rf %s%u-%u-%s.log", p_log_file_cfg[logid][type].logname, (p_log_file_cfg[logid][type].cur_file_idx & 0x7)+1, logid, msg_name); - //system(name); UCP_PRINT_LOG("osp_update_log line:%d logid:%d type:0x%x g_ucFflushEnable:%u name:%s\n", __LINE__, logid, type, g_ucFflushEnable, name); osp_log_cfg_reload(); } @@ -257,7 +253,12 @@ OSP_STATUS osp_update_log(uint32_t len, uint32_t logid, uint32_t msg_type) return OSP_ERROR; } + /*内核缓存同步文件,手动清理内核buff*/ + fd = fileno(p_log_file_cfg[logid][type].file); + fsync(fd); fclose(p_log_file_cfg[logid][type].file); + strcpy(name, "echo 1 > /proc/sys/vm/drop_caches"); + system(name); osp_get_file_path(p_log_file_cfg[logid][type].logname, path); @@ -1007,9 +1008,11 @@ void osp_log_init(void) void osp_log_cfg_reload() { - uint32_t i = 0; - uint32_t j = 0; - + uint32_t i = 0; + uint32_t j = 0; + uint32_t fd = 0; + char cmd[64] = {0}; + for (i = 0; i < MAX_LOG_CFG_NUM; i++) { for(j = 0; j< 4; j++) @@ -1018,11 +1021,20 @@ void osp_log_cfg_reload() log_file_cfg_table[i][j].key = 0; log_file_cfg_table[i][j].cur_sum_len = 0; log_file_cfg_table[i][j].cur_file_idx = 0; - log_file_cfg_table[i][j].file = NULL; + if(NULL != log_file_cfg_table[i][j].file) + { + fd = fileno(log_file_cfg_table[i][j].file); + fsync(fd); + fclose(log_file_cfg_table[i][j].file); + log_file_cfg_table[i][j].file = NULL; + } } } + strcpy(cmd, "echo 1 > /proc/sys/vm/drop_caches"); + system(cmd); + return; }