You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by jp...@apache.org on 2013/08/11 00:53:56 UTC

git commit: TS-2128: Don't link libGeoIP.so.1 into binaries

Updated Branches:
  refs/heads/master 92961cf37 -> f34c62b42


TS-2128: Don't link libGeoIP.so.1 into binaries

AC_SEARCH_LIBS always updates $LIBS, but AC_CHECK_LIB doesn't search
properly. So we have to introduce a wrapper around AC_SEARCH_LIBS
that preserves $LIBS so that we can properly test for libraries
without linking them into everything.

Apply the new TS_SEARCH_LIBRARY macro to the geoip_acl plugin so
that libGeoIP is not linked into every binary.


Project: http://git-wip-us.apache.org/repos/asf/trafficserver/repo
Commit: http://git-wip-us.apache.org/repos/asf/trafficserver/commit/f34c62b4
Tree: http://git-wip-us.apache.org/repos/asf/trafficserver/tree/f34c62b4
Diff: http://git-wip-us.apache.org/repos/asf/trafficserver/diff/f34c62b4

Branch: refs/heads/master
Commit: f34c62b42bbeb62e78ccd47eebe8ae0888e5e184
Parents: 92961cf
Author: James Peach <jp...@apache.org>
Authored: Sat Aug 10 15:51:19 2013 -0700
Committer: James Peach <jp...@apache.org>
Committed: Sat Aug 10 15:51:19 2013 -0700

----------------------------------------------------------------------
 CHANGES                                     |  2 ++
 build/common.m4                             | 25 +++++++++++++++++++++++-
 configure.ac                                | 14 ++++++-------
 lib/ts/ink_config.h.in                      |  1 -
 plugins/experimental/geoip_acl/Makefile.am  |  1 +
 plugins/experimental/geoip_acl/acl.cc       |  8 --------
 plugins/experimental/geoip_acl/acl.h        |  4 ++--
 plugins/experimental/geoip_acl/geoip_acl.cc |  2 --
 8 files changed, 35 insertions(+), 22 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/trafficserver/blob/f34c62b4/CHANGES
----------------------------------------------------------------------
diff --git a/CHANGES b/CHANGES
index cb686e6..0c70a39 100644
--- a/CHANGES
+++ b/CHANGES
@@ -2,6 +2,8 @@
 Changes with Apache Traffic Server 3.5.0
 
 
+  *) [TS-2128] Don't link libGeoIP.so.1 into binaries
+
   *) [TS-2122] Enlarge the 64KB limitation of log buffer size.
 
   *) [TS-2061] LogFile::write_ascii_logbuffer3() can silently drop log

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/f34c62b4/build/common.m4
----------------------------------------------------------------------
diff --git a/build/common.m4 b/build/common.m4
index bf01eed..5e58945 100644
--- a/build/common.m4
+++ b/build/common.m4
@@ -513,7 +513,7 @@ done
 
 ])dnl
 
-dnl TS_FLAG_HEADERS(HEADER-FILE ... )
+dnl TS_FLAG_HEADERS(header-file, [action-if-found], [action-if-not-found], [includes])
 dnl
 AC_DEFUN([TS_FLAG_HEADERS], [
 AC_CHECK_HEADERS([$1], [$2], [$3], [$4])
@@ -560,3 +560,26 @@ AC_DEFUN([TS_ARG_ENABLE_VAR],[
   )
 ])
 
+dnl
+dnl TS_SEARCH_LIBRARY(function, search-libs, [action-if-found], [action-if-not-found])
+dnl This macro works like AC_SEARCH_LIBS, except that $LIBS is not modified. If the library
+dnl is found, it is cached in the ts_cv_lib_${function} variable.
+dnl
+AC_DEFUN([TS_SEARCH_LIBRARY], [
+  __saved_LIBS="$LIBS"
+
+  AC_SEARCH_LIBS($1, $2, [
+    dnl action-if-found
+    case $ac_cv_search_$1 in
+    "none required"|"no") ts_cv_search_$1="" ;;
+    *) ts_cv_search_$1=$ac_cv_search_$1 ;;
+    esac
+    m4_ifval($3, [$3], [true])
+  ], [
+    dnl action-if-not-found
+    m4_ifval($4, [$4], [true])
+  ])
+
+  LIBS="$__saved_LIBS"
+  unset __saved_LIBS
+])

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/f34c62b4/configure.ac
----------------------------------------------------------------------
diff --git a/configure.ac b/configure.ac
index 6cf6c58..e689872 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1308,16 +1308,14 @@ AC_SUBST(use_hwloc)
 # GeoIP as a "helper" plugin, which other plugins can then use. Such a plugin could
 # then manage which libraries to use via explicit dlopen()'s.
 #
-use_maxmind_geoip=0
-AC_SEARCH_LIBS([GeoIP_id_by_code], [GeoIP], [use_maxmind_geoip=1], [use_maxmind_geoip=0])
-AS_IF([test 1 -eq $use_maxmind_geoip], [
-  TS_FLAG_HEADERS([GeoIP.h], [], [
-    AC_MSG_ERROR([Can not locate GeoIP.h, perhaps install GeoIP-devel package?])
-  ])
+enable_maxmind_geoip=no
+TS_SEARCH_LIBRARY([GeoIP_id_by_code], [GeoIP], [
+  GEOIP_LIBS=$ts_cv_search_GeoIP_id_by_code
+  TS_FLAG_HEADERS([GeoIP.h], [ enable_maxmind_geoip=yes ])
 ])
 
-AC_SUBST(use_maxmind_geoip)
-AM_CONDITIONAL([BUILD_GEOIP_PLUGIN], [ test 0 -ne $use_maxmind_geoip ])
+AC_SUBST(GEOIP_LIBS)
+AM_CONDITIONAL([BUILD_GEOIP_PLUGIN], [ test "x${enable_maxmind_geoip}" = x"yes" ])
 
 # Right now, the healthcheck plugins requires inotify_init (and friends)
 AM_CONDITIONAL([BUILD_HEALTHCHECK_PLUGIN], [ test "$ac_cv_func_inotify_init" = "yes" ])

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/f34c62b4/lib/ts/ink_config.h.in
----------------------------------------------------------------------
diff --git a/lib/ts/ink_config.h.in b/lib/ts/ink_config.h.in
index 784702d..9dfb46a 100644
--- a/lib/ts/ink_config.h.in
+++ b/lib/ts/ink_config.h.in
@@ -69,7 +69,6 @@
 #define TS_USE_TLS_SNI                 @use_tls_sni@
 #define TS_USE_LINUX_NATIVE_AIO        @use_linux_native_aio@
 #define TS_USE_COP_DEBUG               @use_cop_debug@
-#define TS_USE_MAXMIND_GEOIP           @use_maxmind_geoip@
 #define TS_USE_INTERIM_CACHE           @has_interim_cache@
 
 

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/f34c62b4/plugins/experimental/geoip_acl/Makefile.am
----------------------------------------------------------------------
diff --git a/plugins/experimental/geoip_acl/Makefile.am b/plugins/experimental/geoip_acl/Makefile.am
index cf9ffcf..0b4e4ff 100644
--- a/plugins/experimental/geoip_acl/Makefile.am
+++ b/plugins/experimental/geoip_acl/Makefile.am
@@ -21,5 +21,6 @@ if BUILD_GEOIP_PLUGIN
 pkglib_LTLIBRARIES = geoip_acl.la
 geoip_acl_la_SOURCES = acl.cc geoip_acl.cc
 geoip_acl_la_LDFLAGS = $(TS_PLUGIN_LDFLAGS)
+geoip_acl_la_LIBADD = $(GEOIP_LIBS)
 
 endif

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/f34c62b4/plugins/experimental/geoip_acl/acl.cc
----------------------------------------------------------------------
diff --git a/plugins/experimental/geoip_acl/acl.cc b/plugins/experimental/geoip_acl/acl.cc
index ad917d5..90bbe79 100644
--- a/plugins/experimental/geoip_acl/acl.cc
+++ b/plugins/experimental/geoip_acl/acl.cc
@@ -24,12 +24,8 @@
 #include "acl.h"
 #include "lulu.h"
 
-
 // Global GeoIP object.
-#if TS_USE_MAXMIND_GEOIP
-#include <GeoIP.h>
 GeoIP* gGI;
-#endif
 
 // Implementation of the ACL base class.
 void
@@ -140,9 +136,7 @@ CountryAcl::add_token(const std::string& str)
   int iso = -1;
 
   Acl::add_token(str);
-#if TS_USE_MAXMIND_GEOIP
   iso = GeoIP_id_by_code(str.c_str());
-#endif
 
   if (iso > 0 && iso < NUM_ISO_CODES) {
     _iso_country_codes[iso] = true;
@@ -215,14 +209,12 @@ CountryAcl::eval(TSRemapRequestInfo *rri, TSHttpTxn txnp) const
     {
       uint32_t ip = ntohl(reinterpret_cast<const struct sockaddr_in *>(addr)->sin_addr.s_addr);
 
-#if TS_USE_MAXMIND_GEOIP
       iso = GeoIP_id_by_ipnum(gGI, ip);
       if (TSIsDebugTagSet(PLUGIN_NAME)) {
         const char* c = GeoIP_country_code_by_ipnum(gGI, ip);
         TSDebug(PLUGIN_NAME, "eval(): IP=%u seems to come from ISO=%d / %s", ip, iso, c);
       }
     }
-#endif
     break;
   case AF_INET6:
     return true;

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/f34c62b4/plugins/experimental/geoip_acl/acl.h
----------------------------------------------------------------------
diff --git a/plugins/experimental/geoip_acl/acl.h b/plugins/experimental/geoip_acl/acl.h
index 08c1a7a..adc91b9 100644
--- a/plugins/experimental/geoip_acl/acl.h
+++ b/plugins/experimental/geoip_acl/acl.h
@@ -27,11 +27,11 @@
 
 #include "lulu.h"
 
-#if TS_USE_MAXMIND_GEOIP
+#if HAVE_GEOIP_H
 #include <GeoIP.h>
-extern GeoIP* gGI;
 #endif
 
+extern GeoIP* gGI;
 
 // See http://www.iso.org/iso/english_country_names_and_code_elements
 // Maxmind allocates 253 country codes,even though there are only 248 according to the above

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/f34c62b4/plugins/experimental/geoip_acl/geoip_acl.cc
----------------------------------------------------------------------
diff --git a/plugins/experimental/geoip_acl/geoip_acl.cc b/plugins/experimental/geoip_acl/geoip_acl.cc
index 3249ea4..87e4d03 100644
--- a/plugins/experimental/geoip_acl/geoip_acl.cc
+++ b/plugins/experimental/geoip_acl/geoip_acl.cc
@@ -47,10 +47,8 @@ TSRemapInit(TSRemapInterface* api_info, char *errbuf, int errbuf_size)
     return TS_ERROR;
   }
 
-#if TS_USE_MAXMIND_GEOIP
   //gGI = GeoIP_new(GEOIP_STANDARD); // This seems to break on threaded apps
   gGI = GeoIP_new(GEOIP_MMAP_CACHE);
-#endif
 
   TSDebug(PLUGIN_NAME, "remap plugin is successfully initialized");
   return TS_SUCCESS;                     /* success */