Compare commits
11 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c30663643c | ||
|
|
01e8b507c6 | ||
|
|
2e7d859fc6 | ||
|
|
16d3e1fa3a | ||
|
|
2fb2ab7552 | ||
|
|
78444a27f8 | ||
|
|
8fdda73c79 | ||
|
|
ac7eb4a56d | ||
|
|
bd18ca0e9e | ||
|
|
34e11538ec | ||
|
|
e0b7a7e83d |
@@ -1,28 +0,0 @@
|
|||||||
#! /usr/bin/make -f
|
|
||||||
|
|
||||||
DEFAULTS = Makefile.config
|
|
||||||
|
|
||||||
include $(DEFAULTS)
|
|
||||||
|
|
||||||
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 $@ $^
|
|
||||||
libnic_shm.so:nicinfo_shm.c
|
|
||||||
$(CC) -fpic -shared -o $@ $^
|
|
||||||
clean:
|
|
||||||
$(RM) *.o
|
|
||||||
$(RM) libnic_shm.so sys_nicmonitor
|
|
||||||
install:
|
|
||||||
$(MKDIR) -p $(LIBDIR)
|
|
||||||
$(MKDIR) -p $(BINDIR)
|
|
||||||
$(MKDIR) -p $(INCDIR)
|
|
||||||
$(CP) libnic_shm.so $(LIBDIR)
|
|
||||||
$(CP) sys_nicmonitor $(BINDIR)
|
|
||||||
$(CP) nicinfo_shm.h $(INCDIR)
|
|
||||||
uninstall:
|
|
||||||
$(RM) -f $(LIBDIR)/libnic_shm.so
|
|
||||||
$(RM) -f $(BINDIR)/sys_nicmonitor
|
|
||||||
$(RM) -f $(INCDIR)/nicinfo_shm.h
|
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -1,209 +0,0 @@
|
|||||||
#include <stdio.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <sys/mman.h>
|
|
||||||
#include <sys/types.h>
|
|
||||||
#include <sys/ipc.h>
|
|
||||||
#include <sys/sem.h>
|
|
||||||
#include <fcntl.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <errno.h>
|
|
||||||
#include <sys/time.h>
|
|
||||||
#include <time.h>
|
|
||||||
#include <dirent.h>
|
|
||||||
#include <pwd.h>
|
|
||||||
|
|
||||||
#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/"
|
|
||||||
|
|
||||||
typedef struct net_info{
|
|
||||||
NETCARD_INFO info[MAXNICNUM];
|
|
||||||
}SHM;
|
|
||||||
|
|
||||||
static int semid = 0;
|
|
||||||
static char log_path[1024];
|
|
||||||
static char shm_path[1024];
|
|
||||||
static char sem_path[1024];
|
|
||||||
SHM *ptr = NULL;
|
|
||||||
|
|
||||||
/* write error in logfile */
|
|
||||||
void record_log(char *str)
|
|
||||||
{
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void get_sem(int semid)
|
|
||||||
{
|
|
||||||
char err_str[200];
|
|
||||||
struct sembuf lock[2];
|
|
||||||
|
|
||||||
lock[0].sem_num = 0;
|
|
||||||
lock[0].sem_op = 0;
|
|
||||||
lock[0].sem_flg = SEM_UNDO;
|
|
||||||
|
|
||||||
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(err_str, sizeof(err_str), "EMERG: semop():\n", strerror(errno));
|
|
||||||
record_log(err_str);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void release_sem(int semid)
|
|
||||||
{
|
|
||||||
int ret;
|
|
||||||
char err_str[200];
|
|
||||||
struct sembuf unlock;
|
|
||||||
|
|
||||||
unlock.sem_num = 0;
|
|
||||||
unlock.sem_op = -1;
|
|
||||||
unlock.sem_flg = SEM_UNDO;
|
|
||||||
|
|
||||||
if((ret = semop(semid, &unlock, 1)) == -1){
|
|
||||||
snprintf(err_str, sizeof(err_str), "EMERG: semop():\n", strerror(errno));
|
|
||||||
record_log(err_str);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int init_nic_info(void)
|
|
||||||
{
|
|
||||||
int fd = -1;
|
|
||||||
int sem_val;
|
|
||||||
char err_str[200];
|
|
||||||
key_t key;
|
|
||||||
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
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);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
/*
|
|
||||||
if((sem_val = semctl(semid, 0, GETVAL, 0)) == -1){
|
|
||||||
snprintf(err_str, sizeof(err_str), "EMERG: semctl: %s !\n", strerror(errno));
|
|
||||||
record_log(err_str);
|
|
||||||
semctl(semid, 0, IPC_RMID);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
if(!sem_val){
|
|
||||||
if(semctl(semid, 0, SETVAL, 1) == -1){
|
|
||||||
snprintf(err_str, sizeof(err_str), "EMERG: semctl: %s !\n", strerror(errno));
|
|
||||||
record_log(err_str);
|
|
||||||
semctl(semid, 0, IPC_RMID);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
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);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
ptr = (SHM*)mmap(NULL, sizeof(SHM), PROT_READ, MAP_SHARED, fd, 0);
|
|
||||||
if(ptr == MAP_FAILED){
|
|
||||||
snprintf(err_str, sizeof(err_str), "EMERG: mmap():%s\n", strerror(errno));
|
|
||||||
record_log(err_str);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
close(fd);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
int get_nic_info(char *nic_name, NETCARD_INFO *net_info)
|
|
||||||
{
|
|
||||||
int i,ret;
|
|
||||||
time_t tamp;
|
|
||||||
struct tm tmptr;
|
|
||||||
DIR *dir;
|
|
||||||
char *s;
|
|
||||||
char buf[128];
|
|
||||||
char err_str[200];
|
|
||||||
struct passwd *user;
|
|
||||||
|
|
||||||
tamp = time(NULL);
|
|
||||||
localtime_r(&tamp, &tmptr);
|
|
||||||
|
|
||||||
if((user = getpwnam("d5000"))!= NULL){
|
|
||||||
sprintf(log_path,"%s",user->pw_dir);
|
|
||||||
sprintf(shm_path,"%s",user->pw_dir);
|
|
||||||
sprintf(sem_path,"%s",user->pw_dir);
|
|
||||||
}
|
|
||||||
strcat(log_path,LOG_PATH);
|
|
||||||
strcat(shm_path,SHM_PATH);
|
|
||||||
strcat(sem_path,SEM_PATH);
|
|
||||||
|
|
||||||
if((dir = opendir(log_path)) == NULL){
|
|
||||||
if(errno == ENOENT){
|
|
||||||
strcpy(log_path, "/tmp/");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
closedir(dir);
|
|
||||||
s = strrchr(log_path, '/');
|
|
||||||
s++;
|
|
||||||
*s = '\0';
|
|
||||||
memset(buf, 0, sizeof(buf));
|
|
||||||
strftime(buf, sizeof(buf), "%Y%m%d_", &tmptr);
|
|
||||||
strcat(buf, "sys_nicmonitor");
|
|
||||||
strcat(buf, ".log");
|
|
||||||
strcat(log_path, buf);
|
|
||||||
if((ret = init_nic_info()) == -1){
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
get_sem(semid);
|
|
||||||
for(i = 0; ptr->info[i].charname[0] != 0; i++){
|
|
||||||
if(!strcmp(ptr->info[i].charname, nic_name)){
|
|
||||||
// get_sem(semid);
|
|
||||||
memcpy(net_info, &ptr->info[i], sizeof(NETCARD_INFO));
|
|
||||||
release_sem(semid);
|
|
||||||
munmap(ptr, sizeof(SHM));
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
release_sem(semid);
|
|
||||||
snprintf(err_str, sizeof(err_str), "NOTICE: No information of %s !\n", nic_name);
|
|
||||||
record_log(err_str);
|
|
||||||
munmap(ptr, sizeof(SHM));
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
@@ -1,198 +0,0 @@
|
|||||||
////////////////////////////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
// Copyright (c) Comets' Grp. of Kedong Corp 2008. All Rights Reserved.
|
|
||||||
//
|
|
||||||
// FileName : procconf.h
|
|
||||||
//
|
|
||||||
// Function : this class realize some basic functions for process managerment,
|
|
||||||
// such as initiate process, report status of process, check status of process,
|
|
||||||
// update status of process, get information of process
|
|
||||||
//
|
|
||||||
// Author :
|
|
||||||
//
|
|
||||||
// Date :
|
|
||||||
//
|
|
||||||
// Modify by :
|
|
||||||
//
|
|
||||||
// Mod Date :
|
|
||||||
//
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
#ifndef _PROCCONF_H
|
|
||||||
#define _PROCCONF_H
|
|
||||||
|
|
||||||
#include <sys/types.h>
|
|
||||||
#include <sys/stat.h>
|
|
||||||
#include <fcntl.h>
|
|
||||||
#include <sys/mman.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <errno.h>
|
|
||||||
//#include <iostream.h>
|
|
||||||
#include <signal.h>
|
|
||||||
|
|
||||||
#include "const.h"
|
|
||||||
|
|
||||||
//for alarm ................................
|
|
||||||
typedef struct MESS_BH
|
|
||||||
{
|
|
||||||
unsigned char mtype;
|
|
||||||
int length;
|
|
||||||
};
|
|
||||||
typedef struct PROCESS_ALM
|
|
||||||
{
|
|
||||||
char context_name[MAX_STRING_LEN];
|
|
||||||
char app_name[MAX_STRING_LEN];
|
|
||||||
char proc_name[MAX_STRING_LEN];
|
|
||||||
unsigned char status;
|
|
||||||
};
|
|
||||||
//for alarm end .............................
|
|
||||||
|
|
||||||
//for mmi....................................
|
|
||||||
const int MAX_BUFFER_LEN = 500;
|
|
||||||
typedef struct MESS_BLOCK
|
|
||||||
{
|
|
||||||
unsigned char num;
|
|
||||||
char buffer[MAX_BUFFER_LEN];
|
|
||||||
};
|
|
||||||
typedef struct MESS_PROC
|
|
||||||
{
|
|
||||||
char context_name[MAX_STRING_LEN];
|
|
||||||
char app_name[MAX_STRING_LEN];
|
|
||||||
char proc_name[MAX_STRING_LEN];
|
|
||||||
char status;
|
|
||||||
};
|
|
||||||
//for mmi end ................................
|
|
||||||
|
|
||||||
const int DEFAULT_PERIOD = 3;
|
|
||||||
const int COUNT_LIMIT = 2;
|
|
||||||
const int START_DEFAULT_PERIOD = 60;
|
|
||||||
const int START_COUNT_LIMIT = 5;
|
|
||||||
const int APP_COUNT_LIMIT = 1;
|
|
||||||
|
|
||||||
//process critical level
|
|
||||||
//const int WST_CRITICAL = 1; // Shutdown and reboot workstation when failed
|
|
||||||
//const int SYS_CRITICAL = 2; // Shutdown and reboot the system on the wst when failed
|
|
||||||
//const int USER_CRITICAL = 3; // Shutdown and reboot the subsystem when failed
|
|
||||||
//const int GENERAL = 4; // reboot the process
|
|
||||||
const int CRUCIAL = 1; // crucial process
|
|
||||||
const int GENERAL = 0; // general process
|
|
||||||
|
|
||||||
|
|
||||||
extern int srv_init(char *service,int port);
|
|
||||||
extern int Tcp_close(int sockfd);
|
|
||||||
extern int Tcp_read(int fd,char *ptr,int nbytes);
|
|
||||||
extern int Tcp_write(int fd,char *ptr,int nbytes);
|
|
||||||
extern int srv_accept(int fd,struct sockaddr *cli_addr,int *clilen);
|
|
||||||
extern int client_tcp_open(char *host,char *service,int port);
|
|
||||||
|
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
char context_name[MAX_STRING_LEN];
|
|
||||||
char app_name[MAX_STRING_LEN];
|
|
||||||
char proc_name[MAX_STRING_LEN];
|
|
||||||
pid_t proc_pid;
|
|
||||||
}PROC_ADM_INFO;
|
|
||||||
|
|
||||||
//***************************************************************
|
|
||||||
// structure name : PROC_INFO
|
|
||||||
// function : store process informatin
|
|
||||||
// author :
|
|
||||||
// date :
|
|
||||||
// modify by :
|
|
||||||
// modification :
|
|
||||||
// mod date :
|
|
||||||
//***************************************************************
|
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
int position;
|
|
||||||
char node_name[MAX_STRING_LEN];
|
|
||||||
char context_name[MAX_STRING_LEN];
|
|
||||||
char app_name[MAX_STRING_LEN];
|
|
||||||
char proc_name[MAX_STRING_LEN];
|
|
||||||
|
|
||||||
unsigned char active_flag;
|
|
||||||
unsigned char master_flag;
|
|
||||||
|
|
||||||
time_t startup_time;
|
|
||||||
time_t refresh_time;
|
|
||||||
short refresh_peri;
|
|
||||||
unsigned char monitor_type;
|
|
||||||
|
|
||||||
pid_t proc_pid;
|
|
||||||
unsigned char auto_start;
|
|
||||||
unsigned char act_timer;
|
|
||||||
unsigned char start_timer;
|
|
||||||
unsigned char critical_level;
|
|
||||||
|
|
||||||
char exefile_path[MAX_EXECMD_LEN];
|
|
||||||
|
|
||||||
}PROC_INFO;
|
|
||||||
|
|
||||||
//***************************************************************
|
|
||||||
// structure name : APP_INFO
|
|
||||||
// function : store application informatin
|
|
||||||
// author :
|
|
||||||
// date :
|
|
||||||
// modify by :
|
|
||||||
// modification :
|
|
||||||
// mod date :
|
|
||||||
//***************************************************************
|
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
int position;
|
|
||||||
char context_name[MAX_STRING_LEN];
|
|
||||||
int context_id;
|
|
||||||
char app_name[MAX_STRING_LEN];
|
|
||||||
int app_id;
|
|
||||||
unsigned char act_timer;
|
|
||||||
unsigned char active_flag;
|
|
||||||
}APP_INFO;
|
|
||||||
|
|
||||||
|
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
int no_proc;
|
|
||||||
int semdes_cfg;
|
|
||||||
PROC_INFO proc[MAX_LOCAL_PROCESS];
|
|
||||||
APP_INFO app[MAX_LOCAL_APP];
|
|
||||||
}PROCCFG;
|
|
||||||
|
|
||||||
class proc_invocation
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
int m_init;
|
|
||||||
PROCCFG *proccfg_p;
|
|
||||||
|
|
||||||
public:
|
|
||||||
proc_invocation();
|
|
||||||
~proc_invocation();
|
|
||||||
|
|
||||||
int conf_create();
|
|
||||||
//int check_proc_status();
|
|
||||||
//int update_rtdb();
|
|
||||||
//int kill_proc(pid_t pid);
|
|
||||||
//int start_proc(char *cmdline);
|
|
||||||
//int send_alarm(char *context_name, char *app_name, char *proc_name, unsigned char status);
|
|
||||||
//int update_proc_status(char *context_name, char *app_name, char *proc_name, char status);
|
|
||||||
|
|
||||||
//int proc_init(char *context_name, char *app_name, char *proc_name, int critical_level);//exefile_path,auto_start
|
|
||||||
int proc_init(char *context_name, char *app_name, char *proc_name);
|
|
||||||
int proc_report(int pos, char status, int intertime=3);
|
|
||||||
int proc_exit(int proc_pos);
|
|
||||||
|
|
||||||
int get_pos(char *context_name, char *app_name, char *proc_name);
|
|
||||||
int is_proc_exist(char *context_name, char *app_name, char *proc_name);
|
|
||||||
int conf_map();
|
|
||||||
|
|
||||||
int get_procinfo(int position, PROC_ADM_INFO *p_info);
|
|
||||||
int get_active_pid(int &num, int *p_pidlist);
|
|
||||||
int is_proc_run(pid_t pid);
|
|
||||||
int is_proc_run(char *context_name, char *app_name, char *proc_name);
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -1,133 +0,0 @@
|
|||||||
#include "mnic.h"
|
|
||||||
|
|
||||||
static char *prase_digit(char **s)
|
|
||||||
{
|
|
||||||
char *retp = NULL;
|
|
||||||
char *p = *s;
|
|
||||||
|
|
||||||
if(!p)return NULL;
|
|
||||||
while(!isdigit(*p)){
|
|
||||||
p++;
|
|
||||||
if(*p == '\0')return NULL;
|
|
||||||
}
|
|
||||||
retp = p;
|
|
||||||
while(isdigit(*p)){
|
|
||||||
p++;
|
|
||||||
if(*p == '\0'){
|
|
||||||
*s = NULL;
|
|
||||||
return retp;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*p = '\0';
|
|
||||||
p++;
|
|
||||||
*s = p;
|
|
||||||
return retp;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
char *get_name(char *name, char *p)
|
|
||||||
{
|
|
||||||
while (isspace(*p))
|
|
||||||
p++;
|
|
||||||
while (*p) {
|
|
||||||
if (isspace(*p))
|
|
||||||
break;
|
|
||||||
if (*p == ':') { /* could be an alias */
|
|
||||||
char *dot = p, *dotname = name;
|
|
||||||
*name++ = *p++;
|
|
||||||
while (isdigit(*p))
|
|
||||||
*name++ = *p++;
|
|
||||||
if (*p != ':') { /* it wasn't, backup */
|
|
||||||
p = dot;
|
|
||||||
name = dotname;
|
|
||||||
}
|
|
||||||
if (*p == '\0')
|
|
||||||
return NULL;
|
|
||||||
p++;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
*name++ = *p++;
|
|
||||||
}
|
|
||||||
*name++ = '\0';
|
|
||||||
return p;
|
|
||||||
}
|
|
||||||
|
|
||||||
int get_dev_fields(char *str, NETCARD_INFO *ife)
|
|
||||||
{
|
|
||||||
int i = 0;
|
|
||||||
char *retp[16];
|
|
||||||
|
|
||||||
while((retp[i] = prase_digit(&str)) != NULL){i++;if(i > 15)break;}
|
|
||||||
ife->rx_bytes = atoll(retp[0]);
|
|
||||||
ife->rx_packets = atoll(retp[1]);
|
|
||||||
ife->rx_errors = atol(retp[2]);
|
|
||||||
ife->rx_dropped = atol(retp[3]);
|
|
||||||
ife->rx_fifo_errors = atol(retp[4]);
|
|
||||||
ife->rx_multicast = atol(retp[7]);
|
|
||||||
ife->tx_bytes = atoll(retp[8]);
|
|
||||||
ife->tx_packets = atoll(retp[9]);
|
|
||||||
ife->tx_errors = atol(retp[10]);
|
|
||||||
ife->tx_dropped = atol(retp[11]);
|
|
||||||
ife->tx_fifo_errors = atol(retp[12]);
|
|
||||||
ife->collisions = atol(retp[13]);
|
|
||||||
ife->tx_carrier_errors = atol(retp[14]);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int if_fetch(NETCARD_INFO *ife)
|
|
||||||
{
|
|
||||||
int skfd;
|
|
||||||
struct ifreq ifr;
|
|
||||||
|
|
||||||
if((skfd = socket(PF_INET, SOCK_DGRAM, 0)) == -1)return -1;
|
|
||||||
|
|
||||||
strcpy(ifr.ifr_name, ife->charname);
|
|
||||||
if (!ioctl(skfd, SIOCGIFFLAGS, &ifr))
|
|
||||||
ife->flags = ifr.ifr_flags;
|
|
||||||
|
|
||||||
if (!ioctl(skfd, SIOCGIFHWADDR, &ifr))
|
|
||||||
ife->hwaddr = ifr.ifr_hwaddr;
|
|
||||||
|
|
||||||
if (!ioctl(skfd, SIOCGIFMTU, &ifr))
|
|
||||||
ife->mtu = ifr.ifr_mtu;
|
|
||||||
|
|
||||||
if (!ioctl(skfd, SIOCGIFTXQLEN, &ifr))
|
|
||||||
ife->tx_queue_len = ifr.ifr_qlen;
|
|
||||||
|
|
||||||
if (!ioctl(skfd, SIOCGIFADDR, &ifr))
|
|
||||||
ife->addr = ifr.ifr_addr;
|
|
||||||
|
|
||||||
if (!ioctl(skfd, SIOCGIFBRDADDR, &ifr))
|
|
||||||
ife->broadaddr = ifr.ifr_broadaddr;
|
|
||||||
|
|
||||||
if (!ioctl(skfd, SIOCGIFNETMASK, &ifr))
|
|
||||||
ife->netmask = ifr.ifr_netmask;
|
|
||||||
|
|
||||||
ife->time_stamp = time(NULL);
|
|
||||||
close(skfd);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int ioc_get_name(NETCARD_INFO *name)
|
|
||||||
{
|
|
||||||
int skfd;
|
|
||||||
int ifrnum;
|
|
||||||
int i = 0;
|
|
||||||
struct ifconf ifc;
|
|
||||||
struct ifreq buf[MAXNICNUM];
|
|
||||||
|
|
||||||
if((skfd = socket(PF_INET, SOCK_DGRAM, 0)) == -1)return -1;
|
|
||||||
memset(buf, 0, sizeof(buf));
|
|
||||||
ifc.ifc_len = sizeof(buf);
|
|
||||||
ifc.ifc_buf = (caddr_t) buf;
|
|
||||||
ioctl(skfd, SIOCGIFCONF, &ifc);
|
|
||||||
ifrnum = ifc.ifc_len / sizeof(struct ifreq);
|
|
||||||
while(ifrnum-- > 0){
|
|
||||||
strcpy(name[i].charname, buf[ifrnum].ifr_name);
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
close(skfd);
|
|
||||||
return i;
|
|
||||||
}
|
|
||||||
|
|
||||||
Binary file not shown.
@@ -1,28 +0,0 @@
|
|||||||
#! /usr/bin/make -f
|
|
||||||
|
|
||||||
DEFAULTS = Makefile.config
|
|
||||||
|
|
||||||
include $(DEFAULTS)
|
|
||||||
|
|
||||||
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 $@ $^
|
|
||||||
libnic_shm.so:nicinfo_shm.c
|
|
||||||
$(CC) -fpic -shared -o $@ $^
|
|
||||||
clean:
|
|
||||||
$(RM) *.o
|
|
||||||
$(RM) libnic_shm.so sys_nicmonitor
|
|
||||||
install:
|
|
||||||
$(MKDIR) -p $(LIBDIR)
|
|
||||||
$(MKDIR) -p $(BINDIR)
|
|
||||||
$(MKDIR) -p $(INCDIR)
|
|
||||||
$(CP) libnic_shm.so $(LIBDIR)
|
|
||||||
$(CP) sys_nicmonitor $(BINDIR)
|
|
||||||
$(CP) nicinfo_shm.h $(INCDIR)
|
|
||||||
uninstall:
|
|
||||||
$(RM) -f $(LIBDIR)/libnic_shm.so
|
|
||||||
$(RM) -f $(BINDIR)/sys_nicmonitor
|
|
||||||
$(RM) -f $(INCDIR)/nicinfo_shm.h
|
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
|
|
||||||
PREFIX = $(DESTDIR)
|
|
||||||
|
|
||||||
BINDIR = $(PREFIX)/usr/bin
|
|
||||||
|
|
||||||
LIBDIR = $(PREFIX)/usr/lib64
|
|
||||||
|
|
||||||
INCDIR = $(PREFIX)/usr/include
|
|
||||||
|
|
||||||
INSTALL_SH = ./install.sh
|
|
||||||
|
|
||||||
CP = cp
|
|
||||||
RM = rm
|
|
||||||
#CC = gcc
|
|
||||||
CC = g++
|
|
||||||
MKDIR = mkdir
|
|
||||||
@@ -1,32 +0,0 @@
|
|||||||
|
|
||||||
lijin:/home/d5000/lijin/sys_nicmonitor # ./sys_nicmonitor
|
|
||||||
shm_path:/home/d5000/tmp/sys_netcard_shm_path
|
|
||||||
log_path:/home/d5000/var/log/netcard/20110110_sys_nicmonitor.log
|
|
||||||
udp bond0
|
|
||||||
nic bond0
|
|
||||||
nic eth0
|
|
||||||
nic eth1
|
|
||||||
|
|
||||||
d5000@lijin:~ > cat var/log/netcard/20110110_sys_nicmonitor.log
|
|
||||||
2011-01-10 11:10:37.761 sys_nicmonitor NOTICE: sys_nicmonitor V1.5 is
|
|
||||||
started !
|
|
||||||
2011-01-10 11:10:37.761 sys_nicmonitor
|
|
||||||
shm_path:/home/d5000/tmp/sys_netcard_shm_path
|
|
||||||
2011-01-10 11:10:37.761 sys_nicmonitor
|
|
||||||
log_path:/home/d5000/var/log/netcard/20110110_sys_nicmonitor.log
|
|
||||||
2011-01-10 11:10:37.761 sys_nicmonitor udp bond0
|
|
||||||
2011-01-10 11:10:37.761 sys_nicmonitor nic bond0
|
|
||||||
2011-01-10 11:10:37.761 sys_nicmonitor nic eth0
|
|
||||||
2011-01-10 11:10:37.762 sys_nicmonitor nic eth1
|
|
||||||
2011-01-10 11:10:37.762 sys_nicmonitor NOTICE: bond0 is NORMAL!
|
|
||||||
2011-01-10 11:10:37.763 sys_nicmonitor NOTICE: eth0 is NORMAL!
|
|
||||||
2011-01-10 11:10:37.763 sys_nicmonitor NOTICE: eth1 is NORMAL!
|
|
||||||
|
|
||||||
与1.4不一样的地方在与增加log文件中的打印语句
|
|
||||||
sys_nicmonitor started! version v1.4
|
|
||||||
shm_path: /home/d5000/tmp
|
|
||||||
log_path: /home/d5000/ var/log/netcard
|
|
||||||
udp bond0
|
|
||||||
nic bond0
|
|
||||||
nic eth0
|
|
||||||
nic eth1
|
|
||||||
@@ -1,51 +0,0 @@
|
|||||||
#ifndef _RTE_CONST_H
|
|
||||||
#define _RTE_CONST_H
|
|
||||||
|
|
||||||
#include <pthread.h>
|
|
||||||
|
|
||||||
|
|
||||||
#define MAX_STRING_LEN 24
|
|
||||||
#define MAX_EXECMD_LEN 200
|
|
||||||
#define MAX_FILENAME_LEN 200
|
|
||||||
|
|
||||||
#define MAX_CONTEXT 8
|
|
||||||
#define MAX_HOSTNAME_LEN 24
|
|
||||||
#define MAX_LOCAL_MESPROC 512
|
|
||||||
#define MAX_LOCAL_PROCESS MAX_LOCAL_MESPROC
|
|
||||||
#define MAX_LOCAL_APP 32
|
|
||||||
#define MAX_LOCAL_NODE 256
|
|
||||||
|
|
||||||
#define MAX_SET 256 //max num of event set
|
|
||||||
#define MAX_EVENT 1300
|
|
||||||
#define MAX_REG_PROC 20
|
|
||||||
|
|
||||||
#define LEN_SHMBLK_BIG 4096
|
|
||||||
#define MAX_MSGBUF_LEN 32767
|
|
||||||
#define FREE_PAGE_SIZE 65536
|
|
||||||
#define MAX_PAGE_NUM 1024
|
|
||||||
|
|
||||||
#define MAX_QUE MAX_LOCAL_MESPROC
|
|
||||||
#define MAX_SEMPHORE_SET MAX_LOCAL_MESPROC*2
|
|
||||||
#define RTE_HAN 0 // queue number for event handeler0(RTE)
|
|
||||||
#define EX_EVENT_HAN RTE_HAN // queue number for extrnal event handeler
|
|
||||||
|
|
||||||
#define DOMAIN_I 1
|
|
||||||
#define DOMAIN_II 2
|
|
||||||
#define DOMAIN_III 3
|
|
||||||
|
|
||||||
//Add 20090225
|
|
||||||
const int PROC_TYPE_RPT =1;
|
|
||||||
const int PROC_TYPE_UNRPT =0;
|
|
||||||
//add end
|
|
||||||
|
|
||||||
|
|
||||||
//status for proc and app
|
|
||||||
const int NON_ACTIVE = 0;
|
|
||||||
const int ACTIVE = 1;
|
|
||||||
const int HANGUP = 2;
|
|
||||||
const int FAILURE = 5;
|
|
||||||
const int START = 6;
|
|
||||||
const int STOP = 7;
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -1,44 +0,0 @@
|
|||||||
#ifndef __MNIC_H
|
|
||||||
#define __MNIC_H
|
|
||||||
|
|
||||||
//#define _GNU_SOURCE
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <stddef.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <ctype.h>
|
|
||||||
#include <errno.h>
|
|
||||||
#include <netinet/in.h>
|
|
||||||
#include <net/if.h>
|
|
||||||
#include <time.h>
|
|
||||||
#include <sys/ioctl.h>
|
|
||||||
#include <sys/socket.h>
|
|
||||||
#include <sys/sem.h>
|
|
||||||
#include <sys/ipc.h>
|
|
||||||
#include <sys/param.h>
|
|
||||||
#include <linux/types.h>
|
|
||||||
#include <glob.h>
|
|
||||||
#include <linux/sockios.h>
|
|
||||||
#include <arpa/inet.h>
|
|
||||||
#include <pthread.h>
|
|
||||||
#include <sys/mman.h>
|
|
||||||
#include <sys/stat.h>
|
|
||||||
#include <fcntl.h>
|
|
||||||
#include <signal.h>
|
|
||||||
#include <sys/time.h>
|
|
||||||
|
|
||||||
#include "sys_netcard.h"
|
|
||||||
#include <pwd.h>
|
|
||||||
#include <sys/types.h>
|
|
||||||
#define IPSIZE 16
|
|
||||||
|
|
||||||
char *get_name(char *, char *);
|
|
||||||
int if_fetch(NETCARD_INFO *);
|
|
||||||
int ioc_get_name(NETCARD_INFO *);
|
|
||||||
int get_dev_fields(char *p, NETCARD_INFO *);
|
|
||||||
int get_user_home(int , char *);
|
|
||||||
void send_alarm(D5000_NIC_ALARM *, int , char *);
|
|
||||||
void record_log(char *);
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,209 +0,0 @@
|
|||||||
#include <stdio.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <sys/mman.h>
|
|
||||||
#include <sys/types.h>
|
|
||||||
#include <sys/ipc.h>
|
|
||||||
#include <sys/sem.h>
|
|
||||||
#include <fcntl.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <errno.h>
|
|
||||||
#include <sys/time.h>
|
|
||||||
#include <time.h>
|
|
||||||
#include <dirent.h>
|
|
||||||
#include <pwd.h>
|
|
||||||
|
|
||||||
#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/"
|
|
||||||
|
|
||||||
typedef struct net_info{
|
|
||||||
NETCARD_INFO info[MAXNICNUM];
|
|
||||||
}SHM;
|
|
||||||
|
|
||||||
static int semid = 0;
|
|
||||||
static char log_path[1024];
|
|
||||||
static char shm_path[1024];
|
|
||||||
static char sem_path[1024];
|
|
||||||
SHM *ptr = NULL;
|
|
||||||
|
|
||||||
/* write error in logfile */
|
|
||||||
void record_log(char *str)
|
|
||||||
{
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void get_sem(int semid)
|
|
||||||
{
|
|
||||||
char err_str[200];
|
|
||||||
struct sembuf lock[2];
|
|
||||||
|
|
||||||
lock[0].sem_num = 0;
|
|
||||||
lock[0].sem_op = 0;
|
|
||||||
lock[0].sem_flg = SEM_UNDO;
|
|
||||||
|
|
||||||
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(err_str, sizeof(err_str), "EMERG: semop():\n", strerror(errno));
|
|
||||||
record_log(err_str);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void release_sem(int semid)
|
|
||||||
{
|
|
||||||
int ret;
|
|
||||||
char err_str[200];
|
|
||||||
struct sembuf unlock;
|
|
||||||
|
|
||||||
unlock.sem_num = 0;
|
|
||||||
unlock.sem_op = -1;
|
|
||||||
unlock.sem_flg = SEM_UNDO;
|
|
||||||
|
|
||||||
if((ret = semop(semid, &unlock, 1)) == -1){
|
|
||||||
snprintf(err_str, sizeof(err_str), "EMERG: semop():\n", strerror(errno));
|
|
||||||
record_log(err_str);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int init_nic_info(void)
|
|
||||||
{
|
|
||||||
int fd = -1;
|
|
||||||
int sem_val;
|
|
||||||
char err_str[200];
|
|
||||||
key_t key;
|
|
||||||
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
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);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
/*
|
|
||||||
if((sem_val = semctl(semid, 0, GETVAL, 0)) == -1){
|
|
||||||
snprintf(err_str, sizeof(err_str), "EMERG: semctl: %s !\n", strerror(errno));
|
|
||||||
record_log(err_str);
|
|
||||||
semctl(semid, 0, IPC_RMID);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
if(!sem_val){
|
|
||||||
if(semctl(semid, 0, SETVAL, 1) == -1){
|
|
||||||
snprintf(err_str, sizeof(err_str), "EMERG: semctl: %s !\n", strerror(errno));
|
|
||||||
record_log(err_str);
|
|
||||||
semctl(semid, 0, IPC_RMID);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
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);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
ptr = (SHM*)mmap(NULL, sizeof(SHM), PROT_READ, MAP_SHARED, fd, 0);
|
|
||||||
if(ptr == MAP_FAILED){
|
|
||||||
snprintf(err_str, sizeof(err_str), "EMERG: mmap():%s\n", strerror(errno));
|
|
||||||
record_log(err_str);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
close(fd);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
int get_nic_info(char *nic_name, NETCARD_INFO *net_info)
|
|
||||||
{
|
|
||||||
int i,ret;
|
|
||||||
time_t tamp;
|
|
||||||
struct tm tmptr;
|
|
||||||
DIR *dir;
|
|
||||||
char *s;
|
|
||||||
char buf[128];
|
|
||||||
char err_str[200];
|
|
||||||
struct passwd *user;
|
|
||||||
|
|
||||||
tamp = time(NULL);
|
|
||||||
localtime_r(&tamp, &tmptr);
|
|
||||||
|
|
||||||
if((user = getpwnam("d5000"))!= NULL){
|
|
||||||
sprintf(log_path,"%s",user->pw_dir);
|
|
||||||
sprintf(shm_path,"%s",user->pw_dir);
|
|
||||||
sprintf(sem_path,"%s",user->pw_dir);
|
|
||||||
}
|
|
||||||
strcat(log_path,LOG_PATH);
|
|
||||||
strcat(shm_path,SHM_PATH);
|
|
||||||
strcat(sem_path,SEM_PATH);
|
|
||||||
|
|
||||||
if((dir = opendir(log_path)) == NULL){
|
|
||||||
if(errno == ENOENT){
|
|
||||||
strcpy(log_path, "/tmp/");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
closedir(dir);
|
|
||||||
s = strrchr(log_path, '/');
|
|
||||||
s++;
|
|
||||||
*s = '\0';
|
|
||||||
memset(buf, 0, sizeof(buf));
|
|
||||||
strftime(buf, sizeof(buf), "%Y%m%d_", &tmptr);
|
|
||||||
strcat(buf, "sys_nicmonitor");
|
|
||||||
strcat(buf, ".log");
|
|
||||||
strcat(log_path, buf);
|
|
||||||
if((ret = init_nic_info()) == -1){
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
get_sem(semid);
|
|
||||||
for(i = 0; ptr->info[i].charname[0] != 0; i++){
|
|
||||||
if(!strcmp(ptr->info[i].charname, nic_name)){
|
|
||||||
// get_sem(semid);
|
|
||||||
memcpy(net_info, &ptr->info[i], sizeof(NETCARD_INFO));
|
|
||||||
release_sem(semid);
|
|
||||||
munmap(ptr, sizeof(SHM));
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
release_sem(semid);
|
|
||||||
snprintf(err_str, sizeof(err_str), "NOTICE: No information of %s !\n", nic_name);
|
|
||||||
record_log(err_str);
|
|
||||||
munmap(ptr, sizeof(SHM));
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
@@ -1,52 +0,0 @@
|
|||||||
#ifndef NIC_SHM_H
|
|
||||||
#define NIC_SHM_H
|
|
||||||
|
|
||||||
#include <sys/socket.h>
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef NIC_NAME_LEN
|
|
||||||
#define NIC_NAME_LEN 64
|
|
||||||
#endif
|
|
||||||
#define SEM_PROJ_ID 's'
|
|
||||||
#define MAXNICNUM 32
|
|
||||||
|
|
||||||
typedef long KEYID;
|
|
||||||
typedef struct _net_info
|
|
||||||
{
|
|
||||||
KEYID ID;
|
|
||||||
char charname[NIC_NAME_LEN];
|
|
||||||
char descr[128];
|
|
||||||
struct sockaddr addr;
|
|
||||||
struct sockaddr broadaddr;
|
|
||||||
struct sockaddr netmask;
|
|
||||||
struct sockaddr hwaddr;
|
|
||||||
int time_stamp;
|
|
||||||
short flags;
|
|
||||||
int mtu;
|
|
||||||
int tx_queue_len;
|
|
||||||
unsigned long long average_flow;
|
|
||||||
unsigned long long rx_packets;
|
|
||||||
unsigned long long tx_packets;
|
|
||||||
unsigned long long rx_bytes;
|
|
||||||
unsigned long long tx_bytes;
|
|
||||||
unsigned long rx_errors;
|
|
||||||
unsigned long tx_errors;
|
|
||||||
unsigned long rx_dropped;
|
|
||||||
unsigned long tx_dropped;
|
|
||||||
unsigned long rx_multicast;
|
|
||||||
unsigned long collisions;
|
|
||||||
unsigned long rx_fifo_errors;
|
|
||||||
unsigned long tx_carrier_errors;
|
|
||||||
unsigned long tx_fifo_errors;
|
|
||||||
}NETCARD_INFO;
|
|
||||||
|
|
||||||
int get_nic_info(char *nic_name, NETCARD_INFO *net_info);
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
@@ -1,198 +0,0 @@
|
|||||||
////////////////////////////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
// Copyright (c) Comets' Grp. of Kedong Corp 2008. All Rights Reserved.
|
|
||||||
//
|
|
||||||
// FileName : procconf.h
|
|
||||||
//
|
|
||||||
// Function : this class realize some basic functions for process managerment,
|
|
||||||
// such as initiate process, report status of process, check status of process,
|
|
||||||
// update status of process, get information of process
|
|
||||||
//
|
|
||||||
// Author :
|
|
||||||
//
|
|
||||||
// Date :
|
|
||||||
//
|
|
||||||
// Modify by :
|
|
||||||
//
|
|
||||||
// Mod Date :
|
|
||||||
//
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
#ifndef _PROCCONF_H
|
|
||||||
#define _PROCCONF_H
|
|
||||||
|
|
||||||
#include <sys/types.h>
|
|
||||||
#include <sys/stat.h>
|
|
||||||
#include <fcntl.h>
|
|
||||||
#include <sys/mman.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <errno.h>
|
|
||||||
//#include <iostream.h>
|
|
||||||
#include <signal.h>
|
|
||||||
|
|
||||||
#include "const.h"
|
|
||||||
|
|
||||||
//for alarm ................................
|
|
||||||
typedef struct MESS_BH
|
|
||||||
{
|
|
||||||
unsigned char mtype;
|
|
||||||
int length;
|
|
||||||
};
|
|
||||||
typedef struct PROCESS_ALM
|
|
||||||
{
|
|
||||||
char context_name[MAX_STRING_LEN];
|
|
||||||
char app_name[MAX_STRING_LEN];
|
|
||||||
char proc_name[MAX_STRING_LEN];
|
|
||||||
unsigned char status;
|
|
||||||
};
|
|
||||||
//for alarm end .............................
|
|
||||||
|
|
||||||
//for mmi....................................
|
|
||||||
const int MAX_BUFFER_LEN = 500;
|
|
||||||
typedef struct MESS_BLOCK
|
|
||||||
{
|
|
||||||
unsigned char num;
|
|
||||||
char buffer[MAX_BUFFER_LEN];
|
|
||||||
};
|
|
||||||
typedef struct MESS_PROC
|
|
||||||
{
|
|
||||||
char context_name[MAX_STRING_LEN];
|
|
||||||
char app_name[MAX_STRING_LEN];
|
|
||||||
char proc_name[MAX_STRING_LEN];
|
|
||||||
char status;
|
|
||||||
};
|
|
||||||
//for mmi end ................................
|
|
||||||
|
|
||||||
const int DEFAULT_PERIOD = 3;
|
|
||||||
const int COUNT_LIMIT = 2;
|
|
||||||
const int START_DEFAULT_PERIOD = 60;
|
|
||||||
const int START_COUNT_LIMIT = 5;
|
|
||||||
const int APP_COUNT_LIMIT = 1;
|
|
||||||
|
|
||||||
//process critical level
|
|
||||||
//const int WST_CRITICAL = 1; // Shutdown and reboot workstation when failed
|
|
||||||
//const int SYS_CRITICAL = 2; // Shutdown and reboot the system on the wst when failed
|
|
||||||
//const int USER_CRITICAL = 3; // Shutdown and reboot the subsystem when failed
|
|
||||||
//const int GENERAL = 4; // reboot the process
|
|
||||||
const int CRUCIAL = 1; // crucial process
|
|
||||||
const int GENERAL = 0; // general process
|
|
||||||
|
|
||||||
|
|
||||||
extern int srv_init(char *service,int port);
|
|
||||||
extern int Tcp_close(int sockfd);
|
|
||||||
extern int Tcp_read(int fd,char *ptr,int nbytes);
|
|
||||||
extern int Tcp_write(int fd,char *ptr,int nbytes);
|
|
||||||
extern int srv_accept(int fd,struct sockaddr *cli_addr,int *clilen);
|
|
||||||
extern int client_tcp_open(char *host,char *service,int port);
|
|
||||||
|
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
char context_name[MAX_STRING_LEN];
|
|
||||||
char app_name[MAX_STRING_LEN];
|
|
||||||
char proc_name[MAX_STRING_LEN];
|
|
||||||
pid_t proc_pid;
|
|
||||||
}PROC_ADM_INFO;
|
|
||||||
|
|
||||||
//***************************************************************
|
|
||||||
// structure name : PROC_INFO
|
|
||||||
// function : store process informatin
|
|
||||||
// author :
|
|
||||||
// date :
|
|
||||||
// modify by :
|
|
||||||
// modification :
|
|
||||||
// mod date :
|
|
||||||
//***************************************************************
|
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
int position;
|
|
||||||
char node_name[MAX_STRING_LEN];
|
|
||||||
char context_name[MAX_STRING_LEN];
|
|
||||||
char app_name[MAX_STRING_LEN];
|
|
||||||
char proc_name[MAX_STRING_LEN];
|
|
||||||
|
|
||||||
unsigned char active_flag;
|
|
||||||
unsigned char master_flag;
|
|
||||||
|
|
||||||
time_t startup_time;
|
|
||||||
time_t refresh_time;
|
|
||||||
short refresh_peri;
|
|
||||||
unsigned char monitor_type;
|
|
||||||
|
|
||||||
pid_t proc_pid;
|
|
||||||
unsigned char auto_start;
|
|
||||||
unsigned char act_timer;
|
|
||||||
unsigned char start_timer;
|
|
||||||
unsigned char critical_level;
|
|
||||||
|
|
||||||
char exefile_path[MAX_EXECMD_LEN];
|
|
||||||
|
|
||||||
}PROC_INFO;
|
|
||||||
|
|
||||||
//***************************************************************
|
|
||||||
// structure name : APP_INFO
|
|
||||||
// function : store application informatin
|
|
||||||
// author :
|
|
||||||
// date :
|
|
||||||
// modify by :
|
|
||||||
// modification :
|
|
||||||
// mod date :
|
|
||||||
//***************************************************************
|
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
int position;
|
|
||||||
char context_name[MAX_STRING_LEN];
|
|
||||||
int context_id;
|
|
||||||
char app_name[MAX_STRING_LEN];
|
|
||||||
int app_id;
|
|
||||||
unsigned char act_timer;
|
|
||||||
unsigned char active_flag;
|
|
||||||
}APP_INFO;
|
|
||||||
|
|
||||||
|
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
int no_proc;
|
|
||||||
int semdes_cfg;
|
|
||||||
PROC_INFO proc[MAX_LOCAL_PROCESS];
|
|
||||||
APP_INFO app[MAX_LOCAL_APP];
|
|
||||||
}PROCCFG;
|
|
||||||
|
|
||||||
class proc_invocation
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
int m_init;
|
|
||||||
PROCCFG *proccfg_p;
|
|
||||||
|
|
||||||
public:
|
|
||||||
proc_invocation();
|
|
||||||
~proc_invocation();
|
|
||||||
|
|
||||||
int conf_create();
|
|
||||||
//int check_proc_status();
|
|
||||||
//int update_rtdb();
|
|
||||||
//int kill_proc(pid_t pid);
|
|
||||||
//int start_proc(char *cmdline);
|
|
||||||
//int send_alarm(char *context_name, char *app_name, char *proc_name, unsigned char status);
|
|
||||||
//int update_proc_status(char *context_name, char *app_name, char *proc_name, char status);
|
|
||||||
|
|
||||||
//int proc_init(char *context_name, char *app_name, char *proc_name, int critical_level);//exefile_path,auto_start
|
|
||||||
int proc_init(char *context_name, char *app_name, char *proc_name);
|
|
||||||
int proc_report(int pos, char status, int intertime=3);
|
|
||||||
int proc_exit(int proc_pos);
|
|
||||||
|
|
||||||
int get_pos(char *context_name, char *app_name, char *proc_name);
|
|
||||||
int is_proc_exist(char *context_name, char *app_name, char *proc_name);
|
|
||||||
int conf_map();
|
|
||||||
|
|
||||||
int get_procinfo(int position, PROC_ADM_INFO *p_info);
|
|
||||||
int get_active_pid(int &num, int *p_pidlist);
|
|
||||||
int is_proc_run(pid_t pid);
|
|
||||||
int is_proc_run(char *context_name, char *app_name, char *proc_name);
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -1,133 +0,0 @@
|
|||||||
#include "mnic.h"
|
|
||||||
|
|
||||||
static char *prase_digit(char **s)
|
|
||||||
{
|
|
||||||
char *retp = NULL;
|
|
||||||
char *p = *s;
|
|
||||||
|
|
||||||
if(!p)return NULL;
|
|
||||||
while(!isdigit(*p)){
|
|
||||||
p++;
|
|
||||||
if(*p == '\0')return NULL;
|
|
||||||
}
|
|
||||||
retp = p;
|
|
||||||
while(isdigit(*p)){
|
|
||||||
p++;
|
|
||||||
if(*p == '\0'){
|
|
||||||
*s = NULL;
|
|
||||||
return retp;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*p = '\0';
|
|
||||||
p++;
|
|
||||||
*s = p;
|
|
||||||
return retp;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
char *get_name(char *name, char *p)
|
|
||||||
{
|
|
||||||
while (isspace(*p))
|
|
||||||
p++;
|
|
||||||
while (*p) {
|
|
||||||
if (isspace(*p))
|
|
||||||
break;
|
|
||||||
if (*p == ':') { /* could be an alias */
|
|
||||||
char *dot = p, *dotname = name;
|
|
||||||
*name++ = *p++;
|
|
||||||
while (isdigit(*p))
|
|
||||||
*name++ = *p++;
|
|
||||||
if (*p != ':') { /* it wasn't, backup */
|
|
||||||
p = dot;
|
|
||||||
name = dotname;
|
|
||||||
}
|
|
||||||
if (*p == '\0')
|
|
||||||
return NULL;
|
|
||||||
p++;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
*name++ = *p++;
|
|
||||||
}
|
|
||||||
*name++ = '\0';
|
|
||||||
return p;
|
|
||||||
}
|
|
||||||
|
|
||||||
int get_dev_fields(char *str, NETCARD_INFO *ife)
|
|
||||||
{
|
|
||||||
int i = 0;
|
|
||||||
char *retp[16];
|
|
||||||
|
|
||||||
while((retp[i] = prase_digit(&str)) != NULL){i++;if(i > 15)break;}
|
|
||||||
ife->rx_bytes = atoll(retp[0]);
|
|
||||||
ife->rx_packets = atoll(retp[1]);
|
|
||||||
ife->rx_errors = atol(retp[2]);
|
|
||||||
ife->rx_dropped = atol(retp[3]);
|
|
||||||
ife->rx_fifo_errors = atol(retp[4]);
|
|
||||||
ife->rx_multicast = atol(retp[7]);
|
|
||||||
ife->tx_bytes = atoll(retp[8]);
|
|
||||||
ife->tx_packets = atoll(retp[9]);
|
|
||||||
ife->tx_errors = atol(retp[10]);
|
|
||||||
ife->tx_dropped = atol(retp[11]);
|
|
||||||
ife->tx_fifo_errors = atol(retp[12]);
|
|
||||||
ife->collisions = atol(retp[13]);
|
|
||||||
ife->tx_carrier_errors = atol(retp[14]);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int if_fetch(NETCARD_INFO *ife)
|
|
||||||
{
|
|
||||||
int skfd;
|
|
||||||
struct ifreq ifr;
|
|
||||||
|
|
||||||
if((skfd = socket(PF_INET, SOCK_DGRAM, 0)) == -1)return -1;
|
|
||||||
|
|
||||||
strcpy(ifr.ifr_name, ife->charname);
|
|
||||||
if (!ioctl(skfd, SIOCGIFFLAGS, &ifr))
|
|
||||||
ife->flags = ifr.ifr_flags;
|
|
||||||
|
|
||||||
if (!ioctl(skfd, SIOCGIFHWADDR, &ifr))
|
|
||||||
ife->hwaddr = ifr.ifr_hwaddr;
|
|
||||||
|
|
||||||
if (!ioctl(skfd, SIOCGIFMTU, &ifr))
|
|
||||||
ife->mtu = ifr.ifr_mtu;
|
|
||||||
|
|
||||||
if (!ioctl(skfd, SIOCGIFTXQLEN, &ifr))
|
|
||||||
ife->tx_queue_len = ifr.ifr_qlen;
|
|
||||||
|
|
||||||
if (!ioctl(skfd, SIOCGIFADDR, &ifr))
|
|
||||||
ife->addr = ifr.ifr_addr;
|
|
||||||
|
|
||||||
if (!ioctl(skfd, SIOCGIFBRDADDR, &ifr))
|
|
||||||
ife->broadaddr = ifr.ifr_broadaddr;
|
|
||||||
|
|
||||||
if (!ioctl(skfd, SIOCGIFNETMASK, &ifr))
|
|
||||||
ife->netmask = ifr.ifr_netmask;
|
|
||||||
|
|
||||||
ife->time_stamp = time(NULL);
|
|
||||||
close(skfd);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int ioc_get_name(NETCARD_INFO *name)
|
|
||||||
{
|
|
||||||
int skfd;
|
|
||||||
int ifrnum;
|
|
||||||
int i = 0;
|
|
||||||
struct ifconf ifc;
|
|
||||||
struct ifreq buf[MAXNICNUM];
|
|
||||||
|
|
||||||
if((skfd = socket(PF_INET, SOCK_DGRAM, 0)) == -1)return -1;
|
|
||||||
memset(buf, 0, sizeof(buf));
|
|
||||||
ifc.ifc_len = sizeof(buf);
|
|
||||||
ifc.ifc_buf = (caddr_t) buf;
|
|
||||||
ioctl(skfd, SIOCGIFCONF, &ifc);
|
|
||||||
ifrnum = ifc.ifc_len / sizeof(struct ifreq);
|
|
||||||
while(ifrnum-- > 0){
|
|
||||||
strcpy(name[i].charname, buf[ifrnum].ifr_name);
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
close(skfd);
|
|
||||||
return i;
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -1,37 +0,0 @@
|
|||||||
#include "mnic.h"
|
|
||||||
|
|
||||||
void send_alarm(D5000_NIC_ALARM *mesg, int socket_port, char *ipv4)
|
|
||||||
{
|
|
||||||
int bytes;
|
|
||||||
int sock_sd;
|
|
||||||
int val;
|
|
||||||
char error_str[200];
|
|
||||||
struct sockaddr_in recever;
|
|
||||||
socklen_t sock_len;
|
|
||||||
|
|
||||||
if((sock_sd = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP)) == -1){
|
|
||||||
snprintf(error_str, sizeof(error_str), "EMERG: socket(): %s\n", strerror(errno));
|
|
||||||
record_log(error_str);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
val=1;
|
|
||||||
if ((setsockopt(sock_sd, SOL_SOCKET, SO_BROADCAST, &val, sizeof(val))) == -1) {
|
|
||||||
snprintf(error_str, sizeof(error_str), "EMERG: setsockopt(): %s\n", strerror(errno));
|
|
||||||
record_log(error_str);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
/* init socket*/
|
|
||||||
recever.sin_family = AF_INET;
|
|
||||||
recever.sin_port = htons(socket_port);
|
|
||||||
inet_pton(AF_INET, ipv4, &recever.sin_addr);
|
|
||||||
sock_len = sizeof(recever);
|
|
||||||
/* send alarm*/
|
|
||||||
if((bytes = sendto(sock_sd, mesg, sizeof(D5000_NIC_ALARM), 0, (const struct sockaddr *)&recever, sock_len)) < 1){
|
|
||||||
snprintf(error_str, sizeof(error_str), "EMERG: sendto(): %s\n", strerror(errno));
|
|
||||||
record_log(error_str);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
//snprintf(error_str, sizeof(error_str), "NOTICE: Alarm information has already send!\n");
|
|
||||||
//record_log(error_str);
|
|
||||||
close(sock_sd);
|
|
||||||
}
|
|
||||||
@@ -1,88 +0,0 @@
|
|||||||
#ifndef _SYS_NETCARD_H
|
|
||||||
#define _SYS_NETCARD_H
|
|
||||||
|
|
||||||
#include <sys/socket.h>
|
|
||||||
|
|
||||||
#ifndef NIC_NAME_LEN
|
|
||||||
#define NIC_NAME_LEN 64
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define SEM_PROJ_ID 's'
|
|
||||||
#define MAXNICNUM 32
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C"{
|
|
||||||
#endif
|
|
||||||
|
|
||||||
typedef long KEYID;
|
|
||||||
|
|
||||||
typedef struct _msg_frame // message frame
|
|
||||||
{
|
|
||||||
short len; // message length
|
|
||||||
short seqno; // send sequence
|
|
||||||
short serv; // services ID
|
|
||||||
short event; // event ID
|
|
||||||
unsigned char domain; // domain ID
|
|
||||||
unsigned char ctxt; // Context ID
|
|
||||||
short stid; // SOURCE task id
|
|
||||||
short dtid; // DESTINATION task ID
|
|
||||||
unsigned char ver_coding; // 版本号 + 编码
|
|
||||||
unsigned char mes_type; // 帧类型
|
|
||||||
}MSG_FRAME, *LPMSG_FRAME;
|
|
||||||
|
|
||||||
typedef struct _net_info
|
|
||||||
{
|
|
||||||
KEYID ID;
|
|
||||||
char charname[NIC_NAME_LEN];
|
|
||||||
char descr[128];
|
|
||||||
struct sockaddr addr;
|
|
||||||
struct sockaddr broadaddr;
|
|
||||||
struct sockaddr netmask;
|
|
||||||
struct sockaddr hwaddr;
|
|
||||||
int time_stamp;
|
|
||||||
short flags;
|
|
||||||
int mtu;
|
|
||||||
int tx_queue_len;
|
|
||||||
unsigned long long average_flow;
|
|
||||||
unsigned long long rx_packets;
|
|
||||||
unsigned long long tx_packets;
|
|
||||||
unsigned long long rx_bytes;
|
|
||||||
unsigned long long tx_bytes;
|
|
||||||
unsigned long rx_errors;
|
|
||||||
unsigned long tx_errors;
|
|
||||||
unsigned long rx_dropped;
|
|
||||||
unsigned long tx_dropped;
|
|
||||||
unsigned long rx_multicast;
|
|
||||||
unsigned long collisions;
|
|
||||||
unsigned long rx_fifo_errors;
|
|
||||||
unsigned long tx_carrier_errors;
|
|
||||||
unsigned long tx_fifo_errors;
|
|
||||||
}NETCARD_INFO, *LPNETCARD_INFO;
|
|
||||||
|
|
||||||
#define NETCARD_ALARM_FAULT 1
|
|
||||||
#define NETCARD_ALARM_RESUME 2
|
|
||||||
#define NETCARD_ALARM_SWITCH 3
|
|
||||||
#define NETCARD_ALARM_ABNORMAL 4
|
|
||||||
#define NETCARD_ALARM_NORMAL 5
|
|
||||||
typedef struct _sys_netcard_alarm
|
|
||||||
{
|
|
||||||
char fault_devname[NIC_NAME_LEN]; /*故障设备名称 */
|
|
||||||
char switch_devname[NIC_NAME_LEN]; /*切换设备名称 */
|
|
||||||
short flags; /* 状态标记 : 1:网卡故障。2:网卡恢复。3:网卡切换。4:流量异常。*/
|
|
||||||
short retrytimes; //0,1,2 重发次数
|
|
||||||
}SYS_NETCARD_ALARM, *LPSYS_NETCARD_ALARM;
|
|
||||||
|
|
||||||
|
|
||||||
typedef struct _d5000_nic_alarm
|
|
||||||
{
|
|
||||||
MSG_FRAME tMsgFrame ;
|
|
||||||
SYS_NETCARD_ALARM tSysNetcardAlarm ;
|
|
||||||
}D5000_NIC_ALARM, *LPD5000_NIC_ALARM;
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
Binary file not shown.
@@ -1,28 +0,0 @@
|
|||||||
#! /usr/bin/make -f
|
|
||||||
|
|
||||||
DEFAULTS = Makefile.config
|
|
||||||
|
|
||||||
include $(DEFAULTS)
|
|
||||||
|
|
||||||
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 $@ $^
|
|
||||||
libnic_shm.so:nicinfo_shm.c
|
|
||||||
$(CC) -fpic -shared -o $@ $^
|
|
||||||
clean:
|
|
||||||
$(RM) *.o
|
|
||||||
$(RM) libnic_shm.so sys_nicmonitor
|
|
||||||
install:
|
|
||||||
$(MKDIR) -p $(LIBDIR)
|
|
||||||
$(MKDIR) -p $(BINDIR)
|
|
||||||
$(MKDIR) -p $(INCDIR)
|
|
||||||
$(CP) libnic_shm.so $(LIBDIR)
|
|
||||||
$(CP) sys_nicmonitor $(BINDIR)
|
|
||||||
$(CP) nicinfo_shm.h $(INCDIR)
|
|
||||||
uninstall:
|
|
||||||
$(RM) -f $(LIBDIR)/libnic_shm.so
|
|
||||||
$(RM) -f $(BINDIR)/sys_nicmonitor
|
|
||||||
$(RM) -f $(INCDIR)/nicinfo_shm.h
|
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
|
|
||||||
PREFIX = $(DESTDIR)
|
|
||||||
|
|
||||||
BINDIR = $(PREFIX)/usr/bin
|
|
||||||
|
|
||||||
LIBDIR = $(PREFIX)/usr/lib64
|
|
||||||
|
|
||||||
INCDIR = $(PREFIX)/usr/include
|
|
||||||
|
|
||||||
INSTALL_SH = ./install.sh
|
|
||||||
|
|
||||||
CP = cp
|
|
||||||
RM = rm
|
|
||||||
#CC = gcc
|
|
||||||
CC = g++
|
|
||||||
MKDIR = mkdir
|
|
||||||
@@ -1,32 +0,0 @@
|
|||||||
|
|
||||||
lijin:/home/d5000/lijin/sys_nicmonitor # ./sys_nicmonitor
|
|
||||||
shm_path:/home/d5000/tmp/sys_netcard_shm_path
|
|
||||||
log_path:/home/d5000/var/log/netcard/20110110_sys_nicmonitor.log
|
|
||||||
udp bond0
|
|
||||||
nic bond0
|
|
||||||
nic eth0
|
|
||||||
nic eth1
|
|
||||||
|
|
||||||
d5000@lijin:~ > cat var/log/netcard/20110110_sys_nicmonitor.log
|
|
||||||
2011-01-10 11:10:37.761 sys_nicmonitor NOTICE: sys_nicmonitor V1.5 is
|
|
||||||
started !
|
|
||||||
2011-01-10 11:10:37.761 sys_nicmonitor
|
|
||||||
shm_path:/home/d5000/tmp/sys_netcard_shm_path
|
|
||||||
2011-01-10 11:10:37.761 sys_nicmonitor
|
|
||||||
log_path:/home/d5000/var/log/netcard/20110110_sys_nicmonitor.log
|
|
||||||
2011-01-10 11:10:37.761 sys_nicmonitor udp bond0
|
|
||||||
2011-01-10 11:10:37.761 sys_nicmonitor nic bond0
|
|
||||||
2011-01-10 11:10:37.761 sys_nicmonitor nic eth0
|
|
||||||
2011-01-10 11:10:37.762 sys_nicmonitor nic eth1
|
|
||||||
2011-01-10 11:10:37.762 sys_nicmonitor NOTICE: bond0 is NORMAL!
|
|
||||||
2011-01-10 11:10:37.763 sys_nicmonitor NOTICE: eth0 is NORMAL!
|
|
||||||
2011-01-10 11:10:37.763 sys_nicmonitor NOTICE: eth1 is NORMAL!
|
|
||||||
|
|
||||||
与1.4不一样的地方在与增加log文件中的打印语句
|
|
||||||
sys_nicmonitor started! version v1.4
|
|
||||||
shm_path: /home/d5000/tmp
|
|
||||||
log_path: /home/d5000/ var/log/netcard
|
|
||||||
udp bond0
|
|
||||||
nic bond0
|
|
||||||
nic eth0
|
|
||||||
nic eth1
|
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
V1.5与V1.6差异
|
|
||||||
将ping_gw中的system调用改为popen减少系统误报
|
|
||||||
@@ -1,51 +0,0 @@
|
|||||||
#ifndef _RTE_CONST_H
|
|
||||||
#define _RTE_CONST_H
|
|
||||||
|
|
||||||
#include <pthread.h>
|
|
||||||
|
|
||||||
|
|
||||||
#define MAX_STRING_LEN 24
|
|
||||||
#define MAX_EXECMD_LEN 200
|
|
||||||
#define MAX_FILENAME_LEN 200
|
|
||||||
|
|
||||||
#define MAX_CONTEXT 8
|
|
||||||
#define MAX_HOSTNAME_LEN 24
|
|
||||||
#define MAX_LOCAL_MESPROC 512
|
|
||||||
#define MAX_LOCAL_PROCESS MAX_LOCAL_MESPROC
|
|
||||||
#define MAX_LOCAL_APP 32
|
|
||||||
#define MAX_LOCAL_NODE 256
|
|
||||||
|
|
||||||
#define MAX_SET 256 //max num of event set
|
|
||||||
#define MAX_EVENT 1300
|
|
||||||
#define MAX_REG_PROC 20
|
|
||||||
|
|
||||||
#define LEN_SHMBLK_BIG 4096
|
|
||||||
#define MAX_MSGBUF_LEN 32767
|
|
||||||
#define FREE_PAGE_SIZE 65536
|
|
||||||
#define MAX_PAGE_NUM 1024
|
|
||||||
|
|
||||||
#define MAX_QUE MAX_LOCAL_MESPROC
|
|
||||||
#define MAX_SEMPHORE_SET MAX_LOCAL_MESPROC*2
|
|
||||||
#define RTE_HAN 0 // queue number for event handeler0(RTE)
|
|
||||||
#define EX_EVENT_HAN RTE_HAN // queue number for extrnal event handeler
|
|
||||||
|
|
||||||
#define DOMAIN_I 1
|
|
||||||
#define DOMAIN_II 2
|
|
||||||
#define DOMAIN_III 3
|
|
||||||
|
|
||||||
//Add 20090225
|
|
||||||
const int PROC_TYPE_RPT =1;
|
|
||||||
const int PROC_TYPE_UNRPT =0;
|
|
||||||
//add end
|
|
||||||
|
|
||||||
|
|
||||||
//status for proc and app
|
|
||||||
const int NON_ACTIVE = 0;
|
|
||||||
const int ACTIVE = 1;
|
|
||||||
const int HANGUP = 2;
|
|
||||||
const int FAILURE = 5;
|
|
||||||
const int START = 6;
|
|
||||||
const int STOP = 7;
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -1,44 +0,0 @@
|
|||||||
#ifndef __MNIC_H
|
|
||||||
#define __MNIC_H
|
|
||||||
|
|
||||||
//#define _GNU_SOURCE
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <stddef.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <ctype.h>
|
|
||||||
#include <errno.h>
|
|
||||||
#include <netinet/in.h>
|
|
||||||
#include <net/if.h>
|
|
||||||
#include <time.h>
|
|
||||||
#include <sys/ioctl.h>
|
|
||||||
#include <sys/socket.h>
|
|
||||||
#include <sys/sem.h>
|
|
||||||
#include <sys/ipc.h>
|
|
||||||
#include <sys/param.h>
|
|
||||||
#include <linux/types.h>
|
|
||||||
#include <glob.h>
|
|
||||||
#include <linux/sockios.h>
|
|
||||||
#include <arpa/inet.h>
|
|
||||||
#include <pthread.h>
|
|
||||||
#include <sys/mman.h>
|
|
||||||
#include <sys/stat.h>
|
|
||||||
#include <fcntl.h>
|
|
||||||
#include <signal.h>
|
|
||||||
#include <sys/time.h>
|
|
||||||
|
|
||||||
#include "sys_netcard.h"
|
|
||||||
#include <pwd.h>
|
|
||||||
#include <sys/types.h>
|
|
||||||
#define IPSIZE 16
|
|
||||||
|
|
||||||
char *get_name(char *, char *);
|
|
||||||
int if_fetch(NETCARD_INFO *);
|
|
||||||
int ioc_get_name(NETCARD_INFO *);
|
|
||||||
int get_dev_fields(char *p, NETCARD_INFO *);
|
|
||||||
int get_user_home(int , char *);
|
|
||||||
void send_alarm(D5000_NIC_ALARM *, int , char *);
|
|
||||||
void record_log(char *);
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,209 +0,0 @@
|
|||||||
#include <stdio.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <sys/mman.h>
|
|
||||||
#include <sys/types.h>
|
|
||||||
#include <sys/ipc.h>
|
|
||||||
#include <sys/sem.h>
|
|
||||||
#include <fcntl.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <errno.h>
|
|
||||||
#include <sys/time.h>
|
|
||||||
#include <time.h>
|
|
||||||
#include <dirent.h>
|
|
||||||
#include <pwd.h>
|
|
||||||
|
|
||||||
#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/"
|
|
||||||
|
|
||||||
typedef struct net_info{
|
|
||||||
NETCARD_INFO info[MAXNICNUM];
|
|
||||||
}SHM;
|
|
||||||
|
|
||||||
static int semid = 0;
|
|
||||||
static char log_path[1024];
|
|
||||||
static char shm_path[1024];
|
|
||||||
static char sem_path[1024];
|
|
||||||
SHM *ptr = NULL;
|
|
||||||
|
|
||||||
/* write error in logfile */
|
|
||||||
void record_log(char *str)
|
|
||||||
{
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void get_sem(int semid)
|
|
||||||
{
|
|
||||||
char err_str[200];
|
|
||||||
struct sembuf lock[2];
|
|
||||||
|
|
||||||
lock[0].sem_num = 0;
|
|
||||||
lock[0].sem_op = 0;
|
|
||||||
lock[0].sem_flg = SEM_UNDO;
|
|
||||||
|
|
||||||
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(err_str, sizeof(err_str), "EMERG: semop():\n", strerror(errno));
|
|
||||||
record_log(err_str);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void release_sem(int semid)
|
|
||||||
{
|
|
||||||
int ret;
|
|
||||||
char err_str[200];
|
|
||||||
struct sembuf unlock;
|
|
||||||
|
|
||||||
unlock.sem_num = 0;
|
|
||||||
unlock.sem_op = -1;
|
|
||||||
unlock.sem_flg = SEM_UNDO;
|
|
||||||
|
|
||||||
if((ret = semop(semid, &unlock, 1)) == -1){
|
|
||||||
snprintf(err_str, sizeof(err_str), "EMERG: semop():\n", strerror(errno));
|
|
||||||
record_log(err_str);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int init_nic_info(void)
|
|
||||||
{
|
|
||||||
int fd = -1;
|
|
||||||
int sem_val;
|
|
||||||
char err_str[200];
|
|
||||||
key_t key;
|
|
||||||
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
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);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
/*
|
|
||||||
if((sem_val = semctl(semid, 0, GETVAL, 0)) == -1){
|
|
||||||
snprintf(err_str, sizeof(err_str), "EMERG: semctl: %s !\n", strerror(errno));
|
|
||||||
record_log(err_str);
|
|
||||||
semctl(semid, 0, IPC_RMID);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
if(!sem_val){
|
|
||||||
if(semctl(semid, 0, SETVAL, 1) == -1){
|
|
||||||
snprintf(err_str, sizeof(err_str), "EMERG: semctl: %s !\n", strerror(errno));
|
|
||||||
record_log(err_str);
|
|
||||||
semctl(semid, 0, IPC_RMID);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
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);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
ptr = (SHM*)mmap(NULL, sizeof(SHM), PROT_READ, MAP_SHARED, fd, 0);
|
|
||||||
if(ptr == MAP_FAILED){
|
|
||||||
snprintf(err_str, sizeof(err_str), "EMERG: mmap():%s\n", strerror(errno));
|
|
||||||
record_log(err_str);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
close(fd);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
int get_nic_info(char *nic_name, NETCARD_INFO *net_info)
|
|
||||||
{
|
|
||||||
int i,ret;
|
|
||||||
time_t tamp;
|
|
||||||
struct tm tmptr;
|
|
||||||
DIR *dir;
|
|
||||||
char *s;
|
|
||||||
char buf[128];
|
|
||||||
char err_str[200];
|
|
||||||
struct passwd *user;
|
|
||||||
|
|
||||||
tamp = time(NULL);
|
|
||||||
localtime_r(&tamp, &tmptr);
|
|
||||||
|
|
||||||
if((user = getpwnam("d5000"))!= NULL){
|
|
||||||
sprintf(log_path,"%s",user->pw_dir);
|
|
||||||
sprintf(shm_path,"%s",user->pw_dir);
|
|
||||||
sprintf(sem_path,"%s",user->pw_dir);
|
|
||||||
}
|
|
||||||
strcat(log_path,LOG_PATH);
|
|
||||||
strcat(shm_path,SHM_PATH);
|
|
||||||
strcat(sem_path,SEM_PATH);
|
|
||||||
|
|
||||||
if((dir = opendir(log_path)) == NULL){
|
|
||||||
if(errno == ENOENT){
|
|
||||||
strcpy(log_path, "/tmp/");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
closedir(dir);
|
|
||||||
s = strrchr(log_path, '/');
|
|
||||||
s++;
|
|
||||||
*s = '\0';
|
|
||||||
memset(buf, 0, sizeof(buf));
|
|
||||||
strftime(buf, sizeof(buf), "%Y%m%d_", &tmptr);
|
|
||||||
strcat(buf, "sys_nicmonitor");
|
|
||||||
strcat(buf, ".log");
|
|
||||||
strcat(log_path, buf);
|
|
||||||
if((ret = init_nic_info()) == -1){
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
get_sem(semid);
|
|
||||||
for(i = 0; ptr->info[i].charname[0] != 0; i++){
|
|
||||||
if(!strcmp(ptr->info[i].charname, nic_name)){
|
|
||||||
// get_sem(semid);
|
|
||||||
memcpy(net_info, &ptr->info[i], sizeof(NETCARD_INFO));
|
|
||||||
release_sem(semid);
|
|
||||||
munmap(ptr, sizeof(SHM));
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
release_sem(semid);
|
|
||||||
snprintf(err_str, sizeof(err_str), "NOTICE: No information of %s !\n", nic_name);
|
|
||||||
record_log(err_str);
|
|
||||||
munmap(ptr, sizeof(SHM));
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
@@ -1,52 +0,0 @@
|
|||||||
#ifndef NIC_SHM_H
|
|
||||||
#define NIC_SHM_H
|
|
||||||
|
|
||||||
#include <sys/socket.h>
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef NIC_NAME_LEN
|
|
||||||
#define NIC_NAME_LEN 64
|
|
||||||
#endif
|
|
||||||
#define SEM_PROJ_ID 's'
|
|
||||||
#define MAXNICNUM 32
|
|
||||||
|
|
||||||
typedef long KEYID;
|
|
||||||
typedef struct _net_info
|
|
||||||
{
|
|
||||||
KEYID ID;
|
|
||||||
char charname[NIC_NAME_LEN];
|
|
||||||
char descr[128];
|
|
||||||
struct sockaddr addr;
|
|
||||||
struct sockaddr broadaddr;
|
|
||||||
struct sockaddr netmask;
|
|
||||||
struct sockaddr hwaddr;
|
|
||||||
int time_stamp;
|
|
||||||
short flags;
|
|
||||||
int mtu;
|
|
||||||
int tx_queue_len;
|
|
||||||
unsigned long long average_flow;
|
|
||||||
unsigned long long rx_packets;
|
|
||||||
unsigned long long tx_packets;
|
|
||||||
unsigned long long rx_bytes;
|
|
||||||
unsigned long long tx_bytes;
|
|
||||||
unsigned long rx_errors;
|
|
||||||
unsigned long tx_errors;
|
|
||||||
unsigned long rx_dropped;
|
|
||||||
unsigned long tx_dropped;
|
|
||||||
unsigned long rx_multicast;
|
|
||||||
unsigned long collisions;
|
|
||||||
unsigned long rx_fifo_errors;
|
|
||||||
unsigned long tx_carrier_errors;
|
|
||||||
unsigned long tx_fifo_errors;
|
|
||||||
}NETCARD_INFO;
|
|
||||||
|
|
||||||
int get_nic_info(char *nic_name, NETCARD_INFO *net_info);
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
@@ -1,198 +0,0 @@
|
|||||||
////////////////////////////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
// Copyright (c) Comets' Grp. of Kedong Corp 2008. All Rights Reserved.
|
|
||||||
//
|
|
||||||
// FileName : procconf.h
|
|
||||||
//
|
|
||||||
// Function : this class realize some basic functions for process managerment,
|
|
||||||
// such as initiate process, report status of process, check status of process,
|
|
||||||
// update status of process, get information of process
|
|
||||||
//
|
|
||||||
// Author :
|
|
||||||
//
|
|
||||||
// Date :
|
|
||||||
//
|
|
||||||
// Modify by :
|
|
||||||
//
|
|
||||||
// Mod Date :
|
|
||||||
//
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
#ifndef _PROCCONF_H
|
|
||||||
#define _PROCCONF_H
|
|
||||||
|
|
||||||
#include <sys/types.h>
|
|
||||||
#include <sys/stat.h>
|
|
||||||
#include <fcntl.h>
|
|
||||||
#include <sys/mman.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <errno.h>
|
|
||||||
//#include <iostream.h>
|
|
||||||
#include <signal.h>
|
|
||||||
|
|
||||||
#include "const.h"
|
|
||||||
|
|
||||||
//for alarm ................................
|
|
||||||
typedef struct MESS_BH
|
|
||||||
{
|
|
||||||
unsigned char mtype;
|
|
||||||
int length;
|
|
||||||
};
|
|
||||||
typedef struct PROCESS_ALM
|
|
||||||
{
|
|
||||||
char context_name[MAX_STRING_LEN];
|
|
||||||
char app_name[MAX_STRING_LEN];
|
|
||||||
char proc_name[MAX_STRING_LEN];
|
|
||||||
unsigned char status;
|
|
||||||
};
|
|
||||||
//for alarm end .............................
|
|
||||||
|
|
||||||
//for mmi....................................
|
|
||||||
const int MAX_BUFFER_LEN = 500;
|
|
||||||
typedef struct MESS_BLOCK
|
|
||||||
{
|
|
||||||
unsigned char num;
|
|
||||||
char buffer[MAX_BUFFER_LEN];
|
|
||||||
};
|
|
||||||
typedef struct MESS_PROC
|
|
||||||
{
|
|
||||||
char context_name[MAX_STRING_LEN];
|
|
||||||
char app_name[MAX_STRING_LEN];
|
|
||||||
char proc_name[MAX_STRING_LEN];
|
|
||||||
char status;
|
|
||||||
};
|
|
||||||
//for mmi end ................................
|
|
||||||
|
|
||||||
const int DEFAULT_PERIOD = 3;
|
|
||||||
const int COUNT_LIMIT = 2;
|
|
||||||
const int START_DEFAULT_PERIOD = 60;
|
|
||||||
const int START_COUNT_LIMIT = 5;
|
|
||||||
const int APP_COUNT_LIMIT = 1;
|
|
||||||
|
|
||||||
//process critical level
|
|
||||||
//const int WST_CRITICAL = 1; // Shutdown and reboot workstation when failed
|
|
||||||
//const int SYS_CRITICAL = 2; // Shutdown and reboot the system on the wst when failed
|
|
||||||
//const int USER_CRITICAL = 3; // Shutdown and reboot the subsystem when failed
|
|
||||||
//const int GENERAL = 4; // reboot the process
|
|
||||||
const int CRUCIAL = 1; // crucial process
|
|
||||||
const int GENERAL = 0; // general process
|
|
||||||
|
|
||||||
|
|
||||||
extern int srv_init(char *service,int port);
|
|
||||||
extern int Tcp_close(int sockfd);
|
|
||||||
extern int Tcp_read(int fd,char *ptr,int nbytes);
|
|
||||||
extern int Tcp_write(int fd,char *ptr,int nbytes);
|
|
||||||
extern int srv_accept(int fd,struct sockaddr *cli_addr,int *clilen);
|
|
||||||
extern int client_tcp_open(char *host,char *service,int port);
|
|
||||||
|
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
char context_name[MAX_STRING_LEN];
|
|
||||||
char app_name[MAX_STRING_LEN];
|
|
||||||
char proc_name[MAX_STRING_LEN];
|
|
||||||
pid_t proc_pid;
|
|
||||||
}PROC_ADM_INFO;
|
|
||||||
|
|
||||||
//***************************************************************
|
|
||||||
// structure name : PROC_INFO
|
|
||||||
// function : store process informatin
|
|
||||||
// author :
|
|
||||||
// date :
|
|
||||||
// modify by :
|
|
||||||
// modification :
|
|
||||||
// mod date :
|
|
||||||
//***************************************************************
|
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
int position;
|
|
||||||
char node_name[MAX_STRING_LEN];
|
|
||||||
char context_name[MAX_STRING_LEN];
|
|
||||||
char app_name[MAX_STRING_LEN];
|
|
||||||
char proc_name[MAX_STRING_LEN];
|
|
||||||
|
|
||||||
unsigned char active_flag;
|
|
||||||
unsigned char master_flag;
|
|
||||||
|
|
||||||
time_t startup_time;
|
|
||||||
time_t refresh_time;
|
|
||||||
short refresh_peri;
|
|
||||||
unsigned char monitor_type;
|
|
||||||
|
|
||||||
pid_t proc_pid;
|
|
||||||
unsigned char auto_start;
|
|
||||||
unsigned char act_timer;
|
|
||||||
unsigned char start_timer;
|
|
||||||
unsigned char critical_level;
|
|
||||||
|
|
||||||
char exefile_path[MAX_EXECMD_LEN];
|
|
||||||
|
|
||||||
}PROC_INFO;
|
|
||||||
|
|
||||||
//***************************************************************
|
|
||||||
// structure name : APP_INFO
|
|
||||||
// function : store application informatin
|
|
||||||
// author :
|
|
||||||
// date :
|
|
||||||
// modify by :
|
|
||||||
// modification :
|
|
||||||
// mod date :
|
|
||||||
//***************************************************************
|
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
int position;
|
|
||||||
char context_name[MAX_STRING_LEN];
|
|
||||||
int context_id;
|
|
||||||
char app_name[MAX_STRING_LEN];
|
|
||||||
int app_id;
|
|
||||||
unsigned char act_timer;
|
|
||||||
unsigned char active_flag;
|
|
||||||
}APP_INFO;
|
|
||||||
|
|
||||||
|
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
int no_proc;
|
|
||||||
int semdes_cfg;
|
|
||||||
PROC_INFO proc[MAX_LOCAL_PROCESS];
|
|
||||||
APP_INFO app[MAX_LOCAL_APP];
|
|
||||||
}PROCCFG;
|
|
||||||
|
|
||||||
class proc_invocation
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
int m_init;
|
|
||||||
PROCCFG *proccfg_p;
|
|
||||||
|
|
||||||
public:
|
|
||||||
proc_invocation();
|
|
||||||
~proc_invocation();
|
|
||||||
|
|
||||||
int conf_create();
|
|
||||||
//int check_proc_status();
|
|
||||||
//int update_rtdb();
|
|
||||||
//int kill_proc(pid_t pid);
|
|
||||||
//int start_proc(char *cmdline);
|
|
||||||
//int send_alarm(char *context_name, char *app_name, char *proc_name, unsigned char status);
|
|
||||||
//int update_proc_status(char *context_name, char *app_name, char *proc_name, char status);
|
|
||||||
|
|
||||||
//int proc_init(char *context_name, char *app_name, char *proc_name, int critical_level);//exefile_path,auto_start
|
|
||||||
int proc_init(char *context_name, char *app_name, char *proc_name);
|
|
||||||
int proc_report(int pos, char status, int intertime=3);
|
|
||||||
int proc_exit(int proc_pos);
|
|
||||||
|
|
||||||
int get_pos(char *context_name, char *app_name, char *proc_name);
|
|
||||||
int is_proc_exist(char *context_name, char *app_name, char *proc_name);
|
|
||||||
int conf_map();
|
|
||||||
|
|
||||||
int get_procinfo(int position, PROC_ADM_INFO *p_info);
|
|
||||||
int get_active_pid(int &num, int *p_pidlist);
|
|
||||||
int is_proc_run(pid_t pid);
|
|
||||||
int is_proc_run(char *context_name, char *app_name, char *proc_name);
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -1,133 +0,0 @@
|
|||||||
#include "mnic.h"
|
|
||||||
|
|
||||||
static char *prase_digit(char **s)
|
|
||||||
{
|
|
||||||
char *retp = NULL;
|
|
||||||
char *p = *s;
|
|
||||||
|
|
||||||
if(!p)return NULL;
|
|
||||||
while(!isdigit(*p)){
|
|
||||||
p++;
|
|
||||||
if(*p == '\0')return NULL;
|
|
||||||
}
|
|
||||||
retp = p;
|
|
||||||
while(isdigit(*p)){
|
|
||||||
p++;
|
|
||||||
if(*p == '\0'){
|
|
||||||
*s = NULL;
|
|
||||||
return retp;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*p = '\0';
|
|
||||||
p++;
|
|
||||||
*s = p;
|
|
||||||
return retp;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
char *get_name(char *name, char *p)
|
|
||||||
{
|
|
||||||
while (isspace(*p))
|
|
||||||
p++;
|
|
||||||
while (*p) {
|
|
||||||
if (isspace(*p))
|
|
||||||
break;
|
|
||||||
if (*p == ':') { /* could be an alias */
|
|
||||||
char *dot = p, *dotname = name;
|
|
||||||
*name++ = *p++;
|
|
||||||
while (isdigit(*p))
|
|
||||||
*name++ = *p++;
|
|
||||||
if (*p != ':') { /* it wasn't, backup */
|
|
||||||
p = dot;
|
|
||||||
name = dotname;
|
|
||||||
}
|
|
||||||
if (*p == '\0')
|
|
||||||
return NULL;
|
|
||||||
p++;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
*name++ = *p++;
|
|
||||||
}
|
|
||||||
*name++ = '\0';
|
|
||||||
return p;
|
|
||||||
}
|
|
||||||
|
|
||||||
int get_dev_fields(char *str, NETCARD_INFO *ife)
|
|
||||||
{
|
|
||||||
int i = 0;
|
|
||||||
char *retp[16];
|
|
||||||
|
|
||||||
while((retp[i] = prase_digit(&str)) != NULL){i++;if(i > 15)break;}
|
|
||||||
ife->rx_bytes = atoll(retp[0]);
|
|
||||||
ife->rx_packets = atoll(retp[1]);
|
|
||||||
ife->rx_errors = atol(retp[2]);
|
|
||||||
ife->rx_dropped = atol(retp[3]);
|
|
||||||
ife->rx_fifo_errors = atol(retp[4]);
|
|
||||||
ife->rx_multicast = atol(retp[7]);
|
|
||||||
ife->tx_bytes = atoll(retp[8]);
|
|
||||||
ife->tx_packets = atoll(retp[9]);
|
|
||||||
ife->tx_errors = atol(retp[10]);
|
|
||||||
ife->tx_dropped = atol(retp[11]);
|
|
||||||
ife->tx_fifo_errors = atol(retp[12]);
|
|
||||||
ife->collisions = atol(retp[13]);
|
|
||||||
ife->tx_carrier_errors = atol(retp[14]);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int if_fetch(NETCARD_INFO *ife)
|
|
||||||
{
|
|
||||||
int skfd;
|
|
||||||
struct ifreq ifr;
|
|
||||||
|
|
||||||
if((skfd = socket(PF_INET, SOCK_DGRAM, 0)) == -1)return -1;
|
|
||||||
|
|
||||||
strcpy(ifr.ifr_name, ife->charname);
|
|
||||||
if (!ioctl(skfd, SIOCGIFFLAGS, &ifr))
|
|
||||||
ife->flags = ifr.ifr_flags;
|
|
||||||
|
|
||||||
if (!ioctl(skfd, SIOCGIFHWADDR, &ifr))
|
|
||||||
ife->hwaddr = ifr.ifr_hwaddr;
|
|
||||||
|
|
||||||
if (!ioctl(skfd, SIOCGIFMTU, &ifr))
|
|
||||||
ife->mtu = ifr.ifr_mtu;
|
|
||||||
|
|
||||||
if (!ioctl(skfd, SIOCGIFTXQLEN, &ifr))
|
|
||||||
ife->tx_queue_len = ifr.ifr_qlen;
|
|
||||||
|
|
||||||
if (!ioctl(skfd, SIOCGIFADDR, &ifr))
|
|
||||||
ife->addr = ifr.ifr_addr;
|
|
||||||
|
|
||||||
if (!ioctl(skfd, SIOCGIFBRDADDR, &ifr))
|
|
||||||
ife->broadaddr = ifr.ifr_broadaddr;
|
|
||||||
|
|
||||||
if (!ioctl(skfd, SIOCGIFNETMASK, &ifr))
|
|
||||||
ife->netmask = ifr.ifr_netmask;
|
|
||||||
|
|
||||||
ife->time_stamp = time(NULL);
|
|
||||||
close(skfd);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int ioc_get_name(NETCARD_INFO *name)
|
|
||||||
{
|
|
||||||
int skfd;
|
|
||||||
int ifrnum;
|
|
||||||
int i = 0;
|
|
||||||
struct ifconf ifc;
|
|
||||||
struct ifreq buf[MAXNICNUM];
|
|
||||||
|
|
||||||
if((skfd = socket(PF_INET, SOCK_DGRAM, 0)) == -1)return -1;
|
|
||||||
memset(buf, 0, sizeof(buf));
|
|
||||||
ifc.ifc_len = sizeof(buf);
|
|
||||||
ifc.ifc_buf = (caddr_t) buf;
|
|
||||||
ioctl(skfd, SIOCGIFCONF, &ifc);
|
|
||||||
ifrnum = ifc.ifc_len / sizeof(struct ifreq);
|
|
||||||
while(ifrnum-- > 0){
|
|
||||||
strcpy(name[i].charname, buf[ifrnum].ifr_name);
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
close(skfd);
|
|
||||||
return i;
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -1,37 +0,0 @@
|
|||||||
#include "mnic.h"
|
|
||||||
|
|
||||||
void send_alarm(D5000_NIC_ALARM *mesg, int socket_port, char *ipv4)
|
|
||||||
{
|
|
||||||
int bytes;
|
|
||||||
int sock_sd;
|
|
||||||
int val;
|
|
||||||
char error_str[200];
|
|
||||||
struct sockaddr_in recever;
|
|
||||||
socklen_t sock_len;
|
|
||||||
|
|
||||||
if((sock_sd = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP)) == -1){
|
|
||||||
snprintf(error_str, sizeof(error_str), "EMERG: socket(): %s\n", strerror(errno));
|
|
||||||
record_log(error_str);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
val=1;
|
|
||||||
if ((setsockopt(sock_sd, SOL_SOCKET, SO_BROADCAST, &val, sizeof(val))) == -1) {
|
|
||||||
snprintf(error_str, sizeof(error_str), "EMERG: setsockopt(): %s\n", strerror(errno));
|
|
||||||
record_log(error_str);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
/* init socket*/
|
|
||||||
recever.sin_family = AF_INET;
|
|
||||||
recever.sin_port = htons(socket_port);
|
|
||||||
inet_pton(AF_INET, ipv4, &recever.sin_addr);
|
|
||||||
sock_len = sizeof(recever);
|
|
||||||
/* send alarm*/
|
|
||||||
if((bytes = sendto(sock_sd, mesg, sizeof(D5000_NIC_ALARM), 0, (const struct sockaddr *)&recever, sock_len)) < 1){
|
|
||||||
snprintf(error_str, sizeof(error_str), "EMERG: sendto(): %s\n", strerror(errno));
|
|
||||||
record_log(error_str);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
//snprintf(error_str, sizeof(error_str), "NOTICE: Alarm information has already send!\n");
|
|
||||||
//record_log(error_str);
|
|
||||||
close(sock_sd);
|
|
||||||
}
|
|
||||||
@@ -1,88 +0,0 @@
|
|||||||
#ifndef _SYS_NETCARD_H
|
|
||||||
#define _SYS_NETCARD_H
|
|
||||||
|
|
||||||
#include <sys/socket.h>
|
|
||||||
|
|
||||||
#ifndef NIC_NAME_LEN
|
|
||||||
#define NIC_NAME_LEN 64
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define SEM_PROJ_ID 's'
|
|
||||||
#define MAXNICNUM 32
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C"{
|
|
||||||
#endif
|
|
||||||
|
|
||||||
typedef long KEYID;
|
|
||||||
|
|
||||||
typedef struct _msg_frame // message frame
|
|
||||||
{
|
|
||||||
short len; // message length
|
|
||||||
short seqno; // send sequence
|
|
||||||
short serv; // services ID
|
|
||||||
short event; // event ID
|
|
||||||
unsigned char domain; // domain ID
|
|
||||||
unsigned char ctxt; // Context ID
|
|
||||||
short stid; // SOURCE task id
|
|
||||||
short dtid; // DESTINATION task ID
|
|
||||||
unsigned char ver_coding; // 版本号 + 编码
|
|
||||||
unsigned char mes_type; // 帧类型
|
|
||||||
}MSG_FRAME, *LPMSG_FRAME;
|
|
||||||
|
|
||||||
typedef struct _net_info
|
|
||||||
{
|
|
||||||
KEYID ID;
|
|
||||||
char charname[NIC_NAME_LEN];
|
|
||||||
char descr[128];
|
|
||||||
struct sockaddr addr;
|
|
||||||
struct sockaddr broadaddr;
|
|
||||||
struct sockaddr netmask;
|
|
||||||
struct sockaddr hwaddr;
|
|
||||||
int time_stamp;
|
|
||||||
short flags;
|
|
||||||
int mtu;
|
|
||||||
int tx_queue_len;
|
|
||||||
unsigned long long average_flow;
|
|
||||||
unsigned long long rx_packets;
|
|
||||||
unsigned long long tx_packets;
|
|
||||||
unsigned long long rx_bytes;
|
|
||||||
unsigned long long tx_bytes;
|
|
||||||
unsigned long rx_errors;
|
|
||||||
unsigned long tx_errors;
|
|
||||||
unsigned long rx_dropped;
|
|
||||||
unsigned long tx_dropped;
|
|
||||||
unsigned long rx_multicast;
|
|
||||||
unsigned long collisions;
|
|
||||||
unsigned long rx_fifo_errors;
|
|
||||||
unsigned long tx_carrier_errors;
|
|
||||||
unsigned long tx_fifo_errors;
|
|
||||||
}NETCARD_INFO, *LPNETCARD_INFO;
|
|
||||||
|
|
||||||
#define NETCARD_ALARM_FAULT 1
|
|
||||||
#define NETCARD_ALARM_RESUME 2
|
|
||||||
#define NETCARD_ALARM_SWITCH 3
|
|
||||||
#define NETCARD_ALARM_ABNORMAL 4
|
|
||||||
#define NETCARD_ALARM_NORMAL 5
|
|
||||||
typedef struct _sys_netcard_alarm
|
|
||||||
{
|
|
||||||
char fault_devname[NIC_NAME_LEN]; /*故障设备名称 */
|
|
||||||
char switch_devname[NIC_NAME_LEN]; /*切换设备名称 */
|
|
||||||
short flags; /* 状态标记 : 1:网卡故障。2:网卡恢复。3:网卡切换。4:流量异常。*/
|
|
||||||
short retrytimes; //0,1,2 重发次数
|
|
||||||
}SYS_NETCARD_ALARM, *LPSYS_NETCARD_ALARM;
|
|
||||||
|
|
||||||
|
|
||||||
typedef struct _d5000_nic_alarm
|
|
||||||
{
|
|
||||||
MSG_FRAME tMsgFrame ;
|
|
||||||
SYS_NETCARD_ALARM tSysNetcardAlarm ;
|
|
||||||
}D5000_NIC_ALARM, *LPD5000_NIC_ALARM;
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
Binary file not shown.
@@ -1,28 +0,0 @@
|
|||||||
#! /usr/bin/make -f
|
|
||||||
|
|
||||||
DEFAULTS = Makefile.config
|
|
||||||
|
|
||||||
include $(DEFAULTS)
|
|
||||||
|
|
||||||
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 $@ $^
|
|
||||||
libnic_shm.so:nicinfo_shm.c
|
|
||||||
$(CC) -fpic -shared -o $@ $^
|
|
||||||
clean:
|
|
||||||
$(RM) *.o
|
|
||||||
$(RM) libnic_shm.so sys_nicmonitor
|
|
||||||
install:
|
|
||||||
$(MKDIR) -p $(LIBDIR)
|
|
||||||
$(MKDIR) -p $(BINDIR)
|
|
||||||
$(MKDIR) -p $(INCDIR)
|
|
||||||
$(CP) libnic_shm.so $(LIBDIR)
|
|
||||||
$(CP) sys_nicmonitor $(BINDIR)
|
|
||||||
$(CP) nicinfo_shm.h $(INCDIR)
|
|
||||||
uninstall:
|
|
||||||
$(RM) -f $(LIBDIR)/libnic_shm.so
|
|
||||||
$(RM) -f $(BINDIR)/sys_nicmonitor
|
|
||||||
$(RM) -f $(INCDIR)/nicinfo_shm.h
|
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
|
|
||||||
PREFIX = $(DESTDIR)
|
|
||||||
|
|
||||||
BINDIR = $(PREFIX)/usr/bin
|
|
||||||
|
|
||||||
LIBDIR = $(PREFIX)/usr/lib64
|
|
||||||
|
|
||||||
INCDIR = $(PREFIX)/usr/include
|
|
||||||
|
|
||||||
INSTALL_SH = ./install.sh
|
|
||||||
|
|
||||||
CP = cp
|
|
||||||
RM = rm
|
|
||||||
#CC = gcc
|
|
||||||
CC = g++
|
|
||||||
MKDIR = mkdir
|
|
||||||
@@ -1,51 +0,0 @@
|
|||||||
#ifndef _RTE_CONST_H
|
|
||||||
#define _RTE_CONST_H
|
|
||||||
|
|
||||||
#include <pthread.h>
|
|
||||||
|
|
||||||
|
|
||||||
#define MAX_STRING_LEN 24
|
|
||||||
#define MAX_EXECMD_LEN 200
|
|
||||||
#define MAX_FILENAME_LEN 200
|
|
||||||
|
|
||||||
#define MAX_CONTEXT 8
|
|
||||||
#define MAX_HOSTNAME_LEN 24
|
|
||||||
#define MAX_LOCAL_MESPROC 512
|
|
||||||
#define MAX_LOCAL_PROCESS MAX_LOCAL_MESPROC
|
|
||||||
#define MAX_LOCAL_APP 32
|
|
||||||
#define MAX_LOCAL_NODE 256
|
|
||||||
|
|
||||||
#define MAX_SET 256 //max num of event set
|
|
||||||
#define MAX_EVENT 1300
|
|
||||||
#define MAX_REG_PROC 20
|
|
||||||
|
|
||||||
#define LEN_SHMBLK_BIG 4096
|
|
||||||
#define MAX_MSGBUF_LEN 32767
|
|
||||||
#define FREE_PAGE_SIZE 65536
|
|
||||||
#define MAX_PAGE_NUM 1024
|
|
||||||
|
|
||||||
#define MAX_QUE MAX_LOCAL_MESPROC
|
|
||||||
#define MAX_SEMPHORE_SET MAX_LOCAL_MESPROC*2
|
|
||||||
#define RTE_HAN 0 // queue number for event handeler0(RTE)
|
|
||||||
#define EX_EVENT_HAN RTE_HAN // queue number for extrnal event handeler
|
|
||||||
|
|
||||||
#define DOMAIN_I 1
|
|
||||||
#define DOMAIN_II 2
|
|
||||||
#define DOMAIN_III 3
|
|
||||||
|
|
||||||
//Add 20090225
|
|
||||||
const int PROC_TYPE_RPT =1;
|
|
||||||
const int PROC_TYPE_UNRPT =0;
|
|
||||||
//add end
|
|
||||||
|
|
||||||
|
|
||||||
//status for proc and app
|
|
||||||
const int NON_ACTIVE = 0;
|
|
||||||
const int ACTIVE = 1;
|
|
||||||
const int HANGUP = 2;
|
|
||||||
const int FAILURE = 5;
|
|
||||||
const int START = 6;
|
|
||||||
const int STOP = 7;
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -1,44 +0,0 @@
|
|||||||
#ifndef __MNIC_H
|
|
||||||
#define __MNIC_H
|
|
||||||
|
|
||||||
//#define _GNU_SOURCE
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <stddef.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <ctype.h>
|
|
||||||
#include <errno.h>
|
|
||||||
#include <netinet/in.h>
|
|
||||||
#include <net/if.h>
|
|
||||||
#include <time.h>
|
|
||||||
#include <sys/ioctl.h>
|
|
||||||
#include <sys/socket.h>
|
|
||||||
#include <sys/sem.h>
|
|
||||||
#include <sys/ipc.h>
|
|
||||||
#include <sys/param.h>
|
|
||||||
#include <linux/types.h>
|
|
||||||
#include <glob.h>
|
|
||||||
#include <linux/sockios.h>
|
|
||||||
#include <arpa/inet.h>
|
|
||||||
#include <pthread.h>
|
|
||||||
#include <sys/mman.h>
|
|
||||||
#include <sys/stat.h>
|
|
||||||
#include <fcntl.h>
|
|
||||||
#include <signal.h>
|
|
||||||
#include <sys/time.h>
|
|
||||||
|
|
||||||
#include "sys_netcard.h"
|
|
||||||
#include <pwd.h>
|
|
||||||
#include <sys/types.h>
|
|
||||||
#define IPSIZE 16
|
|
||||||
|
|
||||||
char *get_name(char *, char *);
|
|
||||||
int if_fetch(NETCARD_INFO *);
|
|
||||||
int ioc_get_name(NETCARD_INFO *);
|
|
||||||
int get_dev_fields(char *p, NETCARD_INFO *);
|
|
||||||
int get_user_home(int , char *);
|
|
||||||
void send_alarm(D5000_NIC_ALARM *, int , char *);
|
|
||||||
void record_log(char *);
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,188 +0,0 @@
|
|||||||
#include <stdio.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <sys/mman.h>
|
|
||||||
#include <sys/types.h>
|
|
||||||
#include <sys/ipc.h>
|
|
||||||
#include <sys/sem.h>
|
|
||||||
#include <fcntl.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <errno.h>
|
|
||||||
#include <sys/time.h>
|
|
||||||
#include <time.h>
|
|
||||||
#include <dirent.h>
|
|
||||||
|
|
||||||
#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/"
|
|
||||||
|
|
||||||
typedef struct net_info{
|
|
||||||
NETCARD_INFO info[MAXNICNUM];
|
|
||||||
}SHM;
|
|
||||||
|
|
||||||
static int semid = 0;
|
|
||||||
static char log_path[1024];
|
|
||||||
SHM *ptr = NULL;
|
|
||||||
|
|
||||||
/* write error in logfile */
|
|
||||||
void record_log(char *str)
|
|
||||||
{
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void get_sem(int semid)
|
|
||||||
{
|
|
||||||
char err_str[200];
|
|
||||||
struct sembuf lock;
|
|
||||||
|
|
||||||
lock.sem_num = 0;
|
|
||||||
lock.sem_op = -1;
|
|
||||||
lock.sem_flg = SEM_UNDO;
|
|
||||||
|
|
||||||
while(semop(semid, &lock, 1)){
|
|
||||||
if (errno == EINTR) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
snprintf(err_str, sizeof(err_str), "EMERG: semop():\n", strerror(errno));
|
|
||||||
record_log(err_str);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void release_sem(int semid)
|
|
||||||
{
|
|
||||||
int ret;
|
|
||||||
char err_str[200];
|
|
||||||
struct sembuf unlock;
|
|
||||||
|
|
||||||
unlock.sem_num = 0;
|
|
||||||
unlock.sem_op = 1;
|
|
||||||
unlock.sem_flg = SEM_UNDO;
|
|
||||||
|
|
||||||
if((ret = semop(semid, &unlock, 1)) == -1){
|
|
||||||
snprintf(err_str, sizeof(err_str), "EMERG: semop():\n", strerror(errno));
|
|
||||||
record_log(err_str);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int init_nic_info(void)
|
|
||||||
{
|
|
||||||
int fd = -1;
|
|
||||||
int sem_val;
|
|
||||||
char err_str[200];
|
|
||||||
key_t key;
|
|
||||||
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
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);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
if((sem_val = semctl(semid, 0, GETVAL, 0)) == -1){
|
|
||||||
snprintf(err_str, sizeof(err_str), "EMERG: semctl: %s !\n", strerror(errno));
|
|
||||||
record_log(err_str);
|
|
||||||
semctl(semid, 0, IPC_RMID);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
if(!sem_val){
|
|
||||||
if(semctl(semid, 0, SETVAL, 1) == -1){
|
|
||||||
snprintf(err_str, sizeof(err_str), "EMERG: semctl: %s !\n", strerror(errno));
|
|
||||||
record_log(err_str);
|
|
||||||
semctl(semid, 0, IPC_RMID);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
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);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
ptr = (SHM*)mmap(NULL, sizeof(SHM), PROT_READ, MAP_SHARED, fd, 0);
|
|
||||||
if(ptr == MAP_FAILED){
|
|
||||||
snprintf(err_str, sizeof(err_str), "EMERG: mmap():%s\n", strerror(errno));
|
|
||||||
record_log(err_str);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
close(fd);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
int get_nic_info(char *nic_name, NETCARD_INFO *net_info)
|
|
||||||
{
|
|
||||||
int i,ret;
|
|
||||||
time_t tamp;
|
|
||||||
struct tm tmptr;
|
|
||||||
DIR *dir;
|
|
||||||
char *s;
|
|
||||||
char buf[128];
|
|
||||||
char err_str[200];
|
|
||||||
|
|
||||||
tamp = time(NULL);
|
|
||||||
localtime_r(&tamp, &tmptr);
|
|
||||||
strcpy(log_path, LOG_PATH);
|
|
||||||
if((dir = opendir(log_path)) == NULL){
|
|
||||||
if(errno == ENOENT){
|
|
||||||
strcpy(log_path, "/tmp/");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
closedir(dir);
|
|
||||||
s = strrchr(log_path, '/');
|
|
||||||
s++;
|
|
||||||
*s = '\0';
|
|
||||||
memset(buf, 0, sizeof(buf));
|
|
||||||
strftime(buf, sizeof(buf), "%Y%m%d_", &tmptr);
|
|
||||||
strcat(buf, "sys_nicmonitor");
|
|
||||||
strcat(buf, ".log");
|
|
||||||
strcat(log_path, buf);
|
|
||||||
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);
|
|
||||||
memcpy(net_info, &ptr->info[i], sizeof(NETCARD_INFO));
|
|
||||||
release_sem(semid);
|
|
||||||
munmap(ptr, sizeof(SHM));
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
snprintf(err_str, sizeof(err_str), "NOTICE: No information of %s !\n", nic_name);
|
|
||||||
record_log(err_str);
|
|
||||||
munmap(ptr, sizeof(SHM));
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
@@ -1,52 +0,0 @@
|
|||||||
#ifndef NIC_SHM_H
|
|
||||||
#define NIC_SHM_H
|
|
||||||
|
|
||||||
#include <sys/socket.h>
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef NIC_NAME_LEN
|
|
||||||
#define NIC_NAME_LEN 64
|
|
||||||
#endif
|
|
||||||
#define SEM_PROJ_ID 's'
|
|
||||||
#define MAXNICNUM 32
|
|
||||||
|
|
||||||
typedef long KEYID;
|
|
||||||
typedef struct _net_info
|
|
||||||
{
|
|
||||||
KEYID ID;
|
|
||||||
char charname[NIC_NAME_LEN];
|
|
||||||
char descr[128];
|
|
||||||
struct sockaddr addr;
|
|
||||||
struct sockaddr broadaddr;
|
|
||||||
struct sockaddr netmask;
|
|
||||||
struct sockaddr hwaddr;
|
|
||||||
int time_stamp;
|
|
||||||
short flags;
|
|
||||||
int mtu;
|
|
||||||
int tx_queue_len;
|
|
||||||
unsigned long long average_flow;
|
|
||||||
unsigned long long rx_packets;
|
|
||||||
unsigned long long tx_packets;
|
|
||||||
unsigned long long rx_bytes;
|
|
||||||
unsigned long long tx_bytes;
|
|
||||||
unsigned long rx_errors;
|
|
||||||
unsigned long tx_errors;
|
|
||||||
unsigned long rx_dropped;
|
|
||||||
unsigned long tx_dropped;
|
|
||||||
unsigned long rx_multicast;
|
|
||||||
unsigned long collisions;
|
|
||||||
unsigned long rx_fifo_errors;
|
|
||||||
unsigned long tx_carrier_errors;
|
|
||||||
unsigned long tx_fifo_errors;
|
|
||||||
}NETCARD_INFO;
|
|
||||||
|
|
||||||
int get_nic_info(char *nic_name, NETCARD_INFO *net_info);
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
@@ -1,198 +0,0 @@
|
|||||||
////////////////////////////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
// Copyright (c) Comets' Grp. of Kedong Corp 2008. All Rights Reserved.
|
|
||||||
//
|
|
||||||
// FileName : procconf.h
|
|
||||||
//
|
|
||||||
// Function : this class realize some basic functions for process managerment,
|
|
||||||
// such as initiate process, report status of process, check status of process,
|
|
||||||
// update status of process, get information of process
|
|
||||||
//
|
|
||||||
// Author :
|
|
||||||
//
|
|
||||||
// Date :
|
|
||||||
//
|
|
||||||
// Modify by :
|
|
||||||
//
|
|
||||||
// Mod Date :
|
|
||||||
//
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
#ifndef _PROCCONF_H
|
|
||||||
#define _PROCCONF_H
|
|
||||||
|
|
||||||
#include <sys/types.h>
|
|
||||||
#include <sys/stat.h>
|
|
||||||
#include <fcntl.h>
|
|
||||||
#include <sys/mman.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <errno.h>
|
|
||||||
//#include <iostream.h>
|
|
||||||
#include <signal.h>
|
|
||||||
|
|
||||||
#include "const.h"
|
|
||||||
|
|
||||||
//for alarm ................................
|
|
||||||
typedef struct MESS_BH
|
|
||||||
{
|
|
||||||
unsigned char mtype;
|
|
||||||
int length;
|
|
||||||
};
|
|
||||||
typedef struct PROCESS_ALM
|
|
||||||
{
|
|
||||||
char context_name[MAX_STRING_LEN];
|
|
||||||
char app_name[MAX_STRING_LEN];
|
|
||||||
char proc_name[MAX_STRING_LEN];
|
|
||||||
unsigned char status;
|
|
||||||
};
|
|
||||||
//for alarm end .............................
|
|
||||||
|
|
||||||
//for mmi....................................
|
|
||||||
const int MAX_BUFFER_LEN = 500;
|
|
||||||
typedef struct MESS_BLOCK
|
|
||||||
{
|
|
||||||
unsigned char num;
|
|
||||||
char buffer[MAX_BUFFER_LEN];
|
|
||||||
};
|
|
||||||
typedef struct MESS_PROC
|
|
||||||
{
|
|
||||||
char context_name[MAX_STRING_LEN];
|
|
||||||
char app_name[MAX_STRING_LEN];
|
|
||||||
char proc_name[MAX_STRING_LEN];
|
|
||||||
char status;
|
|
||||||
};
|
|
||||||
//for mmi end ................................
|
|
||||||
|
|
||||||
const int DEFAULT_PERIOD = 3;
|
|
||||||
const int COUNT_LIMIT = 2;
|
|
||||||
const int START_DEFAULT_PERIOD = 60;
|
|
||||||
const int START_COUNT_LIMIT = 5;
|
|
||||||
const int APP_COUNT_LIMIT = 1;
|
|
||||||
|
|
||||||
//process critical level
|
|
||||||
//const int WST_CRITICAL = 1; // Shutdown and reboot workstation when failed
|
|
||||||
//const int SYS_CRITICAL = 2; // Shutdown and reboot the system on the wst when failed
|
|
||||||
//const int USER_CRITICAL = 3; // Shutdown and reboot the subsystem when failed
|
|
||||||
//const int GENERAL = 4; // reboot the process
|
|
||||||
const int CRUCIAL = 1; // crucial process
|
|
||||||
const int GENERAL = 0; // general process
|
|
||||||
|
|
||||||
|
|
||||||
extern int srv_init(char *service,int port);
|
|
||||||
extern int Tcp_close(int sockfd);
|
|
||||||
extern int Tcp_read(int fd,char *ptr,int nbytes);
|
|
||||||
extern int Tcp_write(int fd,char *ptr,int nbytes);
|
|
||||||
extern int srv_accept(int fd,struct sockaddr *cli_addr,int *clilen);
|
|
||||||
extern int client_tcp_open(char *host,char *service,int port);
|
|
||||||
|
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
char context_name[MAX_STRING_LEN];
|
|
||||||
char app_name[MAX_STRING_LEN];
|
|
||||||
char proc_name[MAX_STRING_LEN];
|
|
||||||
pid_t proc_pid;
|
|
||||||
}PROC_ADM_INFO;
|
|
||||||
|
|
||||||
//***************************************************************
|
|
||||||
// structure name : PROC_INFO
|
|
||||||
// function : store process informatin
|
|
||||||
// author :
|
|
||||||
// date :
|
|
||||||
// modify by :
|
|
||||||
// modification :
|
|
||||||
// mod date :
|
|
||||||
//***************************************************************
|
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
int position;
|
|
||||||
char node_name[MAX_STRING_LEN];
|
|
||||||
char context_name[MAX_STRING_LEN];
|
|
||||||
char app_name[MAX_STRING_LEN];
|
|
||||||
char proc_name[MAX_STRING_LEN];
|
|
||||||
|
|
||||||
unsigned char active_flag;
|
|
||||||
unsigned char master_flag;
|
|
||||||
|
|
||||||
time_t startup_time;
|
|
||||||
time_t refresh_time;
|
|
||||||
short refresh_peri;
|
|
||||||
unsigned char monitor_type;
|
|
||||||
|
|
||||||
pid_t proc_pid;
|
|
||||||
unsigned char auto_start;
|
|
||||||
unsigned char act_timer;
|
|
||||||
unsigned char start_timer;
|
|
||||||
unsigned char critical_level;
|
|
||||||
|
|
||||||
char exefile_path[MAX_EXECMD_LEN];
|
|
||||||
|
|
||||||
}PROC_INFO;
|
|
||||||
|
|
||||||
//***************************************************************
|
|
||||||
// structure name : APP_INFO
|
|
||||||
// function : store application informatin
|
|
||||||
// author :
|
|
||||||
// date :
|
|
||||||
// modify by :
|
|
||||||
// modification :
|
|
||||||
// mod date :
|
|
||||||
//***************************************************************
|
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
int position;
|
|
||||||
char context_name[MAX_STRING_LEN];
|
|
||||||
int context_id;
|
|
||||||
char app_name[MAX_STRING_LEN];
|
|
||||||
int app_id;
|
|
||||||
unsigned char act_timer;
|
|
||||||
unsigned char active_flag;
|
|
||||||
}APP_INFO;
|
|
||||||
|
|
||||||
|
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
int no_proc;
|
|
||||||
int semdes_cfg;
|
|
||||||
PROC_INFO proc[MAX_LOCAL_PROCESS];
|
|
||||||
APP_INFO app[MAX_LOCAL_APP];
|
|
||||||
}PROCCFG;
|
|
||||||
|
|
||||||
class proc_invocation
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
int m_init;
|
|
||||||
PROCCFG *proccfg_p;
|
|
||||||
|
|
||||||
public:
|
|
||||||
proc_invocation();
|
|
||||||
~proc_invocation();
|
|
||||||
|
|
||||||
int conf_create();
|
|
||||||
//int check_proc_status();
|
|
||||||
//int update_rtdb();
|
|
||||||
//int kill_proc(pid_t pid);
|
|
||||||
//int start_proc(char *cmdline);
|
|
||||||
//int send_alarm(char *context_name, char *app_name, char *proc_name, unsigned char status);
|
|
||||||
//int update_proc_status(char *context_name, char *app_name, char *proc_name, char status);
|
|
||||||
|
|
||||||
//int proc_init(char *context_name, char *app_name, char *proc_name, int critical_level);//exefile_path,auto_start
|
|
||||||
int proc_init(char *context_name, char *app_name, char *proc_name);
|
|
||||||
int proc_report(int pos, char status, int intertime=3);
|
|
||||||
int proc_exit(int proc_pos);
|
|
||||||
|
|
||||||
int get_pos(char *context_name, char *app_name, char *proc_name);
|
|
||||||
int is_proc_exist(char *context_name, char *app_name, char *proc_name);
|
|
||||||
int conf_map();
|
|
||||||
|
|
||||||
int get_procinfo(int position, PROC_ADM_INFO *p_info);
|
|
||||||
int get_active_pid(int &num, int *p_pidlist);
|
|
||||||
int is_proc_run(pid_t pid);
|
|
||||||
int is_proc_run(char *context_name, char *app_name, char *proc_name);
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -1,133 +0,0 @@
|
|||||||
#include "mnic.h"
|
|
||||||
|
|
||||||
static char *prase_digit(char **s)
|
|
||||||
{
|
|
||||||
char *retp = NULL;
|
|
||||||
char *p = *s;
|
|
||||||
|
|
||||||
if(!p)return NULL;
|
|
||||||
while(!isdigit(*p)){
|
|
||||||
p++;
|
|
||||||
if(*p == '\0')return NULL;
|
|
||||||
}
|
|
||||||
retp = p;
|
|
||||||
while(isdigit(*p)){
|
|
||||||
p++;
|
|
||||||
if(*p == '\0'){
|
|
||||||
*s = NULL;
|
|
||||||
return retp;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*p = '\0';
|
|
||||||
p++;
|
|
||||||
*s = p;
|
|
||||||
return retp;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
char *get_name(char *name, char *p)
|
|
||||||
{
|
|
||||||
while (isspace(*p))
|
|
||||||
p++;
|
|
||||||
while (*p) {
|
|
||||||
if (isspace(*p))
|
|
||||||
break;
|
|
||||||
if (*p == ':') { /* could be an alias */
|
|
||||||
char *dot = p, *dotname = name;
|
|
||||||
*name++ = *p++;
|
|
||||||
while (isdigit(*p))
|
|
||||||
*name++ = *p++;
|
|
||||||
if (*p != ':') { /* it wasn't, backup */
|
|
||||||
p = dot;
|
|
||||||
name = dotname;
|
|
||||||
}
|
|
||||||
if (*p == '\0')
|
|
||||||
return NULL;
|
|
||||||
p++;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
*name++ = *p++;
|
|
||||||
}
|
|
||||||
*name++ = '\0';
|
|
||||||
return p;
|
|
||||||
}
|
|
||||||
|
|
||||||
int get_dev_fields(char *str, NETCARD_INFO *ife)
|
|
||||||
{
|
|
||||||
int i = 0;
|
|
||||||
char *retp[16];
|
|
||||||
|
|
||||||
while((retp[i] = prase_digit(&str)) != NULL){i++;if(i > 15)break;}
|
|
||||||
ife->rx_bytes = atoll(retp[0]);
|
|
||||||
ife->rx_packets = atoll(retp[1]);
|
|
||||||
ife->rx_errors = atol(retp[2]);
|
|
||||||
ife->rx_dropped = atol(retp[3]);
|
|
||||||
ife->rx_fifo_errors = atol(retp[4]);
|
|
||||||
ife->rx_multicast = atol(retp[7]);
|
|
||||||
ife->tx_bytes = atoll(retp[8]);
|
|
||||||
ife->tx_packets = atoll(retp[9]);
|
|
||||||
ife->tx_errors = atol(retp[10]);
|
|
||||||
ife->tx_dropped = atol(retp[11]);
|
|
||||||
ife->tx_fifo_errors = atol(retp[12]);
|
|
||||||
ife->collisions = atol(retp[13]);
|
|
||||||
ife->tx_carrier_errors = atol(retp[14]);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int if_fetch(NETCARD_INFO *ife)
|
|
||||||
{
|
|
||||||
int skfd;
|
|
||||||
struct ifreq ifr;
|
|
||||||
|
|
||||||
if((skfd = socket(PF_INET, SOCK_DGRAM, 0)) == -1)return -1;
|
|
||||||
|
|
||||||
strcpy(ifr.ifr_name, ife->charname);
|
|
||||||
if (!ioctl(skfd, SIOCGIFFLAGS, &ifr))
|
|
||||||
ife->flags = ifr.ifr_flags;
|
|
||||||
|
|
||||||
if (!ioctl(skfd, SIOCGIFHWADDR, &ifr))
|
|
||||||
ife->hwaddr = ifr.ifr_hwaddr;
|
|
||||||
|
|
||||||
if (!ioctl(skfd, SIOCGIFMTU, &ifr))
|
|
||||||
ife->mtu = ifr.ifr_mtu;
|
|
||||||
|
|
||||||
if (!ioctl(skfd, SIOCGIFTXQLEN, &ifr))
|
|
||||||
ife->tx_queue_len = ifr.ifr_qlen;
|
|
||||||
|
|
||||||
if (!ioctl(skfd, SIOCGIFADDR, &ifr))
|
|
||||||
ife->addr = ifr.ifr_addr;
|
|
||||||
|
|
||||||
if (!ioctl(skfd, SIOCGIFBRDADDR, &ifr))
|
|
||||||
ife->broadaddr = ifr.ifr_broadaddr;
|
|
||||||
|
|
||||||
if (!ioctl(skfd, SIOCGIFNETMASK, &ifr))
|
|
||||||
ife->netmask = ifr.ifr_netmask;
|
|
||||||
|
|
||||||
ife->time_stamp = time(NULL);
|
|
||||||
close(skfd);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int ioc_get_name(NETCARD_INFO *name)
|
|
||||||
{
|
|
||||||
int skfd;
|
|
||||||
int ifrnum;
|
|
||||||
int i = 0;
|
|
||||||
struct ifconf ifc;
|
|
||||||
struct ifreq buf[MAXNICNUM];
|
|
||||||
|
|
||||||
if((skfd = socket(PF_INET, SOCK_DGRAM, 0)) == -1)return -1;
|
|
||||||
memset(buf, 0, sizeof(buf));
|
|
||||||
ifc.ifc_len = sizeof(buf);
|
|
||||||
ifc.ifc_buf = (caddr_t) buf;
|
|
||||||
ioctl(skfd, SIOCGIFCONF, &ifc);
|
|
||||||
ifrnum = ifc.ifc_len / sizeof(struct ifreq);
|
|
||||||
while(ifrnum-- > 0){
|
|
||||||
strcpy(name[i].charname, buf[ifrnum].ifr_name);
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
close(skfd);
|
|
||||||
return i;
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -1,37 +0,0 @@
|
|||||||
#include "mnic.h"
|
|
||||||
|
|
||||||
void send_alarm(D5000_NIC_ALARM *mesg, int socket_port, char *ipv4)
|
|
||||||
{
|
|
||||||
int bytes;
|
|
||||||
int sock_sd;
|
|
||||||
int val;
|
|
||||||
char error_str[200];
|
|
||||||
struct sockaddr_in recever;
|
|
||||||
socklen_t sock_len;
|
|
||||||
|
|
||||||
if((sock_sd = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP)) == -1){
|
|
||||||
snprintf(error_str, sizeof(error_str), "EMERG: socket(): %s\n", strerror(errno));
|
|
||||||
record_log(error_str);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
val=1;
|
|
||||||
if ((setsockopt(sock_sd, SOL_SOCKET, SO_BROADCAST, &val, sizeof(val))) == -1) {
|
|
||||||
snprintf(error_str, sizeof(error_str), "EMERG: setsockopt(): %s\n", strerror(errno));
|
|
||||||
record_log(error_str);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
/* init socket*/
|
|
||||||
recever.sin_family = AF_INET;
|
|
||||||
recever.sin_port = htons(socket_port);
|
|
||||||
inet_pton(AF_INET, ipv4, &recever.sin_addr);
|
|
||||||
sock_len = sizeof(recever);
|
|
||||||
/* send alarm*/
|
|
||||||
if((bytes = sendto(sock_sd, mesg, sizeof(D5000_NIC_ALARM), 0, (const struct sockaddr *)&recever, sock_len)) < 1){
|
|
||||||
snprintf(error_str, sizeof(error_str), "EMERG: sendto(): %s\n", strerror(errno));
|
|
||||||
record_log(error_str);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
//snprintf(error_str, sizeof(error_str), "NOTICE: Alarm information has already send!\n");
|
|
||||||
//record_log(error_str);
|
|
||||||
close(sock_sd);
|
|
||||||
}
|
|
||||||
@@ -1,88 +0,0 @@
|
|||||||
#ifndef _SYS_NETCARD_H
|
|
||||||
#define _SYS_NETCARD_H
|
|
||||||
|
|
||||||
#include <sys/socket.h>
|
|
||||||
|
|
||||||
#ifndef NIC_NAME_LEN
|
|
||||||
#define NIC_NAME_LEN 64
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define SEM_PROJ_ID 's'
|
|
||||||
#define MAXNICNUM 32
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C"{
|
|
||||||
#endif
|
|
||||||
|
|
||||||
typedef long KEYID;
|
|
||||||
|
|
||||||
typedef struct _msg_frame // message frame
|
|
||||||
{
|
|
||||||
short len; // message length
|
|
||||||
short seqno; // send sequence
|
|
||||||
short serv; // services ID
|
|
||||||
short event; // event ID
|
|
||||||
unsigned char domain; // domain ID
|
|
||||||
unsigned char ctxt; // Context ID
|
|
||||||
short stid; // SOURCE task id
|
|
||||||
short dtid; // DESTINATION task ID
|
|
||||||
unsigned char ver_coding; // 版本号 + 编码
|
|
||||||
unsigned char mes_type; // 帧类型
|
|
||||||
}MSG_FRAME, *LPMSG_FRAME;
|
|
||||||
|
|
||||||
typedef struct _net_info
|
|
||||||
{
|
|
||||||
KEYID ID;
|
|
||||||
char charname[NIC_NAME_LEN];
|
|
||||||
char descr[128];
|
|
||||||
struct sockaddr addr;
|
|
||||||
struct sockaddr broadaddr;
|
|
||||||
struct sockaddr netmask;
|
|
||||||
struct sockaddr hwaddr;
|
|
||||||
int time_stamp;
|
|
||||||
short flags;
|
|
||||||
int mtu;
|
|
||||||
int tx_queue_len;
|
|
||||||
unsigned long long average_flow;
|
|
||||||
unsigned long long rx_packets;
|
|
||||||
unsigned long long tx_packets;
|
|
||||||
unsigned long long rx_bytes;
|
|
||||||
unsigned long long tx_bytes;
|
|
||||||
unsigned long rx_errors;
|
|
||||||
unsigned long tx_errors;
|
|
||||||
unsigned long rx_dropped;
|
|
||||||
unsigned long tx_dropped;
|
|
||||||
unsigned long rx_multicast;
|
|
||||||
unsigned long collisions;
|
|
||||||
unsigned long rx_fifo_errors;
|
|
||||||
unsigned long tx_carrier_errors;
|
|
||||||
unsigned long tx_fifo_errors;
|
|
||||||
}NETCARD_INFO, *LPNETCARD_INFO;
|
|
||||||
|
|
||||||
#define NETCARD_ALARM_FAULT 1
|
|
||||||
#define NETCARD_ALARM_RESUME 2
|
|
||||||
#define NETCARD_ALARM_SWITCH 3
|
|
||||||
#define NETCARD_ALARM_ABNORMAL 4
|
|
||||||
#define NETCARD_ALARM_NORMAL 5
|
|
||||||
typedef struct _sys_netcard_alarm
|
|
||||||
{
|
|
||||||
char fault_devname[NIC_NAME_LEN]; /*故障设备名称 */
|
|
||||||
char switch_devname[NIC_NAME_LEN]; /*切换设备名称 */
|
|
||||||
short flags; /* 状态标记 : 1:网卡故障。2:网卡恢复。3:网卡切换。4:流量异常。*/
|
|
||||||
short retrytimes; //0,1,2 重发次数
|
|
||||||
}SYS_NETCARD_ALARM, *LPSYS_NETCARD_ALARM;
|
|
||||||
|
|
||||||
|
|
||||||
typedef struct _d5000_nic_alarm
|
|
||||||
{
|
|
||||||
MSG_FRAME tMsgFrame ;
|
|
||||||
SYS_NETCARD_ALARM tSysNetcardAlarm ;
|
|
||||||
}D5000_NIC_ALARM, *LPD5000_NIC_ALARM;
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
@@ -6,12 +6,15 @@ include $(DEFAULTS)
|
|||||||
|
|
||||||
all:sys_nicmonitor libnic_shm.so test
|
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
|
sys_nicmonitor:mnic.o read_netcard.o send_alarm.o
|
||||||
$(CC) -lman -ldotconf -lpthread -o $@ $^
|
$(CC) -lman -ldotconf -lpthread -o $@ $^
|
||||||
libnic_shm.so:nicinfo_shm.c
|
libnic_shm.so:nicinfo_shm.o
|
||||||
$(CC) -fpic -shared -o $@ $^
|
$(CC) -fpic -shared -o $@ $^
|
||||||
|
nicinfo_shm.o:nicinfo_shm.c
|
||||||
|
$(CC) $(CFLAGS) -fPIC -c $^
|
||||||
test:test.c
|
test:test.c
|
||||||
gcc -o test test.c -lnic_shm -L=./ -lpthread
|
gcc -o test test.c -lnic_shm -L=./ -lpthread
|
||||||
runtest:
|
runtest:
|
||||||
@@ -75,6 +75,19 @@ make runtest
|
|||||||
========
|
========
|
||||||
|
|
||||||
版本说明:
|
版本说明:
|
||||||
|
--V1.22 --
|
||||||
|
2021-12-13
|
||||||
|
1)修复问题:华为5885V3型号服务器科东应用启动网卡监视程序检测到失败
|
||||||
|
问题描述:使用科东应用启动工具启动网卡监视程序失败
|
||||||
|
解决办法:修改调用科东注册接口函数位置,提升优先级优先调用。
|
||||||
|
|
||||||
|
版本说明:
|
||||||
|
--V1.21 --
|
||||||
|
2019-09-05
|
||||||
|
1)修复问题:monitor_interval参数溢出导致cpu 100%
|
||||||
|
问题描述:当monitor_interval参数配置为1000时,出现进程cpu占用100%的问题
|
||||||
|
解决办法:增加对monitor_interval配置的检测和限制
|
||||||
|
|
||||||
--V1.9 --
|
--V1.9 --
|
||||||
2013-08-12
|
2013-08-12
|
||||||
1)修复问题:占用内存快速累加,导致内存占用很大
|
1)修复问题:占用内存快速累加,导致内存占用很大
|
||||||
@@ -117,7 +117,7 @@ static void *record_log_thread( void *arg )
|
|||||||
//free self thread resources
|
//free self thread resources
|
||||||
pthread_detach(pthread_self());
|
pthread_detach(pthread_self());
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* write error in logfile */
|
/* write error in logfile */
|
||||||
@@ -177,6 +177,6 @@ void record_log(char *str)
|
|||||||
log_idx++;
|
log_idx++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
LOG_UNLOCK;
|
LOG_UNLOCK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -119,10 +119,10 @@ CONFIG_FILE_ST conf;
|
|||||||
|
|
||||||
char myconf[][64] = {
|
char myconf[][64] = {
|
||||||
"domain", // 0
|
"domain", // 0
|
||||||
"serv", // 1
|
"serv", // 1
|
||||||
"event", // 2
|
"event", // 2
|
||||||
"udpport", // 3
|
"udpport", // 3
|
||||||
"sys_netcard_shm_path", // 4
|
"sys_netcard_shm_path", // 4
|
||||||
"sys_netcard_sem_path", // 5
|
"sys_netcard_sem_path", // 5
|
||||||
"monitor_interval", // 6
|
"monitor_interval", // 6
|
||||||
"write_interval", // 7
|
"write_interval", // 7
|
||||||
@@ -151,7 +151,7 @@ static const configoption_t options[] = {
|
|||||||
{myconf[9], 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[10], ARG_INT, cb_int, NULL, CTX_ALL},
|
||||||
{myconf[11], ARG_STR, cb_str, 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[13], ARG_STR, cb_str, NULL, CTX_ALL},
|
||||||
{myconf[14], ARG_INT, cb_int, NULL, CTX_ALL},
|
{myconf[14], ARG_INT, cb_int, NULL, CTX_ALL},
|
||||||
{myconf[15], 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_thread_exit = 0;
|
||||||
|
|
||||||
log_fp = fopen(log_path, "a");
|
log_fp = fopen(log_path, "a");
|
||||||
|
|
||||||
while( !log_thread_exit ) {
|
while( !log_thread_exit ) {
|
||||||
if( !log_fp ) {
|
if( !log_fp ) {
|
||||||
log_fp = fopen(log_path, "a");
|
log_fp = fopen(log_path, "a");
|
||||||
@@ -233,7 +233,7 @@ static void *record_log_thread( void *arg )
|
|||||||
log_prepare = NULL;
|
log_prepare = NULL;
|
||||||
log_writing = NULL;
|
log_writing = NULL;
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* write error in logfile */
|
/* write error in logfile */
|
||||||
@@ -266,7 +266,7 @@ void record_log(char *str)
|
|||||||
if(fwrite(log_str, 1, strlen(log_str), log_fp) < 1){
|
if(fwrite(log_str, 1, strlen(log_str), log_fp) < 1){
|
||||||
}
|
}
|
||||||
fclose(log_fp);
|
fclose(log_fp);
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
static int log_thread_started = 0;
|
static int log_thread_started = 0;
|
||||||
time_t tamp;
|
time_t tamp;
|
||||||
@@ -305,9 +305,9 @@ void record_log(char *str)
|
|||||||
log_prepare[log_idx] = keepstr;
|
log_prepare[log_idx] = keepstr;
|
||||||
log_idx++;
|
log_idx++;
|
||||||
}
|
}
|
||||||
LOG_UNLOCK;
|
LOG_UNLOCK;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
#else
|
#else
|
||||||
@@ -385,14 +385,14 @@ static void init_shm(SHM **ptr, CONFIG_FILE_ST *p)
|
|||||||
share_key = 0x1d5010;
|
share_key = 0x1d5010;
|
||||||
|
|
||||||
#if 0
|
#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);
|
"MSG: sys_nic, shm, size:%d, key:0x%x(%d)\n", size, share_key, share_key);
|
||||||
record_log(error_str);
|
record_log(error_str);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
global_share_id = shmget( share_key, size, IPC_CREAT|0666 );
|
global_share_id = shmget( share_key, size, IPC_CREAT|0666 );
|
||||||
if( global_share_id == -1 ) {
|
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);
|
"EMERG: fail shmget, %s, 0x%x\n", strerror(errno), share_key);
|
||||||
record_log(error_str);
|
record_log(error_str);
|
||||||
return;
|
return;
|
||||||
@@ -400,7 +400,7 @@ static void init_shm(SHM **ptr, CONFIG_FILE_ST *p)
|
|||||||
|
|
||||||
shmptr = shmat( global_share_id, NULL, 0 );
|
shmptr = shmat( global_share_id, NULL, 0 );
|
||||||
if( shmptr == (void *)-1 ) {
|
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);
|
"EMERG: fail shmat, %s, %s\n", strerror(errno), path);
|
||||||
record_log(error_str);
|
record_log(error_str);
|
||||||
return;
|
return;
|
||||||
@@ -450,7 +450,7 @@ static void release_sem(int semid)
|
|||||||
char error_str[200];
|
char error_str[200];
|
||||||
struct sembuf unlock;
|
struct sembuf unlock;
|
||||||
|
|
||||||
unlock.sem_num = 0;
|
unlock.sem_num = 0;
|
||||||
unlock.sem_op = 1;
|
unlock.sem_op = 1;
|
||||||
unlock.sem_flg = SEM_UNDO;
|
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)){
|
if(!strncmp(ptr->info[i].charname, net->charname, NIC_NAME_LEN)){
|
||||||
get_sem(semid);
|
get_sem(semid);
|
||||||
memcpy(&ptr->info[i], net, sizeof(NETCARD_INFO));
|
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;
|
return NULL;
|
||||||
}
|
}
|
||||||
s_time.tv_sec = ptr->conf->write_interval;
|
s_time.tv_sec = ptr->conf->write_interval;
|
||||||
s_time.tv_nsec = 0;
|
s_time.tv_nsec = 0;
|
||||||
|
|
||||||
/* copy all net_info*/
|
/* copy all net_info*/
|
||||||
while(1){
|
while(1){
|
||||||
@@ -738,7 +738,7 @@ static void *cacu_flow(void *p)
|
|||||||
//tx_flow,rx_flow,
|
//tx_flow,rx_flow,
|
||||||
rx_flow=(curr->info.rx_bytes -rx_bytes[i])/ptr->mem.conf->flow_interval;
|
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;
|
tx_flow=(curr->info.tx_bytes -tx_bytes[i])/ptr->mem.conf->flow_interval;
|
||||||
|
|
||||||
if(!strncmp(curr->info.charname, "bond", 4)){
|
if(!strncmp(curr->info.charname, "bond", 4)){
|
||||||
count_t = get_netcard_count(curr->info.charname);
|
count_t = get_netcard_count(curr->info.charname);
|
||||||
}else {
|
}else {
|
||||||
@@ -772,8 +772,8 @@ static void *cacu_flow(void *p)
|
|||||||
if(count_no[i] == 0){
|
if(count_no[i] == 0){
|
||||||
send_inc_info_one(&curr->info, ptr->mem.semid, ptr->mem.shm_ptr);
|
send_inc_info_one(&curr->info, ptr->mem.semid, ptr->mem.shm_ptr);
|
||||||
if( sys_nic_debug ) {
|
if( sys_nic_debug ) {
|
||||||
snprintf(error_str, sizeof(error_str),
|
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",
|
"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);
|
curr->info.charname, summit, curr->info.average_flow,rx_flow,tx_flow);
|
||||||
} else {
|
} else {
|
||||||
snprintf(error_str, sizeof(error_str), "NOTICE: %s flow is abnormal !\n", curr->info.charname);
|
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);
|
record_log(err_str);
|
||||||
}
|
}
|
||||||
#endif
|
#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);
|
// snprintf(err_str, sizeof(err_str), "NOTICE: process exit by signal %d\n", sig);
|
||||||
// record_log(err_str);
|
// record_log(err_str);
|
||||||
@@ -1255,6 +1255,11 @@ int get_conf()
|
|||||||
conf.udpport = 15000;
|
conf.udpport = 15000;
|
||||||
if(conf.monitor_interval == 0)
|
if(conf.monitor_interval == 0)
|
||||||
conf.monitor_interval = 100;
|
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)
|
if(conf.write_interval == 0)
|
||||||
conf.write_interval = 300;
|
conf.write_interval = 300;
|
||||||
if(conf.flow_interval == 0)
|
if(conf.flow_interval == 0)
|
||||||
@@ -1436,7 +1441,7 @@ int get_netcard_status(NETCARD_INFO_ST *listp)
|
|||||||
return NIC_UNLINKABLE;
|
return NIC_UNLINKABLE;
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
if(listp->status == NIC_UNLINKABLE)
|
if(listp->status == NIC_UNLINKABLE)
|
||||||
return NIC_UNLINKABLE;
|
return NIC_UNLINKABLE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1505,7 +1510,7 @@ int main(int argc, char ** argv)
|
|||||||
int ret = 0, proc_stat = 0;
|
int ret = 0, proc_stat = 0;
|
||||||
unsigned int i = 0;
|
unsigned int i = 0;
|
||||||
int nic_status;
|
int nic_status;
|
||||||
int sys_time_stamp = 0;
|
int sys_time_stamp = 0;
|
||||||
char *retp = NULL;
|
char *retp = NULL;
|
||||||
char *str = NULL;
|
char *str = NULL;
|
||||||
char bond[128];
|
char bond[128];
|
||||||
@@ -1534,16 +1539,11 @@ int main(int argc, char ** argv)
|
|||||||
char log_record[125]={0};
|
char log_record[125]={0};
|
||||||
char *dir_memory;
|
char *dir_memory;
|
||||||
int shm_key =0x1d6010;
|
int shm_key =0x1d6010;
|
||||||
|
|
||||||
if( getenv("SYS_NIC_DEBUG") ) {
|
if( getenv("SYS_NIC_DEBUG") ) {
|
||||||
sys_nic_debug = 1;
|
sys_nic_debug = 1;
|
||||||
}
|
|
||||||
|
|
||||||
memset(&conf, 0, sizeof(CONFIG_FILE_ST));
|
|
||||||
if(isrun(argv[0]) == 1){
|
|
||||||
printf("the program is already started!\n");
|
|
||||||
exit(0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//process register
|
//process register
|
||||||
#ifndef TESTINTERVAL
|
#ifndef TESTINTERVAL
|
||||||
if((proc_stat=prcm.proc_init("sys","base_srv","sys_nicmonitor"))==-1){
|
if((proc_stat=prcm.proc_init("sys","base_srv","sys_nicmonitor"))==-1){
|
||||||
@@ -1552,14 +1552,20 @@ int main(int argc, char ** argv)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
memset(&conf, 0, sizeof(CONFIG_FILE_ST));
|
||||||
|
if(isrun(argv[0]) == 1){
|
||||||
|
printf("the program is already started!\n");
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
sig.sa_handler = sig_handler;
|
sig.sa_handler = sig_handler;
|
||||||
sigemptyset(&sig.sa_mask);
|
sigemptyset(&sig.sa_mask);
|
||||||
sigaddset(&sig.sa_mask, SIGINT);
|
sigaddset(&sig.sa_mask, SIGINT);
|
||||||
sigaddset(&sig.sa_mask, SIGTERM);
|
sigaddset(&sig.sa_mask, SIGTERM);
|
||||||
sig.sa_flags = 0;
|
sig.sa_flags = 0;
|
||||||
sigaction(SIGTERM, &sig, NULL);
|
sigaction(SIGTERM, &sig, NULL);
|
||||||
sigaction(SIGINT, &sig, NULL);
|
sigaction(SIGINT, &sig, NULL);
|
||||||
sigaction(SIGSEGV, &sig, NULL);
|
sigaction(SIGSEGV, &sig, NULL);
|
||||||
|
|
||||||
/* create dir file path */
|
/* create dir file path */
|
||||||
if((user = getpwnam("d5000")) != NULL){
|
if((user = getpwnam("d5000")) != NULL){
|
||||||
@@ -1615,11 +1621,16 @@ int main(int argc, char ** argv)
|
|||||||
log_time.tv_nsec = 1000000;
|
log_time.tv_nsec = 1000000;
|
||||||
while(log_flag)nanosleep(&log_time, NULL);
|
while(log_flag)nanosleep(&log_time, NULL);
|
||||||
|
|
||||||
/* sure the process is started */
|
if(get_conf()==-2){
|
||||||
snprintf(error_str, sizeof(error_str), "NOTICE: %s V%s is started !\n", process_name, MNIC_VERSION);
|
printf("Error monitor_interval must less than 1000\n");
|
||||||
record_log(error_str);
|
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){
|
if(shm_path){
|
||||||
printf("shm_path:%s\n",shm_path);
|
printf("shm_path:%s\n",shm_path);
|
||||||
@@ -1648,7 +1659,7 @@ int main(int argc, char ** argv)
|
|||||||
|
|
||||||
/* get broadcast address*/
|
/* get broadcast address*/
|
||||||
if((ret = get_broad_ip()) != 0)
|
if((ret = get_broad_ip()) != 0)
|
||||||
return -1;
|
return -1;
|
||||||
if((ret = create_name_list(&all_name_list, &opt_name_list)) != 0)
|
if((ret = create_name_list(&all_name_list, &opt_name_list)) != 0)
|
||||||
return -1;
|
return -1;
|
||||||
/* get hostname */
|
/* get hostname */
|
||||||
@@ -1787,7 +1798,7 @@ int main(int argc, char ** argv)
|
|||||||
munmap(shm_ptr, sizeof(SHM));
|
munmap(shm_ptr, sizeof(SHM));
|
||||||
#else
|
#else
|
||||||
{
|
{
|
||||||
|
|
||||||
void *shmptr = shm_ptr;
|
void *shmptr = shm_ptr;
|
||||||
#if 0
|
#if 0
|
||||||
snprintf(error_str, sizeof(error_str), "NOTICE: free shm %p, glo:%p\n", shmptr, global_shmptr);
|
snprintf(error_str, sizeof(error_str), "NOTICE: free shm %p, glo:%p\n", shmptr, global_shmptr);
|
||||||
@@ -1803,7 +1814,7 @@ int main(int argc, char ** argv)
|
|||||||
|
|
||||||
is_last = *ref_count == 1?1:0;
|
is_last = *ref_count == 1?1:0;
|
||||||
#if 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);
|
size, *ref_count, is_last);
|
||||||
record_log(error_str);
|
record_log(error_str);
|
||||||
#endif
|
#endif
|
||||||
@@ -1819,7 +1830,7 @@ int main(int argc, char ** argv)
|
|||||||
// global_share_id = -1;
|
// global_share_id = -1;
|
||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -33,6 +33,7 @@ SHM *ptr = NULL;
|
|||||||
static char process_name[32] = "get_nic_info";
|
static char process_name[32] = "get_nic_info";
|
||||||
|
|
||||||
static void linx_free_shm( void *addr, int size );
|
static void linx_free_shm( void *addr, int size );
|
||||||
|
static int nic_init_flag = 0;
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
static pthread_mutex_t lock_record_log = PTHREAD_MUTEX_INITIALIZER;
|
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 init_nic_info(void)
|
||||||
{
|
{
|
||||||
int fd = -1;
|
|
||||||
int sem_val;
|
|
||||||
char err_str[200];
|
char err_str[200];
|
||||||
key_t key;
|
key_t key;
|
||||||
|
|
||||||
@@ -234,10 +233,6 @@ int init_nic_info(void)
|
|||||||
void* shmptr = NULL;
|
void* shmptr = NULL;
|
||||||
int size = 0;
|
int size = 0;
|
||||||
key_t share_key;
|
key_t share_key;
|
||||||
int share_id = 0;
|
|
||||||
char *ref_count = NULL;
|
|
||||||
char *flag_str = NULL;
|
|
||||||
char *path = shm_path;
|
|
||||||
|
|
||||||
size = sizeof(SHM);
|
size = sizeof(SHM);
|
||||||
size = size + 16;
|
size = size + 16;
|
||||||
@@ -294,7 +289,6 @@ int get_nic_info(char *nic_name, NETCARD_INFO *net_info)
|
|||||||
char *s;
|
char *s;
|
||||||
char buf[128];
|
char buf[128];
|
||||||
char err_str[200];
|
char err_str[200];
|
||||||
struct passwd *user;
|
|
||||||
int shm_id;
|
int shm_id;
|
||||||
int shm_key = 0x1d6010;
|
int shm_key = 0x1d6010;
|
||||||
char *shm_buf;
|
char *shm_buf;
|
||||||
@@ -339,10 +333,18 @@ int get_nic_info(char *nic_name, NETCARD_INFO *net_info)
|
|||||||
strcat(log_path, buf);
|
strcat(log_path, buf);
|
||||||
LOGPATH_UNLOCK;
|
LOGPATH_UNLOCK;
|
||||||
|
|
||||||
if((ret = init_nic_info()) == -1){
|
if (nic_init_flag != 1){
|
||||||
return -1;
|
ret = init_nic_info();
|
||||||
|
if (ret != 0){
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
nic_init_flag = 1;
|
||||||
}
|
}
|
||||||
get_sem(semid);
|
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++){
|
for(i = 0; ptr->info[i].charname[0] != 0; i++){
|
||||||
if(!strcmp(ptr->info[i].charname, nic_name)){
|
if(!strcmp(ptr->info[i].charname, nic_name)){
|
||||||
// get_sem(semid);
|
// 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 )
|
static void linx_free_shm( void *addr, int size )
|
||||||
{
|
{
|
||||||
|
return ;
|
||||||
|
|
||||||
void *shmptr = addr;
|
void *shmptr = addr;
|
||||||
char err_str[200];
|
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
snprintf(err_str, sizeof(err_str), "NOTICE: free shm 0x%x, size:%d, glo:0x%x\n", addr, size, global_shmptr);
|
snprintf(err_str, sizeof(err_str), "NOTICE: free shm 0x%x, size:%d, glo:0x%x\n", addr, size, global_shmptr);
|
||||||
5
code/sys_nicmonitor/version.h
Normal file
5
code/sys_nicmonitor/version.h
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
// version=1.22
|
||||||
|
#ifndef MNIC_VERSION
|
||||||
|
#define MNIC_VERSION "1.22"
|
||||||
|
#endif
|
||||||
|
|
||||||
@@ -1,32 +0,0 @@
|
|||||||
|
|
||||||
lijin:/home/d5000/lijin/sys_nicmonitor # ./sys_nicmonitor
|
|
||||||
shm_path:/home/d5000/tmp/sys_netcard_shm_path
|
|
||||||
log_path:/home/d5000/var/log/netcard/20110110_sys_nicmonitor.log
|
|
||||||
udp bond0
|
|
||||||
nic bond0
|
|
||||||
nic eth0
|
|
||||||
nic eth1
|
|
||||||
|
|
||||||
d5000@lijin:~ > cat var/log/netcard/20110110_sys_nicmonitor.log
|
|
||||||
2011-01-10 11:10:37.761 sys_nicmonitor NOTICE: sys_nicmonitor V1.5 is
|
|
||||||
started !
|
|
||||||
2011-01-10 11:10:37.761 sys_nicmonitor
|
|
||||||
shm_path:/home/d5000/tmp/sys_netcard_shm_path
|
|
||||||
2011-01-10 11:10:37.761 sys_nicmonitor
|
|
||||||
log_path:/home/d5000/var/log/netcard/20110110_sys_nicmonitor.log
|
|
||||||
2011-01-10 11:10:37.761 sys_nicmonitor udp bond0
|
|
||||||
2011-01-10 11:10:37.761 sys_nicmonitor nic bond0
|
|
||||||
2011-01-10 11:10:37.761 sys_nicmonitor nic eth0
|
|
||||||
2011-01-10 11:10:37.762 sys_nicmonitor nic eth1
|
|
||||||
2011-01-10 11:10:37.762 sys_nicmonitor NOTICE: bond0 is NORMAL!
|
|
||||||
2011-01-10 11:10:37.763 sys_nicmonitor NOTICE: eth0 is NORMAL!
|
|
||||||
2011-01-10 11:10:37.763 sys_nicmonitor NOTICE: eth1 is NORMAL!
|
|
||||||
|
|
||||||
与1.4不一样的地方在与增加log文件中的打印语句
|
|
||||||
sys_nicmonitor started! version v1.4
|
|
||||||
shm_path: /home/d5000/tmp
|
|
||||||
log_path: /home/d5000/ var/log/netcard
|
|
||||||
udp bond0
|
|
||||||
nic bond0
|
|
||||||
nic eth0
|
|
||||||
nic eth1
|
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
V1.5与V1.6差异
|
|
||||||
将ping_gw中的system调用改为popen减少系统误报
|
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
V1.6与V1.7差异
|
|
||||||
共享内存路径修改:
|
|
||||||
由/home/d5000/someone/tmp/sys_netcard_shm_path 改为 /home/d5000/someone/share/sys_netcard_shm_path
|
|
||||||
信号量路径修改:
|
|
||||||
由/home/d5000/someone/tmp/sys_netcard_sem_path 改为 /home/d5000/someone/share/sys_netcard_sem_path
|
|
||||||
|
|
||||||
注意:在编译过程中,需要动态看libman.so,它存放在目录 tags/下面 ,在进行编译的时候需要将其拷贝到
|
|
||||||
/lib64/目录下,编译的基础环境是 Rocky 4.2 系统。
|
|
||||||
|
|
||||||
pkgmk命令的使用:
|
|
||||||
将源代码打包成name-version.tar.gz样式,编写Pkgfile文件。
|
|
||||||
使用命令:
|
|
||||||
pkgmk -um #更新软件包的md5值
|
|
||||||
pkgmk -kw #制作pkg安装包
|
|
||||||
|
|
||||||
@@ -1,28 +0,0 @@
|
|||||||
#! /usr/bin/make -f
|
|
||||||
|
|
||||||
DEFAULTS = Makefile.config
|
|
||||||
|
|
||||||
include $(DEFAULTS)
|
|
||||||
|
|
||||||
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 $@ $^
|
|
||||||
libnic_shm.so:nicinfo_shm.c
|
|
||||||
$(CC) -fpic -shared -o $@ $^
|
|
||||||
clean:
|
|
||||||
$(RM) *.o
|
|
||||||
$(RM) libnic_shm.so sys_nicmonitor
|
|
||||||
install:
|
|
||||||
$(MKDIR) -p $(LIBDIR)
|
|
||||||
$(MKDIR) -p $(BINDIR)
|
|
||||||
$(MKDIR) -p $(INCDIR)
|
|
||||||
$(CP) libnic_shm.so $(LIBDIR)
|
|
||||||
$(CP) sys_nicmonitor $(BINDIR)
|
|
||||||
$(CP) nicinfo_shm.h $(INCDIR)
|
|
||||||
uninstall:
|
|
||||||
$(RM) -f $(LIBDIR)/libnic_shm.so
|
|
||||||
$(RM) -f $(BINDIR)/sys_nicmonitor
|
|
||||||
$(RM) -f $(INCDIR)/nicinfo_shm.h
|
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
|
|
||||||
PREFIX = $(DESTDIR)
|
|
||||||
|
|
||||||
BINDIR = $(PREFIX)/usr/bin
|
|
||||||
|
|
||||||
LIBDIR = $(PREFIX)/usr/lib64
|
|
||||||
|
|
||||||
INCDIR = $(PREFIX)/usr/include
|
|
||||||
|
|
||||||
INSTALL_SH = ./install.sh
|
|
||||||
|
|
||||||
CP = cp
|
|
||||||
RM = rm
|
|
||||||
#CC = gcc
|
|
||||||
CC = g++
|
|
||||||
MKDIR = mkdir
|
|
||||||
@@ -1,51 +0,0 @@
|
|||||||
#ifndef _RTE_CONST_H
|
|
||||||
#define _RTE_CONST_H
|
|
||||||
|
|
||||||
#include <pthread.h>
|
|
||||||
|
|
||||||
|
|
||||||
#define MAX_STRING_LEN 24
|
|
||||||
#define MAX_EXECMD_LEN 200
|
|
||||||
#define MAX_FILENAME_LEN 200
|
|
||||||
|
|
||||||
#define MAX_CONTEXT 8
|
|
||||||
#define MAX_HOSTNAME_LEN 24
|
|
||||||
#define MAX_LOCAL_MESPROC 512
|
|
||||||
#define MAX_LOCAL_PROCESS MAX_LOCAL_MESPROC
|
|
||||||
#define MAX_LOCAL_APP 32
|
|
||||||
#define MAX_LOCAL_NODE 256
|
|
||||||
|
|
||||||
#define MAX_SET 256 //max num of event set
|
|
||||||
#define MAX_EVENT 1300
|
|
||||||
#define MAX_REG_PROC 20
|
|
||||||
|
|
||||||
#define LEN_SHMBLK_BIG 4096
|
|
||||||
#define MAX_MSGBUF_LEN 32767
|
|
||||||
#define FREE_PAGE_SIZE 65536
|
|
||||||
#define MAX_PAGE_NUM 1024
|
|
||||||
|
|
||||||
#define MAX_QUE MAX_LOCAL_MESPROC
|
|
||||||
#define MAX_SEMPHORE_SET MAX_LOCAL_MESPROC*2
|
|
||||||
#define RTE_HAN 0 // queue number for event handeler0(RTE)
|
|
||||||
#define EX_EVENT_HAN RTE_HAN // queue number for extrnal event handeler
|
|
||||||
|
|
||||||
#define DOMAIN_I 1
|
|
||||||
#define DOMAIN_II 2
|
|
||||||
#define DOMAIN_III 3
|
|
||||||
|
|
||||||
//Add 20090225
|
|
||||||
const int PROC_TYPE_RPT =1;
|
|
||||||
const int PROC_TYPE_UNRPT =0;
|
|
||||||
//add end
|
|
||||||
|
|
||||||
|
|
||||||
//status for proc and app
|
|
||||||
const int NON_ACTIVE = 0;
|
|
||||||
const int ACTIVE = 1;
|
|
||||||
const int HANGUP = 2;
|
|
||||||
const int FAILURE = 5;
|
|
||||||
const int START = 6;
|
|
||||||
const int STOP = 7;
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -1,44 +0,0 @@
|
|||||||
#ifndef __MNIC_H
|
|
||||||
#define __MNIC_H
|
|
||||||
|
|
||||||
//#define _GNU_SOURCE
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <stddef.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <ctype.h>
|
|
||||||
#include <errno.h>
|
|
||||||
#include <netinet/in.h>
|
|
||||||
#include <net/if.h>
|
|
||||||
#include <time.h>
|
|
||||||
#include <sys/ioctl.h>
|
|
||||||
#include <sys/socket.h>
|
|
||||||
#include <sys/sem.h>
|
|
||||||
#include <sys/ipc.h>
|
|
||||||
#include <sys/param.h>
|
|
||||||
#include <linux/types.h>
|
|
||||||
#include <glob.h>
|
|
||||||
#include <linux/sockios.h>
|
|
||||||
#include <arpa/inet.h>
|
|
||||||
#include <pthread.h>
|
|
||||||
#include <sys/mman.h>
|
|
||||||
#include <sys/stat.h>
|
|
||||||
#include <fcntl.h>
|
|
||||||
#include <signal.h>
|
|
||||||
#include <sys/time.h>
|
|
||||||
|
|
||||||
#include "sys_netcard.h"
|
|
||||||
#include <pwd.h>
|
|
||||||
#include <sys/types.h>
|
|
||||||
#define IPSIZE 16
|
|
||||||
|
|
||||||
char *get_name(char *, char *);
|
|
||||||
int if_fetch(NETCARD_INFO *);
|
|
||||||
int ioc_get_name(NETCARD_INFO *);
|
|
||||||
int get_dev_fields(char *p, NETCARD_INFO *);
|
|
||||||
int get_user_home(int , char *);
|
|
||||||
void send_alarm(D5000_NIC_ALARM *, int , char *);
|
|
||||||
void record_log(char *);
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,188 +0,0 @@
|
|||||||
#include <stdio.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <sys/mman.h>
|
|
||||||
#include <sys/types.h>
|
|
||||||
#include <sys/ipc.h>
|
|
||||||
#include <sys/sem.h>
|
|
||||||
#include <fcntl.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <errno.h>
|
|
||||||
#include <sys/time.h>
|
|
||||||
#include <time.h>
|
|
||||||
#include <dirent.h>
|
|
||||||
|
|
||||||
#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/"
|
|
||||||
|
|
||||||
typedef struct net_info{
|
|
||||||
NETCARD_INFO info[MAXNICNUM];
|
|
||||||
}SHM;
|
|
||||||
|
|
||||||
static int semid = 0;
|
|
||||||
static char log_path[1024];
|
|
||||||
SHM *ptr = NULL;
|
|
||||||
|
|
||||||
/* write error in logfile */
|
|
||||||
void record_log(char *str)
|
|
||||||
{
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void get_sem(int semid)
|
|
||||||
{
|
|
||||||
char err_str[200];
|
|
||||||
struct sembuf lock;
|
|
||||||
|
|
||||||
lock.sem_num = 0;
|
|
||||||
lock.sem_op = -1;
|
|
||||||
lock.sem_flg = SEM_UNDO;
|
|
||||||
|
|
||||||
while(semop(semid, &lock, 1)){
|
|
||||||
if (errno == EINTR) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
snprintf(err_str, sizeof(err_str), "EMERG: semop():\n", strerror(errno));
|
|
||||||
record_log(err_str);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void release_sem(int semid)
|
|
||||||
{
|
|
||||||
int ret;
|
|
||||||
char err_str[200];
|
|
||||||
struct sembuf unlock;
|
|
||||||
|
|
||||||
unlock.sem_num = 0;
|
|
||||||
unlock.sem_op = 1;
|
|
||||||
unlock.sem_flg = SEM_UNDO;
|
|
||||||
|
|
||||||
if((ret = semop(semid, &unlock, 1)) == -1){
|
|
||||||
snprintf(err_str, sizeof(err_str), "EMERG: semop():\n", strerror(errno));
|
|
||||||
record_log(err_str);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int init_nic_info(void)
|
|
||||||
{
|
|
||||||
int fd = -1;
|
|
||||||
int sem_val;
|
|
||||||
char err_str[200];
|
|
||||||
key_t key;
|
|
||||||
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
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);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
if((sem_val = semctl(semid, 0, GETVAL, 0)) == -1){
|
|
||||||
snprintf(err_str, sizeof(err_str), "EMERG: semctl: %s !\n", strerror(errno));
|
|
||||||
record_log(err_str);
|
|
||||||
semctl(semid, 0, IPC_RMID);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
if(!sem_val){
|
|
||||||
if(semctl(semid, 0, SETVAL, 1) == -1){
|
|
||||||
snprintf(err_str, sizeof(err_str), "EMERG: semctl: %s !\n", strerror(errno));
|
|
||||||
record_log(err_str);
|
|
||||||
semctl(semid, 0, IPC_RMID);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
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);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
ptr = (SHM*)mmap(NULL, sizeof(SHM), PROT_READ, MAP_SHARED, fd, 0);
|
|
||||||
if(ptr == MAP_FAILED){
|
|
||||||
snprintf(err_str, sizeof(err_str), "EMERG: mmap():%s\n", strerror(errno));
|
|
||||||
record_log(err_str);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
close(fd);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
int get_nic_info(char *nic_name, NETCARD_INFO *net_info)
|
|
||||||
{
|
|
||||||
int i,ret;
|
|
||||||
time_t tamp;
|
|
||||||
struct tm tmptr;
|
|
||||||
DIR *dir;
|
|
||||||
char *s;
|
|
||||||
char buf[128];
|
|
||||||
char err_str[200];
|
|
||||||
|
|
||||||
tamp = time(NULL);
|
|
||||||
localtime_r(&tamp, &tmptr);
|
|
||||||
strcpy(log_path, LOG_PATH);
|
|
||||||
if((dir = opendir(log_path)) == NULL){
|
|
||||||
if(errno == ENOENT){
|
|
||||||
strcpy(log_path, "/tmp/");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
closedir(dir);
|
|
||||||
s = strrchr(log_path, '/');
|
|
||||||
s++;
|
|
||||||
*s = '\0';
|
|
||||||
memset(buf, 0, sizeof(buf));
|
|
||||||
strftime(buf, sizeof(buf), "%Y%m%d_", &tmptr);
|
|
||||||
strcat(buf, "sys_nicmonitor");
|
|
||||||
strcat(buf, ".log");
|
|
||||||
strcat(log_path, buf);
|
|
||||||
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);
|
|
||||||
memcpy(net_info, &ptr->info[i], sizeof(NETCARD_INFO));
|
|
||||||
release_sem(semid);
|
|
||||||
munmap(ptr, sizeof(SHM));
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
snprintf(err_str, sizeof(err_str), "NOTICE: No information of %s !\n", nic_name);
|
|
||||||
record_log(err_str);
|
|
||||||
munmap(ptr, sizeof(SHM));
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
@@ -1,52 +0,0 @@
|
|||||||
#ifndef NIC_SHM_H
|
|
||||||
#define NIC_SHM_H
|
|
||||||
|
|
||||||
#include <sys/socket.h>
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef NIC_NAME_LEN
|
|
||||||
#define NIC_NAME_LEN 64
|
|
||||||
#endif
|
|
||||||
#define SEM_PROJ_ID 's'
|
|
||||||
#define MAXNICNUM 32
|
|
||||||
|
|
||||||
typedef long KEYID;
|
|
||||||
typedef struct _net_info
|
|
||||||
{
|
|
||||||
KEYID ID;
|
|
||||||
char charname[NIC_NAME_LEN];
|
|
||||||
char descr[128];
|
|
||||||
struct sockaddr addr;
|
|
||||||
struct sockaddr broadaddr;
|
|
||||||
struct sockaddr netmask;
|
|
||||||
struct sockaddr hwaddr;
|
|
||||||
int time_stamp;
|
|
||||||
short flags;
|
|
||||||
int mtu;
|
|
||||||
int tx_queue_len;
|
|
||||||
unsigned long long average_flow;
|
|
||||||
unsigned long long rx_packets;
|
|
||||||
unsigned long long tx_packets;
|
|
||||||
unsigned long long rx_bytes;
|
|
||||||
unsigned long long tx_bytes;
|
|
||||||
unsigned long rx_errors;
|
|
||||||
unsigned long tx_errors;
|
|
||||||
unsigned long rx_dropped;
|
|
||||||
unsigned long tx_dropped;
|
|
||||||
unsigned long rx_multicast;
|
|
||||||
unsigned long collisions;
|
|
||||||
unsigned long rx_fifo_errors;
|
|
||||||
unsigned long tx_carrier_errors;
|
|
||||||
unsigned long tx_fifo_errors;
|
|
||||||
}NETCARD_INFO;
|
|
||||||
|
|
||||||
int get_nic_info(char *nic_name, NETCARD_INFO *net_info);
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
@@ -1,198 +0,0 @@
|
|||||||
////////////////////////////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
// Copyright (c) Comets' Grp. of Kedong Corp 2008. All Rights Reserved.
|
|
||||||
//
|
|
||||||
// FileName : procconf.h
|
|
||||||
//
|
|
||||||
// Function : this class realize some basic functions for process managerment,
|
|
||||||
// such as initiate process, report status of process, check status of process,
|
|
||||||
// update status of process, get information of process
|
|
||||||
//
|
|
||||||
// Author :
|
|
||||||
//
|
|
||||||
// Date :
|
|
||||||
//
|
|
||||||
// Modify by :
|
|
||||||
//
|
|
||||||
// Mod Date :
|
|
||||||
//
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
#ifndef _PROCCONF_H
|
|
||||||
#define _PROCCONF_H
|
|
||||||
|
|
||||||
#include <sys/types.h>
|
|
||||||
#include <sys/stat.h>
|
|
||||||
#include <fcntl.h>
|
|
||||||
#include <sys/mman.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <errno.h>
|
|
||||||
//#include <iostream.h>
|
|
||||||
#include <signal.h>
|
|
||||||
|
|
||||||
#include "const.h"
|
|
||||||
|
|
||||||
//for alarm ................................
|
|
||||||
typedef struct MESS_BH
|
|
||||||
{
|
|
||||||
unsigned char mtype;
|
|
||||||
int length;
|
|
||||||
};
|
|
||||||
typedef struct PROCESS_ALM
|
|
||||||
{
|
|
||||||
char context_name[MAX_STRING_LEN];
|
|
||||||
char app_name[MAX_STRING_LEN];
|
|
||||||
char proc_name[MAX_STRING_LEN];
|
|
||||||
unsigned char status;
|
|
||||||
};
|
|
||||||
//for alarm end .............................
|
|
||||||
|
|
||||||
//for mmi....................................
|
|
||||||
const int MAX_BUFFER_LEN = 500;
|
|
||||||
typedef struct MESS_BLOCK
|
|
||||||
{
|
|
||||||
unsigned char num;
|
|
||||||
char buffer[MAX_BUFFER_LEN];
|
|
||||||
};
|
|
||||||
typedef struct MESS_PROC
|
|
||||||
{
|
|
||||||
char context_name[MAX_STRING_LEN];
|
|
||||||
char app_name[MAX_STRING_LEN];
|
|
||||||
char proc_name[MAX_STRING_LEN];
|
|
||||||
char status;
|
|
||||||
};
|
|
||||||
//for mmi end ................................
|
|
||||||
|
|
||||||
const int DEFAULT_PERIOD = 3;
|
|
||||||
const int COUNT_LIMIT = 2;
|
|
||||||
const int START_DEFAULT_PERIOD = 60;
|
|
||||||
const int START_COUNT_LIMIT = 5;
|
|
||||||
const int APP_COUNT_LIMIT = 1;
|
|
||||||
|
|
||||||
//process critical level
|
|
||||||
//const int WST_CRITICAL = 1; // Shutdown and reboot workstation when failed
|
|
||||||
//const int SYS_CRITICAL = 2; // Shutdown and reboot the system on the wst when failed
|
|
||||||
//const int USER_CRITICAL = 3; // Shutdown and reboot the subsystem when failed
|
|
||||||
//const int GENERAL = 4; // reboot the process
|
|
||||||
const int CRUCIAL = 1; // crucial process
|
|
||||||
const int GENERAL = 0; // general process
|
|
||||||
|
|
||||||
|
|
||||||
extern int srv_init(char *service,int port);
|
|
||||||
extern int Tcp_close(int sockfd);
|
|
||||||
extern int Tcp_read(int fd,char *ptr,int nbytes);
|
|
||||||
extern int Tcp_write(int fd,char *ptr,int nbytes);
|
|
||||||
extern int srv_accept(int fd,struct sockaddr *cli_addr,int *clilen);
|
|
||||||
extern int client_tcp_open(char *host,char *service,int port);
|
|
||||||
|
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
char context_name[MAX_STRING_LEN];
|
|
||||||
char app_name[MAX_STRING_LEN];
|
|
||||||
char proc_name[MAX_STRING_LEN];
|
|
||||||
pid_t proc_pid;
|
|
||||||
}PROC_ADM_INFO;
|
|
||||||
|
|
||||||
//***************************************************************
|
|
||||||
// structure name : PROC_INFO
|
|
||||||
// function : store process informatin
|
|
||||||
// author :
|
|
||||||
// date :
|
|
||||||
// modify by :
|
|
||||||
// modification :
|
|
||||||
// mod date :
|
|
||||||
//***************************************************************
|
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
int position;
|
|
||||||
char node_name[MAX_STRING_LEN];
|
|
||||||
char context_name[MAX_STRING_LEN];
|
|
||||||
char app_name[MAX_STRING_LEN];
|
|
||||||
char proc_name[MAX_STRING_LEN];
|
|
||||||
|
|
||||||
unsigned char active_flag;
|
|
||||||
unsigned char master_flag;
|
|
||||||
|
|
||||||
time_t startup_time;
|
|
||||||
time_t refresh_time;
|
|
||||||
short refresh_peri;
|
|
||||||
unsigned char monitor_type;
|
|
||||||
|
|
||||||
pid_t proc_pid;
|
|
||||||
unsigned char auto_start;
|
|
||||||
unsigned char act_timer;
|
|
||||||
unsigned char start_timer;
|
|
||||||
unsigned char critical_level;
|
|
||||||
|
|
||||||
char exefile_path[MAX_EXECMD_LEN];
|
|
||||||
|
|
||||||
}PROC_INFO;
|
|
||||||
|
|
||||||
//***************************************************************
|
|
||||||
// structure name : APP_INFO
|
|
||||||
// function : store application informatin
|
|
||||||
// author :
|
|
||||||
// date :
|
|
||||||
// modify by :
|
|
||||||
// modification :
|
|
||||||
// mod date :
|
|
||||||
//***************************************************************
|
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
int position;
|
|
||||||
char context_name[MAX_STRING_LEN];
|
|
||||||
int context_id;
|
|
||||||
char app_name[MAX_STRING_LEN];
|
|
||||||
int app_id;
|
|
||||||
unsigned char act_timer;
|
|
||||||
unsigned char active_flag;
|
|
||||||
}APP_INFO;
|
|
||||||
|
|
||||||
|
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
int no_proc;
|
|
||||||
int semdes_cfg;
|
|
||||||
PROC_INFO proc[MAX_LOCAL_PROCESS];
|
|
||||||
APP_INFO app[MAX_LOCAL_APP];
|
|
||||||
}PROCCFG;
|
|
||||||
|
|
||||||
class proc_invocation
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
int m_init;
|
|
||||||
PROCCFG *proccfg_p;
|
|
||||||
|
|
||||||
public:
|
|
||||||
proc_invocation();
|
|
||||||
~proc_invocation();
|
|
||||||
|
|
||||||
int conf_create();
|
|
||||||
//int check_proc_status();
|
|
||||||
//int update_rtdb();
|
|
||||||
//int kill_proc(pid_t pid);
|
|
||||||
//int start_proc(char *cmdline);
|
|
||||||
//int send_alarm(char *context_name, char *app_name, char *proc_name, unsigned char status);
|
|
||||||
//int update_proc_status(char *context_name, char *app_name, char *proc_name, char status);
|
|
||||||
|
|
||||||
//int proc_init(char *context_name, char *app_name, char *proc_name, int critical_level);//exefile_path,auto_start
|
|
||||||
int proc_init(char *context_name, char *app_name, char *proc_name);
|
|
||||||
int proc_report(int pos, char status, int intertime=3);
|
|
||||||
int proc_exit(int proc_pos);
|
|
||||||
|
|
||||||
int get_pos(char *context_name, char *app_name, char *proc_name);
|
|
||||||
int is_proc_exist(char *context_name, char *app_name, char *proc_name);
|
|
||||||
int conf_map();
|
|
||||||
|
|
||||||
int get_procinfo(int position, PROC_ADM_INFO *p_info);
|
|
||||||
int get_active_pid(int &num, int *p_pidlist);
|
|
||||||
int is_proc_run(pid_t pid);
|
|
||||||
int is_proc_run(char *context_name, char *app_name, char *proc_name);
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -1,133 +0,0 @@
|
|||||||
#include "mnic.h"
|
|
||||||
|
|
||||||
static char *prase_digit(char **s)
|
|
||||||
{
|
|
||||||
char *retp = NULL;
|
|
||||||
char *p = *s;
|
|
||||||
|
|
||||||
if(!p)return NULL;
|
|
||||||
while(!isdigit(*p)){
|
|
||||||
p++;
|
|
||||||
if(*p == '\0')return NULL;
|
|
||||||
}
|
|
||||||
retp = p;
|
|
||||||
while(isdigit(*p)){
|
|
||||||
p++;
|
|
||||||
if(*p == '\0'){
|
|
||||||
*s = NULL;
|
|
||||||
return retp;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*p = '\0';
|
|
||||||
p++;
|
|
||||||
*s = p;
|
|
||||||
return retp;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
char *get_name(char *name, char *p)
|
|
||||||
{
|
|
||||||
while (isspace(*p))
|
|
||||||
p++;
|
|
||||||
while (*p) {
|
|
||||||
if (isspace(*p))
|
|
||||||
break;
|
|
||||||
if (*p == ':') { /* could be an alias */
|
|
||||||
char *dot = p, *dotname = name;
|
|
||||||
*name++ = *p++;
|
|
||||||
while (isdigit(*p))
|
|
||||||
*name++ = *p++;
|
|
||||||
if (*p != ':') { /* it wasn't, backup */
|
|
||||||
p = dot;
|
|
||||||
name = dotname;
|
|
||||||
}
|
|
||||||
if (*p == '\0')
|
|
||||||
return NULL;
|
|
||||||
p++;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
*name++ = *p++;
|
|
||||||
}
|
|
||||||
*name++ = '\0';
|
|
||||||
return p;
|
|
||||||
}
|
|
||||||
|
|
||||||
int get_dev_fields(char *str, NETCARD_INFO *ife)
|
|
||||||
{
|
|
||||||
int i = 0;
|
|
||||||
char *retp[16];
|
|
||||||
|
|
||||||
while((retp[i] = prase_digit(&str)) != NULL){i++;if(i > 15)break;}
|
|
||||||
ife->rx_bytes = atoll(retp[0]);
|
|
||||||
ife->rx_packets = atoll(retp[1]);
|
|
||||||
ife->rx_errors = atol(retp[2]);
|
|
||||||
ife->rx_dropped = atol(retp[3]);
|
|
||||||
ife->rx_fifo_errors = atol(retp[4]);
|
|
||||||
ife->rx_multicast = atol(retp[7]);
|
|
||||||
ife->tx_bytes = atoll(retp[8]);
|
|
||||||
ife->tx_packets = atoll(retp[9]);
|
|
||||||
ife->tx_errors = atol(retp[10]);
|
|
||||||
ife->tx_dropped = atol(retp[11]);
|
|
||||||
ife->tx_fifo_errors = atol(retp[12]);
|
|
||||||
ife->collisions = atol(retp[13]);
|
|
||||||
ife->tx_carrier_errors = atol(retp[14]);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int if_fetch(NETCARD_INFO *ife)
|
|
||||||
{
|
|
||||||
int skfd;
|
|
||||||
struct ifreq ifr;
|
|
||||||
|
|
||||||
if((skfd = socket(PF_INET, SOCK_DGRAM, 0)) == -1)return -1;
|
|
||||||
|
|
||||||
strcpy(ifr.ifr_name, ife->charname);
|
|
||||||
if (!ioctl(skfd, SIOCGIFFLAGS, &ifr))
|
|
||||||
ife->flags = ifr.ifr_flags;
|
|
||||||
|
|
||||||
if (!ioctl(skfd, SIOCGIFHWADDR, &ifr))
|
|
||||||
ife->hwaddr = ifr.ifr_hwaddr;
|
|
||||||
|
|
||||||
if (!ioctl(skfd, SIOCGIFMTU, &ifr))
|
|
||||||
ife->mtu = ifr.ifr_mtu;
|
|
||||||
|
|
||||||
if (!ioctl(skfd, SIOCGIFTXQLEN, &ifr))
|
|
||||||
ife->tx_queue_len = ifr.ifr_qlen;
|
|
||||||
|
|
||||||
if (!ioctl(skfd, SIOCGIFADDR, &ifr))
|
|
||||||
ife->addr = ifr.ifr_addr;
|
|
||||||
|
|
||||||
if (!ioctl(skfd, SIOCGIFBRDADDR, &ifr))
|
|
||||||
ife->broadaddr = ifr.ifr_broadaddr;
|
|
||||||
|
|
||||||
if (!ioctl(skfd, SIOCGIFNETMASK, &ifr))
|
|
||||||
ife->netmask = ifr.ifr_netmask;
|
|
||||||
|
|
||||||
ife->time_stamp = time(NULL);
|
|
||||||
close(skfd);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int ioc_get_name(NETCARD_INFO *name)
|
|
||||||
{
|
|
||||||
int skfd;
|
|
||||||
int ifrnum;
|
|
||||||
int i = 0;
|
|
||||||
struct ifconf ifc;
|
|
||||||
struct ifreq buf[MAXNICNUM];
|
|
||||||
|
|
||||||
if((skfd = socket(PF_INET, SOCK_DGRAM, 0)) == -1)return -1;
|
|
||||||
memset(buf, 0, sizeof(buf));
|
|
||||||
ifc.ifc_len = sizeof(buf);
|
|
||||||
ifc.ifc_buf = (caddr_t) buf;
|
|
||||||
ioctl(skfd, SIOCGIFCONF, &ifc);
|
|
||||||
ifrnum = ifc.ifc_len / sizeof(struct ifreq);
|
|
||||||
while(ifrnum-- > 0){
|
|
||||||
strcpy(name[i].charname, buf[ifrnum].ifr_name);
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
close(skfd);
|
|
||||||
return i;
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -1,37 +0,0 @@
|
|||||||
#include "mnic.h"
|
|
||||||
|
|
||||||
void send_alarm(D5000_NIC_ALARM *mesg, int socket_port, char *ipv4)
|
|
||||||
{
|
|
||||||
int bytes;
|
|
||||||
int sock_sd;
|
|
||||||
int val;
|
|
||||||
char error_str[200];
|
|
||||||
struct sockaddr_in recever;
|
|
||||||
socklen_t sock_len;
|
|
||||||
|
|
||||||
if((sock_sd = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP)) == -1){
|
|
||||||
snprintf(error_str, sizeof(error_str), "EMERG: socket(): %s\n", strerror(errno));
|
|
||||||
record_log(error_str);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
val=1;
|
|
||||||
if ((setsockopt(sock_sd, SOL_SOCKET, SO_BROADCAST, &val, sizeof(val))) == -1) {
|
|
||||||
snprintf(error_str, sizeof(error_str), "EMERG: setsockopt(): %s\n", strerror(errno));
|
|
||||||
record_log(error_str);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
/* init socket*/
|
|
||||||
recever.sin_family = AF_INET;
|
|
||||||
recever.sin_port = htons(socket_port);
|
|
||||||
inet_pton(AF_INET, ipv4, &recever.sin_addr);
|
|
||||||
sock_len = sizeof(recever);
|
|
||||||
/* send alarm*/
|
|
||||||
if((bytes = sendto(sock_sd, mesg, sizeof(D5000_NIC_ALARM), 0, (const struct sockaddr *)&recever, sock_len)) < 1){
|
|
||||||
snprintf(error_str, sizeof(error_str), "EMERG: sendto(): %s\n", strerror(errno));
|
|
||||||
record_log(error_str);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
//snprintf(error_str, sizeof(error_str), "NOTICE: Alarm information has already send!\n");
|
|
||||||
//record_log(error_str);
|
|
||||||
close(sock_sd);
|
|
||||||
}
|
|
||||||
@@ -1,88 +0,0 @@
|
|||||||
#ifndef _SYS_NETCARD_H
|
|
||||||
#define _SYS_NETCARD_H
|
|
||||||
|
|
||||||
#include <sys/socket.h>
|
|
||||||
|
|
||||||
#ifndef NIC_NAME_LEN
|
|
||||||
#define NIC_NAME_LEN 64
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define SEM_PROJ_ID 's'
|
|
||||||
#define MAXNICNUM 32
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C"{
|
|
||||||
#endif
|
|
||||||
|
|
||||||
typedef long KEYID;
|
|
||||||
|
|
||||||
typedef struct _msg_frame // message frame
|
|
||||||
{
|
|
||||||
short len; // message length
|
|
||||||
short seqno; // send sequence
|
|
||||||
short serv; // services ID
|
|
||||||
short event; // event ID
|
|
||||||
unsigned char domain; // domain ID
|
|
||||||
unsigned char ctxt; // Context ID
|
|
||||||
short stid; // SOURCE task id
|
|
||||||
short dtid; // DESTINATION task ID
|
|
||||||
unsigned char ver_coding; // 版本号 + 编码
|
|
||||||
unsigned char mes_type; // 帧类型
|
|
||||||
}MSG_FRAME, *LPMSG_FRAME;
|
|
||||||
|
|
||||||
typedef struct _net_info
|
|
||||||
{
|
|
||||||
KEYID ID;
|
|
||||||
char charname[NIC_NAME_LEN];
|
|
||||||
char descr[128];
|
|
||||||
struct sockaddr addr;
|
|
||||||
struct sockaddr broadaddr;
|
|
||||||
struct sockaddr netmask;
|
|
||||||
struct sockaddr hwaddr;
|
|
||||||
int time_stamp;
|
|
||||||
short flags;
|
|
||||||
int mtu;
|
|
||||||
int tx_queue_len;
|
|
||||||
unsigned long long average_flow;
|
|
||||||
unsigned long long rx_packets;
|
|
||||||
unsigned long long tx_packets;
|
|
||||||
unsigned long long rx_bytes;
|
|
||||||
unsigned long long tx_bytes;
|
|
||||||
unsigned long rx_errors;
|
|
||||||
unsigned long tx_errors;
|
|
||||||
unsigned long rx_dropped;
|
|
||||||
unsigned long tx_dropped;
|
|
||||||
unsigned long rx_multicast;
|
|
||||||
unsigned long collisions;
|
|
||||||
unsigned long rx_fifo_errors;
|
|
||||||
unsigned long tx_carrier_errors;
|
|
||||||
unsigned long tx_fifo_errors;
|
|
||||||
}NETCARD_INFO, *LPNETCARD_INFO;
|
|
||||||
|
|
||||||
#define NETCARD_ALARM_FAULT 1
|
|
||||||
#define NETCARD_ALARM_RESUME 2
|
|
||||||
#define NETCARD_ALARM_SWITCH 3
|
|
||||||
#define NETCARD_ALARM_ABNORMAL 4
|
|
||||||
#define NETCARD_ALARM_NORMAL 5
|
|
||||||
typedef struct _sys_netcard_alarm
|
|
||||||
{
|
|
||||||
char fault_devname[NIC_NAME_LEN]; /*故障设备名称 */
|
|
||||||
char switch_devname[NIC_NAME_LEN]; /*切换设备名称 */
|
|
||||||
short flags; /* 状态标记 : 1:网卡故障。2:网卡恢复。3:网卡切换。4:流量异常。*/
|
|
||||||
short retrytimes; //0,1,2 重发次数
|
|
||||||
}SYS_NETCARD_ALARM, *LPSYS_NETCARD_ALARM;
|
|
||||||
|
|
||||||
|
|
||||||
typedef struct _d5000_nic_alarm
|
|
||||||
{
|
|
||||||
MSG_FRAME tMsgFrame ;
|
|
||||||
SYS_NETCARD_ALARM tSysNetcardAlarm ;
|
|
||||||
}D5000_NIC_ALARM, *LPD5000_NIC_ALARM;
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
@@ -1,28 +0,0 @@
|
|||||||
#! /usr/bin/make -f
|
|
||||||
|
|
||||||
DEFAULTS = Makefile.config
|
|
||||||
|
|
||||||
include $(DEFAULTS)
|
|
||||||
|
|
||||||
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 $@ $^
|
|
||||||
libnic_shm.so:nicinfo_shm.c
|
|
||||||
$(CC) -fpic -shared -o $@ $^
|
|
||||||
clean:
|
|
||||||
$(RM) *.o
|
|
||||||
$(RM) libnic_shm.so sys_nicmonitor
|
|
||||||
install:
|
|
||||||
$(MKDIR) -p $(LIBDIR)
|
|
||||||
$(MKDIR) -p $(BINDIR)
|
|
||||||
$(MKDIR) -p $(INCDIR)
|
|
||||||
$(CP) libnic_shm.so $(LIBDIR)
|
|
||||||
$(CP) sys_nicmonitor $(BINDIR)
|
|
||||||
$(CP) nicinfo_shm.h $(INCDIR)
|
|
||||||
uninstall:
|
|
||||||
$(RM) -f $(LIBDIR)/libnic_shm.so
|
|
||||||
$(RM) -f $(BINDIR)/sys_nicmonitor
|
|
||||||
$(RM) -f $(INCDIR)/nicinfo_shm.h
|
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
|
|
||||||
PREFIX = $(DESTDIR)
|
|
||||||
|
|
||||||
BINDIR = $(PREFIX)/usr/bin
|
|
||||||
|
|
||||||
LIBDIR = $(PREFIX)/usr/lib64
|
|
||||||
|
|
||||||
INCDIR = $(PREFIX)/usr/include
|
|
||||||
|
|
||||||
INSTALL_SH = ./install.sh
|
|
||||||
|
|
||||||
CP = cp
|
|
||||||
RM = rm
|
|
||||||
#CC = gcc
|
|
||||||
CC = g++
|
|
||||||
MKDIR = mkdir
|
|
||||||
@@ -1,51 +0,0 @@
|
|||||||
#ifndef _RTE_CONST_H
|
|
||||||
#define _RTE_CONST_H
|
|
||||||
|
|
||||||
#include <pthread.h>
|
|
||||||
|
|
||||||
|
|
||||||
#define MAX_STRING_LEN 24
|
|
||||||
#define MAX_EXECMD_LEN 200
|
|
||||||
#define MAX_FILENAME_LEN 200
|
|
||||||
|
|
||||||
#define MAX_CONTEXT 8
|
|
||||||
#define MAX_HOSTNAME_LEN 24
|
|
||||||
#define MAX_LOCAL_MESPROC 512
|
|
||||||
#define MAX_LOCAL_PROCESS MAX_LOCAL_MESPROC
|
|
||||||
#define MAX_LOCAL_APP 32
|
|
||||||
#define MAX_LOCAL_NODE 256
|
|
||||||
|
|
||||||
#define MAX_SET 256 //max num of event set
|
|
||||||
#define MAX_EVENT 1300
|
|
||||||
#define MAX_REG_PROC 20
|
|
||||||
|
|
||||||
#define LEN_SHMBLK_BIG 4096
|
|
||||||
#define MAX_MSGBUF_LEN 32767
|
|
||||||
#define FREE_PAGE_SIZE 65536
|
|
||||||
#define MAX_PAGE_NUM 1024
|
|
||||||
|
|
||||||
#define MAX_QUE MAX_LOCAL_MESPROC
|
|
||||||
#define MAX_SEMPHORE_SET MAX_LOCAL_MESPROC*2
|
|
||||||
#define RTE_HAN 0 // queue number for event handeler0(RTE)
|
|
||||||
#define EX_EVENT_HAN RTE_HAN // queue number for extrnal event handeler
|
|
||||||
|
|
||||||
#define DOMAIN_I 1
|
|
||||||
#define DOMAIN_II 2
|
|
||||||
#define DOMAIN_III 3
|
|
||||||
|
|
||||||
//Add 20090225
|
|
||||||
const int PROC_TYPE_RPT =1;
|
|
||||||
const int PROC_TYPE_UNRPT =0;
|
|
||||||
//add end
|
|
||||||
|
|
||||||
|
|
||||||
//status for proc and app
|
|
||||||
const int NON_ACTIVE = 0;
|
|
||||||
const int ACTIVE = 1;
|
|
||||||
const int HANGUP = 2;
|
|
||||||
const int FAILURE = 5;
|
|
||||||
const int START = 6;
|
|
||||||
const int STOP = 7;
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -1,44 +0,0 @@
|
|||||||
#ifndef __MNIC_H
|
|
||||||
#define __MNIC_H
|
|
||||||
|
|
||||||
//#define _GNU_SOURCE
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <stddef.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <ctype.h>
|
|
||||||
#include <errno.h>
|
|
||||||
#include <netinet/in.h>
|
|
||||||
#include <net/if.h>
|
|
||||||
#include <time.h>
|
|
||||||
#include <sys/ioctl.h>
|
|
||||||
#include <sys/socket.h>
|
|
||||||
#include <sys/sem.h>
|
|
||||||
#include <sys/ipc.h>
|
|
||||||
#include <sys/param.h>
|
|
||||||
#include <linux/types.h>
|
|
||||||
#include <glob.h>
|
|
||||||
#include <linux/sockios.h>
|
|
||||||
#include <arpa/inet.h>
|
|
||||||
#include <pthread.h>
|
|
||||||
#include <sys/mman.h>
|
|
||||||
#include <sys/stat.h>
|
|
||||||
#include <fcntl.h>
|
|
||||||
#include <signal.h>
|
|
||||||
#include <sys/time.h>
|
|
||||||
|
|
||||||
#include "sys_netcard.h"
|
|
||||||
#include <pwd.h>
|
|
||||||
#include <sys/types.h>
|
|
||||||
#define IPSIZE 16
|
|
||||||
|
|
||||||
char *get_name(char *, char *);
|
|
||||||
int if_fetch(NETCARD_INFO *);
|
|
||||||
int ioc_get_name(NETCARD_INFO *);
|
|
||||||
int get_dev_fields(char *p, NETCARD_INFO *);
|
|
||||||
int get_user_home(int , char *);
|
|
||||||
void send_alarm(D5000_NIC_ALARM *, int , char *);
|
|
||||||
void record_log(char *);
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,209 +0,0 @@
|
|||||||
#include <stdio.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <sys/mman.h>
|
|
||||||
#include <sys/types.h>
|
|
||||||
#include <sys/ipc.h>
|
|
||||||
#include <sys/sem.h>
|
|
||||||
#include <fcntl.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <errno.h>
|
|
||||||
#include <sys/time.h>
|
|
||||||
#include <time.h>
|
|
||||||
#include <dirent.h>
|
|
||||||
#include <pwd.h>
|
|
||||||
|
|
||||||
#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/"
|
|
||||||
|
|
||||||
typedef struct net_info{
|
|
||||||
NETCARD_INFO info[MAXNICNUM];
|
|
||||||
}SHM;
|
|
||||||
|
|
||||||
static int semid = 0;
|
|
||||||
static char log_path[1024];
|
|
||||||
static char shm_path[1024];
|
|
||||||
static char sem_path[1024];
|
|
||||||
SHM *ptr = NULL;
|
|
||||||
|
|
||||||
/* write error in logfile */
|
|
||||||
void record_log(char *str)
|
|
||||||
{
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void get_sem(int semid)
|
|
||||||
{
|
|
||||||
char err_str[200];
|
|
||||||
struct sembuf lock[2];
|
|
||||||
|
|
||||||
lock[0].sem_num = 0;
|
|
||||||
lock[0].sem_op = 0;
|
|
||||||
lock[0].sem_flg = SEM_UNDO;
|
|
||||||
|
|
||||||
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(err_str, sizeof(err_str), "EMERG: semop():\n", strerror(errno));
|
|
||||||
record_log(err_str);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void release_sem(int semid)
|
|
||||||
{
|
|
||||||
int ret;
|
|
||||||
char err_str[200];
|
|
||||||
struct sembuf unlock;
|
|
||||||
|
|
||||||
unlock.sem_num = 0;
|
|
||||||
unlock.sem_op = -1;
|
|
||||||
unlock.sem_flg = SEM_UNDO;
|
|
||||||
|
|
||||||
if((ret = semop(semid, &unlock, 1)) == -1){
|
|
||||||
snprintf(err_str, sizeof(err_str), "EMERG: semop():\n", strerror(errno));
|
|
||||||
record_log(err_str);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int init_nic_info(void)
|
|
||||||
{
|
|
||||||
int fd = -1;
|
|
||||||
int sem_val;
|
|
||||||
char err_str[200];
|
|
||||||
key_t key;
|
|
||||||
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
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);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
/*
|
|
||||||
if((sem_val = semctl(semid, 0, GETVAL, 0)) == -1){
|
|
||||||
snprintf(err_str, sizeof(err_str), "EMERG: semctl: %s !\n", strerror(errno));
|
|
||||||
record_log(err_str);
|
|
||||||
semctl(semid, 0, IPC_RMID);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
if(!sem_val){
|
|
||||||
if(semctl(semid, 0, SETVAL, 1) == -1){
|
|
||||||
snprintf(err_str, sizeof(err_str), "EMERG: semctl: %s !\n", strerror(errno));
|
|
||||||
record_log(err_str);
|
|
||||||
semctl(semid, 0, IPC_RMID);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
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);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
ptr = (SHM*)mmap(NULL, sizeof(SHM), PROT_READ, MAP_SHARED, fd, 0);
|
|
||||||
if(ptr == MAP_FAILED){
|
|
||||||
snprintf(err_str, sizeof(err_str), "EMERG: mmap():%s\n", strerror(errno));
|
|
||||||
record_log(err_str);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
close(fd);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
int get_nic_info(char *nic_name, NETCARD_INFO *net_info)
|
|
||||||
{
|
|
||||||
int i,ret;
|
|
||||||
time_t tamp;
|
|
||||||
struct tm tmptr;
|
|
||||||
DIR *dir;
|
|
||||||
char *s;
|
|
||||||
char buf[128];
|
|
||||||
char err_str[200];
|
|
||||||
struct passwd *user;
|
|
||||||
|
|
||||||
tamp = time(NULL);
|
|
||||||
localtime_r(&tamp, &tmptr);
|
|
||||||
|
|
||||||
if((user = getpwnam("d5000"))!= NULL){
|
|
||||||
sprintf(log_path,"%s",user->pw_dir);
|
|
||||||
sprintf(shm_path,"%s",user->pw_dir);
|
|
||||||
sprintf(sem_path,"%s",user->pw_dir);
|
|
||||||
}
|
|
||||||
strcat(log_path,LOG_PATH);
|
|
||||||
strcat(shm_path,SHM_PATH);
|
|
||||||
strcat(sem_path,SEM_PATH);
|
|
||||||
|
|
||||||
if((dir = opendir(log_path)) == NULL){
|
|
||||||
if(errno == ENOENT){
|
|
||||||
strcpy(log_path, "/tmp/");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
closedir(dir);
|
|
||||||
s = strrchr(log_path, '/');
|
|
||||||
s++;
|
|
||||||
*s = '\0';
|
|
||||||
memset(buf, 0, sizeof(buf));
|
|
||||||
strftime(buf, sizeof(buf), "%Y%m%d_", &tmptr);
|
|
||||||
strcat(buf, "sys_nicmonitor");
|
|
||||||
strcat(buf, ".log");
|
|
||||||
strcat(log_path, buf);
|
|
||||||
if((ret = init_nic_info()) == -1){
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
get_sem(semid);
|
|
||||||
for(i = 0; ptr->info[i].charname[0] != 0; i++){
|
|
||||||
if(!strcmp(ptr->info[i].charname, nic_name)){
|
|
||||||
// get_sem(semid);
|
|
||||||
memcpy(net_info, &ptr->info[i], sizeof(NETCARD_INFO));
|
|
||||||
release_sem(semid);
|
|
||||||
munmap(ptr, sizeof(SHM));
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
release_sem(semid);
|
|
||||||
snprintf(err_str, sizeof(err_str), "NOTICE: No information of %s !\n", nic_name);
|
|
||||||
record_log(err_str);
|
|
||||||
munmap(ptr, sizeof(SHM));
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
@@ -1,52 +0,0 @@
|
|||||||
#ifndef NIC_SHM_H
|
|
||||||
#define NIC_SHM_H
|
|
||||||
|
|
||||||
#include <sys/socket.h>
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef NIC_NAME_LEN
|
|
||||||
#define NIC_NAME_LEN 64
|
|
||||||
#endif
|
|
||||||
#define SEM_PROJ_ID 's'
|
|
||||||
#define MAXNICNUM 32
|
|
||||||
|
|
||||||
typedef long KEYID;
|
|
||||||
typedef struct _net_info
|
|
||||||
{
|
|
||||||
KEYID ID;
|
|
||||||
char charname[NIC_NAME_LEN];
|
|
||||||
char descr[128];
|
|
||||||
struct sockaddr addr;
|
|
||||||
struct sockaddr broadaddr;
|
|
||||||
struct sockaddr netmask;
|
|
||||||
struct sockaddr hwaddr;
|
|
||||||
int time_stamp;
|
|
||||||
short flags;
|
|
||||||
int mtu;
|
|
||||||
int tx_queue_len;
|
|
||||||
unsigned long long average_flow;
|
|
||||||
unsigned long long rx_packets;
|
|
||||||
unsigned long long tx_packets;
|
|
||||||
unsigned long long rx_bytes;
|
|
||||||
unsigned long long tx_bytes;
|
|
||||||
unsigned long rx_errors;
|
|
||||||
unsigned long tx_errors;
|
|
||||||
unsigned long rx_dropped;
|
|
||||||
unsigned long tx_dropped;
|
|
||||||
unsigned long rx_multicast;
|
|
||||||
unsigned long collisions;
|
|
||||||
unsigned long rx_fifo_errors;
|
|
||||||
unsigned long tx_carrier_errors;
|
|
||||||
unsigned long tx_fifo_errors;
|
|
||||||
}NETCARD_INFO;
|
|
||||||
|
|
||||||
int get_nic_info(char *nic_name, NETCARD_INFO *net_info);
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
@@ -1,198 +0,0 @@
|
|||||||
////////////////////////////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
// Copyright (c) Comets' Grp. of Kedong Corp 2008. All Rights Reserved.
|
|
||||||
//
|
|
||||||
// FileName : procconf.h
|
|
||||||
//
|
|
||||||
// Function : this class realize some basic functions for process managerment,
|
|
||||||
// such as initiate process, report status of process, check status of process,
|
|
||||||
// update status of process, get information of process
|
|
||||||
//
|
|
||||||
// Author :
|
|
||||||
//
|
|
||||||
// Date :
|
|
||||||
//
|
|
||||||
// Modify by :
|
|
||||||
//
|
|
||||||
// Mod Date :
|
|
||||||
//
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
#ifndef _PROCCONF_H
|
|
||||||
#define _PROCCONF_H
|
|
||||||
|
|
||||||
#include <sys/types.h>
|
|
||||||
#include <sys/stat.h>
|
|
||||||
#include <fcntl.h>
|
|
||||||
#include <sys/mman.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <errno.h>
|
|
||||||
//#include <iostream.h>
|
|
||||||
#include <signal.h>
|
|
||||||
|
|
||||||
#include "const.h"
|
|
||||||
|
|
||||||
//for alarm ................................
|
|
||||||
typedef struct MESS_BH
|
|
||||||
{
|
|
||||||
unsigned char mtype;
|
|
||||||
int length;
|
|
||||||
};
|
|
||||||
typedef struct PROCESS_ALM
|
|
||||||
{
|
|
||||||
char context_name[MAX_STRING_LEN];
|
|
||||||
char app_name[MAX_STRING_LEN];
|
|
||||||
char proc_name[MAX_STRING_LEN];
|
|
||||||
unsigned char status;
|
|
||||||
};
|
|
||||||
//for alarm end .............................
|
|
||||||
|
|
||||||
//for mmi....................................
|
|
||||||
const int MAX_BUFFER_LEN = 500;
|
|
||||||
typedef struct MESS_BLOCK
|
|
||||||
{
|
|
||||||
unsigned char num;
|
|
||||||
char buffer[MAX_BUFFER_LEN];
|
|
||||||
};
|
|
||||||
typedef struct MESS_PROC
|
|
||||||
{
|
|
||||||
char context_name[MAX_STRING_LEN];
|
|
||||||
char app_name[MAX_STRING_LEN];
|
|
||||||
char proc_name[MAX_STRING_LEN];
|
|
||||||
char status;
|
|
||||||
};
|
|
||||||
//for mmi end ................................
|
|
||||||
|
|
||||||
const int DEFAULT_PERIOD = 3;
|
|
||||||
const int COUNT_LIMIT = 2;
|
|
||||||
const int START_DEFAULT_PERIOD = 60;
|
|
||||||
const int START_COUNT_LIMIT = 5;
|
|
||||||
const int APP_COUNT_LIMIT = 1;
|
|
||||||
|
|
||||||
//process critical level
|
|
||||||
//const int WST_CRITICAL = 1; // Shutdown and reboot workstation when failed
|
|
||||||
//const int SYS_CRITICAL = 2; // Shutdown and reboot the system on the wst when failed
|
|
||||||
//const int USER_CRITICAL = 3; // Shutdown and reboot the subsystem when failed
|
|
||||||
//const int GENERAL = 4; // reboot the process
|
|
||||||
const int CRUCIAL = 1; // crucial process
|
|
||||||
const int GENERAL = 0; // general process
|
|
||||||
|
|
||||||
|
|
||||||
extern int srv_init(char *service,int port);
|
|
||||||
extern int Tcp_close(int sockfd);
|
|
||||||
extern int Tcp_read(int fd,char *ptr,int nbytes);
|
|
||||||
extern int Tcp_write(int fd,char *ptr,int nbytes);
|
|
||||||
extern int srv_accept(int fd,struct sockaddr *cli_addr,int *clilen);
|
|
||||||
extern int client_tcp_open(char *host,char *service,int port);
|
|
||||||
|
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
char context_name[MAX_STRING_LEN];
|
|
||||||
char app_name[MAX_STRING_LEN];
|
|
||||||
char proc_name[MAX_STRING_LEN];
|
|
||||||
pid_t proc_pid;
|
|
||||||
}PROC_ADM_INFO;
|
|
||||||
|
|
||||||
//***************************************************************
|
|
||||||
// structure name : PROC_INFO
|
|
||||||
// function : store process informatin
|
|
||||||
// author :
|
|
||||||
// date :
|
|
||||||
// modify by :
|
|
||||||
// modification :
|
|
||||||
// mod date :
|
|
||||||
//***************************************************************
|
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
int position;
|
|
||||||
char node_name[MAX_STRING_LEN];
|
|
||||||
char context_name[MAX_STRING_LEN];
|
|
||||||
char app_name[MAX_STRING_LEN];
|
|
||||||
char proc_name[MAX_STRING_LEN];
|
|
||||||
|
|
||||||
unsigned char active_flag;
|
|
||||||
unsigned char master_flag;
|
|
||||||
|
|
||||||
time_t startup_time;
|
|
||||||
time_t refresh_time;
|
|
||||||
short refresh_peri;
|
|
||||||
unsigned char monitor_type;
|
|
||||||
|
|
||||||
pid_t proc_pid;
|
|
||||||
unsigned char auto_start;
|
|
||||||
unsigned char act_timer;
|
|
||||||
unsigned char start_timer;
|
|
||||||
unsigned char critical_level;
|
|
||||||
|
|
||||||
char exefile_path[MAX_EXECMD_LEN];
|
|
||||||
|
|
||||||
}PROC_INFO;
|
|
||||||
|
|
||||||
//***************************************************************
|
|
||||||
// structure name : APP_INFO
|
|
||||||
// function : store application informatin
|
|
||||||
// author :
|
|
||||||
// date :
|
|
||||||
// modify by :
|
|
||||||
// modification :
|
|
||||||
// mod date :
|
|
||||||
//***************************************************************
|
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
int position;
|
|
||||||
char context_name[MAX_STRING_LEN];
|
|
||||||
int context_id;
|
|
||||||
char app_name[MAX_STRING_LEN];
|
|
||||||
int app_id;
|
|
||||||
unsigned char act_timer;
|
|
||||||
unsigned char active_flag;
|
|
||||||
}APP_INFO;
|
|
||||||
|
|
||||||
|
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
int no_proc;
|
|
||||||
int semdes_cfg;
|
|
||||||
PROC_INFO proc[MAX_LOCAL_PROCESS];
|
|
||||||
APP_INFO app[MAX_LOCAL_APP];
|
|
||||||
}PROCCFG;
|
|
||||||
|
|
||||||
class proc_invocation
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
int m_init;
|
|
||||||
PROCCFG *proccfg_p;
|
|
||||||
|
|
||||||
public:
|
|
||||||
proc_invocation();
|
|
||||||
~proc_invocation();
|
|
||||||
|
|
||||||
int conf_create();
|
|
||||||
//int check_proc_status();
|
|
||||||
//int update_rtdb();
|
|
||||||
//int kill_proc(pid_t pid);
|
|
||||||
//int start_proc(char *cmdline);
|
|
||||||
//int send_alarm(char *context_name, char *app_name, char *proc_name, unsigned char status);
|
|
||||||
//int update_proc_status(char *context_name, char *app_name, char *proc_name, char status);
|
|
||||||
|
|
||||||
//int proc_init(char *context_name, char *app_name, char *proc_name, int critical_level);//exefile_path,auto_start
|
|
||||||
int proc_init(char *context_name, char *app_name, char *proc_name);
|
|
||||||
int proc_report(int pos, char status, int intertime=3);
|
|
||||||
int proc_exit(int proc_pos);
|
|
||||||
|
|
||||||
int get_pos(char *context_name, char *app_name, char *proc_name);
|
|
||||||
int is_proc_exist(char *context_name, char *app_name, char *proc_name);
|
|
||||||
int conf_map();
|
|
||||||
|
|
||||||
int get_procinfo(int position, PROC_ADM_INFO *p_info);
|
|
||||||
int get_active_pid(int &num, int *p_pidlist);
|
|
||||||
int is_proc_run(pid_t pid);
|
|
||||||
int is_proc_run(char *context_name, char *app_name, char *proc_name);
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -1,133 +0,0 @@
|
|||||||
#include "mnic.h"
|
|
||||||
|
|
||||||
static char *prase_digit(char **s)
|
|
||||||
{
|
|
||||||
char *retp = NULL;
|
|
||||||
char *p = *s;
|
|
||||||
|
|
||||||
if(!p)return NULL;
|
|
||||||
while(!isdigit(*p)){
|
|
||||||
p++;
|
|
||||||
if(*p == '\0')return NULL;
|
|
||||||
}
|
|
||||||
retp = p;
|
|
||||||
while(isdigit(*p)){
|
|
||||||
p++;
|
|
||||||
if(*p == '\0'){
|
|
||||||
*s = NULL;
|
|
||||||
return retp;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*p = '\0';
|
|
||||||
p++;
|
|
||||||
*s = p;
|
|
||||||
return retp;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
char *get_name(char *name, char *p)
|
|
||||||
{
|
|
||||||
while (isspace(*p))
|
|
||||||
p++;
|
|
||||||
while (*p) {
|
|
||||||
if (isspace(*p))
|
|
||||||
break;
|
|
||||||
if (*p == ':') { /* could be an alias */
|
|
||||||
char *dot = p, *dotname = name;
|
|
||||||
*name++ = *p++;
|
|
||||||
while (isdigit(*p))
|
|
||||||
*name++ = *p++;
|
|
||||||
if (*p != ':') { /* it wasn't, backup */
|
|
||||||
p = dot;
|
|
||||||
name = dotname;
|
|
||||||
}
|
|
||||||
if (*p == '\0')
|
|
||||||
return NULL;
|
|
||||||
p++;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
*name++ = *p++;
|
|
||||||
}
|
|
||||||
*name++ = '\0';
|
|
||||||
return p;
|
|
||||||
}
|
|
||||||
|
|
||||||
int get_dev_fields(char *str, NETCARD_INFO *ife)
|
|
||||||
{
|
|
||||||
int i = 0;
|
|
||||||
char *retp[16];
|
|
||||||
|
|
||||||
while((retp[i] = prase_digit(&str)) != NULL){i++;if(i > 15)break;}
|
|
||||||
ife->rx_bytes = atoll(retp[0]);
|
|
||||||
ife->rx_packets = atoll(retp[1]);
|
|
||||||
ife->rx_errors = atol(retp[2]);
|
|
||||||
ife->rx_dropped = atol(retp[3]);
|
|
||||||
ife->rx_fifo_errors = atol(retp[4]);
|
|
||||||
ife->rx_multicast = atol(retp[7]);
|
|
||||||
ife->tx_bytes = atoll(retp[8]);
|
|
||||||
ife->tx_packets = atoll(retp[9]);
|
|
||||||
ife->tx_errors = atol(retp[10]);
|
|
||||||
ife->tx_dropped = atol(retp[11]);
|
|
||||||
ife->tx_fifo_errors = atol(retp[12]);
|
|
||||||
ife->collisions = atol(retp[13]);
|
|
||||||
ife->tx_carrier_errors = atol(retp[14]);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int if_fetch(NETCARD_INFO *ife)
|
|
||||||
{
|
|
||||||
int skfd;
|
|
||||||
struct ifreq ifr;
|
|
||||||
|
|
||||||
if((skfd = socket(PF_INET, SOCK_DGRAM, 0)) == -1)return -1;
|
|
||||||
|
|
||||||
strcpy(ifr.ifr_name, ife->charname);
|
|
||||||
if (!ioctl(skfd, SIOCGIFFLAGS, &ifr))
|
|
||||||
ife->flags = ifr.ifr_flags;
|
|
||||||
|
|
||||||
if (!ioctl(skfd, SIOCGIFHWADDR, &ifr))
|
|
||||||
ife->hwaddr = ifr.ifr_hwaddr;
|
|
||||||
|
|
||||||
if (!ioctl(skfd, SIOCGIFMTU, &ifr))
|
|
||||||
ife->mtu = ifr.ifr_mtu;
|
|
||||||
|
|
||||||
if (!ioctl(skfd, SIOCGIFTXQLEN, &ifr))
|
|
||||||
ife->tx_queue_len = ifr.ifr_qlen;
|
|
||||||
|
|
||||||
if (!ioctl(skfd, SIOCGIFADDR, &ifr))
|
|
||||||
ife->addr = ifr.ifr_addr;
|
|
||||||
|
|
||||||
if (!ioctl(skfd, SIOCGIFBRDADDR, &ifr))
|
|
||||||
ife->broadaddr = ifr.ifr_broadaddr;
|
|
||||||
|
|
||||||
if (!ioctl(skfd, SIOCGIFNETMASK, &ifr))
|
|
||||||
ife->netmask = ifr.ifr_netmask;
|
|
||||||
|
|
||||||
ife->time_stamp = time(NULL);
|
|
||||||
close(skfd);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int ioc_get_name(NETCARD_INFO *name)
|
|
||||||
{
|
|
||||||
int skfd;
|
|
||||||
int ifrnum;
|
|
||||||
int i = 0;
|
|
||||||
struct ifconf ifc;
|
|
||||||
struct ifreq buf[MAXNICNUM];
|
|
||||||
|
|
||||||
if((skfd = socket(PF_INET, SOCK_DGRAM, 0)) == -1)return -1;
|
|
||||||
memset(buf, 0, sizeof(buf));
|
|
||||||
ifc.ifc_len = sizeof(buf);
|
|
||||||
ifc.ifc_buf = (caddr_t) buf;
|
|
||||||
ioctl(skfd, SIOCGIFCONF, &ifc);
|
|
||||||
ifrnum = ifc.ifc_len / sizeof(struct ifreq);
|
|
||||||
while(ifrnum-- > 0){
|
|
||||||
strcpy(name[i].charname, buf[ifrnum].ifr_name);
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
close(skfd);
|
|
||||||
return i;
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -1,37 +0,0 @@
|
|||||||
#include "mnic.h"
|
|
||||||
|
|
||||||
void send_alarm(D5000_NIC_ALARM *mesg, int socket_port, char *ipv4)
|
|
||||||
{
|
|
||||||
int bytes;
|
|
||||||
int sock_sd;
|
|
||||||
int val;
|
|
||||||
char error_str[200];
|
|
||||||
struct sockaddr_in recever;
|
|
||||||
socklen_t sock_len;
|
|
||||||
|
|
||||||
if((sock_sd = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP)) == -1){
|
|
||||||
snprintf(error_str, sizeof(error_str), "EMERG: socket(): %s\n", strerror(errno));
|
|
||||||
record_log(error_str);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
val=1;
|
|
||||||
if ((setsockopt(sock_sd, SOL_SOCKET, SO_BROADCAST, &val, sizeof(val))) == -1) {
|
|
||||||
snprintf(error_str, sizeof(error_str), "EMERG: setsockopt(): %s\n", strerror(errno));
|
|
||||||
record_log(error_str);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
/* init socket*/
|
|
||||||
recever.sin_family = AF_INET;
|
|
||||||
recever.sin_port = htons(socket_port);
|
|
||||||
inet_pton(AF_INET, ipv4, &recever.sin_addr);
|
|
||||||
sock_len = sizeof(recever);
|
|
||||||
/* send alarm*/
|
|
||||||
if((bytes = sendto(sock_sd, mesg, sizeof(D5000_NIC_ALARM), 0, (const struct sockaddr *)&recever, sock_len)) < 1){
|
|
||||||
snprintf(error_str, sizeof(error_str), "EMERG: sendto(): %s\n", strerror(errno));
|
|
||||||
record_log(error_str);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
//snprintf(error_str, sizeof(error_str), "NOTICE: Alarm information has already send!\n");
|
|
||||||
//record_log(error_str);
|
|
||||||
close(sock_sd);
|
|
||||||
}
|
|
||||||
@@ -1,88 +0,0 @@
|
|||||||
#ifndef _SYS_NETCARD_H
|
|
||||||
#define _SYS_NETCARD_H
|
|
||||||
|
|
||||||
#include <sys/socket.h>
|
|
||||||
|
|
||||||
#ifndef NIC_NAME_LEN
|
|
||||||
#define NIC_NAME_LEN 64
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define SEM_PROJ_ID 's'
|
|
||||||
#define MAXNICNUM 32
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C"{
|
|
||||||
#endif
|
|
||||||
|
|
||||||
typedef long KEYID;
|
|
||||||
|
|
||||||
typedef struct _msg_frame // message frame
|
|
||||||
{
|
|
||||||
short len; // message length
|
|
||||||
short seqno; // send sequence
|
|
||||||
short serv; // services ID
|
|
||||||
short event; // event ID
|
|
||||||
unsigned char domain; // domain ID
|
|
||||||
unsigned char ctxt; // Context ID
|
|
||||||
short stid; // SOURCE task id
|
|
||||||
short dtid; // DESTINATION task ID
|
|
||||||
unsigned char ver_coding; // 版本号 + 编码
|
|
||||||
unsigned char mes_type; // 帧类型
|
|
||||||
}MSG_FRAME, *LPMSG_FRAME;
|
|
||||||
|
|
||||||
typedef struct _net_info
|
|
||||||
{
|
|
||||||
KEYID ID;
|
|
||||||
char charname[NIC_NAME_LEN];
|
|
||||||
char descr[128];
|
|
||||||
struct sockaddr addr;
|
|
||||||
struct sockaddr broadaddr;
|
|
||||||
struct sockaddr netmask;
|
|
||||||
struct sockaddr hwaddr;
|
|
||||||
int time_stamp;
|
|
||||||
short flags;
|
|
||||||
int mtu;
|
|
||||||
int tx_queue_len;
|
|
||||||
unsigned long long average_flow;
|
|
||||||
unsigned long long rx_packets;
|
|
||||||
unsigned long long tx_packets;
|
|
||||||
unsigned long long rx_bytes;
|
|
||||||
unsigned long long tx_bytes;
|
|
||||||
unsigned long rx_errors;
|
|
||||||
unsigned long tx_errors;
|
|
||||||
unsigned long rx_dropped;
|
|
||||||
unsigned long tx_dropped;
|
|
||||||
unsigned long rx_multicast;
|
|
||||||
unsigned long collisions;
|
|
||||||
unsigned long rx_fifo_errors;
|
|
||||||
unsigned long tx_carrier_errors;
|
|
||||||
unsigned long tx_fifo_errors;
|
|
||||||
}NETCARD_INFO, *LPNETCARD_INFO;
|
|
||||||
|
|
||||||
#define NETCARD_ALARM_FAULT 1
|
|
||||||
#define NETCARD_ALARM_RESUME 2
|
|
||||||
#define NETCARD_ALARM_SWITCH 3
|
|
||||||
#define NETCARD_ALARM_ABNORMAL 4
|
|
||||||
#define NETCARD_ALARM_NORMAL 5
|
|
||||||
typedef struct _sys_netcard_alarm
|
|
||||||
{
|
|
||||||
char fault_devname[NIC_NAME_LEN]; /*故障设备名称 */
|
|
||||||
char switch_devname[NIC_NAME_LEN]; /*切换设备名称 */
|
|
||||||
short flags; /* 状态标记 : 1:网卡故障。2:网卡恢复。3:网卡切换。4:流量异常。*/
|
|
||||||
short retrytimes; //0,1,2 重发次数
|
|
||||||
}SYS_NETCARD_ALARM, *LPSYS_NETCARD_ALARM;
|
|
||||||
|
|
||||||
|
|
||||||
typedef struct _d5000_nic_alarm
|
|
||||||
{
|
|
||||||
MSG_FRAME tMsgFrame ;
|
|
||||||
SYS_NETCARD_ALARM tSysNetcardAlarm ;
|
|
||||||
}D5000_NIC_ALARM, *LPD5000_NIC_ALARM;
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
@@ -1,28 +0,0 @@
|
|||||||
#! /usr/bin/make -f
|
|
||||||
|
|
||||||
DEFAULTS = Makefile.config
|
|
||||||
|
|
||||||
include $(DEFAULTS)
|
|
||||||
|
|
||||||
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 $@ $^
|
|
||||||
libnic_shm.so:nicinfo_shm.c
|
|
||||||
$(CC) -fpic -shared -o $@ $^
|
|
||||||
clean:
|
|
||||||
$(RM) *.o
|
|
||||||
$(RM) libnic_shm.so sys_nicmonitor
|
|
||||||
install:
|
|
||||||
$(MKDIR) -p $(LIBDIR)
|
|
||||||
$(MKDIR) -p $(BINDIR)
|
|
||||||
$(MKDIR) -p $(INCDIR)
|
|
||||||
$(CP) libnic_shm.so $(LIBDIR)
|
|
||||||
$(CP) sys_nicmonitor $(BINDIR)
|
|
||||||
$(CP) nicinfo_shm.h $(INCDIR)
|
|
||||||
uninstall:
|
|
||||||
$(RM) -f $(LIBDIR)/libnic_shm.so
|
|
||||||
$(RM) -f $(BINDIR)/sys_nicmonitor
|
|
||||||
$(RM) -f $(INCDIR)/nicinfo_shm.h
|
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
|
|
||||||
PREFIX = $(DESTDIR)
|
|
||||||
|
|
||||||
BINDIR = $(PREFIX)/usr/bin
|
|
||||||
|
|
||||||
LIBDIR = $(PREFIX)/usr/lib64
|
|
||||||
|
|
||||||
INCDIR = $(PREFIX)/usr/include
|
|
||||||
|
|
||||||
INSTALL_SH = ./install.sh
|
|
||||||
|
|
||||||
CP = cp
|
|
||||||
RM = rm
|
|
||||||
#CC = gcc
|
|
||||||
CC = g++
|
|
||||||
MKDIR = mkdir
|
|
||||||
@@ -1,51 +0,0 @@
|
|||||||
#ifndef _RTE_CONST_H
|
|
||||||
#define _RTE_CONST_H
|
|
||||||
|
|
||||||
#include <pthread.h>
|
|
||||||
|
|
||||||
|
|
||||||
#define MAX_STRING_LEN 24
|
|
||||||
#define MAX_EXECMD_LEN 200
|
|
||||||
#define MAX_FILENAME_LEN 200
|
|
||||||
|
|
||||||
#define MAX_CONTEXT 8
|
|
||||||
#define MAX_HOSTNAME_LEN 24
|
|
||||||
#define MAX_LOCAL_MESPROC 512
|
|
||||||
#define MAX_LOCAL_PROCESS MAX_LOCAL_MESPROC
|
|
||||||
#define MAX_LOCAL_APP 32
|
|
||||||
#define MAX_LOCAL_NODE 256
|
|
||||||
|
|
||||||
#define MAX_SET 256 //max num of event set
|
|
||||||
#define MAX_EVENT 1300
|
|
||||||
#define MAX_REG_PROC 20
|
|
||||||
|
|
||||||
#define LEN_SHMBLK_BIG 4096
|
|
||||||
#define MAX_MSGBUF_LEN 32767
|
|
||||||
#define FREE_PAGE_SIZE 65536
|
|
||||||
#define MAX_PAGE_NUM 1024
|
|
||||||
|
|
||||||
#define MAX_QUE MAX_LOCAL_MESPROC
|
|
||||||
#define MAX_SEMPHORE_SET MAX_LOCAL_MESPROC*2
|
|
||||||
#define RTE_HAN 0 // queue number for event handeler0(RTE)
|
|
||||||
#define EX_EVENT_HAN RTE_HAN // queue number for extrnal event handeler
|
|
||||||
|
|
||||||
#define DOMAIN_I 1
|
|
||||||
#define DOMAIN_II 2
|
|
||||||
#define DOMAIN_III 3
|
|
||||||
|
|
||||||
//Add 20090225
|
|
||||||
const int PROC_TYPE_RPT =1;
|
|
||||||
const int PROC_TYPE_UNRPT =0;
|
|
||||||
//add end
|
|
||||||
|
|
||||||
|
|
||||||
//status for proc and app
|
|
||||||
const int NON_ACTIVE = 0;
|
|
||||||
const int ACTIVE = 1;
|
|
||||||
const int HANGUP = 2;
|
|
||||||
const int FAILURE = 5;
|
|
||||||
const int START = 6;
|
|
||||||
const int STOP = 7;
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -1,44 +0,0 @@
|
|||||||
#ifndef __MNIC_H
|
|
||||||
#define __MNIC_H
|
|
||||||
|
|
||||||
//#define _GNU_SOURCE
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <stddef.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <ctype.h>
|
|
||||||
#include <errno.h>
|
|
||||||
#include <netinet/in.h>
|
|
||||||
#include <net/if.h>
|
|
||||||
#include <time.h>
|
|
||||||
#include <sys/ioctl.h>
|
|
||||||
#include <sys/socket.h>
|
|
||||||
#include <sys/sem.h>
|
|
||||||
#include <sys/ipc.h>
|
|
||||||
#include <sys/param.h>
|
|
||||||
#include <linux/types.h>
|
|
||||||
#include <glob.h>
|
|
||||||
#include <linux/sockios.h>
|
|
||||||
#include <arpa/inet.h>
|
|
||||||
#include <pthread.h>
|
|
||||||
#include <sys/mman.h>
|
|
||||||
#include <sys/stat.h>
|
|
||||||
#include <fcntl.h>
|
|
||||||
#include <signal.h>
|
|
||||||
#include <sys/time.h>
|
|
||||||
|
|
||||||
#include "sys_netcard.h"
|
|
||||||
#include <pwd.h>
|
|
||||||
#include <sys/types.h>
|
|
||||||
#define IPSIZE 16
|
|
||||||
|
|
||||||
char *get_name(char *, char *);
|
|
||||||
int if_fetch(NETCARD_INFO *);
|
|
||||||
int ioc_get_name(NETCARD_INFO *);
|
|
||||||
int get_dev_fields(char *p, NETCARD_INFO *);
|
|
||||||
int get_user_home(int , char *);
|
|
||||||
void send_alarm(D5000_NIC_ALARM *, int , char *);
|
|
||||||
void record_log(char *);
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,209 +0,0 @@
|
|||||||
#include <stdio.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <sys/mman.h>
|
|
||||||
#include <sys/types.h>
|
|
||||||
#include <sys/ipc.h>
|
|
||||||
#include <sys/sem.h>
|
|
||||||
#include <fcntl.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <errno.h>
|
|
||||||
#include <sys/time.h>
|
|
||||||
#include <time.h>
|
|
||||||
#include <dirent.h>
|
|
||||||
#include <pwd.h>
|
|
||||||
|
|
||||||
#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/"
|
|
||||||
|
|
||||||
typedef struct net_info{
|
|
||||||
NETCARD_INFO info[MAXNICNUM];
|
|
||||||
}SHM;
|
|
||||||
|
|
||||||
static int semid = 0;
|
|
||||||
static char log_path[1024];
|
|
||||||
static char shm_path[1024];
|
|
||||||
static char sem_path[1024];
|
|
||||||
SHM *ptr = NULL;
|
|
||||||
|
|
||||||
/* write error in logfile */
|
|
||||||
void record_log(char *str)
|
|
||||||
{
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void get_sem(int semid)
|
|
||||||
{
|
|
||||||
char err_str[200];
|
|
||||||
struct sembuf lock[2];
|
|
||||||
|
|
||||||
lock[0].sem_num = 0;
|
|
||||||
lock[0].sem_op = 0;
|
|
||||||
lock[0].sem_flg = SEM_UNDO;
|
|
||||||
|
|
||||||
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(err_str, sizeof(err_str), "EMERG: semop():\n", strerror(errno));
|
|
||||||
record_log(err_str);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void release_sem(int semid)
|
|
||||||
{
|
|
||||||
int ret;
|
|
||||||
char err_str[200];
|
|
||||||
struct sembuf unlock;
|
|
||||||
|
|
||||||
unlock.sem_num = 0;
|
|
||||||
unlock.sem_op = -1;
|
|
||||||
unlock.sem_flg = SEM_UNDO;
|
|
||||||
|
|
||||||
if((ret = semop(semid, &unlock, 1)) == -1){
|
|
||||||
snprintf(err_str, sizeof(err_str), "EMERG: semop():\n", strerror(errno));
|
|
||||||
record_log(err_str);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int init_nic_info(void)
|
|
||||||
{
|
|
||||||
int fd = -1;
|
|
||||||
int sem_val;
|
|
||||||
char err_str[200];
|
|
||||||
key_t key;
|
|
||||||
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
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);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
/*
|
|
||||||
if((sem_val = semctl(semid, 0, GETVAL, 0)) == -1){
|
|
||||||
snprintf(err_str, sizeof(err_str), "EMERG: semctl: %s !\n", strerror(errno));
|
|
||||||
record_log(err_str);
|
|
||||||
semctl(semid, 0, IPC_RMID);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
if(!sem_val){
|
|
||||||
if(semctl(semid, 0, SETVAL, 1) == -1){
|
|
||||||
snprintf(err_str, sizeof(err_str), "EMERG: semctl: %s !\n", strerror(errno));
|
|
||||||
record_log(err_str);
|
|
||||||
semctl(semid, 0, IPC_RMID);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
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);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
ptr = (SHM*)mmap(NULL, sizeof(SHM), PROT_READ, MAP_SHARED, fd, 0);
|
|
||||||
if(ptr == MAP_FAILED){
|
|
||||||
snprintf(err_str, sizeof(err_str), "EMERG: mmap():%s\n", strerror(errno));
|
|
||||||
record_log(err_str);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
close(fd);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
int get_nic_info(char *nic_name, NETCARD_INFO *net_info)
|
|
||||||
{
|
|
||||||
int i,ret;
|
|
||||||
time_t tamp;
|
|
||||||
struct tm tmptr;
|
|
||||||
DIR *dir;
|
|
||||||
char *s;
|
|
||||||
char buf[128];
|
|
||||||
char err_str[200];
|
|
||||||
struct passwd *user;
|
|
||||||
|
|
||||||
tamp = time(NULL);
|
|
||||||
localtime_r(&tamp, &tmptr);
|
|
||||||
|
|
||||||
if((user = getpwnam("d5000"))!= NULL){
|
|
||||||
sprintf(log_path,"%s",user->pw_dir);
|
|
||||||
sprintf(shm_path,"%s",user->pw_dir);
|
|
||||||
sprintf(sem_path,"%s",user->pw_dir);
|
|
||||||
}
|
|
||||||
strcat(log_path,LOG_PATH);
|
|
||||||
strcat(shm_path,SHM_PATH);
|
|
||||||
strcat(sem_path,SEM_PATH);
|
|
||||||
|
|
||||||
if((dir = opendir(log_path)) == NULL){
|
|
||||||
if(errno == ENOENT){
|
|
||||||
strcpy(log_path, "/tmp/");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
closedir(dir);
|
|
||||||
s = strrchr(log_path, '/');
|
|
||||||
s++;
|
|
||||||
*s = '\0';
|
|
||||||
memset(buf, 0, sizeof(buf));
|
|
||||||
strftime(buf, sizeof(buf), "%Y%m%d_", &tmptr);
|
|
||||||
strcat(buf, "sys_nicmonitor");
|
|
||||||
strcat(buf, ".log");
|
|
||||||
strcat(log_path, buf);
|
|
||||||
if((ret = init_nic_info()) == -1){
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
get_sem(semid);
|
|
||||||
for(i = 0; ptr->info[i].charname[0] != 0; i++){
|
|
||||||
if(!strcmp(ptr->info[i].charname, nic_name)){
|
|
||||||
// get_sem(semid);
|
|
||||||
memcpy(net_info, &ptr->info[i], sizeof(NETCARD_INFO));
|
|
||||||
release_sem(semid);
|
|
||||||
munmap(ptr, sizeof(SHM));
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
release_sem(semid);
|
|
||||||
snprintf(err_str, sizeof(err_str), "NOTICE: No information of %s !\n", nic_name);
|
|
||||||
record_log(err_str);
|
|
||||||
munmap(ptr, sizeof(SHM));
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user