1.由于郭海龙修改了提供的库,导致增加了大量南瑞的头文件, 所以新建include目录用于存放所有的南瑞提供的同文件。 2. 修复sys_nicmonitor进程重启后,调用接口告警问题。 3. 增加USER_NUSP宏,用于nusp用户。 4. 由于新增了许多头文件且需交接给郭海龙,所以独立了一版2.0版本以用于区分。 修改: code/README 新文件: code/dep/42/dotconf#1.0.13-1.pkg.tar.gz 新文件: code/dep/42/run.sh 新文件: code/dep/90/libdotconf-dev_1.3-0.2_amd64.deb 新文件: code/dep/90/libdotconf-dev_1.3-0.2_arm64.deb 新文件: code/dep/90/libdotconf0_1.3-0.2_amd64.deb 新文件: code/dep/90/libdotconf0_1.3-0.2_arm64.deb 新文件: code/dep/90/run.sh 新文件: code/dep/libproc_common.so 新文件: code/dep/old/libman.so 新文件: code/dep/proc_common.cpp 新文件: code/sys_nicmonitor-code.tar.gz 修改: code/sys_nicmonitor/Makefile 修改: code/sys_nicmonitor/README 新文件: code/sys_nicmonitor/include/common_types.h 新文件: code/sys_nicmonitor/include/d5000_err.h 新文件: code/sys_nicmonitor/include/db_api/DeleteRecorder.h 新文件: code/sys_nicmonitor/include/db_api/codb_net.h 新文件: code/sys_nicmonitor/include/db_api/mc_rtdb_m.h 新文件: code/sys_nicmonitor/include/db_api/mc_rtdb_mng.h 新文件: code/sys_nicmonitor/include/db_api/odb_apinet.h 新文件: code/sys_nicmonitor/include/db_api/odb_apinet_rtdb_key.h 新文件: code/sys_nicmonitor/include/db_api/odb_apiop.h 新文件: code/sys_nicmonitor/include/db_api/odb_apiop.h.old 新文件: code/sys_nicmonitor/include/db_api/odb_app2id.h 新文件: code/sys_nicmonitor/include/db_api/odb_autolock.h 新文件: code/sys_nicmonitor/include/db_api/odb_baseindex.h 新文件: code/sys_nicmonitor/include/db_api/odb_ckeymanager.h 新文件: code/sys_nicmonitor/include/db_api/odb_common.h 新文件: code/sys_nicmonitor/include/db_api/odb_define.h 新文件: code/sys_nicmonitor/include/db_api/odb_double_overflow_hashindex.h 新文件: code/sys_nicmonitor/include/db_api/odb_field.h 新文件: code/sys_nicmonitor/include/db_api/odb_hashindex.h 新文件: code/sys_nicmonitor/include/db_api/odb_hashpk.h 新文件: code/sys_nicmonitor/include/db_api/odb_intel_ptr.h 新文件: code/sys_nicmonitor/include/db_api/odb_lock.h 新文件: code/sys_nicmonitor/include/db_api/odb_net.h 新文件: code/sys_nicmonitor/include/db_api/odb_net_m.h 新文件: code/sys_nicmonitor/include/db_api/odb_netfactory.h 新文件: code/sys_nicmonitor/include/db_api/odb_nooverflow_pk.h 新文件: code/sys_nicmonitor/include/db_api/odb_orbmgr.h 新文件: code/sys_nicmonitor/include/db_api/odb_profile.h 新文件: code/sys_nicmonitor/include/db_api/odb_prv_struct.h 新文件: code/sys_nicmonitor/include/db_api/odb_public.h 新文件: code/sys_nicmonitor/include/db_api/odb_rtdbbase.h 新文件: code/sys_nicmonitor/include/db_api/odb_rtdbfactory.h 新文件: code/sys_nicmonitor/include/db_api/odb_rtdbop.h 新文件: code/sys_nicmonitor/include/db_api/odb_rtdbtable.h 新文件: code/sys_nicmonitor/include/db_api/odb_struct.h 新文件: code/sys_nicmonitor/include/db_api/odb_system.h 新文件: code/sys_nicmonitor/include/db_api/odb_table.h 新文件: code/sys_nicmonitor/include/db_api/odb_tablebase.h 新文件: code/sys_nicmonitor/include/db_api/odb_tablemgr.h 新文件: code/sys_nicmonitor/include/db_api/odb_tablenet.h 新文件: code/sys_nicmonitor/include/db_api/odb_tableop.h 新文件: code/sys_nicmonitor/include/db_api/odb_where.h 新文件: code/sys_nicmonitor/include/db_api/pub_buf.h 新文件: code/sys_nicmonitor/include/db_api/rtdb_graph_name_list.h 新文件: code/sys_nicmonitor/include/db_api/server2proto.h 新文件: code/sys_nicmonitor/include/db_api/tab2idx.h 新文件: code/sys_nicmonitor/include/db_api/vl_get_data.h 新文件: code/sys_nicmonitor/include/db_api/vl_struct.h 新文件: code/sys_nicmonitor/include/db_api/vl_struct_m.cpp 新文件: code/sys_nicmonitor/include/db_api/vl_struct_m.h 新文件: code/sys_nicmonitor/include/db_com/CAppNo.h 新文件: code/sys_nicmonitor/include/db_com/CCharArray.h 新文件: code/sys_nicmonitor/include/db_com/CDataStream.h 新文件: code/sys_nicmonitor/include/db_com/CDbCommitClient.h 新文件: code/sys_nicmonitor/include/db_com/CDbMonitorClient.h 新文件: code/sys_nicmonitor/include/db_com/CDbMonitorLocal.h 新文件: code/sys_nicmonitor/include/db_com/CDbMonitorShm.h 新文件: code/sys_nicmonitor/include/db_com/CDbRepSet.h 新文件: code/sys_nicmonitor/include/db_com/CDbSem.h 新文件: code/sys_nicmonitor/include/db_com/CDbSemUse.h 新文件: code/sys_nicmonitor/include/db_com/CDbShm.h 新文件: code/sys_nicmonitor/include/db_com/CDyCfgLocal.h 新文件: code/sys_nicmonitor/include/db_com/CDyCommitClient.h 新文件: code/sys_nicmonitor/include/db_com/CDyMonitorClient.h 新文件: code/sys_nicmonitor/include/db_com/CDyMonitorLocal.h 新文件: code/sys_nicmonitor/include/db_com/CDyMonitorShm.h 新文件: code/sys_nicmonitor/include/db_com/CDySem.h 新文件: code/sys_nicmonitor/include/db_com/CDySemUse.h 新文件: code/sys_nicmonitor/include/db_com/CDyShm.h 新文件: code/sys_nicmonitor/include/db_com/CDyTagShmInfo.h 新文件: code/sys_nicmonitor/include/db_com/CErrorLog.h 新文件: code/sys_nicmonitor/include/db_com/CFindFile.h 新文件: code/sys_nicmonitor/include/db_com/CPrecTime.h 新文件: code/sys_nicmonitor/include/db_com/CRecordSet.h 新文件: code/sys_nicmonitor/include/db_com/CRedisAccess.h 新文件: code/sys_nicmonitor/include/db_com/CRepSet.h 新文件: code/sys_nicmonitor/include/db_com/CSaveReCommitSql.h 新文件: code/sys_nicmonitor/include/db_com/CSqlResultAlign.h 新文件: code/sys_nicmonitor/include/db_com/CSqlResultAlignClient.h 新文件: code/sys_nicmonitor/include/db_com/CSqlResultAlignClient2.h 新文件: code/sys_nicmonitor/include/db_com/DBAccess.h 新文件: code/sys_nicmonitor/include/db_com/DBCipher.h 新文件: code/sys_nicmonitor/include/db_com/DBConnectPool.h 新文件: code/sys_nicmonitor/include/db_com/DbFileNetIf.h 新文件: code/sys_nicmonitor/include/db_com/Hbase.h 新文件: code/sys_nicmonitor/include/db_com/Hbase_constants.h 新文件: code/sys_nicmonitor/include/db_com/Hbase_types.h 新文件: code/sys_nicmonitor/include/db_com/MyMutex.h 新文件: code/sys_nicmonitor/include/db_com/cross_region_sync_client.h 新文件: code/sys_nicmonitor/include/db_com/database_rep_m.h 新文件: code/sys_nicmonitor/include/db_com/db_commit_define.h 新文件: code/sys_nicmonitor/include/db_com/db_commit_m.h 新文件: code/sys_nicmonitor/include/db_com/db_error_define.h 新文件: code/sys_nicmonitor/include/db_com/db_extern.h 新文件: code/sys_nicmonitor/include/db_com/db_global.h 新文件: code/sys_nicmonitor/include/db_com/db_micro_define.h 新文件: code/sys_nicmonitor/include/db_com/db_monitor_define.h 新文件: code/sys_nicmonitor/include/db_com/db_monitor_define.h.old 新文件: code/sys_nicmonitor/include/db_com/db_monitor_extern.h 新文件: code/sys_nicmonitor/include/db_com/db_monitor_global.h 新文件: code/sys_nicmonitor/include/db_com/db_monitor_m.h 新文件: code/sys_nicmonitor/include/db_com/db_monitor_m.h.old 新文件: code/sys_nicmonitor/include/db_com/db_rep_lib_define.h 新文件: code/sys_nicmonitor/include/db_com/db_stat_m.h 新文件: code/sys_nicmonitor/include/db_com/db_stat_service_interface.h 新文件: code/sys_nicmonitor/include/db_com/ds_log.h 新文件: code/sys_nicmonitor/include/db_com/dy_commit_m.h 新文件: code/sys_nicmonitor/include/db_com/dy_monitor_define.h 新文件: code/sys_nicmonitor/include/db_com/dy_monitor_m.h 新文件: code/sys_nicmonitor/include/db_com/dy_public_m.h 新文件: code/sys_nicmonitor/include/db_com/dy_sample_define_m.h 新文件: code/sys_nicmonitor/include/db_com/dy_sample_define_service_interface.h 新文件: code/sys_nicmonitor/include/db_com/dy_stat_m.h 新文件: code/sys_nicmonitor/include/db_com/dy_stat_service_interface.h 新文件: code/sys_nicmonitor/include/db_com/hiredis.h 新文件: code/sys_nicmonitor/include/db_com/interpreter_define.h 新文件: code/sys_nicmonitor/include/db_com/interpreter_struct.h 新文件: code/sys_nicmonitor/include/db_com/lexical_anls.h 新文件: code/sys_nicmonitor/include/db_com/public_m.h 新文件: code/sys_nicmonitor/include/db_com/query_sample_m.h 新文件: code/sys_nicmonitor/include/db_com/query_sample_pi.h 新文件: code/sys_nicmonitor/include/db_com/query_sample_pi_m.h 新文件: code/sys_nicmonitor/include/db_com/query_sample_service_interface.h 新文件: code/sys_nicmonitor/include/db_com/query_sample_service_pi_interface.h 新文件: code/sys_nicmonitor/include/db_com/query_stat_m.h 新文件: code/sys_nicmonitor/include/db_com/query_stat_service_interface.h 新文件: code/sys_nicmonitor/include/db_com/rdb_commit_client.h 新文件: code/sys_nicmonitor/include/db_com/rdb_commit_m.h 新文件: code/sys_nicmonitor/include/db_com/rdb_define.pb.h 新文件: code/sys_nicmonitor/include/db_com/read.h 新文件: code/sys_nicmonitor/include/db_com/rtdbkey_defs.h 新文件: code/sys_nicmonitor/include/db_com/sample_data_client_base.h 新文件: code/sys_nicmonitor/include/db_com/sample_data_m.h 新文件: code/sys_nicmonitor/include/db_com/sample_define_m.h 新文件: code/sys_nicmonitor/include/db_com/sample_define_service_interface.h 新文件: code/sys_nicmonitor/include/db_com/sample_modify_m.h 新文件: code/sys_nicmonitor/include/db_com/sample_modify_service_interface.h 新文件: code/sys_nicmonitor/include/db_com/sds.h 新文件: code/sys_nicmonitor/include/db_com/server_define.h 新文件: code/sys_nicmonitor/include/db_com/sheetdataclient.h 新文件: code/sys_nicmonitor/include/db_com/sheetdataclient.h0604 新文件: code/sys_nicmonitor/include/db_com/sql_sp_client_base.h 新文件: code/sys_nicmonitor/include/db_com/sql_sp_define.h 新文件: code/sys_nicmonitor/include/db_com/sql_sp_m.h 新文件: code/sys_nicmonitor/include/db_com/sql_sp_send_client_base.h 新文件: code/sys_nicmonitor/include/db_com/sql_syntax_anls.h 新文件: code/sys_nicmonitor/include/db_com/sql_to_cime.h 新文件: code/sys_nicmonitor/include/db_com/sqlite_access.h 新文件: code/sys_nicmonitor/include/db_com/sqlite_server_client.h 新文件: code/sys_nicmonitor/include/db_com/sqlite_srv_m.h 新文件: code/sys_nicmonitor/include/db_com/store_access_client.h 新文件: code/sys_nicmonitor/include/db_com/trigger_sample_m.h 新文件: code/sys_nicmonitor/include/db_com/trigger_sample_service_interface.h 新文件: code/sys_nicmonitor/include/db_com/wholepubtools.h 新文件: code/sys_nicmonitor/include/db_com/wholesampledata.h 新文件: code/sys_nicmonitor/include/db_com/wholesqlsp.h 新文件: code/sys_nicmonitor/include/log_api.h 新文件: code/sys_nicmonitor/include/log_define.h 新文件: code/sys_nicmonitor/include/logclient.h 新文件: code/sys_nicmonitor/include/port_def.h 新文件: code/sys_nicmonitor/include/proc_common.h 新文件: code/sys_nicmonitor/include/scn_common.h 新文件: code/sys_nicmonitor/include/sysadm/proc_define.h 新文件: code/sys_nicmonitor/include/sysadm/scn_define.h 新文件: code/sys_nicmonitor/include/system.h 修改: code/sys_nicmonitor/mnic.c 修改: code/sys_nicmonitor/nicinfo_shm.c 修改: code/sys_nicmonitor/test.c 修改: code/sys_nicmonitor/version.h 新文件: code/test/test_nic 新文件: code/test/test_nic.cpp 新文件: packages/sys_nicmonitor-2.0-linx90-aarch64-bin-d5000.tar.gz 新文件: packages/sys_nicmonitor-2.0-linx90-aarch64-bin-nusp.tar.gz 新文件: packages/sys_nicmonitor-2.0-linx90-x86_64-bin-d5000.tar.gz 新文件: packages/sys_nicmonitor-2.0-linx90-x86_64-bin-nusp.tar.gz 重命名: sys_nicmonitor-arm-bin.tar.gz -> packages/sys_nicmonitor-arm-bin.tar.gz 重命名: sys_nicmonitor-arm.tar.gz -> packages/sys_nicmonitor-arm.tar.gz 新文件: packages/sys_nicmonitor-mips64-bin.tar.gz 新文件: packages/sys_nicmonitor-mips64.tar.gz Signed-off-by: Wei, Jing <jwei@linx-info.com>
424 lines
9.8 KiB
C
424 lines
9.8 KiB
C
#include <stdio.h>
|
|
#include <string.h>
|
|
#include <stdlib.h>
|
|
#include <sys/mman.h>
|
|
#include <sys/types.h>
|
|
#include <sys/ipc.h>
|
|
#include <sys/shm.h>
|
|
#include <sys/sem.h>
|
|
#include <fcntl.h>
|
|
#include <unistd.h>
|
|
#include <errno.h>
|
|
#include <sys/time.h>
|
|
#include <time.h>
|
|
#include <dirent.h>
|
|
#include <pwd.h>
|
|
#include <pthread.h>
|
|
|
|
//#define _WINDOWS64 0
|
|
#include "nicinfo_shm.h"
|
|
//#include "scn_common.h"
|
|
//#include "proc_common.h"
|
|
|
|
#define SHM_PATH "/share/sys_netcard_shm_path"
|
|
#define SEM_PATH "/share/sys_netcard_sem_path"
|
|
#define LOG_PATH "/var/log/netcard/"
|
|
|
|
typedef struct net_info{
|
|
NETCARD_INFO info[MAXNICNUM];
|
|
}SHM;
|
|
|
|
static int semid = 0;
|
|
char log_path[1024];
|
|
char shm_path[1024];
|
|
char sem_path[1024];
|
|
SHM *ptr = NULL;
|
|
static char process_name[32] = "get_nic_info";
|
|
|
|
static void linx_free_shm( void *addr, int size );
|
|
static int nic_init_flag = 0;
|
|
|
|
#if 0
|
|
static pthread_mutex_t lock_record_log = PTHREAD_MUTEX_INITIALIZER;
|
|
#define LOG_LOCK pthread_mutex_lock(&lock_record_log)
|
|
#define LOG_UNLOCK pthread_mutex_unlock(&lock_record_log)
|
|
|
|
static int is_checkdir = 0;
|
|
|
|
static void *record_log_thread( void *arg )
|
|
{
|
|
char *log_str = (char *)arg;
|
|
FILE *log_fp = NULL;
|
|
|
|
LOG_LOCK;
|
|
if( !is_checkdir ) {
|
|
create_dir( log_path );
|
|
is_checkdir = 1;
|
|
}
|
|
create_dir( log_path );
|
|
if((log_fp = fopen(log_path, "a")) != NULL){
|
|
if(fwrite(log_str, 1, strlen(log_str), log_fp) < 1){
|
|
}
|
|
fclose(log_fp);
|
|
}
|
|
|
|
LOG_UNLOCK;
|
|
free(log_str);
|
|
return NULL;
|
|
}
|
|
|
|
/* write error in logfile */
|
|
void record_log(char *str)
|
|
{
|
|
#if 0
|
|
time_t tamp;
|
|
char str_tm[4];
|
|
char log_str[512];
|
|
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);
|
|
}
|
|
#else
|
|
time_t tamp;
|
|
char str_tm[4];
|
|
char log_str[512];
|
|
// FILE *log_fp = NULL;
|
|
struct tm tmptr;
|
|
struct timeval tv;
|
|
struct timezone tz;
|
|
|
|
// if((log_fp = fopen(log_path, "a")) != NULL){
|
|
tamp = time(NULL);
|
|
memset(str_tm, 0, sizeof(str_tm));
|
|
memset(log_str, 0, sizeof(log_str));
|
|
localtime_r(&tamp, &tmptr);
|
|
gettimeofday(&tv, &tz);
|
|
snprintf(str_tm, sizeof(str_tm), "%d", (int)tv.tv_usec/1000);
|
|
if(str_tm[1] == '\0')str_tm[1] = '0';
|
|
if(str_tm[2] == '\0')str_tm[2] = '0';
|
|
strftime(log_str, sizeof(log_str), "%F %T.", &tmptr);
|
|
strcat(log_str, str_tm);
|
|
strcat(log_str, " ");
|
|
strcat(log_str, "get_nic_info");
|
|
strcat(log_str, " ");
|
|
strcat(log_str, str);
|
|
// if(fwrite(log_str, 1, strlen(log_str), log_fp) < 1){
|
|
// }
|
|
// fclose(log_fp);
|
|
// }
|
|
|
|
{
|
|
pthread_t pid;
|
|
char *keepstr = strdup( log_str );
|
|
pthread_create( &pid, NULL, record_log_thread, (void *)keepstr);
|
|
}
|
|
#endif
|
|
}
|
|
#else
|
|
|
|
#include "common.c"
|
|
|
|
#endif
|
|
|
|
void get_sem(int semid)
|
|
{
|
|
char err_str[200];
|
|
struct sembuf lock[2];
|
|
|
|
lock[0].sem_num = 0;
|
|
lock[0].sem_op = -1;
|
|
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, 1)){
|
|
if (errno == EINTR) {
|
|
continue;
|
|
}
|
|
snprintf(err_str, sizeof(err_str), "EMERG: get_sem semop():%s\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: release_sem semop():%s\n", strerror(errno));
|
|
record_log(err_str);
|
|
return;
|
|
}
|
|
}
|
|
|
|
static int global_share_id = -1;
|
|
static void *global_shmptr = NULL;
|
|
|
|
int init_nic_info(void)
|
|
{
|
|
char err_str[200];
|
|
key_t key;
|
|
|
|
#if 0
|
|
if ((key=ftok(sem_path, SEM_PROJ_ID)) == -1) {
|
|
snprintf(err_str, sizeof(err_str), "EMERG: ftok():%s\n", strerror(errno));
|
|
record_log(err_str);
|
|
return -1;
|
|
}
|
|
#else
|
|
key = 0x1d5200;
|
|
#endif
|
|
if((semid = semget(key, 1, 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;
|
|
}
|
|
}
|
|
*/
|
|
#ifdef USE_OLD_MMSHARE
|
|
if((fd = open(shm_path, O_RDONLY)) == -1){
|
|
snprintf(err_str, sizeof(err_str), "EMERG: Error open %s: %s!\n",shm_path, strerror(errno));
|
|
record_log(err_str);
|
|
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);
|
|
#else
|
|
{
|
|
void* shmptr = NULL;
|
|
int size = 0;
|
|
key_t share_key;
|
|
|
|
size = sizeof(SHM);
|
|
size = size + 16;
|
|
|
|
// share_key = ftok(path, 0x000d5000);
|
|
share_key = 0x1d5010;
|
|
|
|
#if 0
|
|
snprintf( err_str, sizeof( err_str ),
|
|
"MSG: lib, shm, size:%d, key:0x%x(%d)\n", size, share_key, share_key);
|
|
record_log(err_str);
|
|
#endif
|
|
|
|
global_share_id = shmget( share_key, size, 0666 );
|
|
if( global_share_id == -1 ) {
|
|
snprintf( err_str, sizeof( err_str ),
|
|
"EMERG: fail shmget, %s, 0x%x\n", strerror(errno), share_key);
|
|
record_log(err_str);
|
|
return -1;
|
|
}
|
|
|
|
shmptr = shmat( global_share_id, NULL, 0 );
|
|
if( shmptr == (void *)-1 ) {
|
|
snprintf( err_str, sizeof( err_str ), "EMERG: shmat fail.%s,0x%x\n", strerror(errno), share_key );
|
|
record_log( err_str );
|
|
return -1;
|
|
}
|
|
|
|
#if 0
|
|
flag_str = (char *)shmptr+size-16;
|
|
if( strcmp( flag_str, "D5001" ) != 0 ) {
|
|
//first, do init.
|
|
memset( shmptr, 0, size );
|
|
strcpy( flag_str, "D5001" );
|
|
}
|
|
|
|
ref_count = (char *)shmptr+size-1;
|
|
(*ref_count)++;
|
|
#endif
|
|
|
|
global_shmptr = shmptr;
|
|
ptr = (SHM *)shmptr;
|
|
}
|
|
#endif
|
|
|
|
return 0;
|
|
}
|
|
|
|
int get_nic_info(char *nic_name, NETCARD_INFO *net_info)
|
|
{
|
|
int i,ret;
|
|
time_t tamp;
|
|
struct tm tmptr;
|
|
char *s;
|
|
char buf[128];
|
|
char err_str[200];
|
|
int shm_id;
|
|
int shm_key = 0x1d6010;
|
|
char *shm_buf;
|
|
#if 0
|
|
snprintf(err_str, sizeof(err_str), "NOTICE: get nicinfo:%s !\n", nic_name);
|
|
record_log(err_str);
|
|
#endif
|
|
tamp = time(NULL);
|
|
localtime_r(&tamp, &tmptr);
|
|
|
|
if(log_path[0]==0){
|
|
shm_id = shmget(shm_key,128,0666);
|
|
if(shm_id < 0) return -1;
|
|
shm_buf = (char *)shmat(shm_id,NULL,0);
|
|
if(shm_buf == (void *) -1) return -1;
|
|
sprintf(log_path,"%s",shm_buf);
|
|
sprintf(shm_path,"%s",shm_buf);
|
|
sprintf(sem_path,"%s",shm_buf);
|
|
shmdt(shm_buf);
|
|
strcat(log_path,LOG_PATH);
|
|
strcat(shm_path,SHM_PATH);
|
|
strcat(sem_path,SEM_PATH);
|
|
}
|
|
#if 0
|
|
//remove
|
|
if((dir = opendir(log_path)) == NULL){
|
|
if(errno == ENOENT){
|
|
strcpy(log_path, "/tmp/");
|
|
}
|
|
}
|
|
closedir(dir);
|
|
#endif
|
|
|
|
memset(buf, 0, sizeof(buf));
|
|
strftime(buf, sizeof(buf), "%Y%m%d_", &tmptr);
|
|
strcat(buf, "sys_nicmonitor.log");
|
|
|
|
LOGPATH_LOCK;
|
|
s = strrchr(log_path, '/');
|
|
s++;
|
|
*s = '\0';
|
|
strcat(log_path, buf);
|
|
LOGPATH_UNLOCK;
|
|
|
|
shm_id = shmget(shm_key,128,0666);
|
|
if(shm_id < 0){
|
|
nic_init_flag = 0;
|
|
snprintf(err_str, sizeof(err_str), "EMERG: The sys_nicmonitor process status is abnormal !\n");
|
|
record_log(err_str);
|
|
return 1;
|
|
}else{
|
|
if (nic_init_flag != 1){
|
|
ret = init_nic_info();
|
|
if (ret != 0){
|
|
return -1;
|
|
}
|
|
nic_init_flag = 1;
|
|
}
|
|
}
|
|
get_sem(semid);
|
|
// ret = init_nic_info()
|
|
// if((ret = init_nic_info()) == -1){
|
|
// return -1;
|
|
// }
|
|
for(i = 0; ptr->info[i].charname[0] != 0; i++){
|
|
if(!strcmp(ptr->info[i].charname, nic_name)){
|
|
// get_sem(semid);
|
|
memcpy(net_info, &ptr->info[i], sizeof(NETCARD_INFO));
|
|
release_sem(semid);
|
|
#ifdef USE_OLD_MMSHARE
|
|
munmap(ptr, sizeof(SHM));
|
|
#else
|
|
linx_free_shm( ptr, sizeof(SHM) );
|
|
#endif
|
|
return 0;
|
|
}
|
|
}
|
|
release_sem(semid);
|
|
snprintf(err_str, sizeof(err_str), "NOTICE: No information of %s !\n", nic_name);
|
|
record_log(err_str);
|
|
#ifdef USE_OLD_MMSHARE
|
|
munmap(ptr, sizeof(SHM));
|
|
#else
|
|
linx_free_shm( ptr, sizeof(SHM) );
|
|
#endif
|
|
return -1;
|
|
}
|
|
|
|
static void linx_free_shm( void *addr, int size )
|
|
{
|
|
return ;
|
|
|
|
void *shmptr = addr;
|
|
|
|
#if 0
|
|
snprintf(err_str, sizeof(err_str), "NOTICE: free shm 0x%x, size:%d, glo:0x%x\n", addr, size, global_shmptr);
|
|
record_log(err_str);
|
|
#endif
|
|
|
|
if( shmptr == global_shmptr ) {
|
|
char *ref_count = NULL;
|
|
int is_last = 0;
|
|
// int size = sizeof(SHM);
|
|
|
|
ref_count = (char *)shmptr + size + 16 - 1;
|
|
|
|
is_last = *ref_count == 1?1:0;
|
|
|
|
#if 0
|
|
snprintf(err_str, sizeof(err_str), "NOTICE: lib, sref_count: %d, last:%d\n", *ref_count, is_last);
|
|
record_log(err_str);
|
|
#endif
|
|
|
|
#if 0
|
|
if( is_last ) {
|
|
memset( shmptr, 0, size + 16 );
|
|
}
|
|
#endif
|
|
shmdt( shmptr );
|
|
// shmctl( global_share_id, IPC_RMID, NULL );
|
|
// if( is_last ) {
|
|
// global_shmptr = NULL;
|
|
// global_share_id = -1;
|
|
// }
|
|
}
|
|
|
|
}
|
|
|
|
|