Permalink
Browse files

Add support to configure.ac for checking thread local support

and also check IPADDR_LOOPBACK is defined. In test use
loopback if we can to prevent firewall issues and use correct
thread local qualifier in sever. Plus ensure server.h qualifies
calls to std::bind to prevent clash with C socket API.
  • Loading branch information...
Martin2112 committed Aug 14, 2015
1 parent a4bd53a commit be0abe9be8408745ce2d0f6a1c0f4dacc4fe25ca
Showing with 60 additions and 2 deletions.
  1. +3 −0 configure.ac
  2. +17 −1 cpp/net/url_fetcher_test.cc
  3. +1 −1 cpp/server/event.cc
  4. +2 −0 cpp/server/server.h
  5. +37 −0 m4/ct_check_tls.m4
View
@@ -135,6 +135,9 @@ AC_TYPE_UINT32_T
AC_TYPE_UINT64_T
AC_TYPE_UINT8_T
CT_CHECK_TLS
AC_CHECK_DECLS([INADDR_LOOPBACK], [], [], [#include <netinet/in.h>])
AC_MSG_CHECKING([whether pthread_t is a pointer])
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([
#include <pthread.h>
@@ -1,3 +1,5 @@
#include "config.h"
#include <csignal>
#include <fcntl.h>
#include <gflags/gflags.h>
@@ -7,6 +9,9 @@
#include <sys/stat.h>
#include <sys/wait.h>
#include <unistd.h>
#ifdef HAVE_VFORK_H
#include <vfork.h>
#endif
#include "net/connection_pool.h"
#include "net/url_fetcher.h"
@@ -57,7 +62,12 @@ class LocalhostResolver : public libevent::Base::Resolver {
pid_t RunOpenSSLServer(uint16_t port, const std::string& cert_file,
const std::string& key_file,
const std::string& mode = "-www") {
#ifdef HAVE_WORKING_VFORK
pid_t pid(vfork());
#else
pid_t pid(fork());
#endif
if (pid == -1) {
LOG(INFO) << "fork() failed: " << pid;
} else if (pid == 0) {
@@ -315,7 +325,13 @@ int main(int argc, char** argv) {
struct sockaddr_in hang_addr;
bzero((char*)&hang_addr, sizeof(hang_addr));
hang_addr.sin_family = AF_INET;
hang_addr.sin_addr.s_addr = INADDR_ANY;
// Prefer to use INADDR_LOOPBACK if available as it avoids the firewall
// triggering on some platforms if we bind a non-local address.
#ifdef HAVE_INADDR_LOOPBACK
hang_addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
#else
hang_addr.sin_addr.s_addr = htonl(INADDR_ANY);
#endif
hang_addr.sin_port = htons(cert_trans::kHangPort);
CHECK_EQ(0, bind(hang_fd, reinterpret_cast<struct sockaddr*>(&hang_addr),
sizeof(hang_addr)));
View
@@ -251,7 +251,7 @@ bool Services::InitServer(int* sock, int port, const char* ip, int type) {
server.sin_family = AF_INET;
server.sin_port = htons((unsigned short)port);
if (ip == NULL)
server.sin_addr.s_addr = INADDR_ANY;
server.sin_addr.s_addr = htonl(INADDR_ANY);
else
memcpy(&server.sin_addr.s_addr, ip, 4);
View
@@ -36,6 +36,8 @@
#include "util/thread_pool.h"
#include "util/uuid.h"
using std::bind;
DEFINE_int32(node_state_refresh_seconds, 10,
"How often to refresh the ClusterNodeState entry for this node.");
DEFINE_int32(watchdog_seconds, 120,
View
@@ -0,0 +1,37 @@
dnl Checks for thread-local storage support.
dnl
dnl Taken from the openvswitch config code (Apache 2.0 License)
dnl with some local modifications. Does not include <threads.h>
dnl as this does not currently exist on GCC.
dnl Checks whether the compiler and linker support the C11
dnl thread_local macro from <threads.h>, and if so defines
dnl HAVE_THREAD_LOCAL. If not, checks whether the compiler and linker
dnl support the GCC __thread extension, and if so defines
dnl HAVE___THREAD.
AC_DEFUN([CT_CHECK_TLS],
[AC_CACHE_CHECK(
[whether $CC has <threads.h> that supports thread_local],
[ct_cv_thread_local],
[AC_LINK_IFELSE(
[AC_LANG_PROGRAM([ static thread_local int var;], [return var;])],
[ct_cv_thread_local=yes],
[ct_cv_thread_local=no])])
if test $ct_cv_thread_local = yes; then
AC_DEFINE([HAVE_THREAD_LOCAL], [1],
[Define to 1 if the C compiler and linker supports the C11
thread_local macro defined in <threads.h>.])
else
AC_CACHE_CHECK(
[whether $CC supports __thread],
[ct_cv___thread],
[AC_LINK_IFELSE(
[AC_LANG_PROGRAM([static __thread int var;], [return var;])],
[ct_cv___thread=yes],
[ct_cv___thread=no])])
if test $ct_cv___thread = yes; then
AC_DEFINE([HAVE___THREAD], [1],
[Define to 1 if the C compiler and linker supports the
GCC __thread extensions.])
fi
fi])

0 comments on commit be0abe9

Please sign in to comment.