1.2.1 update

git-svn-id: http://172.17.0.253/svn/soft_pkgs/sys_nicmonitor@181 09c3743a-b0dd-45d3-b506-aa74c7a2a6ef
This commit is contained in:
jli
2010-09-10 07:19:40 +00:00
parent a1da11c7f5
commit 0cbf5a693a
3 changed files with 29 additions and 12 deletions

View File

@@ -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) -lman -ldotconf -lpthread -o $@ $^
$(CC) -ldotconf -lpthread -o $@ $^
libnic_shm.so:nicinfo_shm.c
$(CC) -fpic -shared -o $@ $^
clean:

View File

@@ -92,6 +92,8 @@ static char log_flag = 1;
static int sem_id = 0;
static char process_name[64];
char log_path[1024];
char shm_path[1024];
char sem_path[1024];
int host_name_size = 0;
char host_name[HOST_NAME_SIZE];
@@ -188,7 +190,7 @@ static void init_sem(int *semid, CONFIG_FILE_ST *ptr)
/* write error in logfile */
memset(error_str, 0, sizeof(error_str));
if ((key = ftok(SEM_PATH, SEM_PROJ_ID)) == -1) {
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;
@@ -213,8 +215,8 @@ static void init_shm(SHM **ptr, CONFIG_FILE_ST *p)
mode_t mask_tmp;
mask_tmp = umask(0000);
if((fd = open(SHM_PATH, O_RDWR|O_CREAT|O_TRUNC, 0666)) == -1){
printf("could not create %s\n", SHM_PATH);
if((fd = open(shm_path, O_RDWR|O_CREAT|O_TRUNC, 0666)) == -1){
printf("could not create %s\n", shm_path);
return;
}
umask(mask_tmp);
@@ -874,6 +876,7 @@ int find_nic_config(char *dev_name){
DOTCONF_CB(cb_str)
{
int i, index, card_info_index;
char wrong_ip[125] = {0};
//"ping"选项的处理
if((strcmp(cmd ->name, myconf[13]) == 0) && (nicnum <= MAXNICNUM)){
@@ -894,10 +897,15 @@ DOTCONF_CB(cb_str)
card_info_index = index;
while(cmd->data.list[i]){
if((int)(inet_addr(cmd->data.list[i])) != -1){
strncpy(conf.nic[card_info_index].ping_ip[i-1], cmd->data.list[i], strlen(cmd->data.list[i]) >= IPLEN ? IPLEN-1 : strlen(cmd->data.list[i]));
i++;
if((int)(inet_addr(cmd->data.list[i])) == -1){
sprintf(wrong_ip,"%s'%s'","The wrong IP address:",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]));
}
i++;
}
conf.nic[card_info_index].gw_num = i-1;
}
@@ -1083,7 +1091,7 @@ void create_logdir(void)
{
int ret = 0;
strcpy(log_path, LOG_PATH);
//strcpy(log_path, LOG_PATH);
mode_t mask_tmp;
mask_tmp = umask(0000);
if(mkdir(log_path, 0777) != 0){
@@ -1091,7 +1099,7 @@ void create_logdir(void)
strcpy(log_path, "/tmp/");
}
}
if((ret = open(SEM_PATH, O_RDWR | O_CREAT, 0666)) != -1){
if((ret = open(sem_path, O_RDWR | O_CREAT, 0666)) != -1){
close(ret);
}
umask(mask_tmp);
@@ -1227,8 +1235,17 @@ int main(int argc, char ** argv)
NETCARD_INFO_ST inc_info_list, *listp = NULL;
D5000_NIC_ALARM Malarm;
struct sigaction sig;
struct passwd *user;
proc_invocation prcm;
user = getpwnam("d5000");
sprintf(log_path, "%s", user->pw_dir);
strcat(log_path, LOG_PATH);
sprintf(shm_path, "%s", user->pw_dir);
strcat(shm_path, SHM_PATH);
sprintf(sem_path, "%s", user->pw_dir);
strcat(sem_path, SEM_PATH);
memset(&conf, 0, sizeof(CONFIG_FILE_ST));
if(isrun(argv[0]) == 1){
printf("the program is already started!\n");

View File

@@ -14,9 +14,9 @@
#include "nicinfo_shm.h"
#define SHM_PATH "/tmp/sys_netcard_shm_path"
#define SEM_PATH "/tmp/sys_netcard_sem_path"
#define LOG_PATH "/var/log/netcard/"
#define SHM_PATH "/home/d5000/tmp/sys_netcard_shm_path"
#define SEM_PATH "/home/d5000/tmp/sys_netcard_sem_path"
#define LOG_PATH "/home/d5000/var/log/netcard/"
typedef struct net_info{
NETCARD_INFO info[MAXNICNUM];