重命名: trunk/src/README -> ../README 删除: ../branches/sys_nicmonitor-1.4-龙芯-32/Makefile 删除: ../branches/sys_nicmonitor-1.4-龙芯-32/Makefile.config 删除: ../branches/sys_nicmonitor-1.4-龙芯-32/const.h 删除: ../branches/sys_nicmonitor-1.4-龙芯-32/dotconf.h 删除: ../branches/sys_nicmonitor-1.4-龙芯-32/mnic.c 删除: ../branches/sys_nicmonitor-1.4-龙芯-32/mnic.h 删除: ../branches/sys_nicmonitor-1.4-龙芯-32/nicinfo_shm.c 删除: ../branches/sys_nicmonitor-1.4-龙芯-32/nicinfo_shm.h 删除: ../branches/sys_nicmonitor-1.4-龙芯-32/proc_inv.h 删除: ../branches/sys_nicmonitor-1.4-龙芯-32/read_netcard.c 删除: ../branches/sys_nicmonitor-1.4-龙芯-32/send_alarm.c 删除: ../branches/sys_nicmonitor-1.4-龙芯-32/sys_netcard.h 删除: ../branches/sys_nicmonitor-1.4-龙芯-32/sys_nicmonitor 删除: ../branches/sys_nicmonitor-1.5/Makefile 删除: ../branches/sys_nicmonitor-1.5/Makefile.config 删除: ../branches/sys_nicmonitor-1.5/README1.5 删除: ../branches/sys_nicmonitor-1.5/const.h 删除: ../branches/sys_nicmonitor-1.5/mnic.c 删除: ../branches/sys_nicmonitor-1.5/mnic.h 删除: ../branches/sys_nicmonitor-1.5/nicinfo_shm.c 删除: ../branches/sys_nicmonitor-1.5/nicinfo_shm.h 删除: ../branches/sys_nicmonitor-1.5/proc_inv.h 删除: ../branches/sys_nicmonitor-1.5/read_netcard.c 删除: ../branches/sys_nicmonitor-1.5/send_alarm.c 删除: ../branches/sys_nicmonitor-1.5/sys_netcard.h 删除: ../branches/sys_nicmonitor-1.5/sys_nicmonitor 删除: ../branches/sys_nicmonitor-1.6/Makefile 删除: ../branches/sys_nicmonitor-1.6/Makefile.config 删除: ../branches/sys_nicmonitor-1.6/README1.5 删除: ../branches/sys_nicmonitor-1.6/README1.6 删除: ../branches/sys_nicmonitor-1.6/const.h 删除: ../branches/sys_nicmonitor-1.6/mnic.c 删除: ../branches/sys_nicmonitor-1.6/mnic.h 删除: ../branches/sys_nicmonitor-1.6/nicinfo_shm.c 删除: ../branches/sys_nicmonitor-1.6/nicinfo_shm.h 删除: ../branches/sys_nicmonitor-1.6/proc_inv.h 删除: ../branches/sys_nicmonitor-1.6/read_netcard.c 删除: ../branches/sys_nicmonitor-1.6/send_alarm.c 删除: ../branches/sys_nicmonitor-1.6/sys_netcard.h 删除: ../branches/sys_nicmonitor-1.6/sys_nicmonitor 重命名: trunk/sys_nicmonitor/src/Pkgfile -> Pkgfile 重命名: trunk/sys_nicmonitor/src/sys_nicmonitor/README -> README 删除: branches/sys_nicmonitor-1.0/Makefile 删除: branches/sys_nicmonitor-1.0/Makefile.config 删除: branches/sys_nicmonitor-1.0/const.h 删除: branches/sys_nicmonitor-1.0/mnic.c 删除: branches/sys_nicmonitor-1.0/mnic.h 删除: branches/sys_nicmonitor-1.0/nicinfo_shm.c 删除: branches/sys_nicmonitor-1.0/nicinfo_shm.h 删除: branches/sys_nicmonitor-1.0/proc_inv.h 删除: branches/sys_nicmonitor-1.0/read_netcard.c 删除: branches/sys_nicmonitor-1.0/send_alarm.c 删除: branches/sys_nicmonitor-1.0/sys_netcard.h 重命名: trunk/sys_nicmonitor/src/build.sh -> build.sh 重命名: trunk/sys_nicmonitor/src/dep/dotconf#1.0.13-1.pkg.tar.gz -> dep/dotconf#1.0.13-1.pkg.tar.gz 重命名: trunk/sys_nicmonitor/src/dep/libman.so -> dep/libman.so 重命名: trunk/sys_nicmonitor/src/dep/run.sh -> dep/run.sh 重命名: trunk/sys_nicmonitor/src/post_add.sh -> post_add.sh 重命名: trunk/sys_nicmonitor/src/post_mk.sh -> post_mk.sh 重命名: trunk/sys_nicmonitor/src/sys_nicmonitor/Makefile -> sys_nicmonitor/Makefile 重命名: trunk/sys_nicmonitor/src/sys_nicmonitor/Makefile.config -> sys_nicmonitor/Makefile.config 重命名: trunk/sys_nicmonitor/src/README -> sys_nicmonitor/README 重命名: trunk/sys_nicmonitor/src/sys_nicmonitor/common.c -> sys_nicmonitor/common.c 重命名: trunk/sys_nicmonitor/src/sys_nicmonitor/const.h -> sys_nicmonitor/const.h 重命名: trunk/sys_nicmonitor/src/sys_nicmonitor/mnic.c -> sys_nicmonitor/mnic.c 重命名: trunk/sys_nicmonitor/src/sys_nicmonitor/mnic.h -> sys_nicmonitor/mnic.h 重命名: trunk/sys_nicmonitor/src/sys_nicmonitor/nicinfo_shm.c -> sys_nicmonitor/nicinfo_shm.c 重命名: trunk/sys_nicmonitor/src/sys_nicmonitor/nicinfo_shm.h -> sys_nicmonitor/nicinfo_shm.h 重命名: trunk/sys_nicmonitor/src/sys_nicmonitor/proc_inv.h -> sys_nicmonitor/proc_inv.h 重命名: trunk/sys_nicmonitor/src/sys_nicmonitor/read_netcard.c -> sys_nicmonitor/read_netcard.c 重命名: trunk/sys_nicmonitor/src/sys_nicmonitor/send_alarm.c -> sys_nicmonitor/send_alarm.c 重命名: trunk/sys_nicmonitor/src/sys_nicmonitor/sys_netcard.h -> sys_nicmonitor/sys_netcard.h 重命名: trunk/sys_nicmonitor/src/sys_nicmonitor/test.c -> sys_nicmonitor/test.c 重命名: trunk/sys_nicmonitor/src/sys_nicmonitor/testread.c -> sys_nicmonitor/testread.c 重命名: trunk/sys_nicmonitor/src/sys_nicmonitor/version.h -> sys_nicmonitor/version.h 删除: tags/README1.5 删除: tags/README1.6 删除: tags/README1.7 删除: tags/libman.so 删除: tags/sys_nicmonitor-1.0.0/Makefile 删除: tags/sys_nicmonitor-1.0.0/Makefile.config 删除: tags/sys_nicmonitor-1.0.0/const.h 删除: tags/sys_nicmonitor-1.0.0/mnic.c 删除: tags/sys_nicmonitor-1.0.0/mnic.h 删除: tags/sys_nicmonitor-1.0.0/nicinfo_shm.c 删除: tags/sys_nicmonitor-1.0.0/nicinfo_shm.h 删除: tags/sys_nicmonitor-1.0.0/proc_inv.h 删除: tags/sys_nicmonitor-1.0.0/read_netcard.c 删除: tags/sys_nicmonitor-1.0.0/send_alarm.c 删除: tags/sys_nicmonitor-1.0.0/sys_netcard.h 删除: tags/sys_nicmonitor-1.5/Makefile 删除: tags/sys_nicmonitor-1.5/Makefile.config 删除: tags/sys_nicmonitor-1.5/const.h 删除: tags/sys_nicmonitor-1.5/mnic.c 删除: tags/sys_nicmonitor-1.5/mnic.h 删除: tags/sys_nicmonitor-1.5/nicinfo_shm.c 删除: tags/sys_nicmonitor-1.5/nicinfo_shm.h 删除: tags/sys_nicmonitor-1.5/proc_inv.h 删除: tags/sys_nicmonitor-1.5/read_netcard.c 删除: tags/sys_nicmonitor-1.5/send_alarm.c 删除: tags/sys_nicmonitor-1.5/sys_netcard.h 删除: tags/sys_nicmonitor-1.6/Makefile 删除: tags/sys_nicmonitor-1.6/Makefile.config 删除: tags/sys_nicmonitor-1.6/const.h 删除: tags/sys_nicmonitor-1.6/mnic.c 删除: tags/sys_nicmonitor-1.6/mnic.h 删除: tags/sys_nicmonitor-1.6/nicinfo_shm.c 删除: tags/sys_nicmonitor-1.6/nicinfo_shm.h 删除: tags/sys_nicmonitor-1.6/proc_inv.h 删除: tags/sys_nicmonitor-1.6/read_netcard.c 删除: tags/sys_nicmonitor-1.6/send_alarm.c 删除: tags/sys_nicmonitor-1.6/sys_netcard.h 删除: tags/sys_nicmonitor-1.7/Makefile 删除: tags/sys_nicmonitor-1.7/Makefile.config 删除: tags/sys_nicmonitor-1.7/const.h 删除: tags/sys_nicmonitor-1.7/mnic.c 删除: tags/sys_nicmonitor-1.7/mnic.h 删除: tags/sys_nicmonitor-1.7/nicinfo_shm.c 删除: tags/sys_nicmonitor-1.7/nicinfo_shm.h 删除: tags/sys_nicmonitor-1.7/proc_inv.h 删除: tags/sys_nicmonitor-1.7/read_netcard.c 删除: tags/sys_nicmonitor-1.7/send_alarm.c 删除: tags/sys_nicmonitor-1.7/sys_netcard.h 删除: tags/sys_nicmonitor-1.8/bin/README 删除: tags/sys_nicmonitor-1.8/bin/install.sh 删除: tags/sys_nicmonitor-1.8/bin/sys_nicmonitor#1.8-x86_64-Linx-Rocky4.2.pkg.tar.gz 删除: tags/sys_nicmonitor-1.8/doc/网卡监视程序动态库使用手册【新】.doc 删除: tags/sys_nicmonitor-1.8/doc/网卡监视程序安装说明以及使用手册【新】.doc 删除: tags/sys_nicmonitor-1.8/src/Pkgfile 删除: tags/sys_nicmonitor-1.8/src/README1.8 删除: tags/sys_nicmonitor-1.8/src/V1.8 删除: tags/sys_nicmonitor-1.8/src/build.sh 删除: tags/sys_nicmonitor-1.8/src/post_add.sh 删除: tags/sys_nicmonitor-1.8/src/post_mk.sh 删除: tags/sys_nicmonitor-1.8/src/sys_nicmonitor-1.8.tar.gz 删除: tags/sys_nicmonitor-1.8/test/Makefile 删除: tags/sys_nicmonitor-1.8/test/dotconf.h 删除: tags/sys_nicmonitor-1.8/test/getmem 删除: tags/sys_nicmonitor-1.8/test/getmem.c 删除: tags/sys_nicmonitor-1.8/test/mnic.h 删除: tags/sys_nicmonitor-1.8/test/nicinfo_shm.h 删除: tags/sys_nicmonitor-1.8/test/read_shm 删除: tags/sys_nicmonitor-1.8/test/read_shm.c 删除: tags/sys_nicmonitor-1.8/test/recv_msg 删除: tags/sys_nicmonitor-1.8/test/recv_msg.c 删除: tags/sys_nicmonitor-1.8/test/sys_netcard.h 重命名: trunk/test/Makefile -> test/Makefile 重命名: trunk/test/dotconf.h -> test/dotconf.h 重命名: trunk/test/getmem.c -> test/getmem.c 重命名: trunk/test/mnic.h -> test/mnic.h 重命名: trunk/test/nicinfo_shm.h -> test/nicinfo_shm.h 重命名: trunk/test/read_shm.c -> test/read_shm.c 重命名: trunk/test/recv_msg.c -> test/recv_msg.c 重命名: trunk/test/sys_netcard.h -> test/sys_netcard.h 删除: trunk/LATEST 删除: trunk/README 删除: trunk/bin/README 删除: trunk/bin/install.sh 删除: trunk/bin/sys_nicmonitor#1.8.1-x86_64-Linx-Rocky4.2.pkg.tar.gz 删除: trunk/doc/网卡监视程序动态库使用手册【新】.doc 删除: trunk/doc/网卡监视程序安装说明以及使用手册【新】.doc 删除: trunk/src/Pkgfile 删除: trunk/src/build.sh 删除: trunk/src/post_add.sh 删除: trunk/src/post_mk.sh 删除: trunk/src/sys_nicmonitor-1.8.tar.gz 删除: trunk/src/sys_nicmonitor-1.9.tar.gz 删除: trunk/sys_nicmonitor/README.md 删除: trunk/sys_nicmonitor/sys_nicmonitor-from-svn.tar.bz2 Signed-off-by: Zhang, Guodong <gdzhang@linx-info.com>
183 lines
4.0 KiB
C
183 lines
4.0 KiB
C
#include <sys/stat.h>
|
|
#include <sys/types.h>
|
|
|
|
static pthread_mutex_t lock_record_logpath = PTHREAD_MUTEX_INITIALIZER;
|
|
#define LOGPATH_LOCK pthread_mutex_lock(&lock_record_logpath)
|
|
#define LOGPATH_UNLOCK pthread_mutex_unlock(&lock_record_logpath)
|
|
|
|
|
|
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)
|
|
|
|
#define MAX_LOG_COUNT 5000
|
|
static char **log_prepare = NULL;
|
|
static char **log_writing = NULL;
|
|
static int log_thread_exit = 1;
|
|
static int log_idx = 0;
|
|
|
|
void create_dir(char *create_path)
|
|
{
|
|
char tmp_path[256];
|
|
|
|
strcpy(tmp_path,create_path);
|
|
|
|
int i,len = strlen(tmp_path);
|
|
|
|
for(i=1; i<len; i++)
|
|
{
|
|
if(tmp_path[i]=='/')
|
|
{
|
|
tmp_path[i] = 0;
|
|
if( access(tmp_path, F_OK)!=0 )
|
|
{
|
|
if(mkdir(tmp_path, 0755)==-1)
|
|
{
|
|
perror("mkdir error");
|
|
}
|
|
}
|
|
tmp_path[i] = '/';
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
static void *record_log_thread( void *arg )
|
|
{
|
|
char *log_str;
|
|
FILE *log_fp = NULL;
|
|
char **tmp = NULL;
|
|
char tmp_path[256];
|
|
int i = 0;
|
|
LOGPATH_LOCK;
|
|
strcpy(tmp_path,log_path);
|
|
LOGPATH_UNLOCK;
|
|
|
|
// create_dir( log_path );
|
|
create_dir( tmp_path );
|
|
|
|
log_thread_exit = 0;
|
|
|
|
// log_fp = fopen(log_path, "a");
|
|
|
|
while( !log_thread_exit ) {
|
|
LOGPATH_LOCK;
|
|
strcpy(tmp_path,log_path);
|
|
LOGPATH_UNLOCK;
|
|
if( !log_fp ) {
|
|
// LOGPATH_LOCK;
|
|
// log_fp = fopen(log_path, "a");
|
|
log_fp = fopen(tmp_path, "a");
|
|
// LOGPATH_UNLOCK;
|
|
}
|
|
|
|
//prepare log strings
|
|
LOG_LOCK;
|
|
tmp = log_writing;
|
|
log_writing = log_prepare;
|
|
// log_prepare = log_writing;
|
|
log_prepare = tmp;
|
|
log_idx=0;
|
|
LOG_UNLOCK;
|
|
|
|
i = 0;
|
|
while( i < MAX_LOG_COUNT ) {
|
|
log_str = log_writing[i];
|
|
|
|
if( log_str == NULL ) {
|
|
break;
|
|
}
|
|
|
|
if( log_fp ) {
|
|
// fwrite( log_str, 1, strlen(log_str), log_fp ); //write to file
|
|
fwrite( log_str, strlen(log_str), 1, log_fp );
|
|
}
|
|
|
|
free( log_str ); //free
|
|
log_writing[i] = NULL; //clear
|
|
|
|
//next
|
|
i++;
|
|
}
|
|
if(log_fp) {
|
|
fclose(log_fp);
|
|
log_fp = NULL;
|
|
}
|
|
usleep(799999);
|
|
} //while
|
|
|
|
if( log_fp ) {
|
|
fclose(log_fp);
|
|
}
|
|
if( log_prepare ) free( log_prepare );
|
|
if( log_writing ) free( log_writing );
|
|
log_prepare = NULL;
|
|
log_writing = NULL;
|
|
|
|
//free self thread resources
|
|
pthread_detach(pthread_self());
|
|
|
|
return NULL;
|
|
}
|
|
|
|
/* write error in logfile */
|
|
void record_log(char *str)
|
|
{
|
|
static int log_thread_started = 0;
|
|
time_t tamp;
|
|
char str_tm[4];
|
|
char log_str[512];
|
|
struct tm tmptr;
|
|
struct timeval tv;
|
|
struct timezone tz;
|
|
pthread_t pid;
|
|
// int ret = 0;
|
|
char *keepstr = 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';
|
|
// ret = strftime(log_str, sizeof(log_str), "%F %T. ", &tmptr );
|
|
// snprintf(log_str+ret, sizeof(log_str)-ret, " %s %s %s", str_tm, process_name, str );
|
|
//
|
|
strftime(log_str, sizeof(log_str), "%F %T.", &tmptr);
|
|
strcat(log_str, str_tm);
|
|
strcat(log_str, " ");
|
|
strcat(log_str, process_name);
|
|
strcat(log_str, " ");
|
|
strcat(log_str, str);
|
|
|
|
//check log thread
|
|
if( log_thread_started == 0 ) {
|
|
log_thread_started = 1;
|
|
log_prepare = (char **)malloc( sizeof(char *)*MAX_LOG_COUNT );
|
|
log_writing = (char **)malloc( sizeof(char *)*MAX_LOG_COUNT );
|
|
memset( log_prepare, 0, sizeof(char *) *MAX_LOG_COUNT );
|
|
memset( log_writing, 0, sizeof(char *) *MAX_LOG_COUNT );
|
|
log_idx = 0;
|
|
|
|
pthread_create( &pid, NULL, record_log_thread, (void *)NULL );
|
|
}
|
|
|
|
LOG_LOCK;
|
|
if(log_idx < MAX_LOG_COUNT){
|
|
keepstr = strdup( log_str );
|
|
if(!keepstr){
|
|
LOG_UNLOCK;
|
|
return;
|
|
}
|
|
//LOG_LOCK;
|
|
if( log_prepare ) {
|
|
log_prepare[log_idx] = keepstr;
|
|
log_idx++;
|
|
}
|
|
}
|
|
LOG_UNLOCK;
|
|
}
|
|
|