以下内容由钟安修改:
修正common.c中对日志消息队列的操作,其中包括: 交换log_prepare与log_writing队列指针的bug; 以及在写入log_prepare队列时未检查已写入消息是否大于队列长度的 bug。修正了log_path(即日志文件名)不会随时间改变的bug。 修正在记录日志中检查目录时(在函数create_dir中), 由于采用线程进行日志记录,多次调用get_nic_info可 能会导致的将日志文件路径名变错的问题。在get_nic_info中 判断log_path是否被初始化过,如过未初始化,则到共享内存中读取。 否则,为初始化>过,直接使用该值,并在create_dir中使用局部变量保存该值 ,在create_dir中使用操作该局部变量,而不去改变该全局变量的值。 修正在程序开始时对IPC变量删除的错误函数调用。 添加配置项crazyping,当其不为零时,会在每次取网卡信息时进行ping操作。 添加在程序开始前对IPC变量是否已存在在判断,如果已存在,则将其删除。 将宏TESTINTERVAL的定义去除,不然不会调用南瑞的库函数。 在README中添加v1.10的修改内容。 修改版本号及添加新发布版本的安装包。 修改版本号 修正一些拼写错误。 修改Makefile文件令其在编译test时依赖于test.c文件。 将对getpwdnam的调用仅在sys_nicmonitor程序中调用一次,并将其取得的 主目录路径名存储在共享内存。之后每次调用get_nic_info时,再获取该值 时,只需从共享内存中读出,而不再需要调用getpwdnam函数。 修改了IPC相关操作,包括:PV原语操作以及IPC变量获取操作。 去掉pkg编译后的信息 Signed-off-by: Zhang, Jialing <jlzhang@linx-info.com>
This commit is contained in:
0
code/trunk/sys_nicmonitor/README.md
Normal file
0
code/trunk/sys_nicmonitor/README.md
Normal file
24
code/trunk/sys_nicmonitor/src/Pkgfile
Normal file
24
code/trunk/sys_nicmonitor/src/Pkgfile
Normal file
@@ -0,0 +1,24 @@
|
||||
# Description: A system to store and display time-series data.
|
||||
# URL: http://oss.oetiker.ch/rrdtool/index.en.html
|
||||
# Maintainer: Danny Rawlins, monster dot romster at gmail dot com
|
||||
# Packager: Younes Hafri, ycrux at club-internet dot fr
|
||||
# Depends on: libart_lgpl libcgi libgd pango python tcl intltool
|
||||
|
||||
name=sys_nicmonitor
|
||||
version=`grep version ./sys_nicmonitor/version.h | cut -d "=" -f 2`
|
||||
release=x86_64-Linx-Rocky4.2
|
||||
workdir=`pwd`
|
||||
#source=/home/d5000/d5000/linx/1.8/$name-$version.tar.gz
|
||||
#source=/mnt/rbqiu/nanri/sys_nicmonitor/0605/1.8/src/$name-$version.tar.gz
|
||||
echo $workdir
|
||||
source=$workdir/$name-$version.tar.gz
|
||||
|
||||
build() {
|
||||
cd $name-$version
|
||||
|
||||
make
|
||||
make DESTDIR=$PKG install
|
||||
# mkdir -p $PKG/var/log/netcard
|
||||
# chmod 777 $PKG/var/log/netcard
|
||||
}
|
||||
|
||||
@@ -1,3 +1,50 @@
|
||||
--V1.14 --
|
||||
2015-12-29
|
||||
修正了common.c中对日志消息队列的操作,其中包括:交换log_prepare与log_writing>队列指针的bug;以及在写入log_prepare队列时未检查已写入消息是否大于队列长度的b
|
||||
ug。修正了log_path(即日志文件名)不会随时间改变的bug。
|
||||
--V1.13 --
|
||||
2015-12-23
|
||||
修正在记录日志中检查目录时(在函数create_dir中),由于采用线程进行日志记录,多次调用get_nic_info可能会导致的将日志文件路径名变错的问题。在get_nic_info中判断log_path是否被初始化过,如过未初始化,则到共享内存中读取。否则,为初始化过,直接使用该值,并在create_dir中使用局部变量保存该值,在create_dir中使用操作该局部变量,而不去改变该全局变量的值。
|
||||
|
||||
-V1.12 --
|
||||
2015-12-23
|
||||
修正在程序开始时对IPC变量删除的错误函数调用。
|
||||
添加配置项crazyping,当其不为零时,会在每次取网卡信息时进行ping操作。
|
||||
|
||||
|
||||
--V1.11 --
|
||||
2015-12-18
|
||||
添加在程序开始时对IPC变量是否已存在的判断,如果已存在,则将其删除。
|
||||
将宏TESTINTERVAL的定义去除,不然不会调用南瑞的库函数。
|
||||
|
||||
--V1.10 --
|
||||
2015-12-11
|
||||
修改IPC信号量的相关操作
|
||||
|
||||
1)通过对代码的分析发现:在使用信号量时存在错误。在使用进行PV原语操作时,进行了相反的操作,其中加锁操作应减少信号量的计数,而去锁应增加信号量的计数,但库中进行了相反的操作,对其进行了修改。即将get_sem中对信号量的操作改为-1,而在release_sem函数中对信号量的操作变为1(即+1)。同时在init_sem函数中将该信号量的值初始化为1。
|
||||
|
||||
2)信号量应由网卡监控程序sys_nicmonitor创建,而不应由用户程序创建,对其进行了相应的修改(在创建信号量时在flag中添加IPC_EXCL,并将用户程序引用信号量时的flag中去除IPC_CREATE)。
|
||||
|
||||
3)在对获取网卡信息函数get_nic_info中添加获取时间的操作后得知,其中对getpwdnam的调用会减慢函数的工作(该函数并非每次都减慢函数很多,多数在30~40ms左右,但在测试中曾达到2s左右)。对其修改为在sys_nicmonitor程序启动时,调用getpwdnam函数,并将得到的用户主目录名写入到一块共享内存中。当用户程序要获得该目录名时,则从该值从共享内存中读取出来,而不需要每次都通过getpwdnam来获取,故可以提高该函数的速度。
|
||||
|
||||
|
||||
=-======update 2015-11-17
|
||||
编译前,进入dep目录运行sh run.sh,安装编译依赖文件.
|
||||
|
||||
然后sh build.sh编译1.9版本的sys_nicmonitor#1.9-x86_64-Linx-Rocky4.2.pkg.tar.gz
|
||||
|
||||
调试模式下:
|
||||
cd sys_nicmonitor-1.9
|
||||
make clean
|
||||
make
|
||||
make test
|
||||
make runtest
|
||||
|
||||
版本号变更方法,更新sys_nicmonitor/version.h文件,需要同时修改//后面的和define中的,前者用于pkg包,后者用于sys_nicmonitor程序.
|
||||
制作pkg包方法: sh build.sh
|
||||
|
||||
|
||||
|
||||
=========
|
||||
编译前准备:
|
||||
编译前先安装dotconf软件包。
|
||||
15
code/trunk/sys_nicmonitor/src/build.sh
Executable file
15
code/trunk/sys_nicmonitor/src/build.sh
Executable file
@@ -0,0 +1,15 @@
|
||||
verstr=`grep version ./sys_nicmonitor/version.h | cut -d "=" -f 2`
|
||||
echo $verstr
|
||||
worksrc=sys_nicmonitor-$verstr
|
||||
cp -r sys_nicmonitor $worksrc
|
||||
tar -czf $worksrc.tar.gz $worksrc
|
||||
|
||||
pkgmk -um
|
||||
|
||||
#For debug
|
||||
#pkgmk -kw -pa post_add.sh
|
||||
|
||||
#For release
|
||||
pkgmk -pa post_add.sh
|
||||
rm $worksrc.tar.gz
|
||||
rm -rf $worksrc
|
||||
BIN
code/trunk/sys_nicmonitor/src/dep/dotconf#1.0.13-1.pkg.tar.gz
Normal file
BIN
code/trunk/sys_nicmonitor/src/dep/dotconf#1.0.13-1.pkg.tar.gz
Normal file
Binary file not shown.
BIN
code/trunk/sys_nicmonitor/src/dep/libman.so
Normal file
BIN
code/trunk/sys_nicmonitor/src/dep/libman.so
Normal file
Binary file not shown.
2
code/trunk/sys_nicmonitor/src/dep/run.sh
Normal file
2
code/trunk/sys_nicmonitor/src/dep/run.sh
Normal file
@@ -0,0 +1,2 @@
|
||||
pkgadd dotconf#1.0.13-1.pkg.tar.gz
|
||||
cp ./libman.so /usr/lib64/
|
||||
16
code/trunk/sys_nicmonitor/src/post_add.sh
Normal file
16
code/trunk/sys_nicmonitor/src/post_add.sh
Normal file
@@ -0,0 +1,16 @@
|
||||
#!/bin/bash
|
||||
#echo $HOME
|
||||
DFDIR=`cat /etc/passwd | grep d5000 | cut -d ":" -f 6 `
|
||||
#LOGDIR=$DFDIR/var/log/netcard
|
||||
#mkdir -p $LOGDIR
|
||||
echo $DFDIR
|
||||
#echo $LOGDIR
|
||||
|
||||
echo "$DFDIR/lib/libnic_shm.so"
|
||||
echo "$DFDIR/bin/sys_nicmonitor"
|
||||
|
||||
mv /usr/lib64/libnic_shm.so $DFDIR/lib
|
||||
mv /usr/bin/sys_nicmonitor $DFDIR/bin
|
||||
|
||||
chown d5000.d5000 $DFDIR/lib/libnic_shm.so
|
||||
chown d5000.d5000 $DFDIR/bin/sys_nicmonitor
|
||||
10
code/trunk/sys_nicmonitor/src/post_mk.sh
Normal file
10
code/trunk/sys_nicmonitor/src/post_mk.sh
Normal file
@@ -0,0 +1,10 @@
|
||||
#!/bin/bash
|
||||
|
||||
PWD=`pwd`
|
||||
#pkg=`basename $PWD`
|
||||
pkg=sys_nicmonitor
|
||||
|
||||
# install the script which is run just after pkgadd or
|
||||
# when booting from disk first time
|
||||
mkdir -p $PKG/$PI_DIR
|
||||
install -m 755 post_add.sh $PKG/$PI_DIR/${pkg}.post_add
|
||||
@@ -6,15 +6,19 @@ include $(DEFAULTS)
|
||||
|
||||
all:sys_nicmonitor libnic_shm.so
|
||||
|
||||
CFLAGS += -Wall -Wformat=2 -Wno-format-extra-args -Wformat-security -Wformat-nonliteral #-g
|
||||
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 $@ $^
|
||||
test:test.c
|
||||
gcc -o test test.c -lnic_shm -L=./ -lpthread
|
||||
runtest:
|
||||
LD_LIBRARY_PATH=./ ./test bond0 5000 &
|
||||
clean:
|
||||
$(RM) *.o
|
||||
$(RM) libnic_shm.so sys_nicmonitor
|
||||
$(RM) libnic_shm.so sys_nicmonitor test
|
||||
install:
|
||||
$(MKDIR) -p $(LIBDIR)
|
||||
$(MKDIR) -p $(BINDIR)
|
||||
137
code/trunk/sys_nicmonitor/src/sys_nicmonitor/README
Normal file
137
code/trunk/sys_nicmonitor/src/sys_nicmonitor/README
Normal file
@@ -0,0 +1,137 @@
|
||||
--V1.14 --
|
||||
2015-12-29
|
||||
修正了common.c中对日志消息队列的操作,其中包括:交换log_prepare与log_writing>队列指针的bug;以及在写入log_prepare队列时未检查已写入消息是否大于队列长度的b
|
||||
ug。修正了log_path(即日志文件名)不会随时间改变的bug。
|
||||
--V1.13 --
|
||||
2015-12-23
|
||||
修正在记录日志中检查目录时(在函数create_dir中),由于采用线程进行日志记录,多次调用get_nic_info可能会导致的将日志文件路径名变错的问题。在get_nic_info中判断log_path是否被初始化过,如过未初始化,则到共享内存中读取。否则,为初始化过,直接使用该值,并在create_dir中使用局部变量保存该值,在create_dir中使用操作该局部变量,而不去改变该全局变量的值。
|
||||
|
||||
-V1.12 --
|
||||
2015-12-23
|
||||
修正在程序开始时对IPC变量删除的错误函数调用。
|
||||
添加配置项crazyping,当其不为零时,会在每次取网卡信息时进行ping操作。
|
||||
|
||||
|
||||
--V1.11 --
|
||||
2015-12-18
|
||||
添加在程序开始时对IPC变量是否已存在的判断,如果已存在,则将其删除。
|
||||
将宏TESTINTERVAL的定义去除,不然不会调用南瑞的库函数。
|
||||
|
||||
--V1.10 --
|
||||
2015-12-11
|
||||
修改IPC信号量的相关操作
|
||||
|
||||
1)通过对代码的分析发现:在使用信号量时存在错误。在使用进行PV原语操作时,进行了相反的操作,其中加锁操作应减少信号量的计数,而去锁应增加信号量的计数,但库中进行了相反的操作,对其进行了修改。即将get_sem中对信号量的操作改为-1,而在release_sem函数中对信号量的操作变为1(即+1)。同时在init_sem函数中将该信号量的值初始化为1。
|
||||
|
||||
2)信号量应由网卡监控程序sys_nicmonitor创建,而不应由用户程序创建,对其进行了相应的修改(在创建信号量时在flag中添加IPC_EXCL,并将用户程序引用信号量时的flag中去除IPC_CREATE)。
|
||||
|
||||
3)在对获取网卡信息函数get_nic_info中添加获取时间的操作后得知,其中对getpwdnam的调用会减慢函数的工作(该函数并非每次都减慢函数很多,多数在30~40ms左右,但在测试中曾达到2s左右)。对其修改为在sys_nicmonitor程序启动时,调用getpwdnam函数,并将得到的用户主目录名写入到一块共享内存中。当用户程序要获得该目录名时,则从该值从共享内存中读取出来,而不需要每次都通过getpwdnam来获取,故可以提高该函数的速度。
|
||||
|
||||
|
||||
=-======update 2015-11-17
|
||||
编译前,进入dep目录运行sh run.sh,安装编译依赖文件.
|
||||
|
||||
然后sh build.sh编译1.9版本的sys_nicmonitor#1.9-x86_64-Linx-Rocky4.2.pkg.tar.gz
|
||||
|
||||
调试模式下:
|
||||
cd sys_nicmonitor-1.9
|
||||
make clean
|
||||
make
|
||||
make test
|
||||
make runtest
|
||||
|
||||
版本号变更方法,更新sys_nicmonitor/version.h文件,需要同时修改//后面的和define中的,前者用于pkg包,后者用于sys_nicmonitor程序.
|
||||
制作pkg包方法: sh build.sh
|
||||
|
||||
|
||||
|
||||
=========
|
||||
编译前准备:
|
||||
编译前先安装dotconf软件包。
|
||||
libman.so拷贝到/usr/lib64/下
|
||||
pkgadd dotconf#1.0.13-1.pkg.tar.gz
|
||||
|
||||
编译说明:
|
||||
在Rocky 4.2上编译
|
||||
|
||||
执行: sh build.sh
|
||||
将在当前的目录下生成安装包:
|
||||
sys_nicmonitor#1.9-x86_64-Linx-Rocky4.2.pkg.tar.gz
|
||||
|
||||
========
|
||||
安装说明:
|
||||
1)安装,以root的用户执行安装命令:
|
||||
pkgadd sys_nicmonitor#1.9-x86_64-Linx-Rocky4.2.pkg.tar.gz
|
||||
如果之前已经安装,则可先卸载旧的然后再安装,或者通过更新方式安装
|
||||
卸载命令: pkgrm sys_nicmonitor
|
||||
更新方式安装命令:
|
||||
pkgadd -u sys_nicmonitor#1.9-x86_64-Linx-Rocky4.2.pkg.tar.gz
|
||||
|
||||
2)查看安装是否成功
|
||||
pkginfo -i|grep sys_nicmonitor
|
||||
或者
|
||||
查看d5000用户的目录下lib/libnic_shm.so和bin/sys_nicmonitor的日期是否匹配
|
||||
|
||||
========
|
||||
|
||||
版本说明:
|
||||
--V1.9 --
|
||||
2013-08-12
|
||||
1)修复问题:占用内存快速累加,导致内存占用很大
|
||||
问题描述:日志线程资源退出时未回收,导致占用内存快速累加
|
||||
解决办法:修改为一个日志线程,并且线程退出时设置为自动回收。
|
||||
将日志写文件的地方放到common.c中,以便动态库和daemon程序使用一个。
|
||||
|
||||
2)修复问题:日志文件名在家目录或者var目录下,未在规定位置
|
||||
问题描述:日志文件命名在一个单独的线程进行,导致日志线程和该线程对log_path存在同时访问的情况。
|
||||
导致在换天或者换月时,日志文件名变更一半时,日志写线程此时写日志,用未更新完成的
|
||||
log_path创建日志,导致日志文件不再规定的位置。
|
||||
解决办法:增加线程互斥锁pthread_mutex对log_path进行保护,修复该问题。
|
||||
|
||||
|
||||
--V1.8.1--
|
||||
2013-06-05
|
||||
1)修改BUG:ping_gw函数当PING失败时没有尝试对余下的GW进行PING操作
|
||||
2)增加环境变量SYS_NIC_DEBUG用于调试流量抖动问题。
|
||||
|
||||
--V1.8 --
|
||||
2013-05-27
|
||||
对系统高磁盘IO情况下,应用如果进行IO将可能会被阻塞。本版本为此作出调整。
|
||||
cs-fes1上编译测试OK。
|
||||
|
||||
1) 去掉shm和sem的实体文件
|
||||
#define SHM_PATH "$D5000_HOME/share/sys_netcard_shm_path"
|
||||
#define SEM_PATH "$D5000_HOME/share/sys_netcard_sem_path"
|
||||
|
||||
用key=0x1d5200 代替 sem
|
||||
用key=0x1d5010 代替 shm
|
||||
|
||||
|
||||
2)去掉动态库中get_nic_info接口中,判断路径的opendir调用,采用实际路径
|
||||
上层应用每秒可能调用3次这个接口,每判断一个网卡都调用一次,判断都个网卡的状态时就调用多次。
|
||||
|
||||
可改进:一次调用get_nic_info接口,可输入多个网卡,一次返回所有网卡状态信息。
|
||||
|
||||
3) record_log函数为日志函数,每次写一次,都重新打开一次文件。
|
||||
修改为线程模式,当记录日志时,不会被磁盘IO阻塞。
|
||||
|
||||
4) 安装目录为d5000用户的HOME目录下的lib和bin目录
|
||||
|
||||
----
|
||||
|
||||
|
||||
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安装包
|
||||
|
||||
@@ -16,21 +16,25 @@ static int log_idx = 0;
|
||||
|
||||
void create_dir(char *create_path)
|
||||
{
|
||||
int i,len = strlen(create_path);
|
||||
char tmp_path[256];
|
||||
|
||||
strcpy(tmp_path,create_path);
|
||||
|
||||
int i,len = strlen(tmp_path);
|
||||
|
||||
for(i=1; i<len; i++)
|
||||
{
|
||||
if(create_path[i]=='/')
|
||||
if(tmp_path[i]=='/')
|
||||
{
|
||||
create_path[i] = 0;
|
||||
if( access(create_path, F_OK)!=0 )
|
||||
tmp[i] = 0;
|
||||
if( access(tmp_path, F_OK)!=0 )
|
||||
{
|
||||
if(mkdir(create_path, 0755)==-1)
|
||||
if(mkdir(tmp_path, 0755)==-1)
|
||||
{
|
||||
perror("mkdir error");
|
||||
}
|
||||
}
|
||||
create_path[i] = '/';
|
||||
tmp_path[i] = '/';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,25 +46,34 @@ static void *record_log_thread( void *arg )
|
||||
FILE *log_fp = NULL;
|
||||
char **tmp = NULL;
|
||||
int i = 0;
|
||||
LOGPATH_LOCK;
|
||||
strcpy(tmp_path,log_path);
|
||||
LOGPATH_UNLOCK;
|
||||
|
||||
create_dir( log_path );
|
||||
// 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");
|
||||
LOGPATH_UNLOCK;
|
||||
// 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 = log_writing;
|
||||
log_prepare = tmp;
|
||||
log_idx=0;
|
||||
LOG_UNLOCK;
|
||||
|
||||
@@ -73,7 +86,8 @@ static void *record_log_thread( void *arg )
|
||||
}
|
||||
|
||||
if( log_fp ) {
|
||||
fwrite( log_str, 1, strlen(log_str), log_fp ); //write to file
|
||||
// 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
|
||||
@@ -147,13 +161,18 @@ void record_log(char *str)
|
||||
pthread_create( &pid, NULL, record_log_thread, (void *)NULL );
|
||||
}
|
||||
|
||||
keepstr = strdup( log_str );
|
||||
|
||||
LOG_LOCK;
|
||||
if( log_prepare ) {
|
||||
log_prepare[log_idx] = keepstr;
|
||||
log_idx++;
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include <sys/shm.h>
|
||||
#include <pthread.h>
|
||||
#include "proc_inv.h"
|
||||
#include "version.h"
|
||||
|
||||
#define THRNR 10
|
||||
#define DAYS 25
|
||||
@@ -21,7 +22,7 @@
|
||||
#define IPLEN 16
|
||||
#define CONF_FILE "/conf/nic/sys_netcard_conf.txt"
|
||||
|
||||
#define MNIC_VERSION "1.9"
|
||||
//#define MNIC_VERSION "1.9"
|
||||
|
||||
#define NIC_UNKNOWN 0
|
||||
#define NIC_DOWN 1
|
||||
@@ -51,6 +52,7 @@ typedef struct __config_file_st{
|
||||
char ip[IPSIZE];
|
||||
int pingnum; //OPTIONAL!! How many times for once ping check? Default is 2.
|
||||
int pinglap; //OPTIONAL!! How many seconds does ping wait for reply package? Default is 1.
|
||||
int crazyping;
|
||||
}CONFIG_FILE_ST;
|
||||
|
||||
typedef struct inc_name_node{
|
||||
@@ -132,6 +134,7 @@ char myconf[][64] = {
|
||||
"ping", // 13
|
||||
"pingnum", // 14
|
||||
"pinglap", // 15
|
||||
"crazyping", // 16
|
||||
""
|
||||
};
|
||||
|
||||
@@ -152,6 +155,7 @@ static const configoption_t options[] = {
|
||||
{myconf[13], ARG_STR, cb_str, NULL, CTX_ALL},
|
||||
{myconf[14], ARG_INT, cb_int, NULL, CTX_ALL},
|
||||
{myconf[15], ARG_INT, cb_int, NULL, CTX_ALL},
|
||||
{myconf[16], ARG_INT, cb_int, NULL, CTX_ALL},
|
||||
LAST_OPTION
|
||||
};
|
||||
|
||||
@@ -334,7 +338,7 @@ static void init_sem(int *semid, CONFIG_FILE_ST *ptr)
|
||||
record_log(error_str);
|
||||
return;
|
||||
}
|
||||
if(semctl(*semid, 0, SETVAL, 0) == -1){
|
||||
if(semctl(*semid, 0, SETVAL, 1) == -1){
|
||||
snprintf(error_str, sizeof(error_str), "EMERG: semctl: %s !\n", strerror(errno));
|
||||
record_log(error_str);
|
||||
semctl(*semid, 0, IPC_RMID);
|
||||
@@ -343,6 +347,7 @@ static void init_sem(int *semid, CONFIG_FILE_ST *ptr)
|
||||
}
|
||||
|
||||
static int global_share_id = -1;
|
||||
static int dir_share_id = -1;
|
||||
static void *global_shmptr = NULL;
|
||||
|
||||
static void init_shm(SHM **ptr, CONFIG_FILE_ST *p)
|
||||
@@ -427,14 +432,14 @@ static void get_sem(int semid)
|
||||
char error_str[200];
|
||||
|
||||
lock[0].sem_num = 0;
|
||||
lock[0].sem_op = 0;
|
||||
lock[0].sem_op = -1;
|
||||
lock[0].sem_flg = SEM_UNDO;
|
||||
|
||||
lock[1].sem_num = 0;
|
||||
/*lock[1].sem_num = 0;
|
||||
lock[1].sem_op = 1;
|
||||
lock[1].sem_flg = SEM_UNDO;
|
||||
lock[1].sem_flg = SEM_UNDO;*/
|
||||
|
||||
while(semop(semid, lock, 2)){
|
||||
while(semop(semid, lock, 1)){
|
||||
if(errno == EINTR)continue;
|
||||
snprintf(error_str, sizeof(error_str), "EMERG: get_sem semop():%s\n", strerror(errno));
|
||||
record_log(error_str);
|
||||
@@ -449,7 +454,7 @@ static void release_sem(int semid)
|
||||
struct sembuf unlock;
|
||||
|
||||
unlock.sem_num = 0;
|
||||
unlock.sem_op = -1;
|
||||
unlock.sem_op = 1;
|
||||
unlock.sem_flg = SEM_UNDO;
|
||||
|
||||
if((ret = semop(semid, &unlock, 1)) == -1){
|
||||
@@ -981,11 +986,13 @@ static void *create_logfile(void *ptr)
|
||||
close(fd);
|
||||
}
|
||||
umask(mask_tmp);
|
||||
strcpy(del_file[head++], log_path);
|
||||
LOGPATH_UNLOCK;
|
||||
|
||||
old_mon = tmptr.tm_mon+1;
|
||||
old_day = tmptr.tm_mday;
|
||||
strcpy(del_file[head++], log_path);
|
||||
// strcpy(del_file[head++], log_path);
|
||||
|
||||
if(head == DAYS){
|
||||
head = 0;
|
||||
del_flag = 1;
|
||||
@@ -1073,6 +1080,9 @@ void sig_handler(int sig)
|
||||
|
||||
// snprintf(err_str, sizeof(err_str), "NOTICE: process exit by signal %d\n", sig);
|
||||
// record_log(err_str);
|
||||
semctl(semid,0,IPC_RMID,0);
|
||||
shmctl(global_share_id,IPC_RMID,NULL);
|
||||
shmctl(dir_share_id,IPC_RMID,NULL);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
@@ -1184,6 +1194,10 @@ DOTCONF_CB(cb_int)
|
||||
if(strcmp(cmd ->name, myconf[15]) == 0){
|
||||
conf.pinglap = cmd->data.value;
|
||||
}
|
||||
if(strcmp(cmd ->name, myconf[16]) == 0){
|
||||
conf.crazyping = cmd->data.value;
|
||||
}
|
||||
|
||||
|
||||
return NULL;
|
||||
}
|
||||
@@ -1408,7 +1422,7 @@ int get_netcard_status(NETCARD_INFO_ST *listp)
|
||||
return NIC_UNRUNNING;
|
||||
|
||||
//20100510
|
||||
if(elapsed_ping_time == total_ping_time){
|
||||
if(conf.crazyping || (elapsed_ping_time == total_ping_time)){
|
||||
if(ping_gw(listp->info.charname) != 0)
|
||||
return NIC_UNLINKABLE;
|
||||
}
|
||||
@@ -1469,6 +1483,16 @@ int do_alarm(NETCARD_INFO_ST *listp, int nic_status, D5000_NIC_ALARM *Malarm)
|
||||
|
||||
int main(int argc, char ** argv)
|
||||
{
|
||||
int id = -1;
|
||||
if((id = semget(0x1d5200, 1, 0666)) != -1)
|
||||
semctl(id,0,IPC_RMID,0);
|
||||
id = -1;
|
||||
if((id = shmget(0x1d5010,sizeof(SHM) + 16 , 0666)) != -1)
|
||||
shmctl(id,IPC_RMID,0);
|
||||
id = -1;
|
||||
if((id = shmget(0x1d6010, 128, 0666)) != -1)
|
||||
shmctl(id,IPC_RMID,0);
|
||||
|
||||
int ret = 0, proc_stat = 0;
|
||||
unsigned int i = 0;
|
||||
int nic_status;
|
||||
@@ -1493,10 +1517,15 @@ int main(int argc, char ** argv)
|
||||
D5000_NIC_ALARM Malarm;
|
||||
struct sigaction sig;
|
||||
struct passwd *user;
|
||||
|
||||
//#define TESTINTERVAL
|
||||
#ifndef TESTINTERVAL
|
||||
proc_invocation prcm;
|
||||
|
||||
#endif
|
||||
char log_record[125]={0};
|
||||
|
||||
char *dir_memory;
|
||||
int shm_key =0x1d6010;
|
||||
|
||||
if( getenv("SYS_NIC_DEBUG") ) {
|
||||
sys_nic_debug = 1;
|
||||
}
|
||||
@@ -1507,7 +1536,7 @@ int main(int argc, char ** argv)
|
||||
exit(0);
|
||||
}
|
||||
//process register
|
||||
#if 1
|
||||
#ifndef TESTINTERVAL
|
||||
if((proc_stat=prcm.proc_init("sys","base_srv","sys_nicmonitor"))==-1){
|
||||
perror("proc_init()");
|
||||
exit(-1);
|
||||
@@ -1531,6 +1560,13 @@ int main(int argc, char ** argv)
|
||||
sprintf(conf_path,"%s",user->pw_dir);
|
||||
}
|
||||
|
||||
dir_share_id = shmget(shm_key,128,IPC_CREAT|0666);
|
||||
if(dir_share_id == -1)
|
||||
return -1;
|
||||
dir_memory = (char *) shmat(dir_share_id,NULL,0);
|
||||
if(dir_memory == (void *) -1)
|
||||
return -1;
|
||||
strcpy(dir_memory,user->pw_dir);
|
||||
strcat(log_path,LOG_PATH);
|
||||
strcat(shm_path,SHM_PATH);
|
||||
strcat(sem_path,SEM_PATH);
|
||||
@@ -1698,7 +1734,8 @@ int main(int argc, char ** argv)
|
||||
total_ping_time = 1000 / conf.monitor_interval;
|
||||
if(total_ping_time == 0)
|
||||
total_ping_time = 1;
|
||||
elapsed_ping_time = 1;
|
||||
//elapsed_ping_time = 1;
|
||||
elapsed_ping_time = total_ping_time;
|
||||
|
||||
while(1){
|
||||
i = 0;
|
||||
@@ -26,9 +26,9 @@ typedef struct net_info{
|
||||
}SHM;
|
||||
|
||||
static int semid = 0;
|
||||
static char log_path[1024];
|
||||
static char shm_path[1024];
|
||||
static char sem_path[1024];
|
||||
char log_path[1024];
|
||||
char shm_path[1024];
|
||||
char sem_path[1024];
|
||||
SHM *ptr = NULL;
|
||||
static char process_name[32] = "get_nic_info";
|
||||
|
||||
@@ -142,14 +142,14 @@ void get_sem(int semid)
|
||||
struct sembuf lock[2];
|
||||
|
||||
lock[0].sem_num = 0;
|
||||
lock[0].sem_op = 0;
|
||||
lock[0].sem_op = -1;
|
||||
lock[0].sem_flg = SEM_UNDO;
|
||||
|
||||
lock[1].sem_num = 0;
|
||||
/* lock[1].sem_num = 0;
|
||||
lock[1].sem_op = 1;
|
||||
lock[1].sem_flg = SEM_UNDO;
|
||||
lock[1].sem_flg = SEM_UNDO;*/
|
||||
|
||||
while(semop(semid, lock, 2)){
|
||||
while(semop(semid, lock, 1)){
|
||||
if (errno == EINTR) {
|
||||
continue;
|
||||
}
|
||||
@@ -166,7 +166,7 @@ void release_sem(int semid)
|
||||
struct sembuf unlock;
|
||||
|
||||
unlock.sem_num = 0;
|
||||
unlock.sem_op = -1;
|
||||
unlock.sem_op = 1;
|
||||
unlock.sem_flg = SEM_UNDO;
|
||||
|
||||
if((ret = semop(semid, &unlock, 1)) == -1){
|
||||
@@ -195,7 +195,7 @@ int init_nic_info(void)
|
||||
#else
|
||||
key = 0x1d5200;
|
||||
#endif
|
||||
if((semid = semget(key, 1, IPC_CREAT|0666)) == -1){
|
||||
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;
|
||||
@@ -251,7 +251,7 @@ int init_nic_info(void)
|
||||
record_log(err_str);
|
||||
#endif
|
||||
|
||||
global_share_id = shmget( share_key, size, IPC_CREAT|0666 );
|
||||
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);
|
||||
@@ -291,26 +291,33 @@ 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;
|
||||
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((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);
|
||||
|
||||
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);
|
||||
}
|
||||
strcat(log_path,LOG_PATH);
|
||||
strcat(shm_path,SHM_PATH);
|
||||
strcat(sem_path,SEM_PATH);
|
||||
#if 0
|
||||
//remove
|
||||
if((dir = opendir(log_path)) == NULL){
|
||||
@@ -321,14 +328,17 @@ int get_nic_info(char *nic_name, NETCARD_INFO *net_info)
|
||||
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';
|
||||
memset(buf, 0, sizeof(buf));
|
||||
strftime(buf, sizeof(buf), "%Y%m%d_", &tmptr);
|
||||
strcat(buf, "sys_nicmonitor");
|
||||
strcat(buf, ".log");
|
||||
strcat(log_path, buf);
|
||||
LOGPATH_UNLOCK;
|
||||
|
||||
if((ret = init_nic_info()) == -1){
|
||||
return -1;
|
||||
}
|
||||
44
code/trunk/sys_nicmonitor/src/sys_nicmonitor/test.c
Normal file
44
code/trunk/sys_nicmonitor/src/sys_nicmonitor/test.c
Normal file
@@ -0,0 +1,44 @@
|
||||
#include <stdio.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/time.h>
|
||||
#include <string.h>
|
||||
#include "nicinfo_shm.h"
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
NETCARD_INFO ni;
|
||||
int ret = 0;
|
||||
char dev[10];
|
||||
struct timeval st,et;
|
||||
unsigned long uset, stl, etl, to;
|
||||
if( argc >=2 ) strncpy(dev,argv[1],9);
|
||||
else strcpy(dev, "eth0");
|
||||
|
||||
if( argc >=3 ) to = strtol(argv[2], NULL, 10 );
|
||||
else to= 500000ull;
|
||||
|
||||
while(1) {
|
||||
gettimeofday(&st, NULL);
|
||||
ret = get_nic_info( dev, &ni );
|
||||
gettimeofday(&et, NULL);
|
||||
stl = st.tv_sec;
|
||||
stl = stl*1000000 + st.tv_usec;
|
||||
etl = et.tv_sec;
|
||||
etl = etl*1000000 + et.tv_usec;
|
||||
uset = etl - stl;
|
||||
// printf("%d, %x, %x\n", ret, uset, to);
|
||||
if( ret != 0 || uset > to) {
|
||||
///home/d5000/var/log/netcard/testnic.log
|
||||
char buf[120];
|
||||
int log = open("/home/d5000/var/log/netcard/testnic.log", O_CREAT|O_RDWR|O_APPEND, 0666);
|
||||
snprintf(buf,sizeof(buf),"ret:%d, %lld-%lld=%lld\n", ret, etl, stl, uset);
|
||||
write(log, buf, strlen(buf));
|
||||
close(log);
|
||||
}
|
||||
|
||||
// sleep(1);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
5
code/trunk/sys_nicmonitor/src/sys_nicmonitor/version.h
Normal file
5
code/trunk/sys_nicmonitor/src/sys_nicmonitor/version.h
Normal file
@@ -0,0 +1,5 @@
|
||||
// version=1.14
|
||||
#ifndef MNIC_VERSION
|
||||
#define MNIC_VERSION "1.14"
|
||||
#endif
|
||||
|
||||
BIN
code/trunk/sys_nicmonitor/sys_nicmonitor-from-svn.tar.bz2
Normal file
BIN
code/trunk/sys_nicmonitor/sys_nicmonitor-from-svn.tar.bz2
Normal file
Binary file not shown.
@@ -1,15 +0,0 @@
|
||||
|
||||
#include "nicinfo_shm.h"
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
NETCARD_INFO ni;
|
||||
int ret = 0;
|
||||
while(1) {
|
||||
ret = get_nic_info( "eth0", &ni );
|
||||
sleep(1);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user