From bd18ca0e9e4ac3c8cbd203eb7f18d5374bd751c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E5=AE=B6=E5=B2=AD?= Date: Wed, 26 Jun 2019 13:08:18 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=A4=9A=E8=BF=9B=E7=A8=8B?= =?UTF-8?q?=E8=B0=83=E7=94=A8=E6=97=B6=E7=A8=8B=E5=BA=8F=E5=B4=A9=E6=BA=83?= =?UTF-8?q?=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修改: Makefile 修改: nicinfo_shm.c Signed-off-by: 张家岭 --- code/sys_nicmonitor/Makefile | 7 +++++-- code/sys_nicmonitor/nicinfo_shm.c | 22 ++++++++++++---------- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/code/sys_nicmonitor/Makefile b/code/sys_nicmonitor/Makefile index cb76a76..0650dfc 100644 --- a/code/sys_nicmonitor/Makefile +++ b/code/sys_nicmonitor/Makefile @@ -6,12 +6,15 @@ include $(DEFAULTS) all:sys_nicmonitor libnic_shm.so test -CFLAGS += -Wall -Wformat=2 -Wno-format-extra-args -Wformat-security -Wformat-nonliteral #-g +#CFLAGS += -D TESTINTERVAL -Wall -Wformat=2 -Wno-format-extra-args -Wformat-security -Wformat-nonliteral -O0 -g +CFLAGS += -Wall -Wformat=2 -Wno-format-extra-args -Wformat-security -Wformat-nonliteral -O0 -g sys_nicmonitor:mnic.o read_netcard.o send_alarm.o $(CC) -lman -ldotconf -lpthread -o $@ $^ -libnic_shm.so:nicinfo_shm.c +libnic_shm.so:nicinfo_shm.o $(CC) -fpic -shared -o $@ $^ +nicinfo_shm.o:nicinfo_shm.c + $(CC) $(CFLAGS) -fPIC -c $^ test:test.c gcc -o test test.c -lnic_shm -L=./ -lpthread runtest: diff --git a/code/sys_nicmonitor/nicinfo_shm.c b/code/sys_nicmonitor/nicinfo_shm.c index 2009e69..1c046bf 100644 --- a/code/sys_nicmonitor/nicinfo_shm.c +++ b/code/sys_nicmonitor/nicinfo_shm.c @@ -33,6 +33,7 @@ SHM *ptr = NULL; static char process_name[32] = "get_nic_info"; static void linx_free_shm( void *addr, int size ); +static int nic_init_flag = 0; #if 0 static pthread_mutex_t lock_record_log = PTHREAD_MUTEX_INITIALIZER; @@ -181,8 +182,6 @@ static void *global_shmptr = NULL; int init_nic_info(void) { - int fd = -1; - int sem_val; char err_str[200]; key_t key; @@ -234,10 +233,6 @@ int init_nic_info(void) void* shmptr = NULL; int size = 0; key_t share_key; - int share_id = 0; - char *ref_count = NULL; - char *flag_str = NULL; - char *path = shm_path; size = sizeof(SHM); size = size + 16; @@ -294,7 +289,6 @@ int get_nic_info(char *nic_name, NETCARD_INFO *net_info) char *s; char buf[128]; char err_str[200]; - struct passwd *user; int shm_id; int shm_key = 0x1d6010; char *shm_buf; @@ -339,10 +333,18 @@ int get_nic_info(char *nic_name, NETCARD_INFO *net_info) strcat(log_path, buf); LOGPATH_UNLOCK; - if((ret = init_nic_info()) == -1){ - return -1; + if (nic_init_flag != 1){ + ret = init_nic_info(); + if (ret != 0){ + return -1; + } + nic_init_flag = 1; } get_sem(semid); +// ret = init_nic_info() +// if((ret = init_nic_info()) == -1){ +// return -1; +// } for(i = 0; ptr->info[i].charname[0] != 0; i++){ if(!strcmp(ptr->info[i].charname, nic_name)){ // get_sem(semid); @@ -369,9 +371,9 @@ int get_nic_info(char *nic_name, NETCARD_INFO *net_info) static void linx_free_shm( void *addr, int size ) { + return ; void *shmptr = addr; - char err_str[200]; #if 0 snprintf(err_str, sizeof(err_str), "NOTICE: free shm 0x%x, size:%d, glo:0x%x\n", addr, size, global_shmptr);