[ #1 ] 修复monitor_interval 溢出问题

修改:      README
	修改:      mnic.c
	修改:      version.h

Signed-off-by: 张家岭 <jlzhang@linx-info.com>

  (使用 "git reset HEAD^1 <file>..." 撤出暂存区)

  修改:      sys_nicmonitor/README
  修改:      sys_nicmonitor/mnic.c
  修改:      sys_nicmonitor/version.h
This commit is contained in:
张家岭
2019-09-05 11:35:42 +08:00
parent ac7eb4a56d
commit 8fdda73c79
3 changed files with 50 additions and 34 deletions

View File

@@ -75,6 +75,12 @@ make runtest
=======
版本说明:
--V1.21 --
2019-09-05
1修复问题monitor_interval参数溢出导致cpu 100%
问题描述当monitor_interval参数配置为1000时出现进程cpu占用100%的问题
解决办法增加对monitor_interval配置的检测和限制
--V1.9 --
2013-08-12
1修复问题占用内存快速累加导致内存占用很大

View File

@@ -119,10 +119,10 @@ CONFIG_FILE_ST conf;
char myconf[][64] = {
"domain", // 0
"serv", // 1
"serv", // 1
"event", // 2
"udpport", // 3
"sys_netcard_shm_path", // 4
"sys_netcard_shm_path", // 4
"sys_netcard_sem_path", // 5
"monitor_interval", // 6
"write_interval", // 7
@@ -151,7 +151,7 @@ static const configoption_t options[] = {
{myconf[9], ARG_INT, cb_int, NULL, CTX_ALL},
{myconf[10], ARG_INT, cb_int, NULL, CTX_ALL},
{myconf[11], ARG_STR, cb_str, NULL, CTX_ALL},
{myconf[12], ARG_STR, cb_str, NULL, CTX_ALL},
{myconf[12], ARG_STR, cb_str, NULL, CTX_ALL},
{myconf[13], ARG_STR, cb_str, NULL, CTX_ALL},
{myconf[14], ARG_INT, cb_int, NULL, CTX_ALL},
{myconf[15], ARG_INT, cb_int, NULL, CTX_ALL},
@@ -191,7 +191,7 @@ static void *record_log_thread( void *arg )
log_thread_exit = 0;
log_fp = fopen(log_path, "a");
while( !log_thread_exit ) {
if( !log_fp ) {
log_fp = fopen(log_path, "a");
@@ -233,7 +233,7 @@ static void *record_log_thread( void *arg )
log_prepare = NULL;
log_writing = NULL;
return NULL;
return NULL;
}
/* write error in logfile */
@@ -266,7 +266,7 @@ void record_log(char *str)
if(fwrite(log_str, 1, strlen(log_str), log_fp) < 1){
}
fclose(log_fp);
}
}
#else
static int log_thread_started = 0;
time_t tamp;
@@ -305,9 +305,9 @@ void record_log(char *str)
log_prepare[log_idx] = keepstr;
log_idx++;
}
LOG_UNLOCK;
LOG_UNLOCK;
#endif
#endif
}
#else
@@ -385,14 +385,14 @@ static void init_shm(SHM **ptr, CONFIG_FILE_ST *p)
share_key = 0x1d5010;
#if 0
snprintf( error_str, sizeof( error_str ),
snprintf( error_str, sizeof( error_str ),
"MSG: sys_nic, shm, size:%d, key:0x%x(%d)\n", size, share_key, share_key);
record_log(error_str);
#endif
global_share_id = shmget( share_key, size, IPC_CREAT|0666 );
if( global_share_id == -1 ) {
snprintf( error_str, sizeof( error_str ),
snprintf( error_str, sizeof( error_str ),
"EMERG: fail shmget, %s, 0x%x\n", strerror(errno), share_key);
record_log(error_str);
return;
@@ -400,7 +400,7 @@ static void init_shm(SHM **ptr, CONFIG_FILE_ST *p)
shmptr = shmat( global_share_id, NULL, 0 );
if( shmptr == (void *)-1 ) {
snprintf( error_str, sizeof( error_str ),
snprintf( error_str, sizeof( error_str ),
"EMERG: fail shmat, %s, %s\n", strerror(errno), path);
record_log(error_str);
return;
@@ -450,7 +450,7 @@ static void release_sem(int semid)
char error_str[200];
struct sembuf unlock;
unlock.sem_num = 0;
unlock.sem_num = 0;
unlock.sem_op = 1;
unlock.sem_flg = SEM_UNDO;
@@ -616,7 +616,7 @@ static void send_inc_info_one(NETCARD_INFO *net, int semid, SHM *ptr)
if(!strncmp(ptr->info[i].charname, net->charname, NIC_NAME_LEN)){
get_sem(semid);
memcpy(&ptr->info[i], net, sizeof(NETCARD_INFO));
release_sem(semid);
release_sem(semid);
}
}
}
@@ -639,7 +639,7 @@ static void *send_inc_info(void *p)
return NULL;
}
s_time.tv_sec = ptr->conf->write_interval;
s_time.tv_nsec = 0;
s_time.tv_nsec = 0;
/* copy all net_info*/
while(1){
@@ -738,7 +738,7 @@ static void *cacu_flow(void *p)
//tx_flow,rx_flow,
rx_flow=(curr->info.rx_bytes -rx_bytes[i])/ptr->mem.conf->flow_interval;
tx_flow=(curr->info.tx_bytes -tx_bytes[i])/ptr->mem.conf->flow_interval;
if(!strncmp(curr->info.charname, "bond", 4)){
count_t = get_netcard_count(curr->info.charname);
}else {
@@ -772,8 +772,8 @@ static void *cacu_flow(void *p)
if(count_no[i] == 0){
send_inc_info_one(&curr->info, ptr->mem.semid, ptr->mem.shm_ptr);
if( sys_nic_debug ) {
snprintf(error_str, sizeof(error_str),
"NOTICE: %s flow is abnormal, summit is %d, average flow is %lld , rx_flow is %lld , tx_flow is %lld !\n",
snprintf(error_str, sizeof(error_str),
"NOTICE: %s flow is abnormal, summit is %d, average flow is %lld , rx_flow is %lld , tx_flow is %lld !\n",
curr->info.charname, summit, curr->info.average_flow,rx_flow,tx_flow);
} else {
snprintf(error_str, sizeof(error_str), "NOTICE: %s flow is abnormal !\n", curr->info.charname);
@@ -1082,7 +1082,7 @@ void sig_handler(int sig)
record_log(err_str);
}
#endif
// semctl(sem_id, 0, IPC_RMID);
// semctl(sem_id, 0, IPC_RMID);
// snprintf(err_str, sizeof(err_str), "NOTICE: process exit by signal %d\n", sig);
// record_log(err_str);
@@ -1255,6 +1255,11 @@ int get_conf()
conf.udpport = 15000;
if(conf.monitor_interval == 0)
conf.monitor_interval = 100;
if(conf.monitor_interval >= 1000){
sprintf(tmp_str,"%s","Error monitor_interval must less than 1000\n");
record_log(tmp_str);
return -2;
}
if(conf.write_interval == 0)
conf.write_interval = 300;
if(conf.flow_interval == 0)
@@ -1436,7 +1441,7 @@ int get_netcard_status(NETCARD_INFO_ST *listp)
return NIC_UNLINKABLE;
}
else{
if(listp->status == NIC_UNLINKABLE)
if(listp->status == NIC_UNLINKABLE)
return NIC_UNLINKABLE;
}
@@ -1505,7 +1510,7 @@ int main(int argc, char ** argv)
int ret = 0, proc_stat = 0;
unsigned int i = 0;
int nic_status;
int sys_time_stamp = 0;
int sys_time_stamp = 0;
char *retp = NULL;
char *str = NULL;
char bond[128];
@@ -1534,10 +1539,10 @@ int main(int argc, char ** argv)
char log_record[125]={0};
char *dir_memory;
int shm_key =0x1d6010;
if( getenv("SYS_NIC_DEBUG") ) {
sys_nic_debug = 1;
}
}
memset(&conf, 0, sizeof(CONFIG_FILE_ST));
if(isrun(argv[0]) == 1){
@@ -1557,9 +1562,9 @@ int main(int argc, char ** argv)
sigaddset(&sig.sa_mask, SIGINT);
sigaddset(&sig.sa_mask, SIGTERM);
sig.sa_flags = 0;
sigaction(SIGTERM, &sig, NULL);
sigaction(SIGINT, &sig, NULL);
sigaction(SIGSEGV, &sig, NULL);
sigaction(SIGTERM, &sig, NULL);
sigaction(SIGINT, &sig, NULL);
sigaction(SIGSEGV, &sig, NULL);
/* create dir file path */
if((user = getpwnam("d5000")) != NULL){
@@ -1615,11 +1620,16 @@ int main(int argc, char ** argv)
log_time.tv_nsec = 1000000;
while(log_flag)nanosleep(&log_time, NULL);
/* sure the process is started */
snprintf(error_str, sizeof(error_str), "NOTICE: %s V%s is started !\n", process_name, MNIC_VERSION);
record_log(error_str);
if(get_conf()==-2){
printf("Error monitor_interval must less than 1000\n");
return -1;
} else{
snprintf(error_str, sizeof(error_str), "NOTICE: %s V%s is started !\n", process_name, MNIC_VERSION);
record_log(error_str);
}
/* sure the process is started */
get_conf();
if(shm_path){
printf("shm_path:%s\n",shm_path);
@@ -1648,7 +1658,7 @@ int main(int argc, char ** argv)
/* get broadcast address*/
if((ret = get_broad_ip()) != 0)
return -1;
return -1;
if((ret = create_name_list(&all_name_list, &opt_name_list)) != 0)
return -1;
/* get hostname */
@@ -1787,7 +1797,7 @@ int main(int argc, char ** argv)
munmap(shm_ptr, sizeof(SHM));
#else
{
void *shmptr = shm_ptr;
#if 0
snprintf(error_str, sizeof(error_str), "NOTICE: free shm %p, glo:%p\n", shmptr, global_shmptr);
@@ -1803,7 +1813,7 @@ int main(int argc, char ** argv)
is_last = *ref_count == 1?1:0;
#if 0
snprintf(error_str, sizeof(error_str), "NOTICE: sys_nic, size:%d, ref_count: %d, last:%d\n",
snprintf(error_str, sizeof(error_str), "NOTICE: sys_nic, size:%d, ref_count: %d, last:%d\n",
size, *ref_count, is_last);
record_log(error_str);
#endif
@@ -1819,7 +1829,7 @@ int main(int argc, char ** argv)
// global_share_id = -1;
// }
}
}
}
#endif
return 0;
}

View File

@@ -1,5 +1,5 @@
// version=1.20
#ifndef MNIC_VERSION
#define MNIC_VERSION "1.20"
#define MNIC_VERSION "1.21"
#endif