更新至1.8版本。
重新组织目录结构。更新至1.8版本。 git-svn-id: http://172.17.0.253/svn/soft_pkgs/sys_nicmonitor@1398 09c3743a-b0dd-45d3-b506-aa74c7a2a6ef
This commit is contained in:
@@ -9,7 +9,7 @@ all:sys_nicmonitor libnic_shm.so
|
||||
CFLAGS += -Wall -Wformat=2 -Wno-format-extra-args -Wformat-security -Wformat-nonliteral #-g
|
||||
|
||||
sys_nicmonitor:mnic.o read_netcard.o send_alarm.o
|
||||
$(CC) -ldotconf -lpthread -o $@ $^
|
||||
$(CC) -lman -ldotconf -lpthread -o $@ $^
|
||||
libnic_shm.so:nicinfo_shm.c
|
||||
$(CC) -fpic -shared -o $@ $^
|
||||
clean:
|
||||
|
||||
BIN
code/trunk/sys_nicmonitor/bin/sys_nicmonitor
Executable file
BIN
code/trunk/sys_nicmonitor/bin/sys_nicmonitor
Executable file
Binary file not shown.
@@ -2,6 +2,9 @@
|
||||
#include "dotconf.h"
|
||||
#include <arpa/inet.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/ipc.h>
|
||||
#include <sys/shm.h>
|
||||
#include <pthread.h>
|
||||
#include "proc_inv.h"
|
||||
|
||||
#define THRNR 10
|
||||
@@ -10,14 +13,14 @@
|
||||
#define HOST_NAME_SIZE 40
|
||||
#define BOND_PATH "/proc/net/bonding/*"
|
||||
#define LOG_PATH "/var/log/netcard/"
|
||||
#define SHM_PATH "/tmp/sys_netcard_shm_path"
|
||||
#define SEM_PATH "/tmp/sys_netcard_sem_path"
|
||||
#define SHM_PATH "/share/sys_netcard_shm_path"
|
||||
#define SEM_PATH "/share/sys_netcard_sem_path"
|
||||
#define MAX_GW 32
|
||||
#define DEV_MAXLEN 32
|
||||
#define IPLEN 16
|
||||
#define CONF_FILE "/conf/nic/sys_netcard_conf.txt"
|
||||
|
||||
#define MNIC_VERSION "1.6"
|
||||
#define MNIC_VERSION "1.8"
|
||||
|
||||
#define NIC_UNKNOWN 0
|
||||
#define NIC_DOWN 1
|
||||
@@ -33,16 +36,16 @@ typedef struct __nic_dev{
|
||||
}NIC_DEV;
|
||||
|
||||
typedef struct __config_file_st{
|
||||
unsigned char domain;
|
||||
short serv;
|
||||
short event;
|
||||
int udpport;
|
||||
int monitor_interval;
|
||||
int write_interval;
|
||||
int flow_interval;
|
||||
int flow_limit;
|
||||
int flow_peak;
|
||||
char udp[NIC_NAME_LEN];
|
||||
unsigned char domain;
|
||||
short serv;
|
||||
short event;
|
||||
int udpport;
|
||||
int monitor_interval;
|
||||
int write_interval;
|
||||
int flow_interval;
|
||||
int flow_limit;
|
||||
int flow_peak;
|
||||
char udp[NIC_NAME_LEN];
|
||||
NIC_DEV nic[MAXNICNUM]; //被监视网卡的列表
|
||||
char ip[IPSIZE];
|
||||
int pingnum; //OPTIONAL!! How many times for once ping check? Default is 2.
|
||||
@@ -112,49 +115,78 @@ int nicnum = 0;
|
||||
CONFIG_FILE_ST conf;
|
||||
|
||||
char myconf[][64] = {
|
||||
"domain", // 0
|
||||
"serv", // 1
|
||||
"event", // 2
|
||||
"udpport", // 3
|
||||
"sys_netcard_shm_path", // 4
|
||||
"sys_netcard_sem_path", // 5
|
||||
"monitor_interval", // 6
|
||||
"write_interval", // 7
|
||||
"flow_interval", // 8
|
||||
"flow_limit", // 9
|
||||
"flow_peak", // 10
|
||||
"udp", // 11
|
||||
"nic", // 12
|
||||
"ping", // 13
|
||||
"domain", // 0
|
||||
"serv", // 1
|
||||
"event", // 2
|
||||
"udpport", // 3
|
||||
"sys_netcard_shm_path", // 4
|
||||
"sys_netcard_sem_path", // 5
|
||||
"monitor_interval", // 6
|
||||
"write_interval", // 7
|
||||
"flow_interval", // 8
|
||||
"flow_limit", // 9
|
||||
"flow_peak", // 10
|
||||
"udp", // 11
|
||||
"nic", // 12
|
||||
"ping", // 13
|
||||
"pingnum", // 14
|
||||
"pinglap", // 15
|
||||
""
|
||||
""
|
||||
};
|
||||
|
||||
static const configoption_t options[] = {
|
||||
{myconf[0], ARG_INT, cb_int, NULL, CTX_ALL},
|
||||
{myconf[1], ARG_INT, cb_int, NULL, CTX_ALL},
|
||||
{myconf[2], ARG_INT, cb_int, NULL, CTX_ALL},
|
||||
{myconf[3], ARG_INT, cb_int, NULL, CTX_ALL},
|
||||
{myconf[4], ARG_STR, cb_str, NULL, CTX_ALL},
|
||||
{myconf[5], ARG_STR, cb_str, NULL, CTX_ALL},
|
||||
{myconf[6], ARG_INT, cb_int, NULL, CTX_ALL},
|
||||
{myconf[7], ARG_INT, cb_int, NULL, CTX_ALL},
|
||||
{myconf[8], ARG_INT, cb_int, NULL, CTX_ALL},
|
||||
{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[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},
|
||||
LAST_OPTION
|
||||
{myconf[0], ARG_INT, cb_int, NULL, CTX_ALL},
|
||||
{myconf[1], ARG_INT, cb_int, NULL, CTX_ALL},
|
||||
{myconf[2], ARG_INT, cb_int, NULL, CTX_ALL},
|
||||
{myconf[3], ARG_INT, cb_int, NULL, CTX_ALL},
|
||||
{myconf[4], ARG_STR, cb_str, NULL, CTX_ALL},
|
||||
{myconf[5], ARG_STR, cb_str, NULL, CTX_ALL},
|
||||
{myconf[6], ARG_INT, cb_int, NULL, CTX_ALL},
|
||||
{myconf[7], ARG_INT, cb_int, NULL, CTX_ALL},
|
||||
{myconf[8], ARG_INT, cb_int, NULL, CTX_ALL},
|
||||
{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[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},
|
||||
LAST_OPTION
|
||||
};
|
||||
/****dotconf****/
|
||||
|
||||
void create_dir(char *create_path);
|
||||
|
||||
static pthread_mutex_t lock_record_log = PTHREAD_MUTEX_INITIALIZER;
|
||||
#define LOG_LOCK pthread_mutex_lock(&lock_record_log)
|
||||
#define LOG_UNLOCK pthread_mutex_unlock(&lock_record_log)
|
||||
//static int is_checkdir = 0;
|
||||
static void *record_log_thread( void *arg )
|
||||
{
|
||||
char *log_str = (char *)arg;
|
||||
FILE *log_fp = NULL;
|
||||
|
||||
LOG_LOCK;
|
||||
// if( !is_checkdir ) {
|
||||
create_dir( log_path );
|
||||
// is_checkdir = 1;
|
||||
// }
|
||||
if((log_fp = fopen(log_path, "a")) != NULL){
|
||||
if(fwrite(log_str, 1, strlen(log_str), log_fp) < 1){
|
||||
}
|
||||
fclose(log_fp);
|
||||
}
|
||||
|
||||
LOG_UNLOCK;
|
||||
free(log_str);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* write error in logfile */
|
||||
void record_log(char *str)
|
||||
{
|
||||
#if 0
|
||||
time_t tamp;
|
||||
char str_tm[4];
|
||||
char log_str[512];
|
||||
@@ -181,21 +213,62 @@ void record_log(char *str)
|
||||
if(fwrite(log_str, 1, strlen(log_str), log_fp) < 1){
|
||||
}
|
||||
fclose(log_fp);
|
||||
}
|
||||
}
|
||||
#else
|
||||
time_t tamp;
|
||||
char str_tm[4];
|
||||
char log_str[512];
|
||||
// FILE *log_fp = NULL;
|
||||
struct tm tmptr;
|
||||
struct timeval tv;
|
||||
struct timezone tz;
|
||||
|
||||
// if((log_fp = fopen(log_path, "a")) != NULL){
|
||||
tamp = time(NULL);
|
||||
memset(str_tm, 0, sizeof(str_tm));
|
||||
memset(log_str, 0, sizeof(log_str));
|
||||
localtime_r(&tamp, &tmptr);
|
||||
gettimeofday(&tv, &tz);
|
||||
snprintf(str_tm, sizeof(str_tm), "%d", (int)tv.tv_usec/1000);
|
||||
if(str_tm[1] == '\0')str_tm[1] = '0';
|
||||
if(str_tm[2] == '\0')str_tm[2] = '0';
|
||||
strftime(log_str, sizeof(log_str), "%F %T.", &tmptr);
|
||||
strcat(log_str, str_tm);
|
||||
strcat(log_str, " ");
|
||||
strcat(log_str, process_name);
|
||||
strcat(log_str, " ");
|
||||
strcat(log_str, str);
|
||||
// if(fwrite(log_str, 1, strlen(log_str), log_fp) < 1){
|
||||
// }
|
||||
// fclose(log_fp);
|
||||
|
||||
// }
|
||||
|
||||
{
|
||||
pthread_t pid;
|
||||
char *keepstr = strdup( log_str );
|
||||
pthread_create( &pid, NULL, record_log_thread, (void *)keepstr);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
static void init_sem(int *semid, CONFIG_FILE_ST *ptr)
|
||||
{
|
||||
key_t key;
|
||||
char error_str[200];
|
||||
|
||||
/* write error in logfile */
|
||||
|
||||
/* write error in logfile */
|
||||
memset(error_str, 0, sizeof(error_str));
|
||||
#if 0
|
||||
if ((key = ftok(sem_path, SEM_PROJ_ID)) == -1) {
|
||||
snprintf(error_str, sizeof(error_str), "EMERG: ftok():%s\n", strerror(errno));
|
||||
record_log(error_str);
|
||||
return;
|
||||
}
|
||||
#else
|
||||
key = 0x1d5200;
|
||||
#endif
|
||||
|
||||
if((*semid = semget(key, 1, IPC_CREAT|0666)) == -1){
|
||||
snprintf(error_str, sizeof(error_str), "EMERG: semget():%s\n", strerror(errno));
|
||||
record_log(error_str);
|
||||
@@ -209,8 +282,12 @@ static void init_sem(int *semid, CONFIG_FILE_ST *ptr)
|
||||
}
|
||||
}
|
||||
|
||||
static int global_share_id = -1;
|
||||
static void *global_shmptr = NULL;
|
||||
|
||||
static void init_shm(SHM **ptr, CONFIG_FILE_ST *p)
|
||||
{
|
||||
#ifdef USE_OLD_MMSHARE
|
||||
int fd = -1;
|
||||
char error_str[200];
|
||||
|
||||
@@ -221,15 +298,66 @@ static void init_shm(SHM **ptr, CONFIG_FILE_ST *p)
|
||||
return;
|
||||
}
|
||||
umask(mask_tmp);
|
||||
lseek(fd, sizeof(SHM), SEEK_SET);
|
||||
write(fd, "\0", 1);
|
||||
*ptr = (SHM *)mmap(NULL, sizeof(SHM), PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
|
||||
lseek(fd, sizeof(SHM), SEEK_SET);
|
||||
write(fd, "\0", 1);
|
||||
*ptr = (SHM *)mmap(NULL, sizeof(SHM), PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
|
||||
if(*ptr == MAP_FAILED){
|
||||
snprintf(error_str, sizeof(error_str), "EMERG: mmap():%s\n", strerror(errno));
|
||||
record_log(error_str);
|
||||
return;
|
||||
}
|
||||
close(fd);
|
||||
return;
|
||||
}
|
||||
close(fd);
|
||||
#else
|
||||
void* shmptr = NULL;
|
||||
int size = 0;
|
||||
key_t share_key;
|
||||
// char *ref_count = NULL;
|
||||
char *flag_str = NULL;
|
||||
char *path = shm_path;
|
||||
char error_str[200];
|
||||
|
||||
size = sizeof(SHM);
|
||||
size = size + 16;
|
||||
|
||||
// share_key = ftok(path, 0x000d5000);
|
||||
share_key = 0x1d5010;
|
||||
|
||||
#if 0
|
||||
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 ),
|
||||
"EMERG: fail shmget, %s, 0x%x\n", strerror(errno), share_key);
|
||||
record_log(error_str);
|
||||
return;
|
||||
}
|
||||
|
||||
shmptr = shmat( global_share_id, NULL, 0 );
|
||||
if( shmptr == (void *)-1 ) {
|
||||
snprintf( error_str, sizeof( error_str ),
|
||||
"EMERG: fail shmat, %s, %s\n", strerror(errno), path);
|
||||
record_log(error_str);
|
||||
return;
|
||||
}
|
||||
|
||||
flag_str = (char *)shmptr+size-16;
|
||||
|
||||
// if( strcmp( flag_str, "D5001" ) != 0 ) {
|
||||
//first, do init.
|
||||
memset( shmptr, 0, size );
|
||||
// strcpy( flag_str, "D5001" );
|
||||
// }
|
||||
|
||||
global_shmptr = shmptr;
|
||||
|
||||
// ref_count = (char *)shmptr+size-1;
|
||||
// (*ref_count)++;
|
||||
*ptr = (SHM *)shmptr;
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
@@ -245,7 +373,7 @@ static void get_sem(int semid)
|
||||
lock[1].sem_num = 0;
|
||||
lock[1].sem_op = 1;
|
||||
lock[1].sem_flg = SEM_UNDO;
|
||||
|
||||
|
||||
while(semop(semid, lock, 2)){
|
||||
if(errno == EINTR)continue;
|
||||
snprintf(error_str, sizeof(error_str), "EMERG: get_sem semop():%s\n", strerror(errno));
|
||||
@@ -448,13 +576,13 @@ 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){
|
||||
i = 0;
|
||||
get_sem(ptr->semid);
|
||||
memset(ptr->shm_ptr, 0, sizeof(SHM));
|
||||
//memset(ptr->shm_ptr, 0, sizeof(SHM));
|
||||
curr = ptr->listp->next;
|
||||
while(curr != NULL){
|
||||
get_inc_info(&curr->info);
|
||||
@@ -489,7 +617,7 @@ static int get_netcard_count(char *name)
|
||||
|
||||
strncat(path, name, strlen(name));
|
||||
if((fp = fopen(path, "r")) == NULL)return 1;
|
||||
|
||||
|
||||
memset(buf, 0, sizeof(buf));
|
||||
fseek(fp, 65, SEEK_SET);
|
||||
while((retp = fgets(buf, sizeof(buf), fp)) != NULL){
|
||||
@@ -521,10 +649,10 @@ static void *cacu_flow(void *p)
|
||||
snprintf(error_str, sizeof(error_str), "EMERG: Empty Netcard list!\n");
|
||||
record_log(error_str);
|
||||
pthread_mutex_unlock(&mut);
|
||||
return NULL;
|
||||
}
|
||||
s_time.tv_sec = ptr->mem.conf->flow_interval;
|
||||
s_time.tv_nsec = 0;
|
||||
return NULL;
|
||||
}
|
||||
s_time.tv_sec = ptr->mem.conf->flow_interval;
|
||||
s_time.tv_nsec = 0;
|
||||
|
||||
for(i = 0; i < MAXNICNUM ; i++){
|
||||
count_ok[i] = 0;
|
||||
@@ -533,9 +661,9 @@ static void *cacu_flow(void *p)
|
||||
while(1){
|
||||
i = 0;
|
||||
curr = ptr->mem.listp->next;
|
||||
while(curr != NULL){
|
||||
get_inc_info(&curr->info);
|
||||
get_inc_stats(&curr->info);
|
||||
while(curr != NULL){
|
||||
get_inc_info(&curr->info);
|
||||
get_inc_stats(&curr->info);
|
||||
if(flags){
|
||||
bytes[i] = curr->info.rx_bytes + curr->info.tx_bytes;
|
||||
}
|
||||
@@ -622,8 +750,8 @@ static char *parse_str(char **s)
|
||||
|
||||
int ping_gw(char *devname)
|
||||
{
|
||||
FILE *fp;
|
||||
int i, ret = -1, j, k;
|
||||
FILE *fp;
|
||||
int i, j, k;
|
||||
char buf[128];
|
||||
char getbuf[64];
|
||||
|
||||
@@ -636,31 +764,29 @@ int ping_gw(char *devname)
|
||||
|
||||
for(k=0; k<conf.pingnum; ++k){
|
||||
for(j=0; j<conf.nic[i].gw_num; ++j){
|
||||
//snprintf(buf, sizeof(buf), "ping -c 1 -w %d %s > /dev/null 2>&1", conf.pinglap,conf.nic[i].ping_ip[j]);
|
||||
|
||||
snprintf(buf,sizeof(buf),"ping -c 1 -w %d %s|grep received|awk -F, '{print $2}'|awk '{print $1}'", conf.pinglap,conf.nic[i].ping_ip[j]);
|
||||
if((fp = popen(buf,"r")) == NULL)
|
||||
{
|
||||
perror("popen");
|
||||
return 0;
|
||||
}else{
|
||||
fgets(getbuf,sizeof(getbuf),fp);
|
||||
if(strncmp(getbuf,"1",1) == 0)
|
||||
{
|
||||
pclose(fp);
|
||||
return 0;
|
||||
}else{
|
||||
pclose(fp);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
pclose(fp);
|
||||
return 0;
|
||||
snprintf(buf,sizeof(buf),"ping -c 1 -w %d %s|grep received|awk -F, '{print $2}'|awk '{print $1}'", conf.pinglap,conf.nic[i].ping_ip[j]);
|
||||
if((fp = popen(buf,"r")) == NULL)
|
||||
{
|
||||
perror("popen");
|
||||
return 0;
|
||||
}else{
|
||||
fgets(getbuf,sizeof(getbuf),fp);
|
||||
if(strncmp(getbuf,"0",1) != 0)
|
||||
{
|
||||
pclose(fp);
|
||||
return 0;
|
||||
}else{
|
||||
pclose(fp);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
pclose(fp);
|
||||
return 0;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
return -1;
|
||||
}
|
||||
|
||||
static void *check_inc_switch(void *ptr)
|
||||
@@ -669,11 +795,11 @@ static void *check_inc_switch(void *ptr)
|
||||
FILE *fp = NULL;
|
||||
char name[NIC_NAME_LEN];
|
||||
struct timespec s_time, os_time;
|
||||
int count = 0;
|
||||
int count = 0;
|
||||
char linebuf[LINE_SIZE];
|
||||
char error_str[200];
|
||||
char *str = NULL;
|
||||
char *retp = NULL;
|
||||
char *str = NULL;
|
||||
char *retp = NULL;
|
||||
|
||||
if((fp = fopen(arg->bond_file_path, "r")) == NULL){
|
||||
snprintf(error_str, sizeof(error_str), "EMERG: fopen():%s\n", strerror(errno));
|
||||
@@ -691,9 +817,9 @@ static void *check_inc_switch(void *ptr)
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
s_time.tv_sec = 0;
|
||||
s_time.tv_nsec = 100000000;
|
||||
s_time.tv_nsec = 100000000;
|
||||
|
||||
while(1){
|
||||
while((str = fgets(linebuf, sizeof(linebuf), fp)) != NULL){
|
||||
@@ -739,7 +865,7 @@ static void *check_inc_switch(void *ptr)
|
||||
}
|
||||
free(ptr);
|
||||
fclose(fp);
|
||||
return NULL;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void *create_logfile(void *ptr)
|
||||
@@ -801,7 +927,7 @@ void write_time(int semid, SHM *ptr)
|
||||
{
|
||||
int i = 0;
|
||||
int flag_time_stamp;
|
||||
|
||||
|
||||
flag_time_stamp = time(NULL);
|
||||
|
||||
while(ptr->info[i].charname[0] != 0){
|
||||
@@ -827,7 +953,7 @@ char *parse(char *line)
|
||||
void release_name_list(NET_NAME_ST *head)
|
||||
{
|
||||
NET_NAME_ST *curr, *save;
|
||||
|
||||
|
||||
curr = head->next;
|
||||
while(curr != NULL){
|
||||
save = curr->next;
|
||||
@@ -838,7 +964,7 @@ void release_name_list(NET_NAME_ST *head)
|
||||
int get_netcard(char *line, char *nic)
|
||||
{
|
||||
char *begin, *retp;
|
||||
|
||||
|
||||
while(isspace(*line))line++;
|
||||
begin = line;
|
||||
while(!isspace(*line))line++;
|
||||
@@ -854,7 +980,7 @@ int get_netcard(char *line, char *nic)
|
||||
|
||||
void sig_handler(int sig)
|
||||
{
|
||||
// char err_str[200];
|
||||
// char err_str[200];
|
||||
|
||||
#if 0
|
||||
if(unlink(SHM_PATH) == -1){
|
||||
@@ -866,10 +992,10 @@ 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);
|
||||
// snprintf(err_str, sizeof(err_str), "NOTICE: process exit by signal %d\n", sig);
|
||||
// record_log(err_str);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
@@ -885,7 +1011,7 @@ int find_nic_config(char *dev_name){
|
||||
|
||||
for(i=0; i<nicnum; ++i)
|
||||
if(!strcmp(dev_name, conf.nic[i].dev_name))
|
||||
index = i;
|
||||
index = i;
|
||||
|
||||
return index;
|
||||
}
|
||||
@@ -897,7 +1023,7 @@ DOTCONF_CB(cb_str)
|
||||
char wrong_ip[125] = {0};
|
||||
|
||||
//"ping"选项的处理
|
||||
if((strcmp(cmd ->name, myconf[13]) == 0) && (nicnum <= MAXNICNUM)){
|
||||
if((strcmp(cmd ->name, myconf[13]) == 0) && (nicnum <= MAXNICNUM)){
|
||||
i = 1;
|
||||
if(cmd->data.list[0] && cmd->data.list[1]){
|
||||
//查找设备列表中是否已有该网卡
|
||||
@@ -907,43 +1033,43 @@ DOTCONF_CB(cb_str)
|
||||
//如果没找到,则表明先定义了"ping",未定义"nic"或后定义"nic",而未定义"nic"应该是错误的
|
||||
index = find_nic_config(cmd->data.list[0]);
|
||||
if(index == -1){
|
||||
strncpy(conf.nic[nicnum].dev_name, cmd->data.list[0], strlen(cmd->data.list[0]) >= IPLEN ? IPLEN-1 : strlen(cmd->data.list[0]));
|
||||
strncpy(conf.nic[nicnum].dev_name, cmd->data.list[0], strlen(cmd->data.list[0]) >= IPLEN ? IPLEN-1 : strlen(cmd->data.list[0]));
|
||||
card_info_index = nicnum;
|
||||
nicnum++;
|
||||
nicnum++;
|
||||
}
|
||||
else
|
||||
card_info_index = index;
|
||||
|
||||
|
||||
while(cmd->data.list[i]){
|
||||
if((int)(inet_addr(cmd->data.list[i])) == -1){
|
||||
sprintf(wrong_ip,"The wrong IP address:'%s'",cmd->data.list[i]);
|
||||
strcat(wrong_ip,"\n");
|
||||
record_log(wrong_ip);
|
||||
} else{
|
||||
strncpy(conf.nic[card_info_index].ping_ip[conf.nic[card_info_index].gw_num++], cmd->data.list[i], strlen(cmd->data.list[i]) >= IPLEN ? IPLEN-1 : strlen(cmd->data.list[i]));
|
||||
strncpy(conf.nic[card_info_index].ping_ip[conf.nic[card_info_index].gw_num++], cmd->data.list[i], strlen(cmd->data.list[i]) >= IPLEN ? IPLEN-1 : strlen(cmd->data.list[i]));
|
||||
}
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//"nic"选项的处理
|
||||
if((strcmp(cmd ->name, myconf[12]) == 0) && (nicnum <= MAXNICNUM)){
|
||||
if((strcmp(cmd ->name, myconf[12]) == 0) && (nicnum <= MAXNICNUM)){
|
||||
//设备列表中没有给定的网卡设备,则添加一项
|
||||
//否则不必添加
|
||||
//对应配置文件中先指定"ping"后指定"nic"的情况
|
||||
index = find_nic_config(cmd->data.str);
|
||||
if(index == -1){
|
||||
strncpy(conf.nic[nicnum].dev_name, cmd->data.str, strlen(cmd->data.str) >= NIC_NAME_LEN ? NIC_NAME_LEN-1 : strlen(cmd->data.str));
|
||||
nicnum++;
|
||||
strncpy(conf.nic[nicnum].dev_name, cmd->data.str, strlen(cmd->data.str) >= NIC_NAME_LEN ? NIC_NAME_LEN-1 : strlen(cmd->data.str));
|
||||
nicnum++;
|
||||
}
|
||||
}
|
||||
|
||||
if((strcmp(cmd ->name, myconf[11]) == 0)){
|
||||
strncpy(conf.udp, cmd->data.str, strlen(cmd->data.str));
|
||||
}
|
||||
|
||||
return NULL;
|
||||
if((strcmp(cmd ->name, myconf[11]) == 0)){
|
||||
strncpy(conf.udp, cmd->data.str, strlen(cmd->data.str));
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
DOTCONF_CB(cb_int)
|
||||
@@ -981,43 +1107,43 @@ DOTCONF_CB(cb_int)
|
||||
if(strcmp(cmd ->name, myconf[15]) == 0){
|
||||
conf.pinglap = cmd->data.value;
|
||||
}
|
||||
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
DOTCONF_CB(cb_list)
|
||||
{
|
||||
return NULL;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int get_conf()
|
||||
{
|
||||
// int uid;
|
||||
// char buf[1024];
|
||||
// int i;
|
||||
// struct passwd *user;
|
||||
configfile_t *configfile;
|
||||
|
||||
// memset(buf, 0, sizeof(buf));
|
||||
// uid=getuid();
|
||||
// user = getpwnam("d5000");
|
||||
// user = getpwuid(uid);
|
||||
|
||||
// sprintf(buf,"%s", user->pw_dir);
|
||||
// strcat(buf,conf_path);
|
||||
// int uid;
|
||||
// char buf[1024];
|
||||
// int i;
|
||||
// struct passwd *user;
|
||||
configfile_t *configfile;
|
||||
|
||||
configfile = dotconf_create(conf_path, options, NULL, CASE_INSENSITIVE);
|
||||
if (!configfile)
|
||||
{
|
||||
record_log("Warning can't reading config file\n");
|
||||
return -1;
|
||||
}
|
||||
// memset(buf, 0, sizeof(buf));
|
||||
// uid=getuid();
|
||||
// user = getpwnam("d5000");
|
||||
// user = getpwuid(uid);
|
||||
|
||||
if (dotconf_command_loop(configfile) == 0){
|
||||
// sprintf(buf,"%s", user->pw_dir);
|
||||
// strcat(buf,conf_path);
|
||||
|
||||
configfile = dotconf_create(conf_path, options, NULL, CASE_INSENSITIVE);
|
||||
if (!configfile)
|
||||
{
|
||||
record_log("Warning can't reading config file\n");
|
||||
return -1;
|
||||
}
|
||||
dotconf_cleanup(configfile);
|
||||
|
||||
if (dotconf_command_loop(configfile) == 0){
|
||||
record_log("Warning can't reading config file\n");
|
||||
return -1;
|
||||
}
|
||||
dotconf_cleanup(configfile);
|
||||
|
||||
if(conf.domain == 0)
|
||||
conf.domain = 10;
|
||||
@@ -1051,21 +1177,21 @@ int get_conf()
|
||||
|
||||
int isrun(char *p)
|
||||
{
|
||||
char buf[16];
|
||||
char cmdbuf[1024];
|
||||
FILE *fp;
|
||||
char buf[16];
|
||||
char cmdbuf[1024];
|
||||
FILE *fp;
|
||||
|
||||
memset(buf, 0, sizeof(buf));
|
||||
memset(cmdbuf, 0, sizeof(cmdbuf));
|
||||
memset(buf, 0, sizeof(buf));
|
||||
memset(cmdbuf, 0, sizeof(cmdbuf));
|
||||
|
||||
snprintf(cmdbuf, sizeof(cmdbuf), "pidof %s", p);
|
||||
fp=popen(cmdbuf, "r");
|
||||
fread(buf, sizeof(char), sizeof(buf), fp);
|
||||
snprintf(cmdbuf, sizeof(cmdbuf), "pidof %s", p);
|
||||
fp=popen(cmdbuf, "r");
|
||||
fread(buf, sizeof(char), sizeof(buf), fp);
|
||||
pclose(fp);
|
||||
if(strchr(buf, ' ') != NULL)
|
||||
return 1;
|
||||
else
|
||||
return 0;
|
||||
if(strchr(buf, ' ') != NULL)
|
||||
return 1;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
int get_broad_ip(void)
|
||||
@@ -1074,17 +1200,17 @@ int get_broad_ip(void)
|
||||
char error_str[200];
|
||||
int skfd;
|
||||
struct ifreq ifr;
|
||||
|
||||
|
||||
memset(&ifr, 0, sizeof(ifr));
|
||||
memset(ip_p, 0, sizeof(ip_p));
|
||||
|
||||
|
||||
if((skfd = socket(PF_INET, SOCK_DGRAM, 0)) == -1)return -1;
|
||||
strcpy(ifr.ifr_name, conf.udp);
|
||||
if (!ioctl(skfd, SIOCGIFBRDADDR, &ifr)){
|
||||
sprintf(ip_p[0], "%d", (unsigned char)ifr.ifr_broadaddr.sa_data[2]);
|
||||
sprintf(ip_p[1], "%d", (unsigned char)ifr.ifr_broadaddr.sa_data[3]);
|
||||
sprintf(ip_p[2], "%d", (unsigned char)ifr.ifr_broadaddr.sa_data[4]);
|
||||
sprintf(ip_p[3], "%d", (unsigned char)ifr.ifr_broadaddr.sa_data[5]);
|
||||
sprintf(ip_p[0], "%d", (unsigned char)ifr.ifr_broadaddr.sa_data[2]);
|
||||
sprintf(ip_p[1], "%d", (unsigned char)ifr.ifr_broadaddr.sa_data[3]);
|
||||
sprintf(ip_p[2], "%d", (unsigned char)ifr.ifr_broadaddr.sa_data[4]);
|
||||
sprintf(ip_p[3], "%d", (unsigned char)ifr.ifr_broadaddr.sa_data[5]);
|
||||
}else{
|
||||
snprintf(error_str, sizeof(error_str), "EMERG: Invalid broadcast device -- %s\n", conf.udp);
|
||||
record_log(error_str);
|
||||
@@ -1128,6 +1254,7 @@ void create_dir(char *create_path)
|
||||
}
|
||||
void create_semdir()
|
||||
{
|
||||
#if 0
|
||||
int ret = 0;
|
||||
mode_t mask_tmp;
|
||||
|
||||
@@ -1137,9 +1264,11 @@ void create_semdir()
|
||||
close(ret);
|
||||
}
|
||||
umask(mask_tmp);
|
||||
#endif
|
||||
}
|
||||
void create_shmdir()
|
||||
{
|
||||
#if 0
|
||||
int ret = 0;
|
||||
mode_t mask_tmp;
|
||||
|
||||
@@ -1149,6 +1278,7 @@ void create_shmdir()
|
||||
close(ret);
|
||||
}
|
||||
umask(mask_tmp);
|
||||
#endif
|
||||
}
|
||||
void create_confdir()
|
||||
{
|
||||
@@ -1178,13 +1308,13 @@ void create_logdir()
|
||||
|
||||
umask(mask_tmp);
|
||||
}
|
||||
/* create netcard name list */
|
||||
/* create netcard name list */
|
||||
int create_name_list(NET_NAME_ST *all_name_list, NET_NAME_ST *opt_name_list)
|
||||
{
|
||||
int i, count_t, err_val = 0;
|
||||
NET_NAME_ST *curr, *node;
|
||||
char error_str[200];
|
||||
|
||||
|
||||
for(i = 0, count_t = 0; conf.nic[i].dev_name[0] != 0 && (i < MAXNICNUM); i++){
|
||||
curr = all_name_list->next;
|
||||
while(curr != NULL){
|
||||
@@ -1232,7 +1362,7 @@ int get_netcard_status(NETCARD_INFO_ST *listp)
|
||||
if(listp->status == NIC_UNLINKABLE)
|
||||
return NIC_UNLINKABLE;
|
||||
}
|
||||
|
||||
|
||||
return NIC_NORMAL;
|
||||
}
|
||||
|
||||
@@ -1309,8 +1439,8 @@ int main(int argc, char ** argv)
|
||||
D5000_NIC_ALARM Malarm;
|
||||
struct sigaction sig;
|
||||
struct passwd *user;
|
||||
// proc_invocation prcm;
|
||||
|
||||
proc_invocation prcm;
|
||||
|
||||
char log_record[125]={0};
|
||||
|
||||
memset(&conf, 0, sizeof(CONFIG_FILE_ST));
|
||||
@@ -1318,8 +1448,8 @@ int main(int argc, char ** argv)
|
||||
printf("the program is already started!\n");
|
||||
exit(0);
|
||||
}
|
||||
//process register
|
||||
#if 0
|
||||
//process register
|
||||
#if 1
|
||||
if((proc_stat=prcm.proc_init("sys","base_srv","sys_nicmonitor"))==-1){
|
||||
perror("proc_init()");
|
||||
exit(-1);
|
||||
@@ -1347,7 +1477,7 @@ int main(int argc, char ** argv)
|
||||
strcat(shm_path,SHM_PATH);
|
||||
strcat(sem_path,SEM_PATH);
|
||||
strcat(conf_path,CONF_FILE);
|
||||
|
||||
|
||||
create_semdir();
|
||||
create_shmdir();
|
||||
create_logdir();
|
||||
@@ -1549,6 +1679,43 @@ int main(int argc, char ** argv)
|
||||
pthread_join(tid_time, NULL);
|
||||
pthread_mutex_destroy(&mut);
|
||||
globfree(&res);
|
||||
#ifdef USE_OLD_MMSHARE
|
||||
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);
|
||||
record_log(error_str);
|
||||
#endif
|
||||
|
||||
if( shmptr == global_shmptr ) {
|
||||
char *ref_count = NULL;
|
||||
int is_last = 0;
|
||||
int size = sizeof(SHM);
|
||||
|
||||
ref_count = (char *)shmptr + size + 16 - 1;
|
||||
|
||||
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",
|
||||
size, *ref_count, is_last);
|
||||
record_log(error_str);
|
||||
#endif
|
||||
|
||||
// if( is_last ) {
|
||||
memset( shmptr, 0, size + 16 );
|
||||
// }
|
||||
|
||||
shmdt( shmptr );
|
||||
// shmctl( global_share_id, IPC_RMID, NULL );
|
||||
// if( is_last ) {
|
||||
// global_shmptr = NULL;
|
||||
// global_share_id = -1;
|
||||
// }
|
||||
}
|
||||
}
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include <sys/mman.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/ipc.h>
|
||||
#include <sys/shm.h>
|
||||
#include <sys/sem.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
@@ -12,11 +13,12 @@
|
||||
#include <time.h>
|
||||
#include <dirent.h>
|
||||
#include <pwd.h>
|
||||
#include <pthread.h>
|
||||
|
||||
#include "nicinfo_shm.h"
|
||||
|
||||
#define SHM_PATH "/tmp/sys_netcard_shm_path"
|
||||
#define SEM_PATH "/tmp/sys_netcard_sem_path"
|
||||
#define SHM_PATH "/share/sys_netcard_shm_path"
|
||||
#define SEM_PATH "/share/sys_netcard_sem_path"
|
||||
#define LOG_PATH "/var/log/netcard/"
|
||||
|
||||
typedef struct net_info{
|
||||
@@ -29,9 +31,64 @@ static char shm_path[1024];
|
||||
static char sem_path[1024];
|
||||
SHM *ptr = NULL;
|
||||
|
||||
|
||||
static void create_dir(char *create_path)
|
||||
{
|
||||
int i,len = strlen(create_path);
|
||||
|
||||
len = strlen(create_path);
|
||||
|
||||
for(i=1; i<len; i++)
|
||||
{
|
||||
if(create_path[i]=='/')
|
||||
{
|
||||
create_path[i] = 0;
|
||||
if( access(create_path, F_OK)!=0 )
|
||||
{
|
||||
if(mkdir(create_path, 0755)==-1)
|
||||
{
|
||||
perror("mkdir error");
|
||||
}
|
||||
}
|
||||
create_path[i] = '/';
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static pthread_mutex_t lock_record_log = PTHREAD_MUTEX_INITIALIZER;
|
||||
#define LOG_LOCK pthread_mutex_lock(&lock_record_log)
|
||||
#define LOG_UNLOCK pthread_mutex_unlock(&lock_record_log)
|
||||
|
||||
static void linx_free_shm( void *addr, int size );
|
||||
static int is_checkdir = 0;
|
||||
|
||||
static void *record_log_thread( void *arg )
|
||||
{
|
||||
char *log_str = (char *)arg;
|
||||
FILE *log_fp = NULL;
|
||||
|
||||
LOG_LOCK;
|
||||
if( !is_checkdir ) {
|
||||
create_dir( log_path );
|
||||
is_checkdir = 1;
|
||||
}
|
||||
create_dir( log_path );
|
||||
if((log_fp = fopen(log_path, "a")) != NULL){
|
||||
if(fwrite(log_str, 1, strlen(log_str), log_fp) < 1){
|
||||
}
|
||||
fclose(log_fp);
|
||||
}
|
||||
|
||||
LOG_UNLOCK;
|
||||
free(log_str);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* write error in logfile */
|
||||
void record_log(char *str)
|
||||
{
|
||||
#if 0
|
||||
time_t tamp;
|
||||
char str_tm[4];
|
||||
char log_str[512];
|
||||
@@ -59,6 +116,41 @@ void record_log(char *str)
|
||||
}
|
||||
fclose(log_fp);
|
||||
}
|
||||
#else
|
||||
time_t tamp;
|
||||
char str_tm[4];
|
||||
char log_str[512];
|
||||
// FILE *log_fp = NULL;
|
||||
struct tm tmptr;
|
||||
struct timeval tv;
|
||||
struct timezone tz;
|
||||
|
||||
// if((log_fp = fopen(log_path, "a")) != NULL){
|
||||
tamp = time(NULL);
|
||||
memset(str_tm, 0, sizeof(str_tm));
|
||||
memset(log_str, 0, sizeof(log_str));
|
||||
localtime_r(&tamp, &tmptr);
|
||||
gettimeofday(&tv, &tz);
|
||||
snprintf(str_tm, sizeof(str_tm), "%d", (int)tv.tv_usec/1000);
|
||||
if(str_tm[1] == '\0')str_tm[1] = '0';
|
||||
if(str_tm[2] == '\0')str_tm[2] = '0';
|
||||
strftime(log_str, sizeof(log_str), "%F %T.", &tmptr);
|
||||
strcat(log_str, str_tm);
|
||||
strcat(log_str, " ");
|
||||
strcat(log_str, "get_nic_info");
|
||||
strcat(log_str, " ");
|
||||
strcat(log_str, str);
|
||||
// if(fwrite(log_str, 1, strlen(log_str), log_fp) < 1){
|
||||
// }
|
||||
// fclose(log_fp);
|
||||
// }
|
||||
|
||||
{
|
||||
pthread_t pid;
|
||||
char *keepstr = strdup( log_str );
|
||||
pthread_create( &pid, NULL, record_log_thread, (void *)keepstr);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void get_sem(int semid)
|
||||
@@ -101,6 +193,8 @@ void release_sem(int semid)
|
||||
}
|
||||
}
|
||||
|
||||
static int global_share_id = -1;
|
||||
static void *global_shmptr = NULL;
|
||||
|
||||
int init_nic_info(void)
|
||||
{
|
||||
@@ -109,12 +203,15 @@ int init_nic_info(void)
|
||||
char err_str[200];
|
||||
key_t key;
|
||||
|
||||
|
||||
#if 0
|
||||
if ((key=ftok(sem_path, SEM_PROJ_ID)) == -1) {
|
||||
snprintf(err_str, sizeof(err_str), "EMERG: ftok():%s\n", strerror(errno));
|
||||
record_log(err_str);
|
||||
return -1;
|
||||
}
|
||||
#else
|
||||
key = 0x1d5200;
|
||||
#endif
|
||||
if((semid = semget(key, 1, IPC_CREAT|0666)) == -1){
|
||||
snprintf(err_str, sizeof(err_str), "EMERG: Create semaphore error: %s\n", strerror(errno));
|
||||
record_log(err_str);
|
||||
@@ -136,6 +233,7 @@ int init_nic_info(void)
|
||||
}
|
||||
}
|
||||
*/
|
||||
#ifdef USE_OLD_MMSHARE
|
||||
if((fd = open(shm_path, O_RDONLY)) == -1){
|
||||
snprintf(err_str, sizeof(err_str), "EMERG: Error open %s: %s!\n",shm_path, strerror(errno));
|
||||
record_log(err_str);
|
||||
@@ -148,9 +246,63 @@ int init_nic_info(void)
|
||||
return -1;
|
||||
}
|
||||
close(fd);
|
||||
|
||||
#else
|
||||
{
|
||||
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;
|
||||
|
||||
// share_key = ftok(path, 0x000d5000);
|
||||
share_key = 0x1d5010;
|
||||
|
||||
#if 0
|
||||
snprintf( err_str, sizeof( err_str ),
|
||||
"MSG: lib, shm, size:%d, key:0x%x(%d)\n", size, share_key, share_key);
|
||||
record_log(err_str);
|
||||
#endif
|
||||
|
||||
global_share_id = shmget( share_key, size, IPC_CREAT|0666 );
|
||||
if( global_share_id == -1 ) {
|
||||
snprintf( err_str, sizeof( err_str ),
|
||||
"EMERG: fail shmget, %s, 0x%x\n", strerror(errno), share_key);
|
||||
record_log(err_str);
|
||||
return -1;
|
||||
}
|
||||
|
||||
shmptr = shmat( global_share_id, NULL, 0 );
|
||||
if( shmptr == (void *)-1 ) {
|
||||
snprintf( err_str, sizeof( err_str ), "EMERG: shmat fail.%s,0x%x\n", strerror(errno), share_key );
|
||||
record_log( err_str );
|
||||
return -1;
|
||||
}
|
||||
|
||||
#if 0
|
||||
flag_str = (char *)shmptr+size-16;
|
||||
if( strcmp( flag_str, "D5001" ) != 0 ) {
|
||||
//first, do init.
|
||||
memset( shmptr, 0, size );
|
||||
strcpy( flag_str, "D5001" );
|
||||
}
|
||||
|
||||
ref_count = (char *)shmptr+size-1;
|
||||
(*ref_count)++;
|
||||
#endif
|
||||
|
||||
global_shmptr = shmptr;
|
||||
ptr = (SHM *)shmptr;
|
||||
}
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int get_nic_info(char *nic_name, NETCARD_INFO *net_info)
|
||||
{
|
||||
int i,ret;
|
||||
@@ -161,7 +313,10 @@ int get_nic_info(char *nic_name, NETCARD_INFO *net_info)
|
||||
char buf[128];
|
||||
char err_str[200];
|
||||
struct passwd *user;
|
||||
|
||||
#if 0
|
||||
snprintf(err_str, sizeof(err_str), "NOTICE: get nicinfo:%s !\n", nic_name);
|
||||
record_log(err_str);
|
||||
#endif
|
||||
tamp = time(NULL);
|
||||
localtime_r(&tamp, &tmptr);
|
||||
|
||||
@@ -173,13 +328,16 @@ int get_nic_info(char *nic_name, NETCARD_INFO *net_info)
|
||||
strcat(log_path,LOG_PATH);
|
||||
strcat(shm_path,SHM_PATH);
|
||||
strcat(sem_path,SEM_PATH);
|
||||
|
||||
#if 0
|
||||
//remove
|
||||
if((dir = opendir(log_path)) == NULL){
|
||||
if(errno == ENOENT){
|
||||
strcpy(log_path, "/tmp/");
|
||||
}
|
||||
}
|
||||
closedir(dir);
|
||||
#endif
|
||||
|
||||
s = strrchr(log_path, '/');
|
||||
s++;
|
||||
*s = '\0';
|
||||
@@ -197,13 +355,63 @@ int get_nic_info(char *nic_name, NETCARD_INFO *net_info)
|
||||
// get_sem(semid);
|
||||
memcpy(net_info, &ptr->info[i], sizeof(NETCARD_INFO));
|
||||
release_sem(semid);
|
||||
#ifdef USE_OLD_MMSHARE
|
||||
munmap(ptr, sizeof(SHM));
|
||||
#else
|
||||
linx_free_shm( ptr, sizeof(SHM) );
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
release_sem(semid);
|
||||
snprintf(err_str, sizeof(err_str), "NOTICE: No information of %s !\n", nic_name);
|
||||
record_log(err_str);
|
||||
#ifdef USE_OLD_MMSHARE
|
||||
munmap(ptr, sizeof(SHM));
|
||||
#else
|
||||
linx_free_shm( ptr, sizeof(SHM) );
|
||||
#endif
|
||||
return -1;
|
||||
}
|
||||
|
||||
static void linx_free_shm( void *addr, int size )
|
||||
{
|
||||
|
||||
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);
|
||||
record_log(err_str);
|
||||
#endif
|
||||
|
||||
if( shmptr == global_shmptr ) {
|
||||
char *ref_count = NULL;
|
||||
int is_last = 0;
|
||||
// int size = sizeof(SHM);
|
||||
|
||||
ref_count = (char *)shmptr + size + 16 - 1;
|
||||
|
||||
is_last = *ref_count == 1?1:0;
|
||||
|
||||
#if 0
|
||||
snprintf(err_str, sizeof(err_str), "NOTICE: lib, sref_count: %d, last:%d\n", *ref_count, is_last);
|
||||
record_log(err_str);
|
||||
#endif
|
||||
|
||||
#if 0
|
||||
if( is_last ) {
|
||||
memset( shmptr, 0, size + 16 );
|
||||
}
|
||||
#endif
|
||||
shmdt( shmptr );
|
||||
// shmctl( global_share_id, IPC_RMID, NULL );
|
||||
// if( is_last ) {
|
||||
// global_shmptr = NULL;
|
||||
// global_share_id = -1;
|
||||
// }
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user