公司应接入TX平台,编译用的服务器是SUSE 11 SP2, 但TX用的却是非常古老的 SUSE 10 SP1,
将程序编译好后,放到TX服务器上,一直在报读写memcached失败的错误,用GDB定位了一下:
libmemcached
static memcached_return_t network_connect(org::libmemcached::Instance* server)
{
....
int type= server->address_info_next->ai_socktype;
if (HAVE_SOCK_CLOEXEC)
{
type|= SOCK_CLOEXEC;
}
if ((server->fd= socket(server->address_info_next->ai_family,
type,
server->address_info_next->ai_protocol)) < 0)
{
return memcached_set_errno(*server, get_socket_errno(), NULL);
}
if (HAVE_SOCK_CLOEXEC == 0)
{
#ifdef FD_CLOEXEC
int rval;
do
{
rval= fcntl (server->fd, F_SETFD, FD_CLOEXEC);
} while (rval == -1 && (errno == EINTR or errno == EAGAIN));
#endif
}
}
SOCK_CLOEXEC is unsupported on linux kernel olders than 2.6.27
FD_CLOEXEC 这个参数SUSE11才支持,于是,手工将libmemcached目录下的
config.h 中的 #define HAVE_SOCK_CLOEXEC 1 定义改成 #define HAVE_SOCK_CLOEXEC 0
然后重新编译即可!