From 1aba89adfcdd07a0ec0c58eb3ffc670f375e84a2 Mon Sep 17 00:00:00 2001 From: trainman419 Date: Fri, 30 Mar 2018 15:57:58 -0700 Subject: [PATCH 1/5] Handle RLIM_INFINITY --- utilities/xmlrpcpp/src/XmlRpcServer.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/utilities/xmlrpcpp/src/XmlRpcServer.cpp b/utilities/xmlrpcpp/src/XmlRpcServer.cpp index 99154efacb..c22d4f964e 100644 --- a/utilities/xmlrpcpp/src/XmlRpcServer.cpp +++ b/utilities/xmlrpcpp/src/XmlRpcServer.cpp @@ -31,6 +31,9 @@ XmlRpcServer::XmlRpcServer() if(getrlimit(RLIMIT_NOFILE, &limit) == 0) { max_files = limit.rlim_max; + if( max_files == RLIM_INFINITY ) { + max_files = 0; + } } else { XmlRpcUtil::error("Could not get open file limit: %s", strerror(errno)); } @@ -218,6 +221,11 @@ int XmlRpcServer::countFreeFDs() { // Get the current soft limit on the number of file descriptors. if(getrlimit(RLIMIT_NOFILE, &limit) == 0) { + // If we have infinite file descriptors, always return FREE_FD_BUFFER so + // that we never hit the low-water mark. + if( limit.rlim_max == RLIM_INFINITY ) { + return FREE_FD_BUFFER; + } // Poll the available file descriptors. // The POSIX specification guarantees that rlim_cur will always be less or From 7279a8a92ac115da050ec5fab442aea517f0a1e4 Mon Sep 17 00:00:00 2001 From: Nikolaus Demmel Date: Sat, 31 Mar 2018 12:37:08 +0200 Subject: [PATCH 2/5] XmlRpcServer: use unsigned int for rlimit --- utilities/xmlrpcpp/src/XmlRpcServer.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/utilities/xmlrpcpp/src/XmlRpcServer.cpp b/utilities/xmlrpcpp/src/XmlRpcServer.cpp index c22d4f964e..3b84286780 100644 --- a/utilities/xmlrpcpp/src/XmlRpcServer.cpp +++ b/utilities/xmlrpcpp/src/XmlRpcServer.cpp @@ -27,18 +27,18 @@ XmlRpcServer::XmlRpcServer() _accept_retry_time_sec(0.0) { struct rlimit limit = { .rlim_cur = 0, .rlim_max = 0 }; - int max_files = 1024; + unsigned int max_files = 1024; if(getrlimit(RLIMIT_NOFILE, &limit) == 0) { max_files = limit.rlim_max; - if( max_files == RLIM_INFINITY ) { + if( limit.rlim_max == RLIM_INFINITY ) { max_files = 0; } } else { XmlRpcUtil::error("Could not get open file limit: %s", strerror(errno)); } pollfds.resize(max_files); - for(int i=0; i Date: Wed, 4 Apr 2018 10:25:10 -0700 Subject: [PATCH 3/5] Properly link xmlrpcpp tests --- utilities/xmlrpcpp/test/CMakeLists.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/utilities/xmlrpcpp/test/CMakeLists.txt b/utilities/xmlrpcpp/test/CMakeLists.txt index 0c57e69c82..f11d6e5eef 100644 --- a/utilities/xmlrpcpp/test/CMakeLists.txt +++ b/utilities/xmlrpcpp/test/CMakeLists.txt @@ -12,7 +12,7 @@ find_package(Boost REQUIRED COMPONENTS system thread) include_directories(${Boost_INCLUDE_DIRS}) add_library(test_fixtures test_fixtures.cpp) -target_link_libraries(test_fixtures ${Boost_LIBRARIES}) +target_link_libraries(test_fixtures xmlrpcpp ${Boost_LIBRARIES} ${GTEST_LIBRARIES}) catkin_add_gtest(HelloTest HelloTest.cpp) target_link_libraries(HelloTest xmlrpcpp ${Boost_LIBRARIES}) @@ -24,6 +24,7 @@ catkin_add_gtest(test_ulimit test_ulimit.cpp) target_link_libraries(test_ulimit xmlrpcpp test_fixtures ${Boost_LIBRARIES}) add_library(mock_socket mock_socket.cpp) +target_link_libraries(mock_socket ${GTEST_LIBRARIES}) catkin_add_gtest(test_client test_client.cpp From 2dba6d26d2cbbea1d80670c69f44180f77af2010 Mon Sep 17 00:00:00 2001 From: Austin Hendrix Date: Wed, 4 Apr 2018 10:53:49 -0700 Subject: [PATCH 4/5] Exclude test libraries from all target --- utilities/xmlrpcpp/test/CMakeLists.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/utilities/xmlrpcpp/test/CMakeLists.txt b/utilities/xmlrpcpp/test/CMakeLists.txt index f11d6e5eef..7c876016df 100644 --- a/utilities/xmlrpcpp/test/CMakeLists.txt +++ b/utilities/xmlrpcpp/test/CMakeLists.txt @@ -13,6 +13,7 @@ include_directories(${Boost_INCLUDE_DIRS}) add_library(test_fixtures test_fixtures.cpp) target_link_libraries(test_fixtures xmlrpcpp ${Boost_LIBRARIES} ${GTEST_LIBRARIES}) +set_target_properties(test_fixtures PROPERTIES EXCLUDE_FROM_ALL TRUE) catkin_add_gtest(HelloTest HelloTest.cpp) target_link_libraries(HelloTest xmlrpcpp ${Boost_LIBRARIES}) @@ -25,6 +26,7 @@ target_link_libraries(test_ulimit xmlrpcpp test_fixtures ${Boost_LIBRARIES}) add_library(mock_socket mock_socket.cpp) target_link_libraries(mock_socket ${GTEST_LIBRARIES}) +set_target_properties(mock_socket PROPERTIES EXCLUDE_FROM_ALL TRUE) catkin_add_gtest(test_client test_client.cpp From 0a0d7ef1f9de11a2f2174e40fe701371840ba314 Mon Sep 17 00:00:00 2001 From: Austin Hendrix Date: Wed, 4 Apr 2018 23:42:36 -0700 Subject: [PATCH 5/5] Symbol overriding for OSX --- utilities/xmlrpcpp/test/CMakeLists.txt | 24 ++++++++++++++++----- utilities/xmlrpcpp/test/test_dispatch.cpp | 6 ++---- utilities/xmlrpcpp/test/test_system_mocks.c | 9 +++----- 3 files changed, 24 insertions(+), 15 deletions(-) diff --git a/utilities/xmlrpcpp/test/CMakeLists.txt b/utilities/xmlrpcpp/test/CMakeLists.txt index 7c876016df..6a7bb10cd1 100644 --- a/utilities/xmlrpcpp/test/CMakeLists.txt +++ b/utilities/xmlrpcpp/test/CMakeLists.txt @@ -49,10 +49,17 @@ catkin_add_gtest(test_dispatch ../libb64/src/cencode.c ) target_link_libraries(test_dispatch mock_socket ${catkin_LIBRARIES}) +if(APPLE) set_target_properties(test_dispatch PROPERTIES LINK_FLAGS - "-Wl,--wrap=select -Wl,--wrap=poll" + "-Wl,-alias,___wrap_poll,_poll" ) +elseif(UNIX) +set_target_properties(test_dispatch PROPERTIES + LINK_FLAGS + "-Wl,--wrap=poll" +) +endif() if(NOT WIN32) catkin_add_gtest(test_socket @@ -61,10 +68,17 @@ if(NOT WIN32) ../src/XmlRpcSocket.cpp ../src/XmlRpcUtil.cpp ) - set_target_properties(test_socket PROPERTIES - LINK_FLAGS - "-Wl,--wrap=accept -Wl,--wrap=bind -Wl,--wrap=close -Wl,--wrap=connect -Wl,--wrap=getaddrinfo -Wl,--wrap=getsockname -Wl,--wrap=listen -Wl,--wrap=read -Wl,--wrap=setsockopt -Wl,--wrap=select -Wl,--wrap=socket -Wl,--wrap=write -Wl,--wrap=fcntl -Wl,--wrap=freeaddrinfo" - ) + if(APPLE) + set_target_properties(test_socket PROPERTIES + LINK_FLAGS + "-Wl,-alias,___wrap_accept,_accept -Wl,-alias,___wrap_bind,_bind -Wl,-alias,___wrap_close,_close -Wl,-alias,___wrap_connect,_connect -Wl,-alias,___wrap_getaddrinfo,_getaddrinfo -Wl,-alias,___wrap_getsockname,_getsockname -Wl,-alias,___wrap_listen,_listen -Wl,-alias,___wrap_read,_read -Wl,-alias,___wrap_setsockopt,_setsockopt -Wl,-alias,___wrap_select,_select -Wl,-alias,___wrap_select,_select$1050 -Wl,-alias,___wrap_socket,_socket -Wl,-alias,___wrap_write,_write -Wl,-alias,___wrap_fcntl,_fcntl -Wl,-alias,___wrap_freeaddrinfo,_freeaddrinfo" + ) + elseif(UNIX) + set_target_properties(test_socket PROPERTIES + LINK_FLAGS + "-Wl,--wrap=accept -Wl,--wrap=bind -Wl,--wrap=close -Wl,--wrap=connect -Wl,--wrap=getaddrinfo -Wl,--wrap=getsockname -Wl,--wrap=listen -Wl,--wrap=read -Wl,--wrap=setsockopt -Wl,--wrap=select -Wl,--wrap=socket -Wl,--wrap=write -Wl,--wrap=fcntl -Wl,--wrap=freeaddrinfo" + ) + endif() endif() catkin_add_gtest(TestValues TestValues.cpp) diff --git a/utilities/xmlrpcpp/test/test_dispatch.cpp b/utilities/xmlrpcpp/test/test_dispatch.cpp index 0caeb29a35..364367286a 100644 --- a/utilities/xmlrpcpp/test/test_dispatch.cpp +++ b/utilities/xmlrpcpp/test/test_dispatch.cpp @@ -46,15 +46,13 @@ // those symbols instead use __wrap_xxx extern "C" { // Mock for poll -int __real_poll(struct pollfd *fds, nfds_t nfds, int timeout); - int (*fake_poll)(struct pollfd *, nfds_t, int) = 0; int __wrap_poll(struct pollfd *fds, nfds_t nfds, int timeout) { if(fake_poll) { return fake_poll(fds, nfds, timeout); } else { - return __real_poll(fds, nfds, timeout); + return 0; } } @@ -72,7 +70,7 @@ int mock_poll(struct pollfd *fds, nfds_t nfds, int timeout) { EXPECT_EQ(poll_fds.size(), nfds); EXPECT_EQ(poll_timeout, timeout); - for(nfds_t i=0; i