ubuntu 12.04 上 安装 nagios 的 nsca 2.9.1 make error 解决
11 Jun 2012ubuntu 12.04 上 安装 nsca 2.9.1 make all 是报错,如下:
make all
cd ./src/; make all ; cd ..
make[1]: Entering directory `/usr/local/nsca-2.9.1/src'
gcc -g -O2 -DHAVE_LIBMCRYPT -I/usr/include -DHAVE_CONFIG_H -o nsca ./nsca.c ./netutils.c ./utils.c -L/usr/lib -lmcrypt -lnsl
./nsca.c: In function ‘handle_connection’:
./nsca.c:1039:17: warning: format ‘%d’ expects argument of type ‘int’, but argument 4 has type ‘long unsigned int’ [-Wformat]
./nsca.c: In function ‘write_checkresult_file’:
./nsca.c:1246:9: warning: format ‘%d’ expects argument of type ‘int’, but argument 3 has type ‘time_t’ [-Wformat]
./nsca.c: In function ‘main’:
./nsca.c:153:9: warning: ignoring return value of ‘getcwd’, declared with attribute warn_unused_result [-Wunused-result]
./nsca.c: In function ‘write_pid_file’:
./nsca.c:1447:8: warning: ignoring return value of ‘write’, declared with attribute warn_unused_result [-Wunused-result]
./nsca.c:1448:9: warning: ignoring return value of ‘fchown’, declared with attribute warn_unused_result [-Wunused-result]
In file included from /usr/include/fcntl.h:252:0,
from ./../include/config.h:134,
from ./../include/common.h:24,
from ./nsca.c:19:
In function ‘open’,
inlined from ‘read_config_file.constprop.7’ at ./nsca.c:480:48:
/usr/include/x86_64-linux-gnu/bits/fcntl2.h:51:24: error: call to ‘__open_missing_mode’ declared with attribute error: open with O_CREAT in second argument needs 3 arguments
make[1]: *** [nsca] Error 1
make[1]: Leaving directory `/usr/local/nsca-2.9.1/src'
*** Compile finished ***
If the compile finished without any errors, you should
find client and server binaries in the src/ subdirectory.
Read the README file for more information on installing
the binaries, creating configuration files, and using
the server and client.
在网上是找了没找到解决方法,看来只能自己解决了,搜索了“call to ‘_openmissing_mode’ declared with attribute error“找到以下内容
这纯属软件bug,因为使用open函数的时候,如果在第二个参数中使用了 O_CREAT,就必须添加第三个参数:创建文件时赋予的初始权限。而在gcc-3.3.6~3.4.4/gcc/的collect2.c文件中有漏掉第 三个参数的错误,而gcc-4.3对语法错误的检查严格是出了名的(4.1就不会因此错误退出),所以就退出了。 这也是可以解决的,就是在gcc-3.3.6/gcc/collect2.c中的第1535行(或者其他行,可以搜索)改为: redir_handle = open (redir, O_WRONLY | O_TRUNC | O_CREAT, 0777); 哈哈,问题解决了,也就是加了0777那第三个参数
然后就使用以下命令修改nsca.c源码
sed -i '/checkresult_test_fd=open/s/O_CREAT/O_CREAT,0777/' src/nsca.c
make all
搞定,看样子以后要多看看C语言的书了,哈哈!