由于fsync是阻塞的会丢失log,删除fsync调用

This commit is contained in:
huanfeng.wang 2023-11-16 17:44:14 +08:00
parent 8733e5bae9
commit 44b614e333

View File

@ -33,7 +33,7 @@ uint32_t g_ulApeLogMode = 1; /*0: ape log日志写入文件 1: 网口输
uint32_t g_ulArmLogMode = 0; /*0: arm log日志写入文件 1: 网口输出arm log 2:arm log日志shell打印输出*/ uint32_t g_ulArmLogMode = 0; /*0: arm log日志写入文件 1: 网口输出arm log 2:arm log日志shell打印输出*/
uint8_t g_ucPlatformMode = 1; /*0: platform log日志写入文件 1: 网口输出platform log 2:platform log日志shell打印输出*/ uint8_t g_ucPlatformMode = 1; /*0: platform log日志写入文件 1: 网口输出platform log 2:platform log日志shell打印输出*/
uint8_t g_time_now[128]; uint8_t g_time_now[128];
uint8_t g_ucFflushEnable = 0; uint8_t g_ucFflushEnable = 0;
int32_t net_log_txudp_id = -1; /*吐网口log id*/ int32_t net_log_txudp_id = -1; /*吐网口log id*/
Osp_Server_Head gst_server_log; Osp_Server_Head gst_server_log;
@ -224,32 +224,32 @@ OSP_STATUS osp_update_log(uint32_t len, uint32_t logid, uint32_t msg_type)
osp_get_current_time(); 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); 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(); //ulfreeram = osp_get_freeram();
if(1 == g_ucFflushEnable) 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); //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); //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); 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(); osp_log_cfg_reload();
} }
if (p_log_file_cfg[logid][type].cur_sum_len >= p_log_file_cfg[logid][type].max_file_size_M) if (p_log_file_cfg[logid][type].cur_sum_len >= p_log_file_cfg[logid][type].max_file_size_M)
{ {
p_log_file_cfg[logid][type].cur_sum_len = 0; p_log_file_cfg[logid][type].cur_sum_len = 0;
p_log_file_cfg[logid][type].cur_file_idx++; p_log_file_cfg[logid][type].cur_file_idx++;
file_idx = p_log_file_cfg[logid][type].cur_file_idx & 0x7; file_idx = p_log_file_cfg[logid][type].cur_file_idx & 0x7;
if(p_log_file_cfg[logid][type].cur_file_idx >= p_log_file_cfg[logid][type].max_file_num) if(p_log_file_cfg[logid][type].cur_file_idx >= p_log_file_cfg[logid][type].max_file_num)
{ {
/* naming rule: coreid-index-type.log */ /* naming rule: coreid-index-type.log */
sprintf(name, "rm -rf %s%u-%u-%s.log", p_log_file_cfg[logid][type].logname, logid, file_idx, msg_name); sprintf(name, "rm -rf %s%u-%u-%s.log", p_log_file_cfg[logid][type].logname, logid, file_idx, msg_name);
//sprintf(name, "rm -rf %s%u-%u-%s.log", p_log_file_cfg[logid][type].logname, file_idx, logid, msg_name); //sprintf(name, "rm -rf %s%u-%u-%s.log", p_log_file_cfg[logid][type].logname, file_idx, logid, msg_name);
//sprintf(name, "%s-%d-%s-%u-%u-%s.log", p_log_file_cfg[logid][type].logname, getpid(), g_time_now, p_log_file_cfg[logid][type].cur_file_idx, logid, msg_name); //sprintf(name, "%s-%d-%s-%u-%u-%s.log", p_log_file_cfg[logid][type].logname, getpid(), g_time_now, p_log_file_cfg[logid][type].cur_file_idx, logid, msg_name);
system(name); system(name);
UCP_PRINT_LOG("osp_update_log line:%d logid:%d type:0x%x remove name:%s\n", __LINE__, logid, type, name); UCP_PRINT_LOG("osp_update_log line:%d logid:%d type:0x%x remove name:%s\n", __LINE__, logid, type, name);
} }
/*判断当前文件是否合法文件*/ /*判断当前文件是否合法文件*/
if(NULL == p_log_file_cfg[logid][type].file) if(NULL == p_log_file_cfg[logid][type].file)
{ {
@ -257,9 +257,9 @@ OSP_STATUS osp_update_log(uint32_t len, uint32_t logid, uint32_t msg_type)
return OSP_ERROR; return OSP_ERROR;
} }
fclose(p_log_file_cfg[logid][type].file); fclose(p_log_file_cfg[logid][type].file);
osp_get_file_path(p_log_file_cfg[logid][type].logname, path); osp_get_file_path(p_log_file_cfg[logid][type].logname, path);
if (access(path, F_OK) != 0) if (access(path, F_OK) != 0)
{ {
@ -338,27 +338,27 @@ OSP_STATUS osp_update_log(uint32_t len, uint32_t logid, uint32_t msg_type)
return OSP_OK; return OSP_OK;
} }
void osp_log_output(unsigned char level, const char *fmt, ...) void osp_log_output(unsigned char level, const char *fmt, ...)
{ {
uint32_t u32str_len = 0; uint32_t u32str_len = 0;
char acstr[256] = {0}; char acstr[256] = {0};
va_list st_va_list; va_list st_va_list;
if (level > guc_print_level) if (level > guc_print_level)
{ {
return; return;
} }
va_start(st_va_list, fmt); va_start(st_va_list, fmt);
u32str_len = vsprintf((char *)acstr, fmt, st_va_list); u32str_len = vsprintf((char *)acstr, fmt, st_va_list);
va_end(st_va_list); va_end(st_va_list);
printf("%s", acstr); printf("%s", acstr);
osp_net_shell_out(acstr, u32str_len); osp_net_shell_out(acstr, u32str_len);
return; return;
} }
@ -452,7 +452,7 @@ uint32_t osp_get_freeram(void)
/*默认起始端口号portIDStart=32768二进制log的portID = portIDStart + core_id * 2字符串log的portID = portIDStart + core_id * 2 + 1 /*默认起始端口号portIDStart=32768二进制log的portID = portIDStart + core_id * 2字符串log的portID = portIDStart + core_id * 2 + 1
log默认端口号为32800ul_port = ul_platform_port + 2*uc_src_core_id;*/ log默认端口号为32800ul_port = ul_platform_port + 2*uc_src_core_id;*/
uint32_t osp_get_ape_port(osp_sw_msg_info_t *pMsg) uint32_t osp_get_ape_port(osp_sw_msg_info_t *pMsg)
{ {
uint32_t ul_port = 0; uint32_t ul_port = 0;
@ -472,15 +472,15 @@ uint32_t osp_get_ape_port(osp_sw_msg_info_t *pMsg)
case OSP_STR_LOG: case OSP_STR_LOG:
ul_port = ul_start_port + 2*uc_src_core_id + 1; ul_port = ul_start_port + 2*uc_src_core_id + 1;
break; break;
case OSP_PLATFORM_LOG: case OSP_PLATFORM_LOG:
ul_port = ul_platform_port + 2*uc_src_core_id; ul_port = ul_platform_port + 2*uc_src_core_id;
break; break;
default: default:
break; break;
} }
UCP_PRINT_LOG("osp_get_ape_port ul_port:%u uc_src_core_id:%u uc_msg_type:0x%x\n", ul_port, uc_src_core_id, uc_msg_type); UCP_PRINT_LOG("osp_get_ape_port ul_port:%u uc_src_core_id:%u uc_msg_type:0x%x\n", ul_port, uc_src_core_id, uc_msg_type);
return ul_port; return ul_port;
} }
@ -502,7 +502,7 @@ void osp_net_log_proc(char *pMsg, uint32_t len, uint32_t port)
} }
//UCP_PRINT_LOG("osp_net_log_proc line:%d len[%u] udp_id[%u] ip[%s] port[%u]\n", __LINE__, len, net_log_txudp_id, gst_server_log.ip, port); //UCP_PRINT_LOG("osp_net_log_proc line:%d len[%u] udp_id[%u] ip[%s] port[%u]\n", __LINE__, len, net_log_txudp_id, gst_server_log.ip, port);
osp_udp_send(pMsg, len, net_log_txudp_id); osp_udp_send(pMsg, len, net_log_txudp_id);
return; return;
@ -511,10 +511,10 @@ void osp_net_log_proc(char *pMsg, uint32_t len, uint32_t port)
OSP_STATUS osp_write_diaglog(char *pbuf, uint32_t len ,uint32_t logid, uint32_t msg_type) OSP_STATUS osp_write_diaglog(char *pbuf, uint32_t len ,uint32_t logid, uint32_t msg_type)
{ {
int32_t ret = 0; int32_t ret = 0;
static FILE *file = NULL; static FILE *file = NULL;
uint32_t fd; /*uint32_t fd;*/
if (NULL == g_OspLogSem) if (NULL == g_OspLogSem)
{ {
return OSP_ERROR; return OSP_ERROR;
@ -540,40 +540,42 @@ OSP_STATUS osp_write_diaglog(char *pbuf, uint32_t len ,uint32_t logid, uint32_t
if (NULL == file) if (NULL == file)
{ {
osp_sem_give(g_OspLogSem); osp_sem_give(g_OspLogSem);
return OSP_ERROR; return OSP_ERROR;
} }
ret = fwrite(pbuf, sizeof(char), len, file); ret = fwrite(pbuf, sizeof(char), len, file);
if(ret <= 0) if(ret <= 0)
{ {
UCP_PRINT_LOG("fwrite error ret:%d\n", ret); UCP_PRINT_LOG("fwrite error ret:%d\n", ret);
fclose(file); fclose(file);
osp_sem_give(g_OspLogSem); osp_sem_give(g_OspLogSem);
return OSP_ERROR; return OSP_ERROR;
} }
ret = fflush(file); ret = fflush(file);
if(OSP_OK != ret) if(OSP_OK != ret)
{ {
UCP_PRINT_LOG("fflush error ret:%d\n", ret); UCP_PRINT_LOG("fflush error ret:%d\n", ret);
g_ucFflushEnable = 1; g_ucFflushEnable = 1;
} }
else else
{ {
UCP_PRINT_LOG("fflush ok ret:%d\n", ret); UCP_PRINT_LOG("fflush ok ret:%d\n", ret);
g_ucFflushEnable = 0; g_ucFflushEnable = 0;
} }
#if 0 /*feature enhancement1300*/
fd = fileno(file); fd = fileno(file);
ret = fsync(fd); ret = fsync(fd);
if(OSP_OK != ret) if(OSP_OK != ret)
{ {
UCP_PRINT_LOG("fsync error ret:%d\n", ret); UCP_PRINT_LOG("fsync error ret:%d\n", ret);
fclose(file); fclose(file);
osp_sem_give(g_OspLogSem); osp_sem_give(g_OspLogSem);
return OSP_ERROR; return OSP_ERROR;
} }
#endif
osp_sem_give(g_OspLogSem); osp_sem_give(g_OspLogSem);
return OSP_OK; return OSP_OK;
@ -704,7 +706,7 @@ void osp_platform_log_proc(osp_sw_msg_info_t *pMsg)
osp_log_print(pMsg);/*ape结果输出到屏幕*/ osp_log_print(pMsg);/*ape结果输出到屏幕*/
break; break;
default: default:
break; break;
} }
@ -922,7 +924,7 @@ void osp_log_mode_get()
return; return;
} }
uint32_t osp_filter_char(char *str, char c) uint32_t osp_filter_char(char *str, char c)
{ {
uint8_t i = 0; uint8_t i = 0;
@ -955,9 +957,9 @@ void osp_dbg_log_main(osp_sw_msg_info_t *pMsg)
case OSP_BIN_LOG: case OSP_BIN_LOG:
osp_ape_log_proc(pMsg); osp_ape_log_proc(pMsg);
break; break;
case OSP_PLATFORM_LOG: case OSP_PLATFORM_LOG:
osp_platform_log_proc(pMsg); osp_platform_log_proc(pMsg);
break; break;
default: default:
break; break;
} }
@ -1163,8 +1165,8 @@ int32_t osp_log_msg_proc(uint8_t *pu8msg_add, uint32_t u32msg_size)
//printf("i8Data = %p, len = %d, coreid = %d, type = %d\r\n", pstsw_msg_info->i8Data, pstsw_msg_info->u16DataLen, pstsw_msg_info->u8CoreId, pstsw_msg_info->u8PktType); //printf("i8Data = %p, len = %d, coreid = %d, type = %d\r\n", pstsw_msg_info->i8Data, pstsw_msg_info->u16DataLen, pstsw_msg_info->u8CoreId, pstsw_msg_info->u8PktType);
//osp_write_diaglog((char*)pstsw_msg_info->i8Data, pstsw_msg_info->u16DataLen, pstsw_msg_info->u8CoreId, pstsw_msg_info->u8PktType); //osp_write_diaglog((char*)pstsw_msg_info->i8Data, pstsw_msg_info->u16DataLen, pstsw_msg_info->u8CoreId, pstsw_msg_info->u8PktType);
osp_dbg_log_main(pstsw_msg_info); osp_dbg_log_main(pstsw_msg_info);
} }
u32msg_cur_size += u32log_size; u32msg_cur_size += u32log_size;
} }
else if (MSG_TRANSFER_SHELL_MSG_TYPE == u32msg_type) else if (MSG_TRANSFER_SHELL_MSG_TYPE == u32msg_type)
@ -1189,21 +1191,21 @@ int32_t osp_log_msg_proc(uint8_t *pu8msg_add, uint32_t u32msg_size)
return 0; return 0;
} }
uint32_t rx_callback_oam(const char* buf,uint32_t payloadSize) uint32_t rx_callback_oam(const char* buf,uint32_t payloadSize)
{ {
osp_log_msg_info_t stosp_log_msg; osp_log_msg_info_t stosp_log_msg;
int32_t i32log_que_id = osp_log_msg_get_id(); int32_t i32log_que_id = osp_log_msg_get_id();
memset(&stosp_log_msg, 0, sizeof(stosp_log_msg)); memset(&stosp_log_msg, 0, sizeof(stosp_log_msg));
stosp_log_msg.pu8msg_addr = (uint8_t *)buf; stosp_log_msg.pu8msg_addr = (uint8_t *)buf;
stosp_log_msg.u32msg_size = payloadSize; stosp_log_msg.u32msg_size = payloadSize;
//UCP_PRINT_LOG("oam recv: buf = %p, size = %d\r\n", buf, payloadSize); //UCP_PRINT_LOG("oam recv: buf = %p, size = %d\r\n", buf, payloadSize);
osp_log_msg_send(i32log_que_id, (uint8_t*)&stosp_log_msg, sizeof(stosp_log_msg)); osp_log_msg_send(i32log_que_id, (uint8_t*)&stosp_log_msg, sizeof(stosp_log_msg));
return payloadSize; return payloadSize;
} }
uint64_t osp_oam_msg_proc_task(void) uint64_t osp_oam_msg_proc_task(void)