Merge branch 'collectd-5.7'
authorRuben Kerkhof <ruben@rubenkerkhof.com>
Sat, 17 Dec 2016 17:56:47 +0000 (18:56 +0100)
committerRuben Kerkhof <ruben@rubenkerkhof.com>
Sat, 17 Dec 2016 17:56:47 +0000 (18:56 +0100)
197 files changed:
.gitignore
.travis.yml
Makefile.am
README
build.sh
clean.sh
configure.ac
contrib/README
contrib/docker/50docker-apt-conf [new file with mode: 0644]
contrib/docker/Dockerfile [new file with mode: 0644]
contrib/docker/collectd.conf [new file with mode: 0644]
contrib/docker/collectd.conf.d/sample.conf [new file with mode: 0644]
contrib/docker/rootfs_prefix/.gitignore [new file with mode: 0644]
contrib/docker/rootfs_prefix/Makefile [new file with mode: 0644]
contrib/docker/rootfs_prefix/rootfs_prefix.c [new file with mode: 0644]
contrib/redhat/collectd.spec
docs/README.virt.md [new file with mode: 0644]
src/Makefile.am
src/aggregation.c
src/amqp.c
src/apache.c
src/apple_sensors.c
src/aquaero.c
src/ascent.c
src/battery_statefs.c
src/bind.c
src/ceph.c
src/ceph_test.c
src/collectd-tg.c
src/collectd.conf.in
src/collectd.conf.pod
src/collectdctl.c
src/collectdmon.c
src/cpu.c
src/curl.c
src/curl_json.c
src/curl_xml.c
src/daemon/Makefile.am
src/daemon/collectd.h
src/daemon/common.c
src/daemon/common_test.c
src/daemon/configfile.c
src/daemon/filter_chain.c
src/daemon/filter_chain.h
src/daemon/meta_data.c
src/daemon/meta_data.h
src/daemon/meta_data_test.c
src/daemon/plugin.c
src/daemon/plugin.h
src/daemon/plugin_mock.c
src/daemon/types_list.c
src/daemon/utils_avltree_test.c
src/daemon/utils_cache.c
src/daemon/utils_cache.h
src/daemon/utils_complain.c
src/daemon/utils_complain.h
src/daemon/utils_heap.c
src/daemon/utils_heap.h
src/daemon/utils_heap_test.c
src/daemon/utils_random.c
src/daemon/utils_random.h
src/daemon/utils_subst.c
src/daemon/utils_subst.h
src/daemon/utils_subst_test.c
src/daemon/utils_threshold.h
src/daemon/utils_time.c
src/daemon/utils_time.h
src/daemon/utils_time_test.c
src/dbi.c
src/disk.c
src/email.c
src/ethstat.c
src/exec.c
src/filecount.c
src/fscache.c
src/gmond.c
src/grpc.cc
src/intel_rdt.c
src/ipc.c
src/ipmi.c
src/ipvs.c
src/java.c
src/libcollectdclient/client.c
src/libcollectdclient/collectd/client.h
src/libcollectdclient/collectd/lcc_features.h.in
src/libcollectdclient/collectd/network.h
src/libcollectdclient/collectd/network_buffer.h
src/libcollectdclient/network.c
src/libcollectdclient/network_buffer.c
src/liboconfig/oconfig.c
src/liboconfig/oconfig.h
src/log_logstash.c
src/logfile.c
src/lpar.c
src/lua.c
src/match_empty_counter.c
src/match_hashed.c
src/match_regex.c
src/match_timediff.c
src/match_value.c
src/memcachec.c
src/mic.c
src/modbus.c
src/mqtt.c
src/multimeter.c
src/netapp.c
src/netlink.c
src/network.c
src/nginx.c
src/notify_desktop.c
src/notify_email.c
src/notify_nagios.c
src/ntpd.c
src/numa.c
src/nut.c
src/olsrd.c
src/onewire.c
src/openvpn.c
src/oracle.c
src/perl.c
src/pinba.c
src/ping.c
src/postgresql.c
src/powerdns.c
src/processes.c
src/protocols.c
src/redis.c
src/routeros.c
src/rrdcached.c
src/snmp.c
src/statsd.c
src/swap.c
src/table.c
src/tail.c
src/tail_csv.c
src/target_notification.c
src/target_replace.c
src/target_scale.c
src/target_set.c
src/target_v5upgrade.c
src/tcpconns.c
src/teamspeak2.c
src/ted.c
src/threshold.c
src/tokyotyrant.c
src/unixsock.c
src/utils_cmd_flush.c
src/utils_cmd_flush.h
src/utils_cmd_getthreshold.c
src/utils_cmd_getthreshold.h
src/utils_cmd_getval.c
src/utils_cmd_getval.h
src/utils_cmd_listval.c
src/utils_cmd_listval.h
src/utils_cmd_putnotif.c
src/utils_cmd_putnotif.h
src/utils_cmds.c
src/utils_db_query.c
src/utils_db_query.h
src/utils_dns.c
src/utils_fbhash.c
src/utils_fbhash.h
src/utils_format_graphite.c
src/utils_format_graphite_test.c
src/utils_format_json.c
src/utils_format_kairosdb.c
src/utils_latency.c
src/utils_latency.h
src/utils_latency_test.c
src/utils_lua.c
src/utils_lua.h
src/utils_match.c
src/utils_match.h
src/utils_mount_test.c
src/utils_parse_option.c
src/utils_parse_option.h
src/utils_rrdcreate.c
src/utils_rrdcreate.h
src/utils_tail_match.c
src/utils_tail_match.h
src/uuid.c
src/varnish.c
src/virt.c
src/virt_test.c [new file with mode: 0644]
src/vmem.c
src/vserver.c
src/write_graphite.c
src/write_http.c
src/write_log.c
src/write_mongodb.c
src/write_prometheus.c
src/write_redis.c
src/write_riemann.c
src/write_riemann_threshold.c
src/write_sensu.c
src/write_tsdb.c
src/xmms.c

index 8154d73..6927e51 100644 (file)
@@ -4,6 +4,7 @@ Makefile.in
 /aclocal.m4
 /autom4te.cache
 /autom4te.cache
+/build-aux/
 /compile
 /config.guess
 /config.sub
@@ -12,8 +13,15 @@ Makefile.in
 /install-sh
 /libltdl/
 /ltmain.sh
+/m4/libtool.m4
+/m4/ltargz.m4
+/m4/ltdl.m4
+/m4/lt~obsolete.m4
+/m4/ltoptions.m4
+/m4/ltsugar.m4
+/m4/ltversion.m4
 /missing
-src/config.h.in
+/src/config.h.in
 
 # configure stuff:
 Makefile
index 03d9dde..fc250cb 100644 (file)
@@ -16,12 +16,15 @@ before_install:
       libganglia1-dev
       libgcrypt11-dev
       libglib2.0-dev
+      libgps-dev
       libhiredis-dev
       libi2c-dev
       libldap2-dev
       libltdl-dev
+      liblua5.2-dev
       liblvm2-dev
       libmemcached-dev
+      libmicrohttpd-dev
       libmnl-dev
       libmodbus-dev
       libmosquitto0-dev
@@ -53,4 +56,4 @@ before_install:
       perl
       protobuf-c-compiler
       python-dev
-script: sh build.sh && ./configure --with-python=/usr/bin/python && make distcheck DISTCHECK_CONFIGURE_FLAGS="--with-python=/usr/bin/python"
+script: sh build.sh && ./configure && make distcheck
index 03bdd39..83b0d64 100644 (file)
@@ -1,14 +1,6 @@
-ACLOCAL_AMFLAGS = -I libltdl/m4
+ACLOCAL_AMFLAGS = -I m4
 
-SUBDIRS =
-
-if BUILD_INCLUDED_LTDL
-SUBDIRS += libltdl
-endif
-
-SUBDIRS += proto src bindings .
-
-AM_CPPFLAGS = $(LTDLINCL)
+SUBDIRS = proto src bindings .
 
 EXTRA_DIST = contrib version-gen.sh testwrapper.sh
 
@@ -18,6 +10,5 @@ install-exec-hook:
        $(mkinstalldirs) $(DESTDIR)$(localstatedir)/log
 
 maintainer-clean-local:
-       -rm -f -r libltdl
        -rm -f INSTALL
        -rm -f aclocal.m4
diff --git a/README b/README
index 803fbaa..9e6f9bd 100644 (file)
--- a/README
+++ b/README
@@ -750,10 +750,6 @@ Prerequisites
     Used by the `gps' plugin.
     <http://developer.berlios.de/projects/gpsd/>
 
-  * libhal (optional)
-    If present, the `uuid' plugin will check for UUID from HAL.
-    <http://hal.freedesktop.org/>
-
   * libi2c-dev (optional)
     Used for the plugin `barometer', provides just the i2c-dev.h header file
     for user space i2c development.
@@ -981,7 +977,6 @@ To generate the `configure` script, you'll need the following dependencies:
 - flex
 - bison
 - libtool
-- libtool-ltdl
 - pkg-config
 
 The `build.sh' script takes no arguments.
index 57f3d44..465eff9 100755 (executable)
--- a/build.sh
+++ b/build.sh
@@ -54,6 +54,6 @@ set -x
 
 autoheader \
 && aclocal \
-&& $libtoolize --ltdl --copy --force \
+&& $libtoolize --copy --force \
 && automake --add-missing --copy \
 && autoconf
index 6780cda..ac3c310 100755 (executable)
--- a/clean.sh
+++ b/clean.sh
@@ -15,7 +15,6 @@ true \
 && rm -f configure \
 && rm -f depcomp \
 && rm -f install-sh \
-&& rm -f -r libltdl \
 && rm -f libtool \
 && rm -f ltmain.sh \
 && rm -f Makefile \
index 993e319..d78218b 100644 (file)
@@ -3,34 +3,15 @@ AC_PREREQ([2.60])
 AC_INIT([collectd],[m4_esyscmd(./version-gen.sh)])
 AC_CONFIG_SRCDIR(src/target_set.c)
 AC_CONFIG_HEADERS(src/config.h)
-AC_CONFIG_AUX_DIR([libltdl/config])
+AC_CONFIG_AUX_DIR([build-aux])
+AC_CONFIG_MACRO_DIR([m4])
 
 dnl older automake's default of ARFLAGS=cru is noisy on newer binutils;
 dnl we don't really need the 'u' even in older toolchains.  Then there is
 dnl older libtool, which spelled it AR_FLAGS
 m4_divert_text([DEFAULTS], [: "${ARFLAGS=cr} ${AR_FLAGS=cr}"])
 
-m4_ifdef([LT_PACKAGE_VERSION],
-       # libtool >= 2.2
-       [
-        LT_CONFIG_LTDL_DIR([libltdl])
-        LT_INIT([dlopen])
-        LTDL_INIT([convenience])
-        AC_DEFINE(LIBTOOL_VERSION, 2, [Define to used libtool version.])
-       ]
-,
-       # libtool <= 1.5
-       [
-        AC_LIBLTDL_CONVENIENCE
-        AC_SUBST(LTDLINCL)
-        AC_SUBST(LIBLTDL)
-        AC_LIBTOOL_DLOPEN
-        AC_CONFIG_SUBDIRS(libltdl)
-        AC_DEFINE(LIBTOOL_VERSION, 1, [Define to used libtool version.])
-       ]
-)
-
-AM_CONDITIONAL([BUILD_INCLUDED_LTDL], [test "x$LTDLDEPS" != "x"])
+LT_INIT([dlopen disable-static])
 
 AM_INIT_AUTOMAKE([subdir-objects tar-pax dist-bzip2 no-dist-gzip foreign])
 m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])
@@ -53,10 +34,8 @@ AC_PROG_INSTALL
 AC_PROG_LN_S
 AC_PROG_MAKE_SET
 AM_PROG_CC_C_O
-AM_CONDITIONAL(COMPILER_IS_GCC, test "x$GCC" = "xyes")
+AM_CONDITIONAL([COMPILER_IS_GCC], [test "x$GCC" = "xyes"])
 
-AC_DISABLE_STATIC
-AC_PROG_LIBTOOL
 AC_PROG_LEX
 AC_PROG_YACC
 
@@ -67,78 +46,60 @@ m4_pattern_forbid([^_?PKG_[A-Z_]+$],[*** pkg.m4 missing, please install pkg-conf
 
 PKG_PROG_PKG_CONFIG
 
-AC_CACHE_CHECK([if bison is the parser generator],
-       [collectd_cv_prog_bison],
-       [AS_IF([$YACC --version 2>/dev/null | $EGREP -q '^bison '],
-               [collectd_cv_prog_bison=yes], [collectd_cv_prog_bison=no]
-       )]
+AC_CACHE_CHECK([if Bison is the parser generator],
+  [collectd_cv_prog_bison],
+  [
+    AS_IF([$YACC --version 2>/dev/null | $EGREP -q '^bison '],
+      [collectd_cv_prog_bison=yes],
+      [collectd_cv_prog_bison=no]
+    )
+  ]
 )
 
-if test "x$collectd_cv_prog_bison" = "xno" && test ! -f "${srcdir}/src/liboconfig/parser.c"
-then
-       AC_MSG_ERROR([bison is missing and you do not have ${srcdir}/src/liboconfig/parser.c. Please install bison])
+if test "x$collectd_cv_prog_bison" = "xno" && test ! -f "${srcdir}/src/liboconfig/parser.c"; then
+  AC_MSG_ERROR([bison is missing and you do not have ${srcdir}/src/liboconfig/parser.c. Please install bison])
 fi
 
-AC_ARG_VAR([PROTOC], [path to the protoc binary])
-AC_PATH_PROG([PROTOC], [protoc])
-have_protoc3="no"
-if test "x$PROTOC" != "x"; then
-       AC_MSG_CHECKING([for protoc 3.0.0+])
-       if $PROTOC --version | $EGREP libprotoc.3 >/dev/null; then
-               protoc3="yes (`$PROTOC --version`)"
-               have_protoc3="yes"
-       else
-               protoc3="no (`$PROTOC --version`)"
-       fi
-       AC_MSG_RESULT([$protoc3])
-fi
-AM_CONDITIONAL(HAVE_PROTOC3, test "x$have_protoc3" = "xyes")
+AS_IF([test "x$lt_cv_dlopen" = "xno"],
+  [AC_MSG_ERROR([Your system does not support dlopen])]
+)
 
-AC_ARG_VAR([GRPC_CPP_PLUGIN], [path to the grpc_cpp_plugin binary])
-AC_PATH_PROG([GRPC_CPP_PLUGIN], [grpc_cpp_plugin])
-AM_CONDITIONAL(HAVE_GRPC_CPP, test "x$GRPC_CPP_PLUGIN" != "x")
+AC_SUBST([DLOPEN_LIBS], [$lt_cv_dlopen_libs])
 
-AC_ARG_VAR([PROTOC_C], [path to the protoc-c binary])
-AC_PATH_PROG([PROTOC_C], [protoc-c])
-if test "x$PROTOC_C" = "x"
-then
-  have_protoc_c="no (protoc-c compiler not found)"
-else
-  have_protoc_c="yes"
-fi
 
 AC_MSG_CHECKING([for kernel type ($host_os)])
 case $host_os in
-       *linux*)
-       AC_DEFINE([KERNEL_LINUX], 1, [True if program is to be compiled for a Linux kernel])
-       ac_system="Linux"
-       ;;
-       *solaris*)
-       AC_DEFINE([KERNEL_SOLARIS], 1, [True if program is to be compiled for a Solaris kernel])
-       ac_system="Solaris"
-       ;;
-       *darwin*)
-       AC_DEFINE([KERNEL_DARWIN], 1, [True if program is to be compiled for a Darwin kernel])
-       ac_system="Darwin"
-       ;;
-       *openbsd*)
-       AC_DEFINE([KERNEL_OPENBSD], 1, [True if program is to be compiled for an OpenBSD kernel])
-       ac_system="OpenBSD"
-       ;;
-       *netbsd*)
-       AC_DEFINE([KERNEL_NETBSD], 1, [True if program is to be compiled for a NetBSD kernel])
-       ac_system="NetBSD"
-       ;;
-       *aix*)
-       AC_DEFINE([KERNEL_AIX], 1, [True if program is to be compiled for a AIX kernel])
-       ac_system="AIX"
-       ;;
-       *freebsd*)
-       AC_DEFINE([KERNEL_FREEBSD], 1, [True if program is to be compiled for a FreeBSD kernel])
-       ac_system="FreeBSD"
-       ;;
-       *)
-       ac_system="unknown"
+  *aix*)
+    AC_DEFINE([KERNEL_AIX], [1], [True if program is to be compiled for a AIX kernel])
+    ac_system="AIX"
+    ;;
+  *darwin*)
+    AC_DEFINE([KERNEL_DARWIN], [1], [True if program is to be compiled for a Darwin kernel])
+    ac_system="Darwin"
+    ;;
+  *freebsd*)
+    AC_DEFINE([KERNEL_FREEBSD], [1], [True if program is to be compiled for a FreeBSD kernel])
+    ac_system="FreeBSD"
+    ;;
+  *linux*)
+    AC_DEFINE([KERNEL_LINUX], [1], [True if program is to be compiled for a Linux kernel])
+    ac_system="Linux"
+    ;;
+  *netbsd*)
+    AC_DEFINE([KERNEL_NETBSD], [1], [True if program is to be compiled for a NetBSD kernel])
+    ac_system="NetBSD"
+    ;;
+  *openbsd*)
+    AC_DEFINE([KERNEL_OPENBSD], [1], [True if program is to be compiled for an OpenBSD kernel])
+    ac_system="OpenBSD"
+    ;;
+  *solaris*)
+    AC_DEFINE([KERNEL_SOLARIS], [1], [True if program is to be compiled for a Solaris kernel])
+    ac_system="Solaris"
+    ;;
+  *)
+    ac_system="unknown"
+    ;;
 esac
 AC_MSG_RESULT([$ac_system])
 
@@ -149,77 +110,55 @@ AM_CONDITIONAL([BUILD_LINUX], [test "x$ac_system" = "xLinux"])
 AM_CONDITIONAL([BUILD_OPENBSD], [test "x$ac_system" = "xOpenBSD"])
 AM_CONDITIONAL([BUILD_SOLARIS], [test "x$ac_system" = "xSolaris"])
 
-if test "x$ac_system" = "xLinux"
-then
-       AC_ARG_VAR([KERNEL_DIR], [path to Linux kernel sources])
-       if test -z "$KERNEL_DIR"
-       then
-               KERNEL_DIR="/lib/modules/`uname -r`/source"
-       fi
+if test "x$ac_system" = "xLinux"; then
+  AC_ARG_VAR([KERNEL_DIR], [path to Linux kernel sources])
+  if test "x$KERNEL_DIR" = "x"; then
+    KERNEL_DIR="/lib/modules/`uname -r`/source"
+  fi
+  KERNEL_CFLAGS="-I$KERNEL_DIR/include"
+  AC_SUBST([KERNEL_CFLAGS])
+fi
+
+if test "x$ac_system" = "xSolaris"; then
+  AC_DEFINE([_POSIX_PTHREAD_SEMANTICS], [1], [Define to enforce POSIX thread semantics under Solaris.])
+  AC_DEFINE([_REENTRANT], [1], [Define to enable reentrancy interfaces.])
 
-       KERNEL_CFLAGS="-I$KERNEL_DIR/include"
-       AC_SUBST(KERNEL_CFLAGS)
+  AC_MSG_CHECKING([whether compiler builds 64bit binaries])
+  AC_COMPILE_IFELSE(
+    [
+      AC_LANG_PROGRAM(
+        [
+          #ifndef _LP64
+          # error "Compiler not in 64bit mode."
+          #endif
+        ]
+      )
+    ],
+    [AC_MSG_RESULT([yes])],
+    [
+      AC_MSG_RESULT([no])
+      AC_MSG_NOTICE([Solaris detected. Please consider building a 64-bit binary.])
+    ]
+  )
 fi
 
-if test "x$ac_system" = "xSolaris"
-then
-       AC_DEFINE(_POSIX_PTHREAD_SEMANTICS, 1, [Define to enforce POSIX thread semantics under Solaris.])
-       AC_DEFINE(_REENTRANT,               1, [Define to enable reentrancy interfaces.])
-
-       AC_MSG_CHECKING([whether compiler builds 64bit binaries])
-       AC_COMPILE_IFELSE([AC_LANG_PROGRAM([
-                          #ifndef _LP64
-                          # error "Compiler not in 64bit mode."
-                          #endif
-                          ])],
-                          [AC_MSG_RESULT([yes])],
-                          [
-                           AC_MSG_RESULT([no])
-                           AC_MSG_NOTICE([Solaris detected. Please consider building a 64-bit binary.])
-                          ])
-fi
-
-if test "x$ac_system" = "xAIX"
-then
-       AC_DEFINE(_THREAD_SAFE_ERRNO, 1, [Define to use the thread-safe version of errno under AIX.])
+if test "x$ac_system" = "xAIX"; then
+  AC_DEFINE([_THREAD_SAFE_ERRNO], [1], [Define to use the thread-safe version of errno under AIX.])
 fi
 
 # Where to install .pc files.
 pkgconfigdir="${libdir}/pkgconfig"
-AC_SUBST(pkgconfigdir)
-
-# Check for standards compliance mode
-AC_ARG_ENABLE(standards,
-             AS_HELP_STRING([--enable-standards], [Enable standards compliance mode]),
-             [enable_standards="$enableval"],
-             [enable_standards="no"])
-if test "x$enable_standards" = "xyes"
-then
-       AC_DEFINE(_ISOC99_SOURCE,        1, [Define to enforce ISO C99 compliance.])
-       AC_DEFINE(_POSIX_C_SOURCE, 200809L, [Define to enforce POSIX.1-2008 compliance.])
-       AC_DEFINE(_XOPEN_SOURCE,       700, [Define to enforce X/Open 7 (XSI) compliance.])
-       AC_DEFINE(_REENTRANT,            1, [Define to enable reentrancy interfaces.])
-       if test "x$GCC" = "xyes"
-       then
-               CFLAGS="$CFLAGS -std=c99"
-       fi
-fi
-AM_CONDITIONAL(BUILD_FEATURE_STANDARDS, test "x$enable_standards" = "xyes")
+AC_SUBST([pkgconfigdir])
 
 #
 # Checks for header files.
 #
-AC_HEADER_STDC
 AC_HEADER_SYS_WAIT
 AC_HEADER_DIRENT
-AC_HEADER_STDBOOL
 
-AC_CHECK_HEADERS([ \
+AC_CHECK_HEADERS_ONCE([ \
   arpa/inet.h \
-  assert.h \
-  ctype.h \
   endian.h \
-  errno.h \
   fcntl.h \
   fnmatch.h \
   fs_info.h \
@@ -228,9 +167,6 @@ AC_CHECK_HEADERS([ \
   kstat.h \
   kvm.h \
   libgen.h \
-  limits.h \
-  locale.h \
-  math.h \
   mntent.h \
   mnttab.h \
   netdb.h \
@@ -239,9 +175,6 @@ AC_CHECK_HEADERS([ \
   pthread_np.h \
   pwd.h \
   regex.h \
-  signal.h \
-  stdarg.h \
-  stdio.h \
   sys/fs_types.h \
   sys/fstyp.h \
   sys/ioctl.h \
@@ -260,450 +193,461 @@ AC_CHECK_HEADERS([ \
   sys/vfstab.h \
   sys/vmmeter.h \
   syslog.h \
-  wordexp.h \
+  wordexp.h
 ])
 
-# For entropy plugin on newer NetBSD
-AC_CHECK_HEADERS(sys/rndio.h, [], [],
-[#if HAVE_SYS_TYPES_H
-# include <sys/types.h>
-#endif
-#if HAVE_SYS_IOCTL_H
-# include <sys/ioctl.h>
-#endif
-#if HAVE_SYS_PARAM_H
-# include <sys/param.h>
-#endif
-])
+if test "x$ac_system" = "xNetBSD"; then
+  # For entropy plugin on newer NetBSD
+  AC_CHECK_HEADERS([sys/rndio.h], [], [],
+    [[
+      #if HAVE_SYS_TYPES_H
+      # include <sys/types.h>
+      #endif
+      #if HAVE_SYS_IOCTL_H
+      # include <sys/ioctl.h>
+      #endif
+      #if HAVE_SYS_PARAM_H
+      # include <sys/param.h>
+      #endif
+    ]]
+  )
+fi
 
 # For ping library
-AC_CHECK_HEADERS(netinet/in_systm.h, [], [],
-[#if HAVE_STDINT_H
-# include <stdint.h>
-#endif
-#if HAVE_SYS_TYPES_H
-# include <sys/types.h>
-#endif
-])
-AC_CHECK_HEADERS(netinet/in.h, [], [],
-[#if HAVE_STDINT_H
-# include <stdint.h>
-#endif
-#if HAVE_SYS_TYPES_H
-# include <sys/types.h>
-#endif
-#if HAVE_NETINET_IN_SYSTM_H
-# include <netinet/in_systm.h>
-#endif
-])
-AC_CHECK_HEADERS(netinet/ip.h, [], [],
-[#if HAVE_STDINT_H
-# include <stdint.h>
-#endif
-#if HAVE_SYS_TYPES_H
-# include <sys/types.h>
-#endif
-#if HAVE_NETINET_IN_SYSTM_H
-# include <netinet/in_systm.h>
-#endif
-#if HAVE_NETINET_IN_H
-# include <netinet/in.h>
-#endif
-])
-AC_CHECK_HEADERS(netinet/ip_icmp.h, [], [],
-[#if HAVE_STDINT_H
-# include <stdint.h>
-#endif
-#if HAVE_SYS_TYPES_H
-# include <sys/types.h>
-#endif
-#if HAVE_NETINET_IN_SYSTM_H
-# include <netinet/in_systm.h>
-#endif
-#if HAVE_NETINET_IN_H
-# include <netinet/in.h>
-#endif
-#if HAVE_NETINET_IP_H
-# include <netinet/ip.h>
-#endif
-])
-AC_CHECK_HEADERS(netinet/ip_var.h, [], [],
-[#if HAVE_STDINT_H
-# include <stdint.h>
-#endif
-#if HAVE_SYS_TYPES_H
-# include <sys/types.h>
-#endif
-#if HAVE_NETINET_IN_SYSTM_H
-# include <netinet/in_systm.h>
-#endif
-#if HAVE_NETINET_IN_H
-# include <netinet/in.h>
-#endif
-#if HAVE_NETINET_IP_H
-# include <netinet/ip.h>
-#endif
-])
-AC_CHECK_HEADERS(netinet/ip6.h, [], [],
-[#if HAVE_STDINT_H
-# include <stdint.h>
-#endif
-#if HAVE_SYS_TYPES_H
-# include <sys/types.h>
-#endif
-#if HAVE_NETINET_IN_SYSTM_H
-# include <netinet/in_systm.h>
-#endif
-#if HAVE_NETINET_IN_H
-# include <netinet/in.h>
-#endif
-])
-AC_CHECK_HEADERS(netinet/icmp6.h, [], [],
-[#if HAVE_STDINT_H
-# include <stdint.h>
-#endif
-#if HAVE_SYS_TYPES_H
-# include <sys/types.h>
-#endif
-#if HAVE_NETINET_IN_SYSTM_H
-# include <netinet/in_systm.h>
-#endif
-#if HAVE_NETINET_IN_H
-# include <netinet/in.h>
-#endif
-#if HAVE_NETINET_IP6_H
-# include <netinet/ip6.h>
-#endif
-])
-AC_CHECK_HEADERS(netinet/tcp.h, [], [],
-[#if HAVE_STDINT_H
-# include <stdint.h>
-#endif
-#if HAVE_SYS_TYPES_H
-# include <sys/types.h>
-#endif
-#if HAVE_NETINET_IN_SYSTM_H
-# include <netinet/in_systm.h>
-#endif
-#if HAVE_NETINET_IN_H
-# include <netinet/in.h>
-#endif
-#if HAVE_NETINET_IP_H
-# include <netinet/ip.h>
-#endif
-])
-AC_CHECK_HEADERS(netinet/udp.h, [], [],
-[#if HAVE_STDINT_H
-# include <stdint.h>
-#endif
-#if HAVE_SYS_TYPES_H
-# include <sys/types.h>
-#endif
-#if HAVE_NETINET_IN_SYSTM_H
-# include <netinet/in_systm.h>
-#endif
-#if HAVE_NETINET_IN_H
-# include <netinet/in.h>
-#endif
-#if HAVE_NETINET_IP_H
-# include <netinet/ip.h>
-#endif
-])
-
-have_ip6_ext="no"
-AC_CHECK_TYPES([struct ip6_ext], [have_ip6_ext="yes"], [have_ip6_ext="no"],
-[#if HAVE_STDINT_H
-# include <stdint.h>
-#endif
-#if HAVE_SYS_TYPES_H
-# include <sys/types.h>
-#endif
-#if HAVE_NETINET_IN_SYSTM_H
-# include <netinet/in_systm.h>
-#endif
-#if HAVE_NETINET_IN_H
-# include <netinet/in.h>
-#endif
-#if HAVE_NETINET_IP6_H
-# include <netinet/ip6.h>
-#endif
-])
+AC_CHECK_HEADERS([netinet/in_systm.h], [], [],
+  [[
+    #include <stdint.h>
+    #if HAVE_SYS_TYPES_H
+    # include <sys/types.h>
+    #endif
+  ]]
+)
 
-if test "x$have_ip6_ext" = "xno"; then
-       SAVE_CFLAGS="$CFLAGS"
-       CFLAGS="$CFLAGS -DSOLARIS2=8"
-
-       AC_CHECK_TYPES([struct ip6_ext],
-                      [have_ip6_ext="yes, with -DSOLARIS2=8"],
-                      [have_ip6_ext="no"],
-[#if HAVE_STDINT_H
-# include <stdint.h>
-#endif
-#if HAVE_SYS_TYPES_H
-# include <sys/types.h>
-#endif
-#if HAVE_NETINET_IN_SYSTM_H
-# include <netinet/in_systm.h>
-#endif
-#if HAVE_NETINET_IN_H
-# include <netinet/in.h>
-#endif
-#if HAVE_NETINET_IP6_H
-# include <netinet/ip6.h>
-#endif
-])
+AC_CHECK_HEADERS([netinet/in.h], [], [],
+  [[
+    #include <stdint.h>
+    #if HAVE_SYS_TYPES_H
+    # include <sys/types.h>
+    #endif
+    #if HAVE_NETINET_IN_SYSTM_H
+    # include <netinet/in_systm.h>
+    #endif
+  ]]
+)
 
-       if test "x$have_ip6_ext" = "xno"; then
-               CFLAGS="$SAVE_CFLAGS"
-       fi
-fi
+AC_CHECK_HEADERS([netinet/ip.h], [], [],
+  [[
+    #include <stdint.h>
+    #if HAVE_SYS_TYPES_H
+    # include <sys/types.h>
+    #endif
+    #if HAVE_NETINET_IN_SYSTM_H
+    # include <netinet/in_systm.h>
+    #endif
+    #if HAVE_NETINET_IN_H
+    # include <netinet/in.h>
+    #endif
+  ]]
+)
 
-# For cpu modules
-AC_CHECK_HEADERS(sys/dkstat.h)
-if test "x$ac_system" = "xDarwin"
-then
-       AC_CHECK_HEADERS(mach/mach_init.h mach/host_priv.h mach/mach_error.h mach/mach_host.h mach/mach_port.h mach/mach_types.h mach/message.h mach/processor_set.h mach/processor.h mach/processor_info.h mach/task.h mach/thread_act.h mach/vm_region.h mach/vm_map.h mach/vm_prot.h mach/vm_statistics.h mach/kern_return.h)
-       AC_CHECK_HEADERS(CoreFoundation/CoreFoundation.h IOKit/IOKitLib.h IOKit/IOTypes.h IOKit/ps/IOPSKeys.h IOKit/IOBSD.h IOKit/storage/IOBlockStorageDriver.h)
-       # For the battery plugin
-       AC_CHECK_HEADERS(IOKit/ps/IOPowerSources.h, [], [],
-[
-#if HAVE_IOKIT_IOKITLIB_H
-#  include <IOKit/IOKitLib.h>
-#endif
-#if HAVE_IOKIT_IOTYPES_H
-#  include <IOKit/IOTypes.h>
-#endif
-])
+AC_CHECK_HEADERS([netinet/ip_icmp.h], [], [],
+  [[
+    #include <stdint.h>
+    #if HAVE_SYS_TYPES_H
+    # include <sys/types.h>
+    #endif
+    #if HAVE_NETINET_IN_SYSTM_H
+    # include <netinet/in_systm.h>
+    #endif
+    #if HAVE_NETINET_IN_H
+    # include <netinet/in.h>
+    #endif
+    #if HAVE_NETINET_IP_H
+    # include <netinet/ip.h>
+    #endif
+  ]]
+)
 
-fi
+AC_CHECK_HEADERS([netinet/ip_var.h], [], [],
+  [[
+    #include <stdint.h>
+    #if HAVE_SYS_TYPES_H
+    # include <sys/types.h>
+    #endif
+    #if HAVE_NETINET_IN_SYSTM_H
+    # include <netinet/in_systm.h>
+    #endif
+    #if HAVE_NETINET_IN_H
+    # include <netinet/in.h>
+    #endif
+    #if HAVE_NETINET_IP_H
+    # include <netinet/ip.h>
+    #endif
+  ]]
+)
 
-AC_CHECK_HEADERS(sys/sysctl.h, [], [],
-[
-#if HAVE_SYS_TYPES_H
-#  include <sys/types.h>
-#endif
-#if HAVE_SYS_PARAM_H
-# include <sys/param.h>
-#endif
-])
+AC_CHECK_HEADERS([netinet/ip6.h], [], [],
+  [[
+    #include <stdint.h>
+    #if HAVE_SYS_TYPES_H
+    # include <sys/types.h>
+    #endif
+    #if HAVE_NETINET_IN_SYSTM_H
+    # include <netinet/in_systm.h>
+    #endif
+    #if HAVE_NETINET_IN_H
+    # include <netinet/in.h>
+    #endif
+  ]]
+)
 
-AC_MSG_CHECKING([for sysctl kern.cp_times])
-if test -x /sbin/sysctl
-then
-       /sbin/sysctl kern.cp_times >/dev/null 2>&1
-       if test $? -eq 0
-       then
-               AC_MSG_RESULT([yes])
-               AC_DEFINE(HAVE_SYSCTL_KERN_CP_TIMES, 1,
-               [Define if sysctl supports kern.cp_times])
-       else
-               AC_MSG_RESULT([no])
-       fi
-else
-       AC_MSG_RESULT([no])
-fi
+AC_CHECK_HEADERS([netinet/icmp6.h], [], [],
+  [[
+    #include <stdint.h>
+    #if HAVE_SYS_TYPES_H
+    # include <sys/types.h>
+    #endif
+    #if HAVE_NETINET_IN_SYSTM_H
+    # include <netinet/in_systm.h>
+    #endif
+    #if HAVE_NETINET_IN_H
+    # include <netinet/in.h>
+    #endif
+    #if HAVE_NETINET_IP6_H
+    # include <netinet/ip6.h>
+    #endif
+  ]]
+)
 
-AC_MSG_CHECKING([for sysctl kern.cp_time])
-if test -x /sbin/sysctl
-then
-       /sbin/sysctl kern.cp_time >/dev/null 2>&1
-       if test $? -eq 0
-       then
-               AC_MSG_RESULT([yes])
-               AC_DEFINE(HAVE_SYSCTL_KERN_CP_TIME, 1,
-                       [Define if sysctl supports kern.cp_time])
-       else
-               AC_MSG_RESULT([no])
-       fi
-else
-       AC_MSG_RESULT([no])
-fi
+AC_CHECK_HEADERS([netinet/tcp.h], [], [],
+  [[
+    #include <stdint.h>
+    #if HAVE_SYS_TYPES_H
+    # include <sys/types.h>
+    #endif
+    #if HAVE_NETINET_IN_SYSTM_H
+    # include <netinet/in_systm.h>
+    #endif
+    #if HAVE_NETINET_IN_H
+    # include <netinet/in.h>
+    #endif
+    #if HAVE_NETINET_IP_H
+    # include <netinet/ip.h>
+    #endif
+  ]]
+)
 
-# For hddtemp module
-AC_CHECK_HEADERS(linux/major.h)
+AC_CHECK_HEADERS([netinet/udp.h], [], [],
+  [[
+    #include <stdint.h>
+    #if HAVE_SYS_TYPES_H
+    # include <sys/types.h>
+    #endif
+    #if HAVE_NETINET_IN_SYSTM_H
+    # include <netinet/in_systm.h>
+    #endif
+    #if HAVE_NETINET_IN_H
+    # include <netinet/in.h>
+    #endif
+    #if HAVE_NETINET_IP_H
+    # include <netinet/ip.h>
+    #endif
+  ]]
+)
 
-# For md module (Linux only)
-if test "x$ac_system" = "xLinux"
-then
-       AC_CHECK_HEADERS(linux/raid/md_u.h,
-                        [have_linux_raid_md_u_h="yes"],
-                        [have_linux_raid_md_u_h="no"],
-[
-#include <sys/ioctl.h>
-#include <linux/major.h>
-#include <linux/types.h>
-])
-       AC_CHECK_HEADERS([sys/sysmacros.h])
-else
-       have_linux_raid_md_u_h="no"
-fi
+# For cpu modules
+AC_CHECK_HEADERS([sys/dkstat.h])
+if test "x$ac_system" = "xDarwin"; then
+  AC_CHECK_HEADERS(
+    [[ \
+      mach/mach_init.h \
+      mach/host_priv.h \
+      mach/mach_error.h \
+      mach/mach_host.h \
+      mach/mach_port.h \
+      mach/mach_types.h \
+      mach/message.h \
+      mach/processor_set.h \
+      mach/processor.h \
+      mach/processor_info.h \
+      mach/task.h \
+      mach/thread_act.h \
+      mach/vm_region.h \
+      mach/vm_map.h \
+      mach/vm_prot.h \
+      mach/vm_statistics.h \
+      mach/kern_return.h \
+      CoreFoundation/CoreFoundation.h \
+      IOKit/IOKitLib.h \
+      IOKit/IOTypes.h \
+      IOKit/ps/IOPSKeys.h \
+      IOKit/IOBSD.h \
+      IOKit/storage/IOBlockStorageDriver.h
+    ]]
+  )
 
-# For the wireless module
-have_linux_wireless_h="no"
-if test "x$ac_system" = "xLinux"
-then
-  AC_CHECK_HEADERS(linux/wireless.h,
-                  [have_linux_wireless_h="yes"],
-                  [have_linux_wireless_h="no"],
-[
-#include <dirent.h>
-#include <sys/ioctl.h>
-#include <sys/socket.h>
-])
+  # For the battery plugin
+  AC_CHECK_HEADERS([IOKit/ps/IOPowerSources.h], [], [],
+    [[
+      #if HAVE_IOKIT_IOKITLIB_H
+      #  include <IOKit/IOKitLib.h>
+      #endif
+      #if HAVE_IOKIT_IOTYPES_H
+      #  include <IOKit/IOTypes.h>
+      #endif
+    ]]
+  )
 fi
 
-# For the swap module
-have_sys_swap_h="yes"
-AC_CHECK_HEADERS(sys/swap.h vm/anon.h, [], [have_sys_swap_h="no"],
-[
-#undef _FILE_OFFSET_BITS
-#undef _LARGEFILE64_SOURCE
-#if HAVE_SYS_TYPES_H
-#  include <sys/types.h>
-#endif
-#if HAVE_SYS_PARAM_H
-# include <sys/param.h>
-#endif
-])
-
-# For load module
-# For the processes plugin
-# For users module
-AC_CHECK_HEADERS(sys/loadavg.h linux/config.h utmp.h utmpx.h)
+AC_CHECK_HEADERS([sys/sysctl.h], [], [],
+  [[
+    #if HAVE_SYS_TYPES_H
+    #  include <sys/types.h>
+    #endif
+    #if HAVE_SYS_PARAM_H
+    # include <sys/param.h>
+    #endif
+  ]]
+)
 
 # For interface plugin
-AC_CHECK_HEADERS(ifaddrs.h)
-AC_CHECK_HEADERS(net/if.h, [], [],
-[
-#if HAVE_SYS_TYPES_H
-#  include <sys/types.h>
-#endif
-#if HAVE_SYS_SOCKET_H
-#  include <sys/socket.h>
-#endif
-])
-AC_CHECK_HEADERS(linux/if.h, [], [],
-[
-#if HAVE_SYS_TYPES_H
-#  include <sys/types.h>
-#endif
-#if HAVE_SYS_SOCKET_H
-#  include <sys/socket.h>
-#endif
-])
-AC_CHECK_HEADERS(linux/inet_diag.h, [], [],
-[
-#if HAVE_SYS_TYPES_H
-#  include <sys/types.h>
-#endif
-#if HAVE_SYS_SOCKET_H
-#  include <sys/socket.h>
-#endif
-#if HAVE_LINUX_INET_DIAG_H
-# include <linux/inet_diag.h>
-#endif
-])
-AC_CHECK_HEADERS(linux/netdevice.h, [], [],
-[
-#if HAVE_SYS_TYPES_H
-#  include <sys/types.h>
-#endif
-#if HAVE_SYS_SOCKET_H
-#  include <sys/socket.h>
-#endif
-#if HAVE_LINUX_IF_H
-# include <linux/if.h>
-#endif
-])
+AC_CHECK_HEADERS([ifaddrs.h])
+AC_CHECK_HEADERS([net/if.h], [], [],
+  [[
+    #if HAVE_SYS_TYPES_H
+    #  include <sys/types.h>
+    #endif
+    #if HAVE_SYS_SOCKET_H
+    #  include <sys/socket.h>
+    #endif
+  ]]
+)
+
+if test "x$ac_system" = "xLinux"; then
+  # For hddtemp module
+  AC_CHECK_HEADERS([linux/major.h])
+
+  # For md module (Linux only)
+  AC_CHECK_HEADERS([linux/raid/md_u.h],
+    [have_linux_raid_md_u_h="yes"],
+    [have_linux_raid_md_u_h="no"],
+    [[
+      #include <sys/ioctl.h>
+      #include <linux/major.h>
+      #include <linux/types.h>
+    ]]
+  )
+  AC_CHECK_HEADERS([sys/sysmacros.h])
+
+  AC_CHECK_HEADERS([linux/wireless.h],
+    [have_linux_wireless_h="yes"],
+    [have_linux_wireless_h="no"],
+    [[
+      #include <dirent.h>
+      #include <sys/ioctl.h>
+      #include <sys/socket.h>
+    ]]
+  )
 
-# For ethstat module
-AC_CHECK_HEADERS(linux/sockios.h,
+  AC_CHECK_HEADERS([linux/if.h], [], [],
+    [[
+      #if HAVE_SYS_TYPES_H
+      #  include <sys/types.h>
+      #endif
+      #if HAVE_SYS_SOCKET_H
+      #  include <sys/socket.h>
+      #endif
+    ]]
+  )
+  
+  AC_CHECK_HEADERS([linux/inet_diag.h], [], [],
+    [[
+      #if HAVE_SYS_TYPES_H
+      #  include <sys/types.h>
+      #endif
+      #if HAVE_SYS_SOCKET_H
+      #  include <sys/socket.h>
+      #endif
+    ]]
+  )
+  
+  AC_CHECK_HEADERS([linux/netdevice.h], [], [],
+    [[
+      #if HAVE_SYS_TYPES_H
+      #  include <sys/types.h>
+      #endif
+      #if HAVE_SYS_SOCKET_H
+      #  include <sys/socket.h>
+      #endif
+      #if HAVE_LINUX_IF_H
+      # include <linux/if.h>
+      #endif
+    ]]
+  )
+  
+  # For ethstat module
+  AC_CHECK_HEADERS([linux/sockios.h],
     [have_linux_sockios_h="yes"],
     [have_linux_sockios_h="no"],
-    [
-#if HAVE_SYS_IOCTL_H
-# include <sys/ioctl.h>
-#endif
-#if HAVE_NET_IF_H
-# include <net/if.h>
-#endif
-    ])
-AC_CHECK_HEADERS(linux/ethtool.h,
+    [[
+      #if HAVE_SYS_IOCTL_H
+      # include <sys/ioctl.h>
+      #endif
+      #if HAVE_NET_IF_H
+      # include <net/if.h>
+      #endif
+    ]]
+  )
+  
+  AC_CHECK_HEADERS([linux/ethtool.h],
     [have_linux_ethtool_h="yes"],
     [have_linux_ethtool_h="no"],
-    [
-#if HAVE_SYS_IOCTL_H
-# include <sys/ioctl.h>
-#endif
-#if HAVE_NET_IF_H
-# include <net/if.h>
-#endif
-#if HAVE_LINUX_SOCKIOS_H
-# include <linux/sockios.h>
-#endif
-    ])
-
-# For ipvs module
-have_linux_ip_vs_h="no"
-have_net_ip_vs_h="no"
-have_ip_vs_h="no"
-ip_vs_h_needs_kernel_cflags="no"
-if test "x$ac_system" = "xLinux"
-then
-       AC_CHECK_HEADERS(linux/ip_vs.h, [have_linux_ip_vs_h="yes"])
-       AC_CHECK_HEADERS(net/ip_vs.h, [have_net_ip_vs_h="yes"])
-       AC_CHECK_HEADERS(ip_vs.h, [have_ip_vs_h="yes"])
+    [[
+      #if HAVE_SYS_IOCTL_H
+      # include <sys/ioctl.h>
+      #endif
+      #if HAVE_NET_IF_H
+      # include <net/if.h>
+      #endif
+      #if HAVE_LINUX_SOCKIOS_H
+      # include <linux/sockios.h>
+      #endif
+    ]]
+  )
 
-       if test "x$have_linux_ip_vs_h$have_net_ip_vs_h$have_ip_vs_h" = "xnonono" && test -d "$KERNEL_DIR"
-       then
-               SAVE_CFLAGS="$CFLAGS"
-               CFLAGS="$CFLAGS $KERNEL_CFLAGS"
+  # For ipvs module
+  AC_CHECK_HEADERS([linux/ip_vs.h], [have_linux_ip_vs_h="yes"], [have_linux_ip_vs="no"])
+  AC_CHECK_HEADERS([net/ip_vs.h], [have_net_ip_vs_h="yes"], [have_net_ip_vs_h="no"])
+  AC_CHECK_HEADERS([ip_vs.h], [have_ip_vs_h="yes"], [have_ip_vs_h="no"])
+
+  ip_vs_h_needs_kernel_cflags="no"
+  
+  if test "x$have_linux_ip_vs_h$have_net_ip_vs_h$have_ip_vs_h" = "xnonono" && test -d "$KERNEL_DIR"; then
+    SAVE_CFLAGS="$CFLAGS"
+    CFLAGS="$CFLAGS $KERNEL_CFLAGS"
+    
+    AC_MSG_NOTICE([Did not find ip_vs.h. Trying again using headers from $KERNEL_DIR.])
+    
+    AC_CHECK_HEADERS([linux/ip_vs.h], [have_linux_ip_vs_h="yes"])
+    AC_CHECK_HEADERS([net/ip_vs.h], [have_net_ip_vs_h="yes"])
+    AC_CHECK_HEADERS([ip_vs.h], [have_ip_vs_h="yes"])
+    
+    if test "x$have_linux_ip_vs_h" = "xyes" || test "x$have_net_ip_vs_h" = "xyes" || test "x$have_ip_vs_h" = "xyes"; then
+      ip_vs_h_needs_kernel_cflags="yes"
+    fi
+    
+    CFLAGS="$SAVE_CFLAGS"
+  fi
 
-               AC_MSG_NOTICE([Did not find ip_vs.h. Trying again using headers from $KERNEL_DIR.])
+  # For the email plugin
+  AC_CHECK_HEADERS([linux/un.h], [], [],
+    [[
+      #if HAVE_SYS_SOCKET_H
+      #  include <sys/socket.h>
+      #endif
+    ]]
+  )
+  # For the turbostat plugin
+  AC_CHECK_HEADERS([asm/msr-index.h],
+    [have_asm_msrindex_h="yes"],
+    [have_asm_msrindex_h="no"]
+  )
+  
+  if test "x$have_asm_msrindex_h" = "xyes"; then
+    AC_CACHE_CHECK([whether asm/msr-index.h has MSR_PKG_C10_RESIDENCY],
+      [c_cv_have_usable_asm_msrindex_h],
+      [
+        AC_COMPILE_IFELSE(
+          [
+            AC_LANG_PROGRAM(
+              [[#include<asm/msr-index.h>]],
+              [[
+                int y = MSR_PKG_C10_RESIDENCY;
+                return(y);
+              ]]
+            )
+          ],
+          [c_cv_have_usable_asm_msrindex_h="yes"],
+          [c_cv_have_usable_asm_msrindex_h="no"],
+        )
+      ]
+    )
+  fi
+  
+  AC_CHECK_HEADERS([cpuid.h],
+    [have_cpuid_h="yes"],
+    [have_cpuid_h="no (cpuid.h not found)"]
+  )
+  
+  AC_CHECK_HEADERS([sys/capability.h],
+    [have_capability="yes"],
+    [have_capability="no (<sys/capability.h> not found)"]
+  )
 
-               AC_CHECK_HEADERS(linux/ip_vs.h, [have_linux_ip_vs_h="yes"])
-               AC_CHECK_HEADERS(net/ip_vs.h, [have_net_ip_vs_h="yes"])
-               AC_CHECK_HEADERS(ip_vs.h, [have_ip_vs_h="yes"])
+  if test "x$have_capability" = "xyes"; then
+    AC_CHECK_LIB([cap], [cap_get_bound],
+      [have_capability="yes"],
+      [have_capability="no (cap_get_bound() not found)"]
+    )
+  fi
 
-               if test "x$have_linux_ip_vs_h" = "xyes" || test "x$have_net_ip_vs_h" = "xyes" || test "x$have_ip_vs_h" = "xyes"
-               then
-                       ip_vs_h_needs_kernel_cflags="yes"
-               fi
+  if test "x$have_capability" = "xyes"; then
+    AC_DEFINE([HAVE_CAPABILITY], [1], [Define to 1 if you have cap_get_bound() (-lcap).])
+  fi
 
-               CFLAGS="$SAVE_CFLAGS"
-       fi
+else
+  have_linux_raid_md_u_h="no"
+  have_linux_wireless_h="no"
 fi
-AM_CONDITIONAL(IP_VS_H_NEEDS_KERNEL_CFLAGS, test "x$ip_vs_h_needs_kernel_cflags" = "xyes")
+
+AM_CONDITIONAL([IP_VS_H_NEEDS_KERNEL_CFLAGS], [test "x$ip_vs_h_needs_kernel_cflags" = "xyes"])
+AM_CONDITIONAL([BUILD_WITH_CAPABILITY], [test "x$have_capability" = "xyes"])
+
+# For the swap module
+have_sys_swap_h="yes"
+AC_CHECK_HEADERS([sys/swap.h vm/anon.h],
+  [],
+  [have_sys_swap_h="no"],
+  [[
+    #undef _FILE_OFFSET_BITS
+    #undef _LARGEFILE64_SOURCE
+    #if HAVE_SYS_TYPES_H
+    #  include <sys/types.h>
+    #endif
+    #if HAVE_SYS_PARAM_H
+    # include <sys/param.h>
+    #endif
+  ]]
+)
+
+# For load module
+# For the processes plugin
+# For users module
+AC_CHECK_HEADERS([sys/loadavg.h linux/config.h utmp.h utmpx.h])
 
 # For quota module
-AC_CHECK_HEADERS(sys/ucred.h, [], [],
-[
-#if HAVE_SYS_TYPES_H
-#  include <sys/types.h>
-#endif
-#if HAVE_SYS_PARAM_H
-# include <sys/param.h>
-#endif
-])
+AC_CHECK_HEADERS([sys/ucred.h], [], [],
+  [[
+    #if HAVE_SYS_TYPES_H
+    #  include <sys/types.h>
+    #endif
+    #if HAVE_SYS_PARAM_H
+    # include <sys/param.h>
+    #endif
+  ]]
+)
 
 # For mount interface
-AC_CHECK_HEADERS(sys/mount.h, [], [],
-[
-#if HAVE_SYS_TYPES_H
-#  include <sys/types.h>
-#endif
-#if HAVE_SYS_PARAM_H
-# include <sys/param.h>
-#endif
-])
-
-# For the email plugin
-AC_CHECK_HEADERS(linux/un.h, [], [],
-[
-#if HAVE_SYS_SOCKET_H
-#      include <sys/socket.h>
-#endif
-])
+AC_CHECK_HEADERS([sys/mount.h], [], [],
+  [[
+    #if HAVE_SYS_TYPES_H
+    #  include <sys/types.h>
+    #endif
+    #if HAVE_SYS_PARAM_H
+    # include <sys/param.h>
+    #endif
+  ]]
+)
 
 # --enable-xfs {{{
 AC_ARG_ENABLE([xfs],
@@ -727,122 +671,95 @@ fi
 # }}}
 
 # For the dns plugin
-AC_CHECK_HEADERS(arpa/nameser.h)
-AC_CHECK_HEADERS(arpa/nameser_compat.h, [], [],
-[
-#if HAVE_ARPA_NAMESER_H
-# include <arpa/nameser.h>
-#endif
-])
+AC_CHECK_HEADERS([arpa/nameser.h])
+AC_CHECK_HEADERS([arpa/nameser_compat.h], [], [],
+  [[
+    #if HAVE_ARPA_NAMESER_H
+    # include <arpa/nameser.h>
+    #endif
+  ]]
+)
 
-AC_CHECK_HEADERS(net/if_arp.h, [], [],
-[#if HAVE_SYS_SOCKET_H
-# include <sys/socket.h>
-#endif
-])
-AC_CHECK_HEADERS(net/ppp_defs.h)
-AC_CHECK_HEADERS(net/if_ppp.h, [], [],
-[#if HAVE_NET_PPP_DEFS_H
-# include <net/ppp_defs.h>
-#endif
-])
-AC_CHECK_HEADERS(netinet/if_ether.h, [], [],
-[#if HAVE_STDINT_H
-# include <stdint.h>
-#endif
-#if HAVE_SYS_TYPES_H
-# include <sys/types.h>
-#endif
-#if HAVE_SYS_SOCKET_H
-# include <sys/socket.h>
-#endif
-#if HAVE_NET_IF_H
-# include <net/if.h>
-#endif
-#if HAVE_NETINET_IN_H
-# include <netinet/in.h>
-#endif
-])
+AC_CHECK_HEADERS([net/if_arp.h], [], [],
+  [[
+    #if HAVE_SYS_SOCKET_H
+    # include <sys/socket.h>
+    #endif
+  ]]
+)
 
-have_net_pfvar_h="no"
-AC_CHECK_HEADERS(net/pfvar.h,
-               [have_net_pfvar_h="yes"],
-               [have_net_pfvar_h="no"],
-[
-#if HAVE_SYS_IOCTL_H
-# include <sys/ioctl.h>
-#endif
-#if HAVE_SYS_SOCKET_H
-# include <sys/socket.h>
-#endif
-#if HAVE_NET_IF_H
-# include <net/if.h>
-#endif
-#if HAVE_NETINET_IN_H
-# include <netinet/in.h>
-#endif
-])
+AC_CHECK_HEADERS([net/ppp_defs.h])
+AC_CHECK_HEADERS([net/if_ppp.h], [], [],
+  [[
+    #if HAVE_NET_PPP_DEFS_H
+    # include <net/ppp_defs.h>
+    #endif
+  ]]
+)
+
+AC_CHECK_HEADERS([netinet/if_ether.h], [], [],
+  [[
+    #include <stdint.h>
+    #if HAVE_SYS_TYPES_H
+    # include <sys/types.h>
+    #endif
+    #if HAVE_SYS_SOCKET_H
+    # include <sys/socket.h>
+    #endif
+    #if HAVE_NET_IF_H
+    # include <net/if.h>
+    #endif
+    #if HAVE_NETINET_IN_H
+    # include <netinet/in.h>
+    #endif
+  ]]
+)
+
+AC_CHECK_HEADERS([net/pfvar.h],
+  [have_net_pfvar_h="yes"],
+  [have_net_pfvar_h="no"],
+  [[
+    #if HAVE_SYS_IOCTL_H
+    # include <sys/ioctl.h>
+    #endif
+    #if HAVE_SYS_SOCKET_H
+    # include <sys/socket.h>
+    #endif
+    #if HAVE_NET_IF_H
+    # include <net/if.h>
+    #endif
+    #if HAVE_NETINET_IN_H
+    # include <netinet/in.h>
+    #endif
+  ]]
+)
 
 # For the multimeter plugin
-have_termios_h="no"
-AC_CHECK_HEADERS(termios.h, [have_termios_h="yes"])
+AC_CHECK_HEADERS([termios.h],
+  [have_termios_h="yes"],
+  [have_termios_h="no"]
+)
 
 # For cpusleep plugin
 AC_CACHE_CHECK([whether clock_boottime and clock_monotonic are supported],
-                      [c_cv_have_clock_boottime_monotonic],
-                      AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
-[[
-#include <time.h>
-]],
-[[
- struct timespec b, m;
- clock_gettime(CLOCK_BOOTTIME, &b );
- clock_gettime(CLOCK_MONOTONIC, &m );
-]]
-                      )],
-                      [c_cv_have_clock_boottime_monotonic="yes"],
-                      [c_cv_have_clock_boottime_monotonic="no"]))
-
-
-# For the turbostat plugin
-have_asm_msrindex_h="no"
-AC_CHECK_HEADERS(asm/msr-index.h, [have_asm_msrindex_h="yes"])
-
-if test "x$have_asm_msrindex_h" = "xyes"
-then
-  AC_CACHE_CHECK([whether asm/msr-index.h has MSR_PKG_C10_RESIDENCY],
-                 [c_cv_have_usable_asm_msrindex_h],
-                 AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
-[[[
-#include<asm/msr-index.h>
-]]],
-[[[
-int y = MSR_PKG_C10_RESIDENCY;
-return(y);
-]]]
-  )],
-                 [c_cv_have_usable_asm_msrindex_h="yes"],
-                 [c_cv_have_usable_asm_msrindex_h="no"],
-                                  )
-                 )
-fi
-
-have_cpuid_h="no"
-AC_CHECK_HEADERS(cpuid.h, [have_cpuid_h="yes"])
-
-have_capability="yes"
-AC_CHECK_HEADERS(sys/capability.h,
-                 [have_capability="yes"],
-                 [have_capability="no (<sys/capability.h> not found)"])
-if test "x$have_capability" = "xyes"; then
-AC_CHECK_LIB(cap, cap_get_bound,
-                 [have_capability="yes"],
-                 [have_capability="no (cap_get_bound() not found)"])
-fi
-if test "x$have_capability" = "xyes"; then
-  AC_DEFINE(HAVE_CAPABILITY, 1, [Define to 1 if you have cap_get_bound() (-lcap).])
-fi
-AM_CONDITIONAL(BUILD_WITH_CAPABILITY, test "x$have_capability" = "xyes")
+  [c_cv_have_clock_boottime_monotonic],
+  [
+    AC_COMPILE_IFELSE(
+      [AC_LANG_PROGRAM(
+        [[#include <time.h>]],
+        [[
+          struct timespec b, m;
+          clock_gettime(CLOCK_BOOTTIME, &b );
+          clock_gettime(CLOCK_MONOTONIC, &m );
+        ]]
+      )
+      ],
+      [c_cv_have_clock_boottime_monotonic="yes"],
+      [c_cv_have_clock_boottime_monotonic="no"]
+    )
+  ]
+)
+
 
 #
 # Checks for typedefs, structures, and compiler characteristics.
@@ -853,1412 +770,1602 @@ AC_TYPE_SIZE_T
 AC_TYPE_UID_T
 AC_HEADER_TIME
 
+test_cxx_flags() {
+  AC_LANG_PUSH([C++])
+  AC_LANG_CONFTEST(
+    [AC_LANG_SOURCE([[int main(void){}]]) ]
+  )
+  $CXX -c conftest.cpp $CXXFLAGS $@ > /dev/null 2> /dev/null
+  ret=$?
+  rm -f conftest.o
+  AC_LANG_POP([C++])
+  return $ret
+}
+
 #
 # Checks for library functions.
 #
-AC_CHECK_FUNCS(gettimeofday select strdup strtol getaddrinfo getnameinfo strchr memcpy strstr strcmp strncmp strncpy strlen strncasecmp strcasecmp openlog closelog sysconf setenv if_indextoname setlocale asprintf)
+AC_CHECK_FUNCS_ONCE([ \
+    asprintf \
+    closelog \
+    getaddrinfo \
+    getgrnam_r \
+    getnameinfo \
+    getpwnam_r \
+    gettimeofday \
+    if_indextoname \
+    openlog \
+    regcomp \
+    regerror \
+    regexec \
+    regfree \
+    select \
+    setenv \
+    setgroups \
+    strcasecmp \
+    strdup \
+    strncasecmp \
+    sysconf
+  ]
+)
 
 AC_FUNC_STRERROR_R
 
-test_cxx_flags() {
-       AC_LANG_PUSH([C++])
-       AC_LANG_CONFTEST([
-               AC_LANG_SOURCE([[int main(void){}]])
-       ])
-       $CXX -c conftest.cpp $CXXFLAGS $@ > /dev/null 2> /dev/null
-       ret=$?
-       rm -f conftest.o
-       AC_LANG_POP([C++])
-       return $ret
-}
-
 SAVE_CFLAGS="$CFLAGS"
 # Emulate behavior of src/Makefile.am
-if test "x$GCC" = "xyes"
-then
-       CFLAGS="$CFLAGS -Wall -Werror"
+if test "x$GCC" = "xyes"; then
+  CFLAGS="$CFLAGS -Wall -Werror"
 fi
 
 AC_CACHE_CHECK([for strtok_r],
   [c_cv_have_strtok_r_default],
-  AC_LINK_IFELSE(
-    [AC_LANG_PROGRAM(
-[[[
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-]]],
-[[[
-      char buffer[] = "foo,bar,baz";
-      char *token;
-      char *dummy;
-      char *saveptr;
-
-      dummy = buffer;
-      saveptr = NULL;
-      while ((token = strtok_r (dummy, ",", &saveptr)) != NULL)
-      {
-        dummy = NULL;
-        printf ("token = %s;\n", token);
-      }
-]]]
-    )],
-    [c_cv_have_strtok_r_default="yes"],
-    [c_cv_have_strtok_r_default="no"]
-  )
+  [
+    AC_LINK_IFELSE(
+      [
+        AC_LANG_PROGRAM(
+          [[
+            #include <stdlib.h>
+            #include <stdio.h>
+            #include <string.h>
+          ]],
+          [[
+            char buffer[] = "foo,bar,baz";
+            char *token;
+            char *dummy;
+            char *saveptr;
+
+            dummy = buffer;
+            saveptr = NULL;
+            while ((token = strtok_r (dummy, ",", &saveptr)) != NULL)
+            {
+              dummy = NULL;
+              printf ("token = %s;\n", token);
+            }
+          ]]
+        )
+      ],
+      [c_cv_have_strtok_r_default="yes"],
+      [c_cv_have_strtok_r_default="no"]
+    )
+  ]
 )
 
-if test "x$c_cv_have_strtok_r_default" = "xno"
-then
+if test "x$c_cv_have_strtok_r_default" = "xno"; then
   CFLAGS="$CFLAGS -D_REENTRANT=1"
 
   AC_CACHE_CHECK([if strtok_r needs _REENTRANT],
     [c_cv_have_strtok_r_reentrant],
-    AC_LINK_IFELSE(
-      [AC_LANG_PROGRAM(
-[[[
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-]]],
-[[[
-        char buffer[] = "foo,bar,baz";
-        char *token;
-        char *dummy;
-        char *saveptr;
-
-        dummy = buffer;
-        saveptr = NULL;
-        while ((token = strtok_r (dummy, ",", &saveptr)) != NULL)
-        {
-          dummy = NULL;
-          printf ("token = %s;\n", token);
-        }
-]]]
-      )],
-      [c_cv_have_strtok_r_reentrant="yes"],
-      [AC_MSG_FAILURE([strtok_r isn't available. Please file a bugreport!])]
-    )
+    [
+      AC_LINK_IFELSE(
+        [
+          AC_LANG_PROGRAM(
+            [[
+              #include <stdlib.h>
+              #include <stdio.h>
+              #include <string.h>
+            ]],
+            [[
+              char buffer[] = "foo,bar,baz";
+              char *token;
+              char *dummy;
+              char *saveptr;
+
+              dummy = buffer;
+              saveptr = NULL;
+              while ((token = strtok_r (dummy, ",", &saveptr)) != NULL)
+              {
+                dummy = NULL;
+                printf ("token = %s;\n", token);
+              }
+            ]]
+          )
+        ],
+        [c_cv_have_strtok_r_reentrant="yes"],
+        [AC_MSG_FAILURE([strtok_r is not available. Please file a bugreport!])]
+      )
+    ]
   )
 fi
 
 CFLAGS="$SAVE_CFLAGS"
-if test "x$c_cv_have_strtok_r_reentrant" = "xyes"
-then
-       CFLAGS="$CFLAGS -D_REENTRANT=1"
+if test "x$c_cv_have_strtok_r_reentrant" = "xyes"; then
+  CFLAGS="$CFLAGS -D_REENTRANT=1"
 fi
 
-AC_CHECK_FUNCS(getpwnam_r getgrnam_r setgroups regcomp regerror regexec regfree)
-
-socket_needs_socket="no"
-AC_CHECK_FUNCS(socket, [], AC_CHECK_LIB(socket, socket, [socket_needs_socket="yes"], AC_MSG_ERROR(cannot find socket)))
-AM_CONDITIONAL(BUILD_WITH_LIBSOCKET, test "x$socket_needs_socket" = "xyes")
+AC_CHECK_FUNCS([socket],
+  [],
+  [
+    AC_CHECK_LIB([socket], [socket],
+      [socket_needs_socket="yes"],
+      [AC_MSG_ERROR([cannot find socket() in libsocket])]
+    )
+  ]
+)
+AM_CONDITIONAL([BUILD_WITH_LIBSOCKET], [test "x$socket_needs_socket" = "xyes"])
 
-clock_gettime_needs_rt="no"
 clock_gettime_needs_posix4="no"
-have_clock_gettime="no"
-AC_CHECK_FUNCS(clock_gettime, [have_clock_gettime="yes"])
-if test "x$have_clock_gettime" = "xno"
-then
-       AC_CHECK_LIB(rt, clock_gettime, [clock_gettime_needs_rt="yes"
-                                        have_clock_gettime="yes"])
+AC_CHECK_FUNCS([clock_gettime],
+  [have_clock_gettime="yes"],
+  [have_clock_gettime="no"]
+)
+
+if test "x$have_clock_gettime" = "xno"; then
+  AC_CHECK_LIB([rt], [clock_gettime],
+    [
+      clock_gettime_needs_rt="yes"
+      have_clock_gettime="yes"
+    ]
+  )
 fi
-if test "x$have_clock_gettime" = "xno"
-then
-       AC_CHECK_LIB(posix4, clock_gettime, [clock_gettime_needs_posix4="yes"
-                                            have_clock_gettime="yes"])
+
+if test "x$have_clock_gettime" = "xno"; then
+  AC_CHECK_LIB([posix4], [clock_gettime],
+    [
+      clock_gettime_needs_posix4="yes"
+      have_clock_gettime="yes"
+    ]
+  )
 fi
-if test "x$have_clock_gettime" = "xyes"
-then
-       AC_DEFINE(HAVE_CLOCK_GETTIME, 1, [Define if the clock_gettime(2) function is available.])
+
+if test "x$have_clock_gettime" = "xyes"; then
+  AC_DEFINE([HAVE_CLOCK_GETTIME], [1], [Define if the clock_gettime(2) function is available.])
 fi
 
-nanosleep_needs_rt="no"
-nanosleep_needs_posix4="no"
-AC_CHECK_FUNCS(nanosleep,
-    [],
-    AC_CHECK_LIB(rt, nanosleep,
-        [nanosleep_needs_rt="yes"],
-        AC_CHECK_LIB(posix4, nanosleep,
-            [nanosleep_needs_posix4="yes"],
-            AC_MSG_ERROR(cannot find nanosleep))))
-
-AM_CONDITIONAL(BUILD_WITH_LIBRT, test "x$clock_gettime_needs_rt" = "xyes" || test "x$nanosleep_needs_rt" = "xyes")
-AM_CONDITIONAL(BUILD_WITH_LIBPOSIX4, test "x$clock_gettime_needs_posix4" = "xyes" || test "x$nanosleep_needs_posix4" = "xyes")
-
-AC_CHECK_FUNCS(sysctl, [have_sysctl="yes"], [have_sysctl="no"])
-AC_CHECK_FUNCS(sysctlbyname, [have_sysctlbyname="yes"], [have_sysctlbyname="no"])
-AC_CHECK_FUNCS(host_statistics, [have_host_statistics="yes"], [have_host_statistics="no"])
-AC_CHECK_FUNCS(processor_info, [have_processor_info="yes"], [have_processor_info="no"])
-AC_CHECK_FUNCS(thread_info, [have_thread_info="yes"], [have_thread_info="no"])
-AC_CHECK_FUNCS(statfs, [have_statfs="yes"], [have_statfs="no"])
-AC_CHECK_FUNCS(statvfs, [have_statvfs="yes"], [have_statvfs="no"])
-AC_CHECK_FUNCS(getifaddrs, [have_getifaddrs="yes"], [have_getifaddrs="no"])
-AC_CHECK_FUNCS(getloadavg, [have_getloadavg="yes"], [have_getloadavg="no"])
-AC_CHECK_FUNCS(syslog, [have_syslog="yes"], [have_syslog="no"])
-AC_CHECK_FUNCS(getutent, [have_getutent="yes"], [have_getutent="no"])
-AC_CHECK_FUNCS(getutxent, [have_getutxent="yes"], [have_getutxent="no"])
+AC_CHECK_FUNCS([nanosleep], [],
+  AC_CHECK_LIB([rt], [nanosleep],
+    [nanosleep_needs_rt="yes"],
+    [
+      AC_CHECK_LIB([posix4], [nanosleep],
+        [nanosleep_needs_posix4="yes"],
+        [AC_MSG_ERROR([cannot find nanosleep])]
+      )
+    ]
+  )
+)
+
+AM_CONDITIONAL([BUILD_WITH_LIBRT], [test "x$clock_gettime_needs_rt" = "xyes" || test "x$nanosleep_needs_rt" = "xyes"])
+AM_CONDITIONAL([BUILD_WITH_LIBPOSIX4], [test "x$clock_gettime_needs_posix4" = "xyes" || test "x$nanosleep_needs_posix4" = "xyes"])
+
+AC_CHECK_FUNCS([getifaddrs], [have_getifaddrs="yes"], [have_getifaddrs="no"])
+AC_CHECK_FUNCS([getloadavg], [have_getloadavg="yes"], [have_getloadavg="no"])
+AC_CHECK_FUNCS([getutent], [have_getutent="yes"], [have_getutent="no"])
+AC_CHECK_FUNCS([getutxent], [have_getutxent="yes"], [have_getutxent="no"])
+AC_CHECK_FUNCS([host_statistics], [have_host_statistics="yes"], [have_host_statistics="no"])
+AC_CHECK_FUNCS([processor_info], [have_processor_info="yes"], [have_processor_info="no"])
+AC_CHECK_FUNCS([statfs], [have_statfs="yes"], [have_statfs="no"])
+AC_CHECK_FUNCS([statvfs], [have_statvfs="yes"], [have_statvfs="no"])
+AC_CHECK_FUNCS([sysctl], [have_sysctl="yes"], [have_sysctl="no"])
+AC_CHECK_FUNCS([sysctlbyname], [have_sysctlbyname="yes"], [have_sysctlbyname="no"])
+AC_CHECK_FUNCS([syslog], [have_syslog="yes"], [have_syslog="no"])
+AC_CHECK_FUNCS([thread_info], [have_thread_info="yes"], [have_thread_info="no"])
 
 # Check for strptime {{{
-if test "x$GCC" = "xyes"
-then
-       SAVE_CFLAGS="$CFLAGS"
-       CFLAGS="$CFLAGS -Wall -Wextra -Werror"
+if test "x$GCC" = "xyes"; then
+  SAVE_CFLAGS="$CFLAGS"
+  CFLAGS="$CFLAGS -Wall -Wextra -Werror"
 fi
 
-AC_CHECK_FUNCS(strptime, [have_strptime="yes"], [have_strptime="no"])
-if test "x$have_strptime" = "xyes"
-then
-       AC_CACHE_CHECK([whether strptime is exported by default],
-                      [c_cv_have_strptime_default],
-                      AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
-[[[
-#include <time.h>
-]]],
-[[[
- struct tm stm;
- (void) strptime ("2010-12-30%13:42:42", "%Y-%m-%dT%T", &stm);
-]]]
-                      )],
-                      [c_cv_have_strptime_default="yes"],
-                      [c_cv_have_strptime_default="no"]))
-fi
-if test "x$have_strptime" = "xyes" && test "x$c_cv_have_strptime_default" = "xno"
-then
-       AC_CACHE_CHECK([whether strptime needs standards mode],
-                      [c_cv_have_strptime_standards],
-                      AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
-[[[
-#ifndef _ISOC99_SOURCE
-# define _ISOC99_SOURCE 1
-#endif
-#ifndef _POSIX_C_SOURCE
-# define _POSIX_C_SOURCE 200112L
-#endif
-#ifndef _XOPEN_SOURCE
-# define _XOPEN_SOURCE 500
-#endif
-#include <time.h>
-]]],
-[[[
- struct tm stm;
- (void) strptime ("2010-12-30%13:42:42", "%Y-%m-%dT%T", &stm);
-]]]
-                      )],
-                      [c_cv_have_strptime_standards="yes"],
-                      [c_cv_have_strptime_standards="no"]))
-
-       if test "x$c_cv_have_strptime_standards" = "xyes"
-       then
-               AC_DEFINE([STRPTIME_NEEDS_STANDARDS], 1, [Set to true if strptime is only exported in X/Open mode (GNU libc).])
-       else
-               have_strptime="no"
-       fi
+AC_CHECK_FUNCS([strptime], [have_strptime="yes"], [have_strptime="no"])
+if test "x$have_strptime" = "xyes"; then
+  AC_CACHE_CHECK([whether strptime is exported by default],
+    [c_cv_have_strptime_default],
+    [
+      AC_COMPILE_IFELSE(
+        [
+          AC_LANG_PROGRAM(
+            [[#include <time.h>]],
+            [[
+              struct tm stm;
+              (void)strptime ("2010-12-30%13:42:42", "%Y-%m-%dT%T", &stm);
+            ]]
+          )
+        ],
+        [c_cv_have_strptime_default="yes"],
+        [c_cv_have_strptime_default="no"])
+    ]
+  )
 fi
 
-if test "x$GCC" = "xyes"
-then
-       CFLAGS="$SAVE_CFLAGS"
+if test "x$have_strptime" = "xyes" && test "x$c_cv_have_strptime_default" = "xno"; then
+  AC_CACHE_CHECK([whether strptime needs standards mode],
+    [c_cv_have_strptime_standards],
+    [
+      AC_COMPILE_IFELSE(
+        [
+          AC_LANG_PROGRAM(
+            [[
+              #ifndef _ISOC99_SOURCE
+              # define _ISOC99_SOURCE 1
+              #endif
+              #ifndef _POSIX_C_SOURCE
+              # define _POSIX_C_SOURCE 200112L
+              #endif
+              #ifndef _XOPEN_SOURCE
+              # define _XOPEN_SOURCE 500
+              #endif
+              #include <time.h>
+            ]],
+            [[
+              struct tm stm;
+              (void)strptime ("2010-12-30%13:42:42", "%Y-%m-%dT%T", &stm);
+            ]]
+          )
+        ],
+        [c_cv_have_strptime_standards="yes"],
+        [c_cv_have_strptime_standards="no"]
+      )
+    ]
+  )
+
+  if test "x$c_cv_have_strptime_standards" = "xyes"; then
+    AC_DEFINE([STRPTIME_NEEDS_STANDARDS], [1],
+      [Set to true if strptime is only exported in X/Open mode (GNU libc).]
+    )
+  else
+    have_strptime="no"
+  fi
+fi
+
+if test "x$GCC" = "xyes"; then
+  CFLAGS="$SAVE_CFLAGS"
 fi
 # }}} Check for strptime
 
-AC_CHECK_FUNCS(swapctl, [have_swapctl="yes"], [have_swapctl="no"])
+AC_MSG_CHECKING([for sysctl kern.cp_times])
+if test -x /sbin/sysctl; then
+  /sbin/sysctl kern.cp_times >/dev/null 2>&1
+  if test $? -eq 0; then
+    AC_MSG_RESULT([yes])
+    AC_DEFINE([HAVE_SYSCTL_KERN_CP_TIMES], [1], [Define if sysctl supports kern.cp_times])
+  else
+    AC_MSG_RESULT([no])
+  fi
+else
+  AC_MSG_RESULT([no])
+fi
+
+AC_MSG_CHECKING([for sysctl kern.cp_time])
+if test -x /sbin/sysctl; then
+  /sbin/sysctl kern.cp_time >/dev/null 2>&1
+  if test $? -eq 0
+  then
+    AC_MSG_RESULT([yes])
+    AC_DEFINE([HAVE_SYSCTL_KERN_CP_TIME], [1], [Define if sysctl supports kern.cp_time])
+  else
+    AC_MSG_RESULT([no])
+  fi
+else
+  AC_MSG_RESULT([no])
+fi
+
+AC_CHECK_FUNCS([swapctl], [have_swapctl="yes"], [have_swapctl="no"])
 if test "x$have_swapctl" = "xyes"; then
-        AC_CACHE_CHECK([whether swapctl takes two arguments],
-                [c_cv_have_swapctl_two_args],
-                AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
-[[[
-#if HAVE_SYS_SWAP_H && !defined(_LP64) && _FILE_OFFSET_BITS == 64
-#  undef _FILE_OFFSET_BITS
-#  undef _LARGEFILE64_SOURCE
-#endif
-#include <sys/stat.h>
-#include <sys/param.h>
-#include <sys/swap.h>
-#include <unistd.h>
-]]],
-[[[
-int num = swapctl(0, NULL);
-]]]
-                        )],
-                        [c_cv_have_swapctl_two_args="yes"],
-                        [c_cv_have_swapctl_two_args="no"]
-                )
-        )
-        AC_CACHE_CHECK([whether swapctl takes three arguments],
-                [c_cv_have_swapctl_three_args],
-                AC_COMPILE_IFELSE(
-                        [AC_LANG_PROGRAM(
-[[[
-#if HAVE_SYS_SWAP_H && !defined(_LP64) && _FILE_OFFSET_BITS == 64
-#  undef _FILE_OFFSET_BITS
-#  undef _LARGEFILE64_SOURCE
-#endif
-#include <sys/stat.h>
-#include <sys/param.h>
-#include <sys/swap.h>
-#include <unistd.h>
-]]],
-[[[
-int num = swapctl(0, NULL, 0);
-]]]
-                        )],
-                        [c_cv_have_swapctl_three_args="yes"],
-                        [c_cv_have_swapctl_three_args="no"]
-                )
-        )
+  AC_CACHE_CHECK([whether swapctl takes two arguments],
+    [c_cv_have_swapctl_two_args],
+    [
+      AC_COMPILE_IFELSE(
+        [
+          AC_LANG_PROGRAM(
+            [[
+              #if HAVE_SYS_SWAP_H && !defined(_LP64) && _FILE_OFFSET_BITS == 64
+              #  undef _FILE_OFFSET_BITS
+              #  undef _LARGEFILE64_SOURCE
+              #endif
+              #include <sys/stat.h>
+              #include <sys/param.h>
+              #include <sys/swap.h>
+              #include <unistd.h>
+            ]],
+            [[int num = swapctl(0, NULL);]]
+          )
+        ],
+        [c_cv_have_swapctl_two_args="yes"],
+        [c_cv_have_swapctl_two_args="no"]
+      )
+    ]
+  )
+
+  AC_CACHE_CHECK([whether swapctl takes three arguments],
+    [c_cv_have_swapctl_three_args],
+    [
+      AC_COMPILE_IFELSE(
+        [
+          AC_LANG_PROGRAM(
+            [[
+              #if HAVE_SYS_SWAP_H && !defined(_LP64) && _FILE_OFFSET_BITS == 64
+              #  undef _FILE_OFFSET_BITS
+              #  undef _LARGEFILE64_SOURCE
+              #endif
+              #include <sys/stat.h>
+              #include <sys/param.h>
+              #include <sys/swap.h>
+              #include <unistd.h>
+            ]],
+            [[int num = swapctl(0, NULL, 0);]]
+          )
+        ],
+        [c_cv_have_swapctl_three_args="yes"],
+        [c_cv_have_swapctl_three_args="no"]
+      )
+    ]
+  )
 fi
+
 # Check for different versions of `swapctl' here..
 if test "x$have_swapctl" = "xyes"; then
-        if test "x$c_cv_have_swapctl_two_args" = "xyes"; then
-                AC_DEFINE(HAVE_SWAPCTL_TWO_ARGS, 1,
-                          [Define if the function swapctl exists and takes two arguments.])
-        fi
-        if test "x$c_cv_have_swapctl_three_args" = "xyes"; then
-                AC_DEFINE(HAVE_SWAPCTL_THREE_ARGS, 1,
-                          [Define if the function swapctl exists and takes three arguments.])
-        fi
+  if test "x$c_cv_have_swapctl_two_args" = "xyes"; then
+    AC_DEFINE([HAVE_SWAPCTL_TWO_ARGS], [1], [Define if the function swapctl exists and takes two arguments.])
+  fi
+
+  if test "x$c_cv_have_swapctl_three_args" = "xyes"; then
+    AC_DEFINE([HAVE_SWAPCTL_THREE_ARGS], [1], [Define if the function swapctl exists and takes three arguments.])
+  fi
 fi
 
 # Check for NAN
-AC_ARG_WITH(nan-emulation, [AS_HELP_STRING([--with-nan-emulation], [use emulated NAN. For crosscompiling only.])],
-[
- if test "x$withval" = "xno"; then
-        nan_type="none"
- else if test "x$withval" = "xyes"; then
-        nan_type="zero"
- else
-        nan_type="$withval"
- fi; fi
-],
-[nan_type="none"])
+AC_ARG_WITH([nan-emulation],
+  [AS_HELP_STRING([--with-nan-emulation], [use emulated NAN. For crosscompiling only.])],
+  [
+    if test "x$withval" = "xno"; then
+      nan_type="none"
+    else if test "x$withval" = "xyes"; then
+      nan_type="zero"
+    else
+      nan_type="$withval"
+    fi; fi
+  ],
+  [nan_type="none"]
+)
+
 if test "x$nan_type" = "xnone"; then
   AC_CACHE_CHECK([whether NAN is defined by default],
     [c_cv_have_nan_default],
-    AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
-[[[
-#include <stdlib.h>
-#include <math.h>
-static double foo = NAN;
-]]],
-[[[
-       if (isnan (foo))
-        return 0;
-       else
-       return 1;
-]]]
-      )],
-      [c_cv_have_nan_default="yes"],
-      [c_cv_have_nan_default="no"]
-    )
+    [
+      AC_COMPILE_IFELSE(
+        [
+          AC_LANG_PROGRAM(
+            [[
+              #include <stdlib.h>
+              #include <math.h>
+              static double foo = NAN;
+            ]],
+            [[
+              if (isnan (foo))
+                return 0;
+              return 1;
+            ]]
+          )
+        ],
+        [c_cv_have_nan_default="yes"],
+        [c_cv_have_nan_default="no"]
+      )
+    ]
   )
-  if test "x$c_cv_have_nan_default" = "xyes"
-  then
-    nan_type="default"
-  fi
 fi
+
+if test "x$c_cv_have_nan_default" = "xyes"; then
+  nan_type="default"
+fi
+
 if test "x$nan_type" = "xnone"; then
   AC_CACHE_CHECK([whether NAN is defined by __USE_ISOC99],
     [c_cv_have_nan_isoc],
-    AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
-[[[
-#include <stdlib.h>
-#define __USE_ISOC99 1
-#include <math.h>
-static double foo = NAN;
-]]],
-[[[
-       if (isnan (foo))
-        return 0;
-       else
-       return 1;
-]]]
-      )],
-      [c_cv_have_nan_isoc="yes"],
-      [c_cv_have_nan_isoc="no"]
-    )
+    [
+      AC_COMPILE_IFELSE(
+        [
+          AC_LANG_PROGRAM(
+            [[
+              #include <stdlib.h>
+              #define __USE_ISOC99 1
+              #include <math.h>
+              static double foo = NAN;
+            ]],
+            [[
+              if (isnan (foo))
+                return 0;
+              return 1;
+            ]]
+          )
+        ],
+        [c_cv_have_nan_isoc="yes"],
+        [c_cv_have_nan_isoc="no"]
+      )
+    ]
   )
-  if test "x$c_cv_have_nan_isoc" = "xyes"
-  then
-    nan_type="isoc99"
-  fi
 fi
+
+if test "x$c_cv_have_nan_isoc" = "xyes"; then
+  nan_type="isoc99"
+fi
+
 if test "x$nan_type" = "xnone"; then
-  SAVE_LDFLAGS=$LDFLAGS
+  SAVE_LDFLAGS="$LDFLAGS"
   LDFLAGS="$LDFLAGS -lm"
   AC_CACHE_CHECK([whether NAN can be defined by 0/0],
     [c_cv_have_nan_zero],
-    AC_RUN_IFELSE([AC_LANG_PROGRAM(
-[[[
-#include <stdlib.h>
-#include <math.h>
-#ifdef NAN
-# undef NAN
-#endif
-#define NAN (0.0 / 0.0)
-#ifndef isnan
-# define isnan(f) ((f) != (f))
-#endif
-static double foo = NAN;
-]]],
-[[[
-       if (isnan (foo))
-        return 0;
-       else
-       return 1;
-]]]
-      )],
-      [c_cv_have_nan_zero="yes"],
-      [c_cv_have_nan_zero="no"]
-    )
+    [
+      AC_RUN_IFELSE(
+        [
+          AC_LANG_PROGRAM(
+            [[
+              #include <stdlib.h>
+              #include <math.h>
+              #ifdef NAN
+              # undef NAN
+              #endif
+              #define NAN (0.0 / 0.0)
+              #ifndef isnan
+              # define isnan(f) ((f) != (f))
+              #endif
+              static double foo = NAN;
+            ]],
+            [[
+              if (isnan (foo))
+                return 0;
+              return 1;
+            ]]
+          )
+        ],
+        [c_cv_have_nan_zero="yes"],
+        [c_cv_have_nan_zero="no"]
+      )
+    ]
   )
   LDFLAGS=$SAVE_LDFLAGS
-  if test "x$c_cv_have_nan_zero" = "xyes"
-  then
-    nan_type="zero"
-  fi
+fi
+
+if test "x$c_cv_have_nan_zero" = "xyes"; then
+  nan_type="zero"
 fi
 
 if test "x$nan_type" = "xdefault"; then
-  AC_DEFINE(NAN_STATIC_DEFAULT, 1,
-    [Define if NAN is defined by default and can initialize static variables.])
+  AC_DEFINE([NAN_STATIC_DEFAULT], [1],
+    [Define if NAN is defined by default and can initialize static variables.]
+  )
 else if test "x$nan_type" = "xisoc99"; then
-  AC_DEFINE(NAN_STATIC_ISOC, 1,
-    [Define if NAN is defined by __USE_ISOC99 and can initialize static variables.])
+  AC_DEFINE([NAN_STATIC_ISOC], [1],
+    [Define if NAN is defined by __USE_ISOC99 and can initialize static variables.]
+  )
 else if test "x$nan_type" = "xzero"; then
-  AC_DEFINE(NAN_ZERO_ZERO, 1,
-    [Define if NAN can be defined as (0.0 / 0.0)])
+  AC_DEFINE([NAN_ZERO_ZERO], [1],
+    [Define if NAN can be defined as (0.0 / 0.0)]
+  )
 else
   AC_MSG_ERROR([Didn't find out how to statically initialize variables to NAN. Sorry.])
 fi; fi; fi
 
-AC_ARG_WITH(fp-layout, [AS_HELP_STRING([--with-fp-layout], [set the memory layout of doubles. For crosscompiling only.])],
-[
- if test "x$withval" = "xnothing"; then
-       fp_layout_type="nothing"
- else if test "x$withval" = "xendianflip"; then
-       fp_layout_type="endianflip"
- else if test "x$withval" = "xintswap"; then
-       fp_layout_type="intswap"
- else
-       AC_MSG_ERROR([Invalid argument for --with-fp-layout. Valid arguments are: nothing, endianflip, intswap]);
-fi; fi; fi
-],
-[fp_layout_type="unknown"])
+AC_ARG_WITH([fp-layout],
+  [
+    AS_HELP_STRING([--with-fp-layout],
+      [set the memory layout of doubles. For crosscompiling only.]
+    )
+  ],
+  [
+    if test "x$withval" = "xnothing"; then
+      fp_layout_type="nothing"
+    else if test "x$withval" = "xendianflip"; then
+      fp_layout_type="endianflip"
+    else if test "x$withval" = "xintswap"; then
+      fp_layout_type="intswap"
+    else
+      AC_MSG_ERROR([Invalid argument for --with-fp-layout. Valid arguments are: nothing, endianflip, intswap]);
+    fi; fi; fi
+  ],
+  [fp_layout_type="unknown"]
+)
 
 if test "x$fp_layout_type" = "xunknown"; then
   AC_CACHE_CHECK([if doubles are stored in x86 representation],
     [c_cv_fp_layout_need_nothing],
-    AC_RUN_IFELSE([AC_LANG_PROGRAM(
-[[[
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-#if HAVE_STDINT_H
-# include <stdint.h>
-#endif
-#if HAVE_INTTYPES_H
-# include <inttypes.h>
-#endif
-#if HAVE_STDBOOL_H
-# include <stdbool.h>
-#endif
-]]],
-[[[
-       uint64_t i0;
-       uint64_t i1;
-       uint8_t c[8];
-       double d;
-
-       d = 8.642135e130;
-       memcpy ((void *) &i0, (void *) &d, 8);
-
-       i1 = i0;
-       memcpy ((void *) c, (void *) &i1, 8);
-
-       if ((c[0] == 0x2f) && (c[1] == 0x25)
-                       && (c[2] == 0xc0) && (c[3] == 0xc7)
-                       && (c[4] == 0x43) && (c[5] == 0x2b)
-                       && (c[6] == 0x1f) && (c[7] == 0x5b))
-               return (0);
-       else
-               return (1);
-]]]
-      )],
-      [c_cv_fp_layout_need_nothing="yes"],
-      [c_cv_fp_layout_need_nothing="no"]
-    )
+    [
+      AC_RUN_IFELSE(
+        [
+          AC_LANG_PROGRAM(
+            [[
+              #include <stdlib.h>
+              #include <stdio.h>
+              #include <string.h>
+              #include <stdint.h>
+              #include <inttypes.h>
+              #include <stdbool.h>
+            ]],
+            [[
+              uint64_t i0;
+              uint64_t i1;
+              uint8_t c[8];
+              double d;
+
+              d = 8.642135e130;
+              memcpy ((void *) &i0, (void *) &d, 8);
+
+              i1 = i0;
+              memcpy ((void *) c, (void *) &i1, 8);
+
+              if ((c[0] == 0x2f) && (c[1] == 0x25)
+                  && (c[2] == 0xc0) && (c[3] == 0xc7)
+                  && (c[4] == 0x43) && (c[5] == 0x2b)
+                  && (c[6] == 0x1f) && (c[7] == 0x5b))
+                return (0);
+              return (1);
+            ]]
+          )
+        ],
+        [c_cv_fp_layout_need_nothing="yes"],
+        [c_cv_fp_layout_need_nothing="no"]
+      )
+    ]
   )
-  if test "x$c_cv_fp_layout_need_nothing" = "xyes"; then
-    fp_layout_type="nothing"
-  fi
 fi
+
+if test "x$c_cv_fp_layout_need_nothing" = "xyes"; then
+  fp_layout_type="nothing"
+fi
+
 if test "x$fp_layout_type" = "xunknown"; then
   AC_CACHE_CHECK([if endianflip converts to x86 representation],
     [c_cv_fp_layout_need_endianflip],
-    AC_RUN_IFELSE([AC_LANG_PROGRAM(
-[[[
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-#if HAVE_STDINT_H
-# include <stdint.h>
-#endif
-#if HAVE_INTTYPES_H
-# include <inttypes.h>
-#endif
-#if HAVE_STDBOOL_H
-# include <stdbool.h>
-#endif
-#define endianflip(A) ((((uint64_t)(A) & 0xff00000000000000LL) >> 56) | \
-                       (((uint64_t)(A) & 0x00ff000000000000LL) >> 40) | \
-                       (((uint64_t)(A) & 0x0000ff0000000000LL) >> 24) | \
-                       (((uint64_t)(A) & 0x000000ff00000000LL) >> 8)  | \
-                       (((uint64_t)(A) & 0x00000000ff000000LL) << 8)  | \
-                       (((uint64_t)(A) & 0x0000000000ff0000LL) << 24) | \
-                       (((uint64_t)(A) & 0x000000000000ff00LL) << 40) | \
-                       (((uint64_t)(A) & 0x00000000000000ffLL) << 56))
-]]],
-[[[
-       uint64_t i0;
-       uint64_t i1;
-       uint8_t c[8];
-       double d;
-
-       d = 8.642135e130;
-       memcpy ((void *) &i0, (void *) &d, 8);
-
-       i1 = endianflip (i0);
-       memcpy ((void *) c, (void *) &i1, 8);
-
-       if ((c[0] == 0x2f) && (c[1] == 0x25)
-                       && (c[2] == 0xc0) && (c[3] == 0xc7)
-                       && (c[4] == 0x43) && (c[5] == 0x2b)
-                       && (c[6] == 0x1f) && (c[7] == 0x5b))
-               return (0);
-       else
-               return (1);
-]]]
-      )],
-      [c_cv_fp_layout_need_endianflip="yes"],
-      [c_cv_fp_layout_need_endianflip="no"]
+    [
+      AC_RUN_IFELSE(
+        [
+          AC_LANG_PROGRAM(
+            [[
+              #include <stdlib.h>
+              #include <stdio.h>
+              #include <string.h>
+              #include <stdint.h>
+              #include <inttypes.h>
+              #include <stdbool.h>
+              #define endianflip(A) ((((uint64_t)(A) & 0xff00000000000000LL) >> 56) | \
+                                     (((uint64_t)(A) & 0x00ff000000000000LL) >> 40) | \
+                                     (((uint64_t)(A) & 0x0000ff0000000000LL) >> 24) | \
+                                     (((uint64_t)(A) & 0x000000ff00000000LL) >> 8)  | \
+                                     (((uint64_t)(A) & 0x00000000ff000000LL) << 8)  | \
+                                     (((uint64_t)(A) & 0x0000000000ff0000LL) << 24) | \
+                                     (((uint64_t)(A) & 0x000000000000ff00LL) << 40) | \
+                                     (((uint64_t)(A) & 0x00000000000000ffLL) << 56))
+            ]],
+            [[
+              uint64_t i0;
+              uint64_t i1;
+              uint8_t c[8];
+              double d;
+              
+              d = 8.642135e130;
+              memcpy ((void *) &i0, (void *) &d, 8);
+              
+              i1 = endianflip (i0);
+              memcpy ((void *) c, (void *) &i1, 8);
+              
+              if ((c[0] == 0x2f) && (c[1] == 0x25)
+                  && (c[2] == 0xc0) && (c[3] == 0xc7)
+                  && (c[4] == 0x43) && (c[5] == 0x2b)
+                  && (c[6] == 0x1f) && (c[7] == 0x5b))
+                return (0);
+              return (1);
+            ]]
+          )
+        ],
+        [c_cv_fp_layout_need_endianflip="yes"],
+        [c_cv_fp_layout_need_endianflip="no"]
+      ]
     )
   )
-  if test "x$c_cv_fp_layout_need_endianflip" = "xyes"; then
-    fp_layout_type="endianflip"
-  fi
 fi
+
+if test "x$c_cv_fp_layout_need_endianflip" = "xyes"; then
+  fp_layout_type="endianflip"
+fi
+
 if test "x$fp_layout_type" = "xunknown"; then
   AC_CACHE_CHECK([if intswap converts to x86 representation],
     [c_cv_fp_layout_need_intswap],
-    AC_RUN_IFELSE([AC_LANG_PROGRAM(
-[[[
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-#if HAVE_STDINT_H
-# include <stdint.h>
-#endif
-#if HAVE_INTTYPES_H
-# include <inttypes.h>
-#endif
-#if HAVE_STDBOOL_H
-# include <stdbool.h>
-#endif
-#define intswap(A)    ((((uint64_t)(A) & 0xffffffff00000000LL) >> 32) | \
-                       (((uint64_t)(A) & 0x00000000ffffffffLL) << 32))
-]]],
-[[[
-       uint64_t i0;
-       uint64_t i1;
-       uint8_t c[8];
-       double d;
-
-       d = 8.642135e130;
-       memcpy ((void *) &i0, (void *) &d, 8);
-
-       i1 = intswap (i0);
-       memcpy ((void *) c, (void *) &i1, 8);
-
-       if ((c[0] == 0x2f) && (c[1] == 0x25)
-                       && (c[2] == 0xc0) && (c[3] == 0xc7)
-                       && (c[4] == 0x43) && (c[5] == 0x2b)
-                       && (c[6] == 0x1f) && (c[7] == 0x5b))
-               return (0);
-       else
-               return (1);
-]]]
-      )],
-      [c_cv_fp_layout_need_intswap="yes"],
-      [c_cv_fp_layout_need_intswap="no"]
-    )
+    [
+      AC_RUN_IFELSE(
+        [
+          AC_LANG_PROGRAM(
+            [[
+              #include <stdlib.h>
+              #include <stdio.h>
+              #include <string.h>
+              #include <stdint.h>
+              #include <inttypes.h>
+              #include <stdbool.h>
+              #define intswap(A)    ((((uint64_t)(A) & 0xffffffff00000000LL) >> 32) | \
+                                     (((uint64_t)(A) & 0x00000000ffffffffLL) << 32))
+            ]],
+            [[
+              uint64_t i0;
+              uint64_t i1;
+              uint8_t c[8];
+              double d;
+              
+              d = 8.642135e130;
+              memcpy ((void *) &i0, (void *) &d, 8);
+              
+              i1 = intswap (i0);
+              memcpy ((void *) c, (void *) &i1, 8);
+              
+              if ((c[0] == 0x2f) && (c[1] == 0x25)
+                  && (c[2] == 0xc0) && (c[3] == 0xc7)
+                  && (c[4] == 0x43) && (c[5] == 0x2b)
+                  && (c[6] == 0x1f) && (c[7] == 0x5b))
+                return (0);
+              return (1);
+            ]]
+          )
+        ],
+        [c_cv_fp_layout_need_intswap="yes"],
+        [c_cv_fp_layout_need_intswap="no"]
+      )
+    ]
   )
-  if test "x$c_cv_fp_layout_need_intswap" = "xyes"; then
-    fp_layout_type="intswap"
-  fi
+fi
+
+if test "x$c_cv_fp_layout_need_intswap" = "xyes"; then
+  fp_layout_type="intswap"
 fi
 
 if test "x$fp_layout_type" = "xnothing"; then
-  AC_DEFINE(FP_LAYOUT_NEED_NOTHING, 1,
-  [Define if doubles are stored in x86 representation.])
+  AC_DEFINE([FP_LAYOUT_NEED_NOTHING], [1],
+    [Define if doubles are stored in x86 representation.]
+  )
 else if test "x$fp_layout_type" = "xendianflip"; then
-  AC_DEFINE(FP_LAYOUT_NEED_ENDIANFLIP, 1,
-  [Define if endianflip is needed to convert to x86 representation.])
+  AC_DEFINE([FP_LAYOUT_NEED_ENDIANFLIP], [1],
+    [Define if endianflip is needed to convert to x86 representation.]
+  )
 else if test "x$fp_layout_type" = "xintswap"; then
-  AC_DEFINE(FP_LAYOUT_NEED_INTSWAP, 1,
-  [Define if intswap is needed to convert to x86 representation.])
+  AC_DEFINE([FP_LAYOUT_NEED_INTSWAP], [1],
+    [Define if intswap is needed to convert to x86 representation.]
+  )
 else
   AC_MSG_ERROR([Didn't find out how doubles are stored in memory. Sorry.])
 fi; fi; fi
 
+# For cpusleep plugin
+AC_CACHE_CHECK([whether clock_boottime and clock_monotonic are supported],
+  [c_cv_have_clock_boottime_monotonic],
+  [
+    AC_COMPILE_IFELSE(
+      [AC_LANG_PROGRAM(
+        [[#include <time.h>]],
+        [[
+          struct timespec b, m;
+          clock_gettime(CLOCK_BOOTTIME, &b );
+          clock_gettime(CLOCK_MONOTONIC, &m );
+        ]]
+      )
+      ],
+      [c_cv_have_clock_boottime_monotonic="yes"],
+      [c_cv_have_clock_boottime_monotonic="no"]
+    )
+  ]
+)
+
 # --with-useragent {{{
-AC_ARG_WITH(useragent, [AS_HELP_STRING([--with-useragent@<:@=AGENT@:>@], [User agent to use on http requests])],
-[
-    if test "x$withval" != "xno" && test "x$withval" != "xyes"
-    then
-        AC_DEFINE_UNQUOTED(COLLECTD_USERAGENT, ["$withval"], [User agent for http requests])
+AC_ARG_WITH([useragent],
+  [AS_HELP_STRING([--with-useragent@<:@=AGENT@:>@], [User agent to use on http requests])],
+  [
+    if test "x$withval" != "xno" && test "x$withval" != "xyes"; then
+      AC_DEFINE_UNQUOTED([COLLECTD_USERAGENT], ["$withval"], [User agent for http requests])
     fi
-])
+  ]
+)
 
 # }}}
 
 # --with-data-max-name-len {{{
-AC_ARG_WITH(data-max-name-len, [AS_HELP_STRING([--with-data-max-name-len@<:@=VALUE@:>@], [Maximum length of data buffers])],
-[
-    if test "x$withval" != "x" && test $withval -gt 0
-    then
-        AC_DEFINE_UNQUOTED(DATA_MAX_NAME_LEN, [$withval], [Maximum length of data buffers])
+AC_ARG_WITH([data-max-name-len],
+  [AS_HELP_STRING([--with-data-max-name-len@<:@=VALUE@:>@], [Maximum length of data buffers])],
+  [
+    if test "x$withval" != "x" && test $withval -gt 0; then
+      AC_DEFINE_UNQUOTED([DATA_MAX_NAME_LEN], [$withval], [Maximum length of data buffers])
     else
-        AC_MSG_ERROR([DATA_MAX_NAME_LEN must be a positive integer -- $withval given])
+      AC_MSG_ERROR([DATA_MAX_NAME_LEN must be a positive integer -- $withval given])
     fi
-],
-[   AC_DEFINE(DATA_MAX_NAME_LEN, 128, [Maximum length of data buffers])]
+  ],
+  [AC_DEFINE([DATA_MAX_NAME_LEN], [128], [Maximum length of data buffers])]
 )
 # }}}
 
-have_getfsstat="no"
-AC_CHECK_FUNCS(getfsstat, [have_getfsstat="yes"])
-have_getvfsstat="no"
-AC_CHECK_FUNCS(getvfsstat, [have_getvfsstat="yes"])
-have_listmntent="no"
-AC_CHECK_FUNCS(listmntent, [have_listmntent="yes"])
-have_getmntent_r="no"
-AC_CHECK_FUNCS(getmntent_r, [have_getmntent_r="yes"])
-
-have_getmntent="no"
-AC_CHECK_FUNCS(getmntent, [have_getmntent="c"])
+AC_CHECK_FUNCS([getfsstat], [have_getfsstat="yes"], [have_getfsstat="no"])
+AC_CHECK_FUNCS(getvfsstat, [have_getvfsstat="yes"], [have_getvfsstat="no"])
+AC_CHECK_FUNCS(listmntent, [have_listmntent="yes"], [have_listmntent="no"])
+AC_CHECK_FUNCS(getmntent_r, [have_getmntent_r="yes"], [have_getmntent_r="no"])
+
+AC_CHECK_FUNCS(getmntent, [have_getmntent="libc"], [have_getmntent="no"])
 if test "x$have_getmntent" = "xno"; then
-       AC_CHECK_LIB(sun, getmntent, [have_getmntent="sun"])
+  AC_CHECK_LIB([sun], [getmntent],
+    [have_getmntent="sun"],
+    [have_gemntent="no"]
+  )
 fi
+
 if test "x$have_getmntent" = "xno"; then
-       AC_CHECK_LIB(seq, getmntent, [have_getmntent="seq"])
+  AC_CHECK_LIB([seq], [getmntent],
+    [have_getmntent="seq"],
+    [have_getmntent="no"]
+  )
 fi
+
 if test "x$have_getmntent" = "xno"; then
-       AC_CHECK_LIB(gen, getmntent, [have_getmntent="gen"])
-fi
-
-if test "x$have_getmntent" = "xc"; then
-       AC_CACHE_CHECK([whether getmntent takes one argument],
-               [c_cv_have_one_getmntent],
-               AC_COMPILE_IFELSE(
-                       [AC_LANG_PROGRAM(
-[[[
-#include "$srcdir/src/utils_mount.h"
-]]],
-[[[
-FILE *fh;
-struct mntent *me;
-fh = setmntent ("/etc/mtab", "r");
-me = getmntent (fh);
-return(me->mnt_passno);
-]]]
-                       )],
-                       [c_cv_have_one_getmntent="yes"],
-                       [c_cv_have_one_getmntent="no"]
-               )
-       )
-       AC_CACHE_CHECK([whether getmntent takes two arguments],
-               [c_cv_have_two_getmntent],
-               AC_COMPILE_IFELSE(
-                       [AC_LANG_PROGRAM(
-[[[
-#include "$srcdir/src/utils_mount.h"
-]]],
-[[[
-                                FILE *fh;
-                                struct mnttab mt;
-                                int status;
-                                fh = fopen ("/etc/mnttab", "r");
-                                status = getmntent (fh, &mt);
-                                return(status);
-]]]
-                       )],
-                       [c_cv_have_two_getmntent="yes"],
-                       [c_cv_have_two_getmntent="no"]
-               )
-       )
+  AC_CHECK_LIB([gen], [getmntent],
+    [have_getmntent="gen"],
+    [have_getmntent="no"]
+  )
+fi
+
+if test "x$have_getmntent" = "xlibc"; then
+  AC_CACHE_CHECK([whether getmntent takes one argument],
+    [c_cv_have_one_getmntent],
+    [
+      AC_COMPILE_IFELSE(
+        [
+          AC_LANG_PROGRAM(
+            [[#include "$srcdir/src/utils_mount.h"]],
+            [[
+              FILE *fh;
+              struct mntent *me;
+              fh = setmntent ("/etc/mtab", "r");
+              me = getmntent (fh);
+              return(me->mnt_passno);
+            ]]
+          )
+        ],
+        [c_cv_have_one_getmntent="yes"],
+        [c_cv_have_one_getmntent="no"]
+      )
+    ]
+  )
+
+  AC_CACHE_CHECK([whether getmntent takes two arguments],
+    [c_cv_have_two_getmntent],
+    [
+      AC_COMPILE_IFELSE(
+        [
+          AC_LANG_PROGRAM(
+            [[#include "$srcdir/src/utils_mount.h"]],
+            [[
+              FILE *fh;
+              struct mnttab mt;
+              int status;
+              fh = fopen ("/etc/mnttab", "r");
+              status = getmntent (fh, &mt);
+              return(status);
+            ]]
+          )
+        ],
+        [c_cv_have_two_getmntent="yes"],
+        [c_cv_have_two_getmntent="no"]
+      )
+    ]
+  )
 fi
 
 # Check for different versions of `getmntent' here..
 
-if test "x$have_getmntent" = "xc"; then
-       if test "x$c_cv_have_one_getmntent" = "xyes"; then
-               AC_DEFINE(HAVE_ONE_GETMNTENT, 1,
-                         [Define if the function getmntent exists and takes one argument.])
-       fi
-       if test "x$c_cv_have_two_getmntent" = "xyes"; then
-               AC_DEFINE(HAVE_TWO_GETMNTENT, 1,
-                         [Define if the function getmntent exists and takes two arguments.])
-       fi
+if test "x$have_getmntent" = "xlibc"; then
+  if test "x$c_cv_have_one_getmntent" = "xyes"; then
+    AC_DEFINE([HAVE_ONE_GETMNTENT], [1],
+      [Define if the function getmntent exists and takes one argument.]
+    )
+  fi
+
+  if test "x$c_cv_have_two_getmntent" = "xyes"; then
+    AC_DEFINE([HAVE_TWO_GETMNTENT], [1],
+      [Define if the function getmntent exists and takes two arguments.]
+    )
+  fi
 fi
+
 if test "x$have_getmntent" = "xsun"; then
-       AC_DEFINE(HAVE_SUN_GETMNTENT, 1,
-                 [Define if the function getmntent exists. It is the version from libsun.])
-fi
-if test "x$have_getmntent" = "xseq"; then
-       AC_DEFINE(HAVE_SEQ_GETMNTENT, 1,
-                 [Define if the function getmntent exists. It is the version from libseq.])
+  AC_DEFINE([HAVE_SUN_GETMNTENT], [1],
+    [Define if the function getmntent exists. It is the version from libsun.]
+  )
 fi
+
 if test "x$have_getmntent" = "xgen"; then
-       AC_DEFINE(HAVE_GEN_GETMNTENT, 1,
-                 [Define if the function getmntent exists. It is the version from libgen.])
+  AC_DEFINE([HAVE_GEN_GETMNTENT], [1],
+    [Define if the function getmntent exists. It is the version from libgen.]
+  )
 fi
 
 # Check for htonll
-AC_CACHE_CHECK([if have htonll defined],
-                  [c_cv_have_htonll],
-                  AC_LINK_IFELSE([AC_LANG_PROGRAM(
-[[[
-#include <sys/types.h>
-#include <netinet/in.h>
-#if HAVE_INTTYPES_H
-# include <inttypes.h>
-#endif
-]]],
-[[[
-          return htonll(0);
-]]]
-    )],
-    [c_cv_have_htonll="yes"],
-    [c_cv_have_htonll="no"]
-  )
+AC_CACHE_CHECK([whether htonll is defined],
+  [c_cv_have_htonll],
+  [
+    AC_LINK_IFELSE(
+      [
+        AC_LANG_PROGRAM(
+          [[
+            #include <inttypes.h>
+            #include <sys/types.h>
+            #include <netinet/in.h>
+          ]],
+          [[return htonll(0);]]
+        )
+      ],
+      [c_cv_have_htonll="yes"],
+      [c_cv_have_htonll="no"]
+    )
+  ]
 )
-if test "x$c_cv_have_htonll" = "xyes"
-then
-    AC_DEFINE(HAVE_HTONLL, 1, [Define if the function htonll exists.])
+
+if test "x$c_cv_have_htonll" = "xyes"; then
+  AC_DEFINE([HAVE_HTONLL], [1], [Define if the function htonll exists.])
 fi
 
 # Check for structures
 AC_CHECK_MEMBERS([struct if_data.ifi_ibytes, struct if_data.ifi_opackets, struct if_data.ifi_ierrors],
-       [AC_DEFINE(HAVE_STRUCT_IF_DATA, 1, [Define if struct if_data exists and is usable.])],
-       [],
-       [
-       #include <sys/types.h>
-       #include <sys/socket.h>
-       #include <net/if.h>
-       ])
+  [AC_DEFINE([HAVE_STRUCT_IF_DATA], [1], [Define if struct if_data exists and is usable.])],
+  [],
+  [[
+    #include <sys/types.h>
+    #include <sys/socket.h>
+    #include <net/if.h>
+  ]]
+)
+
 AC_CHECK_MEMBERS([struct net_device_stats.rx_bytes, struct net_device_stats.tx_packets, struct net_device_stats.rx_errors],
-       [AC_DEFINE(HAVE_STRUCT_NET_DEVICE_STATS, 1, [Define if struct net_device_stats exists and is usable.])],
-       [],
-       [
-       #include <sys/types.h>
-       #include <sys/socket.h>
-       #include <linux/if.h>
-       #include <linux/netdevice.h>
-       ])
-AC_CHECK_MEMBERS([struct inet_diag_req.id, struct inet_diag_req.idiag_states],
-       [AC_DEFINE(HAVE_STRUCT_LINUX_INET_DIAG_REQ, 1, [Define if struct inet_diag_req exists and is usable.])],
-       [],
-       [
-       #include <linux/inet_diag.h>
-       ])
+  [AC_DEFINE([HAVE_STRUCT_NET_DEVICE_STATS], [1], [Define if struct net_device_stats exists and is usable.])],
+  [],
+  [[
+    #include <sys/types.h>
+    #include <sys/socket.h>
+    #include <linux/if.h>
+    #include <linux/netdevice.h>
+  ]]
+)
 
+AC_CHECK_MEMBERS([struct inet_diag_req.id, struct inet_diag_req.idiag_states],
+  [AC_DEFINE([HAVE_STRUCT_LINUX_INET_DIAG_REQ], [1], [Define if struct inet_diag_req exists and is usable.])],
+  [],
+  [[#include <linux/inet_diag.h>]]
+)
 
 AC_CHECK_MEMBERS([struct ip_mreqn.imr_ifindex], [],
-       [],
-       [
-       #include <netinet/in.h>
-       #include <net/if.h>
-       ])
+  [],
+  [[
+    #include <netinet/in.h>
+    #include <net/if.h>
+  ]]
+)
 
 AC_CHECK_MEMBERS([struct kinfo_proc.ki_pid, struct kinfo_proc.ki_rssize, struct kinfo_proc.ki_rusage],
-       [
-               AC_DEFINE(HAVE_STRUCT_KINFO_PROC_FREEBSD, 1,
-                       [Define if struct kinfo_proc exists in the FreeBSD variant.])
-               have_struct_kinfo_proc_freebsd="yes"
-       ],
-       [
-               have_struct_kinfo_proc_freebsd="no"
-       ],
-       [
-#include <kvm.h>
-#include <sys/param.h>
-#include <sys/sysctl.h>
-#include <sys/user.h>
-       ])
+  [
+    AC_DEFINE([HAVE_STRUCT_KINFO_PROC_FREEBSD], [1], [Define if struct kinfo_proc exists in the FreeBSD variant.])
+    have_struct_kinfo_proc_freebsd="yes"
+  ],
+  [],
+  [[
+    #include <kvm.h>
+    #include <sys/param.h>
+    #include <sys/sysctl.h>
+    #include <sys/user.h>
+  ]]
+)
 
 AC_CHECK_MEMBERS([struct kinfo_proc.p_pid, struct kinfo_proc.p_vm_rssize],
-       [
-               AC_DEFINE(HAVE_STRUCT_KINFO_PROC_OPENBSD, 1,
-                       [Define if struct kinfo_proc exists in the OpenBSD variant.])
-               have_struct_kinfo_proc_openbsd="yes"
-       ],
-       [
-               have_struct_kinfo_proc_openbsd="no"
-       ],
-       [
-#include <sys/param.h>
-#include <sys/sysctl.h>
-#include <kvm.h>
-       ])
-
+  [
+    AC_DEFINE([HAVE_STRUCT_KINFO_PROC_OPENBSD], [1], [Define if struct kinfo_proc exists in the OpenBSD variant.])
+    have_struct_kinfo_proc_openbsd="yes"
+  ],
+  [],
+  [[
+    #include <sys/param.h>
+    #include <sys/sysctl.h>
+    #include <kvm.h>
+  ]]
+)
 
 AC_CHECK_MEMBERS([struct kinfo_proc2.p_pid, struct kinfo_proc2.p_uru_maxrss],
-       [
-               AC_DEFINE(HAVE_STRUCT_KINFO_PROC2_NETBSD, 1,
-                       [Define if struct kinfo_proc2 exists in the NetBSD variant.])
-               have_struct_kinfo_proc2_netbsd="yes"
-       ],
-       [
-               have_struct_kinfo_proc2_netbsd="no"
-       ],
-       [
-#include <sys/param.h>
-#include <sys/sysctl.h>
-#include <kvm.h>
-       ])
-
-
-
-AC_CHECK_MEMBERS([struct udphdr.uh_dport, struct udphdr.uh_sport], [], [],
-[#define _BSD_SOURCE
-#define _DEFAULT_SOURCE
-#if HAVE_STDINT_H
-# include <stdint.h>
-#endif
-#if HAVE_SYS_TYPES_H
-# include <sys/types.h>
-#endif
-#if HAVE_NETINET_IN_SYSTM_H
-# include <netinet/in_systm.h>
-#endif
-#if HAVE_NETINET_IN_H
-# include <netinet/in.h>
-#endif
-#if HAVE_NETINET_IP_H
-# include <netinet/ip.h>
-#endif
-#if HAVE_NETINET_UDP_H
-# include <netinet/udp.h>
-#endif
-])
-AC_CHECK_MEMBERS([struct udphdr.dest, struct udphdr.source], [], [],
-[#define _BSD_SOURCE
-#define _DEFAULT_SOURCE
-#if HAVE_STDINT_H
-# include <stdint.h>
-#endif
-#if HAVE_SYS_TYPES_H
-# include <sys/types.h>
-#endif
-#if HAVE_NETINET_IN_SYSTM_H
-# include <netinet/in_systm.h>
-#endif
-#if HAVE_NETINET_IN_H
-# include <netinet/in.h>
-#endif
-#if HAVE_NETINET_IP_H
-# include <netinet/ip.h>
-#endif
-#if HAVE_NETINET_UDP_H
-# include <netinet/udp.h>
-#endif
-])
+  [
+    AC_DEFINE([HAVE_STRUCT_KINFO_PROC2_NETBSD], [1], [Define if struct kinfo_proc2 exists in the NetBSD variant.])
+    have_struct_kinfo_proc2_netbsd="yes"
+  ],
+  [],
+  [[
+    #include <sys/param.h>
+    #include <sys/sysctl.h>
+    #include <kvm.h>
+  ]]
+)
 
-AC_CHECK_MEMBERS([kstat_io_t.nwritten, kstat_io_t.writes, kstat_io_t.nwrites, kstat_io_t.wtime],
-       [],
-       [],
-       [
-#if HAVE_KSTAT_H
-# include <kstat.h>
-#endif
-       ])
+AC_CHECK_MEMBERS([struct udphdr.uh_dport, struct udphdr.uh_sport],
+  [],
+  [],
+  [[
+    #define _BSD_SOURCE
+    #define _DEFAULT_SOURCE
+    #include <stdint.h>
+    #if HAVE_SYS_TYPES_H
+    # include <sys/types.h>
+    #endif
+    #if HAVE_NETINET_IN_SYSTM_H
+    # include <netinet/in_systm.h>
+    #endif
+    #if HAVE_NETINET_IN_H
+    # include <netinet/in.h>
+    #endif
+    #if HAVE_NETINET_IP_H
+    # include <netinet/ip.h>
+    #endif
+    #if HAVE_NETINET_UDP_H
+    # include <netinet/udp.h>
+    #endif
+  ]]
+)
+
+AC_CHECK_MEMBERS([struct udphdr.dest, struct udphdr.source],
+  [],
+  [],
+  [[
+    #define _BSD_SOURCE
+    #define _DEFAULT_SOURCE
+    #include <stdint.h>
+    #if HAVE_SYS_TYPES_H
+    # include <sys/types.h>
+    #endif
+    #if HAVE_NETINET_IN_SYSTM_H
+    # include <netinet/in_systm.h>
+    #endif
+    #if HAVE_NETINET_IN_H
+    # include <netinet/in.h>
+    #endif
+    #if HAVE_NETINET_IP_H
+    # include <netinet/ip.h>
+    #endif
+    #if HAVE_NETINET_UDP_H
+    # include <netinet/udp.h>
+    #endif
+  ]]
+)
+
+AC_CHECK_MEMBERS([kstat_io_t.nwritten, kstat_io_t.writes, kstat_io_t.nwrites, kstat_io_t.wtime],
+  [],
+  [],
+  [[# include <kstat.h>]]
+)
 
 # check for pthread_setname_np
 SAVE_LDFLAGS="$LDFLAGS"
 LDFLAGS="$LDFLAGS -lpthread"
 
 AC_MSG_CHECKING([for pthread_setname_np])
-       have_pthread_setname_np="no"
-       AC_LINK_IFELSE([AC_LANG_PROGRAM(
-[[
-#define _GNU_SOURCE
-#include <pthread.h>
-]],
-[[
-        pthread_setname_np((pthread_t) {0}, "conftest");
-]]
-       )], [
-               have_pthread_setname_np="yes"
-               AC_DEFINE(HAVE_PTHREAD_SETNAME_NP, 1, [pthread_setname_np() is available.])
-       ])
+have_pthread_setname_np="no"
+AC_LINK_IFELSE(
+  [
+    AC_LANG_PROGRAM(
+      [[
+        #define _GNU_SOURCE
+        #include <pthread.h>
+      ]],
+      [[pthread_setname_np((pthread_t) {0}, "conftest");]]
+    )
+  ],
+  [
+    have_pthread_setname_np="yes"
+    AC_DEFINE(HAVE_PTHREAD_SETNAME_NP, 1, [pthread_setname_np() is available.])
+  ]
+)
 
 AC_MSG_RESULT([$have_pthread_setname_np])
 
 # check for pthread_set_name_np(3) (FreeBSD)
 AC_MSG_CHECKING([for pthread_set_name_np])
-       have_pthread_set_name_np="no"
-       AC_LINK_IFELSE([AC_LANG_PROGRAM(
-[[
-#include <pthread_np.h>
-]],
-[[
-        pthread_set_name_np((pthread_t) {0}, "conftest");
-]]
-       )], [
-               have_pthread_set_name_np="yes"
-               AC_DEFINE(HAVE_PTHREAD_SET_NAME_NP, 1, [pthread_set_name_np() is available.])
-       ])
+have_pthread_set_name_np="no"
+AC_LINK_IFELSE(
+  [
+    AC_LANG_PROGRAM(
+      [[#include <pthread_np.h>]],
+      [[pthread_set_name_np((pthread_t) {0}, "conftest");]]
+    )
+   ],
+  [
+    have_pthread_set_name_np="yes"
+    AC_DEFINE(HAVE_PTHREAD_SET_NAME_NP, 1, [pthread_set_name_np() is available.])
+  ]
+)
 AC_MSG_RESULT([$have_pthread_set_name_np])
 
 LDFLAGS="$SAVE_LDFLAGS"
 
-#
-# Checks for libraries begin here
-#
+AC_CHECK_TYPES([struct ip6_ext],
+  [have_ip6_ext="yes"],
+  [have_ip6_ext="no"],
+  [[
+    #include <stdint.h>
+    #if HAVE_SYS_TYPES_H
+    # include <sys/types.h>
+    #endif
+    #if HAVE_NETINET_IN_SYSTM_H
+    # include <netinet/in_systm.h>
+    #endif
+    #if HAVE_NETINET_IN_H
+    # include <netinet/in.h>
+    #endif
+    #if HAVE_NETINET_IP6_H
+    # include <netinet/ip6.h>
+    #endif
+  ]]
+)
 
-with_libresolv="yes"
-AC_CHECK_LIB(resolv, res_search,
-[
-       AC_DEFINE(HAVE_LIBRESOLV, 1, [Define to 1 if you have the 'resolv' library (-lresolv).])
-],
-[with_libresolv="no"])
-AM_CONDITIONAL(BUILD_WITH_LIBRESOLV, test "x$with_libresolv" = "xyes")
+if test "x$have_ip6_ext" = "xno"; then
+  SAVE_CFLAGS="$CFLAGS"
+  CFLAGS="$CFLAGS -DSOLARIS2=8"
+  AC_CHECK_TYPES([struct ip6_ext],
+    [have_ip6_ext="yes, with -DSOLARIS2=8"],
+    [have_ip6_ext="no"],
+    [[
+      #include <stdint.h>
+      #if HAVE_SYS_TYPES_H
+      # include <sys/types.h>
+      #endif
+      #if HAVE_NETINET_IN_SYSTM_H
+      # include <netinet/in_systm.h>
+      #endif
+      #if HAVE_NETINET_IN_H
+      # include <netinet/in.h>
+      #endif
+      #if HAVE_NETINET_IP6_H
+      # include <netinet/ip6.h>
+      #endif
+    ]]
+  )
+  if test "x$have_ip6_ext" = "xno"; then
+    CFLAGS="$SAVE_CFLAGS"
+  fi
+fi
 
-dnl Check for HAL (hardware abstraction library)
-with_libhal="no"
-PKG_CHECK_MODULES([HAL], [hal],
-  [
-    SAVE_LIBS="$LIBS"
-    LIBS="$HAL_LIBS $LIBS"
-    AC_CHECK_LIB([hal], [libhal_device_property_exists],
-      [
-        SAVE_CPPFLAGS="$CPPFLAGS"
-        CPPFLAGS="$HAL_CFLAGS $CPPFLAGS"
-        AC_CHECK_HEADERS([libhal.h],
-        [
-          with_libhal="yes"
-          BUILD_WITH_LIBHAL_CFLAGS="$HAL_CFLAGS"
-          BUILD_WITH_LIBHAL_LIBS="$HAL_LIBS"
-        ])
-        CPPFLAGS="$SAVE_CPPFLAGS"
-      ],
-      [ : ]
-    )
-    LIBS="$SAVE_LIBS"
-  ],
-  [ : ]
-)
-AC_SUBST(BUILD_WITH_LIBHAL_CFLAGS)
-AC_SUBST(BUILD_WITH_LIBHAL_LIBS)
+# libi2c-dev
+if test "x$ac_system" = "xLinux"; then
+  AC_CHECK_DECL([i2c_smbus_read_i2c_block_data],
+    [with_libi2c="yes"],
+    [with_libi2c="no (symbol i2c_smbus_read_i2c_block_data not found - have you installed libi2c-dev ?)"],
+    [[
+      #include <stdlib.h>
+      #include <linux/i2c-dev.h>
+    ]]
+  )
+else
+  with_libi2c="no (Linux only)"
+fi
 
+#
+# Checks for libraries begin here
+#
 
+# Check for libpthread
 SAVE_LIBS="$LIBS"
 AC_CHECK_LIB([pthread],
   [pthread_create],
   [],
-  [AC_MSG_ERROR([Symbol 'pthread_create' not found in libpthread"])],
+  [AC_MSG_ERROR([Symbol 'pthread_create' not found in libpthread])],
   []
 )
 PTHREAD_LIBS="$LIBS"
 LIBS="$SAVE_LIBS"
+AC_SUBST([PTHREAD_LIBS])
 
 AC_CHECK_HEADERS([pthread.h],
   [],
   [AC_MSG_ERROR([pthread.h not found])]
 )
-AC_SUBST([PTHREAD_LIBS])
 
 m4_divert_once([HELP_WITH], [
-collectd additional packages:])
+Collectd additional packages:])
 
-if test "x$ac_system" = "xAIX"
-then
-       with_perfstat="yes"
-       with_procinfo="yes"
+if test "x$ac_system" = "xAIX"; then
+  with_perfstat="yes"
+  with_procinfo="yes"
 else
-       with_perfstat="no (AIX only)"
-       with_procinfo="no (AIX only)"
+  with_perfstat="no (AIX only)"
+  with_procinfo="no (AIX only)"
 fi
 
-if test "x$with_perfstat" = "xyes"
-then
-       AC_CHECK_LIB(perfstat, perfstat_reset, [with_perfstat="yes"], [with_perfstat="no (perfstat not found)"], [])
-#      AC_CHECK_HEADERS(sys/protosw.h libperfstat.h,, [with_perfstat="no (perfstat not found)"])
+if test "x$with_perfstat" = "xyes"; then
+  AC_CHECK_LIB([perfstat], [perfstat_reset],
+    [with_perfstat="yes"],
+    [with_perfstat="no (perfstat not found)"]
+  )
 fi
-if test "x$with_perfstat" = "xyes"
-then
-        AC_DEFINE(HAVE_PERFSTAT, 1, [Define to 1 if you have the 'perfstat' library (-lperfstat)])
-        # struct members pertaining to donation have been added to libperfstat somewhere between AIX5.3ML5 and AIX5.3ML9
-        AC_CHECK_MEMBER([perfstat_partition_type_t.b.donate_enabled], [], [], [[#include <libperfstat.h]])
-        if test "x$av_cv_member_perfstat_partition_type_t_b_donate_enabled" = "xyes"
-        then
-               AC_DEFINE(PERFSTAT_SUPPORTS_DONATION, 1, [Define to 1 if your version of the 'perfstat' library supports donation])
-        fi
+
+if test "x$with_perfstat" = "xyes"; then
+  AC_DEFINE([HAVE_PERFSTAT], [1], [Define to 1 if you have the 'perfstat' library (-lperfstat)])
+  # struct members pertaining to donation have been added to libperfstat somewhere between AIX5.3ML5 and AIX5.3ML9
+  AC_CHECK_MEMBER([perfstat_partition_type_t.b.donate_enabled],
+    [],
+    [],
+    [[#include <libperfstat.h]]
+  )
+  if test "x$av_cv_member_perfstat_partition_type_t_b_donate_enabled" = "xyes"; then
+    AC_DEFINE([PERFSTAT_SUPPORTS_DONATION], [1], [Define to 1 if your version of the 'perfstat' library supports donation])
+  fi
 fi
-AM_CONDITIONAL(BUILD_WITH_PERFSTAT, test "x$with_perfstat" = "xyes")
+AM_CONDITIONAL([BUILD_WITH_PERFSTAT], [test "x$with_perfstat" = "xyes"])
 
 # Processes plugin under AIX.
-if test "x$with_procinfo" = "xyes"
-then
-       AC_CHECK_HEADERS(procinfo.h,, [with_procinfo="no (procinfo.h not found)"])
-fi
-if test "x$with_procinfo" = "xyes"
-then
-        AC_DEFINE(HAVE_PROCINFO_H, 1, [Define to 1 if you have the procinfo.h])
+if test "x$with_procinfo" = "xyes"; then
+  AC_CHECK_HEADERS([procinfo.h],
+    [AC_DEFINE([HAVE_PROCINFO_H], [1], [Define to 1 if you have the procinfo.h])],
+    [with_procinfo="no (procinfo.h not found)"]
+  )
 fi
 
-if test "x$ac_system" = "xSolaris"
-then
-       with_kstat="yes"
-       with_devinfo="yes"
+if test "x$ac_system" = "xSolaris"; then
+  with_kstat="yes"
+  with_devinfo="yes"
 else
-       with_kstat="no (Solaris only)"
-       with_devinfo="no (Solaris only)"
+  with_kstat="no (Solaris only)"
+  with_devinfo="no (Solaris only)"
 fi
 
-if test "x$with_kstat" = "xyes"
-then
-       AC_CHECK_LIB(kstat, kstat_open, [with_kstat="yes"], [with_kstat="no (libkstat not found)"], [])
-fi
-if test "x$with_kstat" = "xyes"
-then
-       AC_CHECK_LIB(devinfo, di_init, [with_devinfo="yes"], [with_devinfo="no (not found)"], [])
-       AC_CHECK_HEADERS(kstat.h,, [with_kstat="no (kstat.h not found)"])
+if test "x$with_kstat" = "xyes"; then
+  AC_CHECK_LIB([kstat], [kstat_open],
+    [with_kstat="yes"],
+    [with_kstat="no (libkstat not found)"]
+  )
 fi
-if test "x$with_kstat" = "xyes"
-then
-       AC_DEFINE(HAVE_LIBKSTAT, 1,
-                 [Define to 1 if you have the 'kstat' library (-lkstat)])
+
+if test "x$with_kstat" = "xyes"; then
+  AC_CHECK_LIB([devinfo], [di_init],
+    [with_devinfo="yes"],
+    [with_devinfo="no (not found)"]
+  )
+  AC_CHECK_HEADERS([kstat.h],
+    [AC_DEFINE(HAVE_LIBKSTAT, [1], [Define to 1 if you have the 'kstat' library (-lkstat)])],
+    [with_kstat="no (kstat.h not found)"]
+  )
 fi
-AM_CONDITIONAL(BUILD_WITH_LIBKSTAT, test "x$with_kstat" = "xyes")
-AM_CONDITIONAL(BUILD_WITH_LIBDEVINFO, test "x$with_devinfo" = "xyes")
 
-with_libiokit="no"
-if test "x$ac_system" = "xDarwin"
-then
-       with_libiokit="yes"
+AM_CONDITIONAL([BUILD_WITH_LIBDEVINFO], [test "x$with_devinfo" = "xyes"])
+AM_CONDITIONAL([BUILD_WITH_LIBKSTAT], [test "x$with_kstat" = "xyes"])
+
+if test "x$ac_system" = "xDarwin"; then
+  with_libiokit="yes"
 else
-       with_libiokit="no"
+  with_libiokit="no"
 fi
-AM_CONDITIONAL(BUILD_WITH_LIBIOKIT, test "x$with_libiokit" = "xyes")
+AM_CONDITIONAL([BUILD_WITH_LIBIOKIT], [test "x$with_libiokit" = "xyes"])
 
 with_libkvm="no"
-AC_CHECK_LIB(kvm, kvm_getprocs, [with_kvm_getprocs="yes"], [with_kvm_getprocs="no"])
-if test "x$with_kvm_getprocs" = "xyes"
-then
-       AC_DEFINE(HAVE_LIBKVM_GETPROCS, 1,
-                 [Define to 1 if you have the 'kvm' library with the 'kvm_getprocs' symbol (-lkvm)])
-       with_libkvm="yes"
+AC_CHECK_LIB([kvm], [kvm_getprocs],
+  [with_kvm_getprocs="yes"],
+  [with_kvm_getprocs="no"]
+)
+
+if test "x$with_kvm_getprocs" = "xyes"; then
+  AC_DEFINE([HAVE_LIBKVM_GETPROCS], [1],
+    [Define to 1 if you have the 'kvm' library with the 'kvm_getprocs' symbol (-lkvm)]
+  )
+  with_libkvm="yes"
 fi
-AM_CONDITIONAL(BUILD_WITH_LIBKVM_GETPROCS, test "x$with_kvm_getprocs" = "xyes")
 
-AC_CHECK_LIB(kvm, kvm_getswapinfo, [with_kvm_getswapinfo="yes"], [with_kvm_getswapinfo="no"])
-if test "x$with_kvm_getswapinfo" = "xyes"
-then
-       AC_DEFINE(HAVE_LIBKVM_GETSWAPINFO, 1,
-                 [Define to 1 if you have the 'kvm' library with the 'kvm_getswapinfo' symbol (-lkvm)])
-       with_libkvm="yes"
+AM_CONDITIONAL([BUILD_WITH_LIBKVM_GETPROCS], [test "x$with_kvm_getprocs" = "xyes"])
+
+AC_CHECK_LIB([kvm], [kvm_getswapinfo],
+  [with_kvm_getswapinfo="yes"],
+  [with_kvm_getswapinfo="no"]
+)
+
+if test "x$with_kvm_getswapinfo" = "xyes"; then
+  AC_DEFINE([HAVE_LIBKVM_GETSWAPINFO], [1],
+    [Define to 1 if you have the 'kvm' library with the 'kvm_getswapinfo' symbol (-lkvm)]
+  )
+  with_libkvm="yes"
 fi
-AM_CONDITIONAL(BUILD_WITH_LIBKVM_GETSWAPINFO, test "x$with_kvm_getswapinfo" = "xyes")
 
-AC_CHECK_LIB(kvm, kvm_nlist, [with_kvm_nlist="yes"], [with_kvm_nlist="no"])
-if test "x$with_kvm_nlist" = "xyes"
-then
-       AC_CHECK_HEADERS(bsd/nlist.h nlist.h)
-       AC_DEFINE(HAVE_LIBKVM_NLIST, 1,
-                 [Define to 1 if you have the 'kvm' library with the 'kvm_nlist' symbol (-lkvm)])
-       with_libkvm="yes"
+AM_CONDITIONAL([BUILD_WITH_LIBKVM_GETSWAPINFO], [test "x$with_kvm_getswapinfo" = "xyes"])
+
+AC_CHECK_LIB([kvm], [kvm_nlist],
+  [with_kvm_nlist="yes"],
+  [with_kvm_nlist="no"]
+)
+
+if test "x$with_kvm_nlist" = "xyes"; then
+  AC_CHECK_HEADERS([bsd/nlist.h nlist.h])
+  AC_DEFINE([HAVE_LIBKVM_NLIST], [1],
+    [Define to 1 if you have the 'kvm' library with the 'kvm_nlist' symbol (-lkvm)]
+  )
+  with_libkvm="yes"
 fi
-AM_CONDITIONAL(BUILD_WITH_LIBKVM_NLIST, test "x$with_kvm_nlist" = "xyes")
 
-AC_CHECK_LIB(kvm, kvm_openfiles, [with_kvm_openfiles="yes"], [with_kvm_openfiles="no"])
-if test "x$with_kvm_openfiles" = "xyes"
-then
-       AC_DEFINE(HAVE_LIBKVM_NLIST, 1,
-                 [Define to 1 if you have the 'kvm' library with the 'kvm_openfiles' symbol (-lkvm)])
-       with_libkvm="yes"
+AM_CONDITIONAL([BUILD_WITH_LIBKVM_NLIST], [test "x$with_kvm_nlist" = "xyes"])
+
+AC_CHECK_LIB([kvm], [kvm_openfiles],
+  [with_kvm_openfiles="yes"],
+  [with_kvm_openfiles="no"]
+)
+
+if test "x$with_kvm_openfiles" = "xyes"; then
+  AC_DEFINE([HAVE_LIBKVM_NLIST], [1],
+    [Define to 1 if you have the 'kvm' library with the 'kvm_openfiles' symbol (-lkvm)]
+  )
+  with_libkvm="yes"
 fi
-AM_CONDITIONAL(BUILD_WITH_LIBKVM_OPENFILES, test "x$with_kvm_openfiles" = "xyes")
 
 # --with-libaquaero5 {{{
-AC_ARG_WITH(libaquaero5, [AS_HELP_STRING([--with-libaquaero5@<:@=PREFIX@:>@], [Path to aquatools-ng source code.])],
-[
- if test "x$withval" = "xyes"
- then
-        with_libaquaero5="yes"
- else if test "x$withval" = "xno"
- then
-        with_libaquaero5="no"
- else
-        with_libaquaero5="yes"
-        LIBAQUAERO5_CFLAGS="$LIBAQUAERO5_CFLAGS -I$withval/src"
-        LIBAQUAERO5_LDFLAGS="$LIBAQUAERO5_LDFLAGS -L$withval/obj"
- fi; fi
-],
-[with_libaquaero5="yes"])
+AC_ARG_WITH([libaquaero5],
+  [AS_HELP_STRING([--with-libaquaero5@<:@=PREFIX@:>@], [Path to aquatools-ng source code.])],
+  [
   if test "x$withval" = "xyes"; then
+      with_libaquaero5="yes"
+    else if test "x$withval" = "xno"; then
+      with_libaquaero5="no"
+    else
+      with_libaquaero5="yes"
+      LIBAQUAERO5_CFLAGS="$LIBAQUAERO5_CFLAGS -I$withval/src"
+      LIBAQUAERO5_LDFLAGS="$LIBAQUAERO5_LDFLAGS -L$withval/obj"
+    fi; fi
+  ],
+  [with_libaquaero5="yes"]
+)
 
 SAVE_CPPFLAGS="$CPPFLAGS"
 SAVE_LDFLAGS="$LDFLAGS"
-
 CPPFLAGS="$CPPFLAGS $LIBAQUAERO5_CFLAGS"
 LDFLAGS="$LDFLAGS $LIBAQUAERO5_LDFLAGS"
 
-if test "x$with_libaquaero5" = "xyes"
-then
-       if test "x$LIBAQUAERO5_CFLAGS" != "x"
-       then
-               AC_MSG_NOTICE([libaquaero5 CPPFLAGS: $LIBAQUAERO5_CFLAGS])
-       fi
-       AC_CHECK_HEADERS(libaquaero5.h,
-       [with_libaquaero5="yes"],
-       [with_libaquaero5="no (libaquaero5.h not found)"])
+if test "x$with_libaquaero5" = "xyes"; then
+  if test "x$LIBAQUAERO5_CFLAGS" != "x"; then
+    AC_MSG_NOTICE([libaquaero5 CPPFLAGS: $LIBAQUAERO5_CFLAGS])
+  fi
+  AC_CHECK_HEADERS([libaquaero5.h],
+    [with_libaquaero5="yes"],
+    [with_libaquaero5="no (libaquaero5.h not found)"]
+  )
 fi
-if test "x$with_libaquaero5" = "xyes"
-then
-       if test "x$LIBAQUAERO5_LDFLAGS" != "x"
-       then
-               AC_MSG_NOTICE([libaquaero5 LDFLAGS: $LIBAQUAERO5_LDFLAGS])
-       fi
-       AC_CHECK_LIB(aquaero5, libaquaero5_poll,
-       [with_libaquaero5="yes"],
-       [with_libaquaero5="no (symbol 'libaquaero5_poll' not found)"])
+
+if test "x$with_libaquaero5" = "xyes"; then
+  if test "x$LIBAQUAERO5_LDFLAGS" != "x"; then
+    AC_MSG_NOTICE([libaquaero5 LDFLAGS: $LIBAQUAERO5_LDFLAGS])
+  fi
+  AC_CHECK_LIB([aquaero5], libaquaero5_poll,
+    [with_libaquaero5="yes"],
+    [with_libaquaero5="no (symbol 'libaquaero5_poll' not found)"]
+  )
 fi
 
 CPPFLAGS="$SAVE_CPPFLAGS"
 LDFLAGS="$SAVE_LDFLAGS"
 
-if test "x$with_libaquaero5" = "xyes"
-then
-       BUILD_WITH_LIBAQUAERO5_CFLAGS="$LIBAQUAERO5_CFLAGS"
-       BUILD_WITH_LIBAQUAERO5_LDFLAGS="$LIBAQUAERO5_LDFLAGS"
-       AC_SUBST(BUILD_WITH_LIBAQUAERO5_CFLAGS)
-       AC_SUBST(BUILD_WITH_LIBAQUAERO5_LDFLAGS)
+if test "x$with_libaquaero5" = "xyes"; then
+  BUILD_WITH_LIBAQUAERO5_CFLAGS="$LIBAQUAERO5_CFLAGS"
+  BUILD_WITH_LIBAQUAERO5_LDFLAGS="$LIBAQUAERO5_LDFLAGS"
 fi
-AM_CONDITIONAL(BUILD_WITH_LIBAQUAERO5, test "x$with_libaquaero5" = "xyes")
+AC_SUBST([BUILD_WITH_LIBAQUAERO5_CFLAGS])
+AC_SUBST([BUILD_WITH_LIBAQUAERO5_LDFLAGS])
 # }}}
 
 # --with-libhiredis {{{
-AC_ARG_WITH(libhiredis, [AS_HELP_STRING([--with-libhiredis@<:@=PREFIX@:>@],
-      [Path to libhiredis.])],
-[
- if test "x$withval" = "xyes"
- then
-        with_libhiredis="yes"
- else if test "x$withval" = "xno"
- then
-        with_libhiredis="no"
- else
-        with_libhiredis="yes"
-        LIBHIREDIS_CPPFLAGS="$LIBHIREDIS_CPPFLAGS -I$withval/include"
-        LIBHIREDIS_LDFLAGS="$LIBHIREDIS_LDFLAGS -L$withval/lib"
- fi; fi
-],
-[with_libhiredis="yes"])
+AC_ARG_WITH([libhiredis],
+  [AS_HELP_STRING([--with-libhiredis@<:@=PREFIX@:>@], [Path to libhiredis.])],
+  [
+    if test "x$withval" = "xyes"; then
+      with_libhiredis="yes"
+    else if test "x$withval" = "xno"; then
+      with_libhiredis="no"
+    else
+      with_libhiredis="yes"
+      LIBHIREDIS_CPPFLAGS="$LIBHIREDIS_CPPFLAGS -I$withval/include"
+      LIBHIREDIS_LDFLAGS="$LIBHIREDIS_LDFLAGS -L$withval/lib"
+    fi; fi
+  ],
+  [with_libhiredis="yes"]
+)
 
 SAVE_CPPFLAGS="$CPPFLAGS"
 SAVE_LDFLAGS="$LDFLAGS"
-
 CPPFLAGS="$CPPFLAGS $LIBHIREDIS_CPPFLAGS"
 LDFLAGS="$LDFLAGS $LIBHIREDIS_LDFLAGS"
 
-if test "x$with_libhiredis" = "xyes"
-then
-       if test "x$LIBHIREDIS_CPPFLAGS" != "x"
-       then
-               AC_MSG_NOTICE([libhiredis CPPFLAGS: $LIBHIREDIS_CPPFLAGS])
-       fi
-       AC_CHECK_HEADERS(hiredis/hiredis.h,
-       [with_libhiredis="yes"],
-       [with_libhiredis="no (hiredis.h not found)"])
+if test "x$with_libhiredis" = "xyes"; then
+  if test "x$LIBHIREDIS_CPPFLAGS" != "x"; then
+    AC_MSG_NOTICE([libhiredis CPPFLAGS: $LIBHIREDIS_CPPFLAGS])
+  fi
+  AC_CHECK_HEADERS([hiredis/hiredis.h],
+    [with_libhiredis="yes"],
+    [with_libhiredis="no (hiredis.h not found)"]
+  )
 fi
-if test "x$with_libhiredis" = "xyes"
-then
-       if test "x$LIBHIREDIS_LDFLAGS" != "x"
-       then
-               AC_MSG_NOTICE([libhiredis LDFLAGS: $LIBHIREDIS_LDFLAGS])
-       fi
-       AC_CHECK_LIB(hiredis, redisCommand,
-       [with_libhiredis="yes"],
-       [with_libhiredis="no (symbol 'redisCommand' not found)"])
 
+if test "x$with_libhiredis" = "xyes"; then
+  if test "x$LIBHIREDIS_LDFLAGS" != "x"; then
+    AC_MSG_NOTICE([libhiredis LDFLAGS: $LIBHIREDIS_LDFLAGS])
+  fi
+  AC_CHECK_LIB([hiredis], [redisCommand],
+    [with_libhiredis="yes"],
+    [with_libhiredis="no (symbol 'redisCommand' not found)"]
+  )
 fi
 
 CPPFLAGS="$SAVE_CPPFLAGS"
 LDFLAGS="$SAVE_LDFLAGS"
 
-if test "x$with_libhiredis" = "xyes"
-then
-       BUILD_WITH_LIBHIREDIS_CPPFLAGS="$LIBHIREDIS_CPPFLAGS"
-       BUILD_WITH_LIBHIREDIS_LDFLAGS="$LIBHIREDIS_LDFLAGS"
-       AC_SUBST(BUILD_WITH_LIBHIREDIS_CPPFLAGS)
-       AC_SUBST(BUILD_WITH_LIBHIREDIS_LDFLAGS)
+if test "x$with_libhiredis" = "xyes"; then
+  BUILD_WITH_LIBHIREDIS_CPPFLAGS="$LIBHIREDIS_CPPFLAGS"
+  BUILD_WITH_LIBHIREDIS_LDFLAGS="$LIBHIREDIS_LDFLAGS"
 fi
-AM_CONDITIONAL(BUILD_WITH_LIBHIREDIS, test "x$with_libhiredis" = "xyes")
+
+AC_SUBST([BUILD_WITH_LIBHIREDIS_CPPFLAGS])
+AC_SUBST([BUILD_WITH_LIBHIREDIS_LDFLAGS])
 # }}}
 
 # --with-libcurl {{{
 with_curl_config="curl-config"
 with_curl_cflags=""
 with_curl_libs=""
-AC_ARG_WITH(libcurl, [AS_HELP_STRING([--with-libcurl@<:@=PREFIX@:>@], [Path to libcurl.])],
-[
-       if test "x$withval" = "xno"
-       then
-               with_libcurl="no"
-       else if test "x$withval" = "xyes"
-       then
-               with_libcurl="yes"
-       else
-               if test -f "$withval" && test -x "$withval"
-               then
-                       with_curl_config="$withval"
-                       with_libcurl="yes"
-               else if test -x "$withval/bin/curl-config"
-               then
-                       with_curl_config="$withval/bin/curl-config"
-                       with_libcurl="yes"
-               fi; fi
-               with_libcurl="yes"
-       fi; fi
-],
-[
-       with_libcurl="yes"
-])
-if test "x$with_libcurl" = "xyes"
-then
-       with_curl_cflags=`$with_curl_config --cflags 2>/dev/null`
-       curl_config_status=$?
+AC_ARG_WITH(libcurl,
+  [AS_HELP_STRING([--with-libcurl@<:@=PREFIX@:>@], [Path to libcurl.])],
+  [
+    if test "x$withval" = "xno"; then
+      with_libcurl="no"
+    else if test "x$withval" = "xyes"; then
+      with_libcurl="yes"
+    else
+      if test -f "$withval" && test -x "$withval"; then
+        with_curl_config="$withval"
+        with_libcurl="yes"
+      else if test -x "$withval/bin/curl-config"; then
+        with_curl_config="$withval/bin/curl-config"
+        with_libcurl="yes"
+      fi; fi
+      with_libcurl="yes"
+    fi; fi
+  ],
+  [with_libcurl="yes"]
+)
 
-       if test $curl_config_status -ne 0
-       then
-               with_libcurl="no ($with_curl_config failed)"
-       else
-               SAVE_CPPFLAGS="$CPPFLAGS"
-               CPPFLAGS="$CPPFLAGS $with_curl_cflags"
+if test "x$with_libcurl" = "xyes"; then
+  with_curl_cflags=`$with_curl_config --cflags 2>/dev/null`
+  curl_config_status=$?
+
+  if test $curl_config_status -ne 0; then
+    with_libcurl="no ($with_curl_config failed)"
+  else
+    SAVE_CPPFLAGS="$CPPFLAGS"
+    CPPFLAGS="$CPPFLAGS $with_curl_cflags"
 
-               AC_CHECK_HEADERS(curl/curl.h, [], [with_libcurl="no (curl/curl.h not found)"], [])
+    AC_CHECK_HEADERS([curl/curl.h],
+      [with_libcurl="yes"],
+      [with_libcurl="no (curl/curl.h not found)"]
+    )
 
-               CPPFLAGS="$SAVE_CPPFLAGS"
-       fi
+    CPPFLAGS="$SAVE_CPPFLAGS"
+  fi
 fi
-if test "x$with_libcurl" = "xyes"
-then
-       with_curl_libs=`$with_curl_config --libs 2>/dev/null`
-       curl_config_status=$?
 
-       if test $curl_config_status -ne 0
-       then
-               with_libcurl="no ($with_curl_config failed)"
-       else
-               AC_CHECK_LIB(curl, curl_easy_init,
-                [with_libcurl="yes"],
-                [with_libcurl="no (symbol 'curl_easy_init' not found)"],
-                [$with_curl_libs])
-               AC_CHECK_DECL(CURLOPT_USERNAME,
-                [have_curlopt_username="yes"],
-                [have_curlopt_username="no"],
-                [[#include <curl/curl.h>]])
-               AC_CHECK_DECL(CURLOPT_TIMEOUT_MS,
-                [have_curlopt_timeout="yes"],
-                [have_curlopt_timeout="no"],
-                [[#include <curl/curl.h>]])
-       fi
+if test "x$with_libcurl" = "xyes"; then
+  with_curl_libs=`$with_curl_config --libs 2>/dev/null`
+  curl_config_status=$?
+
+  if test $curl_config_status -ne 0; then
+    with_libcurl="no ($with_curl_config failed)"
+  else
+    AC_CHECK_LIB([curl], [curl_easy_init],
+      [with_libcurl="yes"],
+      [with_libcurl="no (symbol 'curl_easy_init' not found)"],
+      [$with_curl_libs]
+    )
+
+    AC_CHECK_DECL([CURLOPT_USERNAME],
+      [have_curlopt_username="yes"],
+      [have_curlopt_username="no"],
+      [[#include <curl/curl.h>]]
+    )
+
+    AC_CHECK_DECL(CURLOPT_TIMEOUT_MS,
+      [have_curlopt_timeout="yes"],
+      [have_curlopt_timeout="no"],
+      [[#include <curl/curl.h>]]
+    )
+  fi
 fi
-if test "x$with_libcurl" = "xyes"
-then
-       SAVE_CPPFLAGS="$CPPFLAGS"
-       SAVE_LDFLAGS="$LDFLAGS"
-       CPPFLAGS="$CPPFLAGS $with_curl_cflags"
-       LDFLAGS="$LDFLAGS $with_curl_libs"
-       AC_CACHE_CHECK([for CURLINFO_APPCONNECT_TIME],
-               [c_cv_have_curlinfo_appconnect_time],
-               AC_LINK_IFELSE([AC_LANG_PROGRAM(
-[[
-#include <curl/curl.h>
-]],
-[[
-int val = CURLINFO_APPCONNECT_TIME;
-return val;
-]]
-                       )],
-                       [c_cv_have_curlinfo_appconnect_time="yes"],
-                       [c_cv_have_curlinfo_appconnect_time="no"]
-               )
-       )
-       CPPFLAGS="$SAVE_CPPFLAGS"
-       LDFLAGS="$SAVE_LDFLAGS"
+
+if test "x$with_libcurl" = "xyes"; then
+  SAVE_CPPFLAGS="$CPPFLAGS"
+  SAVE_LDFLAGS="$LDFLAGS"
+  CPPFLAGS="$CPPFLAGS $with_curl_cflags"
+  LDFLAGS="$LDFLAGS $with_curl_libs"
+  AC_CACHE_CHECK([for CURLINFO_APPCONNECT_TIME],
+    [c_cv_have_curlinfo_appconnect_time],
+    [
+      AC_LINK_IFELSE(
+        [
+          AC_LANG_PROGRAM(
+            [[#include <curl/curl.h>]],
+            [[
+              int val = CURLINFO_APPCONNECT_TIME;
+              return val;
+            ]]
+          )
+        ],
+        [c_cv_have_curlinfo_appconnect_time="yes"],
+        [c_cv_have_curlinfo_appconnect_time="no"]
+      )
+    ]
+  )
+  CPPFLAGS="$SAVE_CPPFLAGS"
+  LDFLAGS="$SAVE_LDFLAGS"
 fi
-AM_CONDITIONAL(BUILD_WITH_LIBCURL, test "x$with_libcurl" = "xyes")
-if test "x$c_cv_have_curlinfo_appconnect_time" = "xyes"
-then
-       AC_DEFINE(HAVE_CURLINFO_APPCONNECT_TIME, 1, [Define if curl.h defines CURLINFO_APPCONNECT_TIME.])
+
+if test "x$c_cv_have_curlinfo_appconnect_time" = "xyes"; then
+  AC_DEFINE([HAVE_CURLINFO_APPCONNECT_TIME], [1],
+    [Define if curl.h defines CURLINFO_APPCONNECT_TIME.]
+  )
 fi
 
-if test "x$with_libcurl" = "xyes"
-then
-       BUILD_WITH_LIBCURL_CFLAGS="$with_curl_cflags"
-       BUILD_WITH_LIBCURL_LIBS="$with_curl_libs"
-       AC_SUBST(BUILD_WITH_LIBCURL_CFLAGS)
-       AC_SUBST(BUILD_WITH_LIBCURL_LIBS)
+if test "x$with_libcurl" = "xyes"; then
+  BUILD_WITH_LIBCURL_CFLAGS="$with_curl_cflags"
+  BUILD_WITH_LIBCURL_LIBS="$with_curl_libs"
 
-       if test "x$have_curlopt_username" = "xyes"
-       then
-               AC_DEFINE(HAVE_CURLOPT_USERNAME, 1, [Define if libcurl supports CURLOPT_USERNAME option.])
-       fi
+  if test "x$have_curlopt_username" = "xyes"; then
+    AC_DEFINE([HAVE_CURLOPT_USERNAME], [1],
+      [Define if libcurl supports CURLOPT_USERNAME option.]
+    )
+  fi
 
-       if test "x$have_curlopt_timeout" = "xyes"
-       then
-               AC_DEFINE(HAVE_CURLOPT_TIMEOUT_MS, 1, [Define if libcurl supports CURLOPT_TIMEOUT_MS option.])
-       fi
+  if test "x$have_curlopt_timeout" = "xyes"; then
+    AC_DEFINE([HAVE_CURLOPT_TIMEOUT_MS], [1],
+      [Define if libcurl supports CURLOPT_TIMEOUT_MS option.]
+    )
+  fi
 fi
+
+AC_SUBST(BUILD_WITH_LIBCURL_CFLAGS)
+AC_SUBST(BUILD_WITH_LIBCURL_LIBS)
 # }}}
 
 # --with-libdbi {{{
-with_libdbi_cppflags=""
-with_libdbi_ldflags=""
-AC_ARG_WITH(libdbi, [AS_HELP_STRING([--with-libdbi@<:@=PREFIX@:>@], [Path to libdbi.])],
-[
-       if test "x$withval" != "xno" && test "x$withval" != "xyes"
-       then
-               with_libdbi_cppflags="-I$withval/include"
-               with_libdbi_ldflags="-L$withval/lib"
-               with_libdbi="yes"
-       else
-               with_libdbi="$withval"
-       fi
-],
-[
-       with_libdbi="yes"
-])
-if test "x$with_libdbi" = "xyes"
-then
-       SAVE_CPPFLAGS="$CPPFLAGS"
-       CPPFLAGS="$CPPFLAGS $with_libdbi_cppflags"
+AC_ARG_WITH([libdbi],
+  [AS_HELP_STRING([--with-libdbi@<:@=PREFIX@:>@], [Path to libdbi.])],
+  [
+    if test "x$withval" != "xno" && test "x$withval" != "xyes"; then
+      with_libdbi_cppflags="-I$withval/include"
+      with_libdbi_ldflags="-L$withval/lib"
+      with_libdbi="yes"
+    else
+      with_libdbi="$withval"
+    fi
+  ],
+  [with_libdbi="yes"]
+)
 
-       AC_CHECK_HEADERS(dbi/dbi.h, [with_libdbi="yes"], [with_libdbi="no (dbi/dbi.h not found)"])
+if test "x$with_libdbi" = "xyes"; then
+  SAVE_CPPFLAGS="$CPPFLAGS"
+  CPPFLAGS="$CPPFLAGS $with_libdbi_cppflags"
 
-       CPPFLAGS="$SAVE_CPPFLAGS"
+  AC_CHECK_HEADERS([dbi/dbi.h],
+    [with_libdbi="yes"],
+    [with_libdbi="no (dbi/dbi.h not found)"]
+  )
+
+  CPPFLAGS="$SAVE_CPPFLAGS"
 fi
-if test "x$with_libdbi" = "xyes"
-then
-       SAVE_CPPFLAGS="$CPPFLAGS"
-       SAVE_LDFLAGS="$LDFLAGS"
-       CPPFLAGS="$CPPFLAGS $with_libdbi_cppflags"
-       LDFLAGS="$LDFLAGS $with_libdbi_ldflags"
 
-       AC_CHECK_LIB(dbi, dbi_initialize, [with_libdbi="yes"], [with_libdbi="no (Symbol 'dbi_initialize' not found)"])
+if test "x$with_libdbi" = "xyes"; then
+  SAVE_LDFLAGS="$LDFLAGS"
+  LDFLAGS="$LDFLAGS $with_libdbi_ldflags"
 
-       CPPFLAGS="$SAVE_CPPFLAGS"
-       LDFLAGS="$SAVE_LDFLAGS"
+  AC_CHECK_LIB([dbi], [dbi_initialize],
+    [with_libdbi="yes"],
+    [with_libdbi="no (Symbol 'dbi_initialize' not found)"]
+  )
+
+  LDFLAGS="$SAVE_LDFLAGS"
 fi
-if test "x$with_libdbi" = "xyes"
-then
-       BUILD_WITH_LIBDBI_CPPFLAGS="$with_libdbi_cppflags"
-       BUILD_WITH_LIBDBI_LDFLAGS="$with_libdbi_ldflags"
-       BUILD_WITH_LIBDBI_LIBS="-ldbi"
-       AC_SUBST(BUILD_WITH_LIBDBI_CPPFLAGS)
-       AC_SUBST(BUILD_WITH_LIBDBI_LDFLAGS)
-       AC_SUBST(BUILD_WITH_LIBDBI_LIBS)
-fi
-AM_CONDITIONAL(BUILD_WITH_LIBDBI, test "x$with_libdbi" = "xyes")
+
+BUILD_WITH_LIBDBI_CPPFLAGS="$with_libdbi_cppflags"
+BUILD_WITH_LIBDBI_LDFLAGS="$with_libdbi_ldflags"
+BUILD_WITH_LIBDBI_LIBS="-ldbi"
+AC_SUBST(BUILD_WITH_LIBDBI_CPPFLAGS)
+AC_SUBST(BUILD_WITH_LIBDBI_LDFLAGS)
+AC_SUBST(BUILD_WITH_LIBDBI_LIBS)
 # }}}
 
 # --with-libesmtp {{{
-AC_ARG_WITH(libesmtp, [AS_HELP_STRING([--with-libesmtp@<:@=PREFIX@:>@], [Path to libesmtp.])],
-[
-       if test "x$withval" != "xno" && test "x$withval" != "xyes"
-       then
-               LDFLAGS="$LDFLAGS -L$withval/lib"
-               CPPFLAGS="$CPPFLAGS -I$withval/include -D_THREAD_SAFE"
-               with_libesmtp="yes"
-       else
-               with_libesmtp="$withval"
-       fi
-],
-[
-       with_libesmtp="yes"
-])
-if test "x$with_libesmtp" = "xyes"
-then
-       AC_CHECK_LIB(esmtp, smtp_create_session,
-       [
-               AC_DEFINE(HAVE_LIBESMTP, 1, [Define to 1 if you have the esmtp library (-lesmtp).])
-       ], [with_libesmtp="no (libesmtp not found)"])
-fi
-if test "x$with_libesmtp" = "xyes"
-then
-       AC_CHECK_HEADERS(libesmtp.h,
-       [
-               AC_DEFINE(HAVE_LIBESMTP_H, 1, [Define to 1 if you have the <libesmtp.h> header file.])
-       ], [with_libesmtp="no (libesmtp.h not found)"])
-fi
-if test "x$with_libesmtp" = "xyes"
-then
-       collect_libesmtp=1
-else
-       collect_libesmtp=0
-fi
-AC_DEFINE_UNQUOTED(COLLECT_LIBESMTP, [$collect_libesmtp],
-       [Wether or not to use the esmtp library])
-AM_CONDITIONAL(BUILD_WITH_LIBESMTP, test "x$with_libesmtp" = "xyes")
-# }}}
+AC_ARG_WITH([libesmtp],
+  [AS_HELP_STRING([--with-libesmtp@<:@=PREFIX@:>@], [Path to libesmtp.])],
+  [
+    if test "x$withval" != "xno" && test "x$withval" != "xyes"; then
+      with_libesmtp_cppflags="-I$withval/include"
+      with_libesmtp_ldflags="-L$withval/lib"
+      with_libesmtp="yes"
+    else
+      with_libesmtp="$withval"
+    fi
+  ],
+  [with_libesmtp="yes"]
+)
 
-# --with-libganglia {{{
-AC_ARG_WITH(libganglia, [AS_HELP_STRING([--with-libganglia@<:@=PREFIX@:>@], [Path to libganglia.])],
-[
- if test -f "$withval" && test -x "$withval"
- then
-        with_libganglia_config="$withval"
-        with_libganglia="yes"
- else if test -f "$withval/bin/ganglia-config" && test -x "$withval/bin/ganglia-config"
- then
-        with_libganglia_config="$withval/bin/ganglia-config"
-        with_libganglia="yes"
- else if test -d "$withval"
- then
-        GANGLIA_CPPFLAGS="-I$withval/include"
-        GANGLIA_LDFLAGS="-L$withval/lib"
-        with_libganglia="yes"
- else
-        with_libganglia="$withval"
- fi; fi; fi
-],
-[
- with_libganglia="yes"
-])
+if test "x$with_libesmtp" = "xyes"; then
+  SAVE_CPPFLAGS="$CPPFLAGS"
+  CPPFLAGS="$CPPFLAGS $with_libesmtp_cppflags"
 
-if test "x$with_libganglia" = "xyes"
-then
-       if test "x$with_libganglia_config" != "x"
-       then
-               if test "x$GANGLIA_CPPFLAGS" = "x"
-               then
-                       GANGLIA_CPPFLAGS=`"$with_libganglia_config" --cflags 2>/dev/null`
-               fi
-
-               if test "x$GANGLIA_LDFLAGS" = "x"
-               then
-                       GANGLIA_LDFLAGS=`"$with_libganglia_config" --ldflags 2>/dev/null`
-               fi
-
-               if test "x$GANGLIA_LIBS" = "x"
-               then
-                       GANGLIA_LIBS=`"$with_libganglia_config" --libs 2>/dev/null`
-               fi
-       else
-               GANGLIA_LIBS="-lganglia"
-       fi
+  AC_CHECK_HEADERS([libesmtp.h],
+    [with_libesmtp="yes"],
+    [with_libesmtp="no (libesmtp.h not found)"]
+  )
+
+  CPPFLAGS="$SAVE_CPPFLAGS"
+fi
+
+if test "x$with_libesmtp" = "xyes"; then
+  SAVE_LDFLAGS="$LDFLAGS"
+  LDFLAGS="$LDFLAGS $with_esmtp_ldflags"
+
+  AC_CHECK_LIB([esmtp], [smtp_create_session],
+    [with_libesmtp="yes"],
+    [with_libesmtp="no (Symbol 'smtp_create_session' not found)"]
+  )
+
+  LDFLAGS="$SAVE_LDFLAGS"
+fi
+
+BUILD_WITH_LIBESMTP_CPPFLAGS="$with_libesmtp_cppflags"
+BUILD_WITH_LIBESMTP_LDFLAGS="$with_libesmtp_ldflags"
+BUILD_WITH_LIBESMTP_LIBS="-lesmtp"
+AC_SUBST(BUILD_WITH_LIBESMTP_CPPFLAGS)
+AC_SUBST(BUILD_WITH_LIBESMTP_LDFLAGS)
+AC_SUBST(BUILD_WITH_LIBESMTP_LIBS)
+# }}}
+
+# --with-libganglia {{{
+AC_ARG_WITH([libganglia],
+  [AS_HELP_STRING([--with-libganglia@<:@=PREFIX@:>@], [Path to libganglia.])],
+  [
+    if test -f "$withval" && test -x "$withval"; then
+      with_libganglia_config="$withval"
+      with_libganglia="yes"
+    else if test -f "$withval/bin/ganglia-config" && test -x "$withval/bin/ganglia-config"; then
+      with_libganglia_config="$withval/bin/ganglia-config"
+      with_libganglia="yes"
+    else if test -d "$withval"; then
+      GANGLIA_CPPFLAGS="-I$withval/include"
+      GANGLIA_LDFLAGS="-L$withval/lib"
+      with_libganglia="yes"
+    else
+      with_libganglia="$withval"
+    fi; fi; fi
+  ],
+  [with_libganglia="yes"]
+)
+
+if test "x$with_libganglia" = "xyes"; then
+  if test "x$with_libganglia_config" != "x"; then
+    if test "x$GANGLIA_CPPFLAGS" = "x"; then
+      GANGLIA_CPPFLAGS=`"$with_libganglia_config" --cflags 2>/dev/null`
+    fi
+
+    if test "x$GANGLIA_LDFLAGS" = "x"; then
+      GANGLIA_LDFLAGS=`"$with_libganglia_config" --ldflags 2>/dev/null`
+    fi
+
+    if test "x$GANGLIA_LIBS" = "x"; then
+      GANGLIA_LIBS=`"$with_libganglia_config" --libs 2>/dev/null`
+    fi
+  else
+    GANGLIA_LIBS="-lganglia"
+  fi
 fi
 
 SAVE_CPPFLAGS="$CPPFLAGS"
@@ -2266,22 +2373,18 @@ SAVE_LDFLAGS="$LDFLAGS"
 CPPFLAGS="$CPPFLAGS $GANGLIA_CPPFLAGS"
 LDFLAGS="$LDFLAGS $GANGLIA_LDFLAGS"
 
-if test "x$with_libganglia" = "xyes"
-then
-       AC_CHECK_HEADERS(gm_protocol.h,
-       [
-               AC_DEFINE(HAVE_GM_PROTOCOL_H, 1,
-                         [Define to 1 if you have the <gm_protocol.h> header file.])
-       ], [with_libganglia="no (gm_protocol.h not found)"])
+if test "x$with_libganglia" = "xyes"; then
+  AC_CHECK_HEADERS([gm_protocol.h],
+    [with_libganglia="yes"],
+    [with_libganglia="no (gm_protocol.h not found)"]
+  )
 fi
 
-if test "x$with_libganglia" = "xyes"
-then
-       AC_CHECK_LIB(ganglia, xdr_Ganglia_value_msg,
-       [
-               AC_DEFINE(HAVE_LIBGANGLIA, 1,
-                         [Define to 1 if you have the ganglia library (-lganglia).])
-       ], [with_libganglia="no (symbol xdr_Ganglia_value_msg not found)"])
+if test "x$with_libganglia" = "xyes"; then
+  AC_CHECK_LIB([ganglia], [xdr_Ganglia_value_msg],
+    [with_libganglia="yes"],
+    [with_libganglia="no (symbol xdr_Ganglia_value_msg not found)"]
+  )
 fi
 
 CPPFLAGS="$SAVE_CPPFLAGS"
@@ -2290,49 +2393,44 @@ LDFLAGS="$SAVE_LDFLAGS"
 AC_SUBST(GANGLIA_CPPFLAGS)
 AC_SUBST(GANGLIA_LDFLAGS)
 AC_SUBST(GANGLIA_LIBS)
-AM_CONDITIONAL(BUILD_WITH_LIBGANGLIA, test "x$with_libganglia" = "xyes")
 # }}}
 
 # --with-libgcrypt {{{
 GCRYPT_CPPFLAGS="$GCRYPT_CPPFLAGS"
 GCRYPT_LDFLAGS="$GCRYPT_LDFLAGS"
 GCRYPT_LIBS="$GCRYPT_LIBS"
-AC_ARG_WITH(libgcrypt, [AS_HELP_STRING([--with-libgcrypt@<:@=PREFIX@:>@], [Path to libgcrypt.])],
-[
- if test -f "$withval" && test -x "$withval"
- then
-        with_libgcrypt_config="$withval"
-        with_libgcrypt="yes"
- else if test -f "$withval/bin/gcrypt-config" && test -x "$withval/bin/gcrypt-config"
- then
-        with_libgcrypt_config="$withval/bin/gcrypt-config"
-        with_libgcrypt="yes"
- else if test -d "$withval"
- then
-        GCRYPT_CPPFLAGS="$GCRYPT_CPPFLAGS -I$withval/include"
-        GCRYPT_LDFLAGS="$GCRYPT_LDFLAGS -L$withval/lib"
-        with_libgcrypt="yes"
- else
-        with_libgcrypt_config="gcrypt-config"
-        with_libgcrypt="$withval"
- fi; fi; fi
-],
-[
- with_libgcrypt_config="libgcrypt-config"
- with_libgcrypt="yes"
-])
+AC_ARG_WITH([libgcrypt],
+  [AS_HELP_STRING([--with-libgcrypt@<:@=PREFIX@:>@], [Path to libgcrypt.])],
+  [
+    if test -f "$withval" && test -x "$withval"; then
+      with_libgcrypt_config="$withval"
+      with_libgcrypt="yes"
+    else if test -f "$withval/bin/gcrypt-config" && test -x "$withval/bin/gcrypt-config"; then
+      with_libgcrypt_config="$withval/bin/gcrypt-config"
+      with_libgcrypt="yes"
+    else if test -d "$withval"; then
+      GCRYPT_CPPFLAGS="$GCRYPT_CPPFLAGS -I$withval/include"
+      GCRYPT_LDFLAGS="$GCRYPT_LDFLAGS -L$withval/lib"
+      with_libgcrypt="yes"
+    else
+      with_libgcrypt_config="gcrypt-config"
+      with_libgcrypt="$withval"
+    fi; fi; fi
+  ],
+  [
+    with_libgcrypt_config="libgcrypt-config"
+    with_libgcrypt="yes"
+  ]
+)
 
-if test "x$with_libgcrypt" = "xyes" && test "x$with_libgcrypt_config" != "x"
-then
-       if test "x$GCRYPT_CPPFLAGS" = "x"
-       then
-               GCRYPT_CPPFLAGS=`"$with_libgcrypt_config" --cflags 2>/dev/null`
-       fi
+if test "x$with_libgcrypt" = "xyes" && test "x$with_libgcrypt_config" != "x"; then
+  if test "x$GCRYPT_CPPFLAGS" = "x"; then
+    GCRYPT_CPPFLAGS=`"$with_libgcrypt_config" --cflags 2>/dev/null`
+  fi
 
-       if test "x$GCRYPT_LIBS" = "x"
-       then
-               GCRYPT_LIBS=`"$with_libgcrypt_config" --libs 2>/dev/null`
-       fi
+  if test "x$GCRYPT_LIBS" = "x"; then
+    GCRYPT_LIBS=`"$with_libgcrypt_config" --libs 2>/dev/null`
+  fi
 fi
 
 SAVE_CPPFLAGS="$CPPFLAGS"
@@ -2342,118 +2440,108 @@ CPPFLAGS="$CPPFLAGS $GCRYPT_CPPFLAGS"
 LDFLAGS="$LDFLAGS $GCRYPT_LDFLAGS"
 LIBS="$LIBS $GCRYPT_LIBS"
 
-if test "x$with_libgcrypt" = "xyes"
-then
-       if test "x$GCRYPT_CPPFLAGS" != "x"
-       then
-               AC_MSG_NOTICE([gcrypt CPPFLAGS: $GCRYPT_CPPFLAGS])
-       fi
-       AC_CHECK_HEADERS(gcrypt.h,
-               [with_libgcrypt="yes"],
-               [with_libgcrypt="no (gcrypt.h not found)"])
+if test "x$with_libgcrypt" = "xyes"; then
+  if test "x$GCRYPT_CPPFLAGS" != "x"; then
+    AC_MSG_NOTICE([gcrypt CPPFLAGS: $GCRYPT_CPPFLAGS])
+  fi
+  AC_CHECK_HEADERS([gcrypt.h],
+    [with_libgcrypt="yes"],
+    [with_libgcrypt="no (gcrypt.h not found)"]
+  )
 fi
 
-if test "x$with_libgcrypt" = "xyes"
-then
-       AC_CHECK_LIB(gcrypt, gcry_md_hash_buffer,
-               [with_libgcrypt="yes"],
-               [with_libgcrypt="no (symbol gcry_md_hash_buffer not found)"])
+if test "x$with_libgcrypt" = "xyes"; then
+  AC_CHECK_LIB(gcrypt, gcry_md_hash_buffer,
+    [with_libgcrypt="yes"],
+    [with_libgcrypt="no (symbol gcry_md_hash_buffer not found)"]
+  )
 fi
 
 CPPFLAGS="$SAVE_CPPFLAGS"
 LDFLAGS="$SAVE_LDFLAGS"
 LIBS="$SAVE_LIBS"
 
-if test "x$with_libgcrypt" = "xyes"
-then
-       AC_DEFINE(HAVE_LIBGCRYPT, 1, [Define to 1 if you have the gcrypt library (-lgcrypt).])
-fi
-
-AC_SUBST(GCRYPT_CPPFLAGS)
-AC_SUBST(GCRYPT_LDFLAGS)
-AC_SUBST(GCRYPT_LIBS)
-AM_CONDITIONAL(BUILD_WITH_LIBGCRYPT, test "x$with_libgcrypt" = "xyes")
+AC_SUBST([GCRYPT_CPPFLAGS])
+AC_SUBST([GCRYPT_LDFLAGS])
+AC_SUBST([GCRYPT_LIBS])
+AM_CONDITIONAL([BUILD_WITH_LIBGCRYPT], [test "x$with_libgcrypt" = "xyes"])
 # }}}
 
 # --with-libgps {{{
-with_libgps_cflags=""
-with_libgps_ldflags=""
-AC_ARG_WITH(libgps, [AS_HELP_STRING([--with-libgps@<:@=PREFIX@:>@], [Path to libgps.])],
-[
-       if test "x$withval" != "xno" && test "x$withval" != "xyes"
-       then
-               with_libgps_cflags="-I$withval/include"
-               with_libgps_ldflags="-L$withval/lib"
-               with_libgps="yes"
-       else
-               with_libgps="$withval"
-       fi
-],
-[
-       with_libgps="yes"
-])
-if test "x$with_libgps" = "xyes"
-then
-       SAVE_CFLAGS="$CFLAGS"
-       CFLAGS="$CFLAGS $with_libgps_cflags"
+AC_ARG_WITH([libgps],
+  [AS_HELP_STRING([--with-libgps@<:@=PREFIX@:>@], [Path to libgps.])],
+  [
+    if test "x$withval" != "xno" && test "x$withval" != "xyes"; then
+      with_libgps_cflags="-I$withval/include"
+      with_libgps_ldflags="-L$withval/lib"
+      with_libgps="yes"
+    else
+      with_libgps="$withval"
+    fi
+  ],
+  [with_libgps="yes"]
+)
+
+if test "x$with_libgps" = "xyes"; then
+  SAVE_CFLAGS="$CFLAGS"
+  CFLAGS="$CFLAGS $with_libgps_cflags"
 
-       AC_CHECK_HEADERS(gps.h, [with_libgps="yes"], [with_libgps="no (gps.h not found)"])
+  AC_CHECK_HEADERS([gps.h],
+    [with_libgps="yes"],
+    [with_libgps="no (gps.h not found)"]
+  )
 
-       CFLAGS="$SAVE_CFLAGS"
+  CFLAGS="$SAVE_CFLAGS"
 fi
-if test "x$with_libgps" = "xyes"
-then
-       SAVE_CFLAGS="$CFLAGS"
-       SAVE_LDFLAGS="$LDFLAGS"
-       CFLAGS="$CFLAGS $with_libgps_cflags"
-       LDFLAGS="$LDFLAGS $with_libgps_ldflags"
 
-       AC_CHECK_LIB(gps, gps_open, [with_libgps="yes"], [with_libgps="no (symbol gps_open not found)"])
+if test "x$with_libgps" = "xyes"; then
+  SAVE_LDFLAGS="$LDFLAGS"
+  LDFLAGS="$LDFLAGS $with_libgps_ldflags"
+
+  AC_CHECK_LIB([gps], [gps_open],
+    [with_libgps="yes"],
+    [with_libgps="no (symbol gps_open not found)"]
+  )
 
-       CFLAGS="$SAVE_CFLAGS"
-       LDFLAGS="$SAVE_LDFLAGS"
+  LDFLAGS="$SAVE_LDFLAGS"
 fi
-if test "x$with_libgps" = "xyes"
-then
-       BUILD_WITH_LIBGPS_CFLAGS="$with_libgps_cflags"
-       BUILD_WITH_LIBGPS_LDFLAGS="$with_libgps_ldflags"
-       BUILD_WITH_LIBGPS_LIBS="-lgps"
-       AC_SUBST(BUILD_WITH_LIBGPS_CFLAGS)
-       AC_SUBST(BUILD_WITH_LIBGPS_LDFLAGS)
-       AC_SUBST(BUILD_WITH_LIBGPS_LIBS)
-fi
-AM_CONDITIONAL(BUILD_WITH_LIBGPS, test "x$with_libgps" = "xyes")
+
+if test "x$with_libgps" = "xyes"; then
+  BUILD_WITH_LIBGPS_CFLAGS="$with_libgps_cflags"
+  BUILD_WITH_LIBGPS_LDFLAGS="$with_libgps_ldflags"
+  BUILD_WITH_LIBGPS_LIBS="-lgps"
+fi
+
+AC_SUBST([BUILD_WITH_LIBGPS_CFLAGS])
+AC_SUBST([BUILD_WITH_LIBGPS_LDFLAGS])
+AC_SUBST([BUILD_WITH_LIBGPS_LIBS])
+
 # }}}
 
 # --with-libgrpc++ {{{
-with_libgrpcpp_cppflags=""
-with_libgrpcpp_ldflags=""
-AC_ARG_WITH([libgrpc++], [AS_HELP_STRING([--with-libgrpc++@<:@=PREFIX@:>@], [Path to libgrpc++.])],
+AC_ARG_WITH([libgrpc++],
+  [AS_HELP_STRING([--with-libgrpc++@<:@=PREFIX@:>@], [Path to libgrpc++.])],
   [
     with_grpcpp="$withval"
-    if test "x$withval" != "xno" && test "x$withval" != "xyes"
-    then
+    if test "x$withval" != "xno" && test "x$withval" != "xyes"; then
       with_libgrpcpp_cppflags="-I$withval/include"
       with_libgrpcpp_ldflags="-L$withval/lib"
       with_libgrpcpp="yes"
     fi
-    if test "x$withval" = "xno"
-    then
+    if test "x$withval" = "xno"; then
       with_libgrpcpp="no (disabled on command line)"
     fi
   ],
   [withval="yes"]
 )
-if test "x$withval" = "xyes"
-then
+if test "x$withval" = "xyes"; then
 PKG_CHECK_MODULES([GRPCPP], [grpc++],
   [with_libgrpcpp="yes"],
   [with_libgrpcpp="no (pkg-config could not find libgrpc++)"]
 )
 fi
 
-if test "x$withval" != "xno"
-then
+if test "x$withval" != "xno"; then
   AC_MSG_CHECKING([whether $CXX accepts -std=c++11])
   if test_cxx_flags -std=c++11; then
     AC_MSG_RESULT([yes])
@@ -2463,40 +2551,40 @@ then
   fi
 fi
 
-if test "x$with_libgrpcpp" = "xyes"
-then
+if test "x$with_libgrpcpp" = "xyes"; then
   AC_LANG_PUSH(C++)
   SAVE_CPPFLAGS="$CPPFLAGS"
   CPPFLAGS="-std=c++11 $with_libgrpcpp_cppflags $GRPCPP_CFLAGS $CPPFLAGS"
-  AC_CHECK_HEADERS([grpc++/grpc++.h], [],
+  AC_CHECK_HEADERS([grpc++/grpc++.h],
+    [with_libgrpcpp="yes"],
     [with_libgrpcpp="no (<grpc++/grpc++.h> not found)"]
   )
   CPPFLAGS="$SAVE_CPPFLAGS"
   AC_LANG_POP(C++)
 fi
-if test "x$with_libgrpcpp" = "xyes"
-then
+
+if test "x$with_libgrpcpp" = "xyes"; then
   AC_LANG_PUSH(C++)
   SAVE_CPPFLAGS="$CPPFLAGS"
   SAVE_LDFLAGS="$LDFLAGS"
   SAVE_LIBS="$LIBS"
   CPPFLAGS="-std=c++11 $with_libgrpcpp_cppflags $GRPCPP_CFLAGS $CPPFLAGS"
   LDFLAGS="$with_libgrpcpp_ldflags"
-  if test "x$GRPCPP_LIBS" = "x"
-  then
+  if test "x$GRPCPP_LIBS" = "x"; then
     LIBS="-lgrpc++"
   else
     LIBS="$GRPCPP_LIBS"
   fi
   AC_LINK_IFELSE(
-    [AC_LANG_PROGRAM(
-      [[#include <grpc++/grpc++.h>]],
-      [[grpc::ServerBuilder sb;]]
-    )],
+    [
+      AC_LANG_PROGRAM(
+        [[#include <grpc++/grpc++.h>]],
+        [[grpc::ServerBuilder sb;]]
+      )
+    ],
     [
       with_libgrpcpp="yes"
-      if test "x$GRPCPP_LIBS" = "x"
-      then
+      if test "x$GRPCPP_LIBS" = "x"; then
         GRPCPP_LIBS="-lgrpc++"
       fi
     ],
@@ -2507,6 +2595,7 @@ then
   LIBS="$SAVE_LIBS"
   AC_LANG_POP(C++)
 fi
+
 BUILD_WITH_LIBGRPCPP_CPPFLAGS="-std=c++11 $with_libgrpcpp_cppflags $GRPCPP_CFLAGS"
 BUILD_WITH_LIBGRPCPP_LDFLAGS="$with_libgrpcpp_ldflags"
 BUILD_WITH_LIBGRPCPP_LIBS="$GRPCPP_LIBS"
@@ -2515,94 +2604,94 @@ AC_SUBST([BUILD_WITH_LIBGRPCPP_LDFLAGS])
 AC_SUBST([BUILD_WITH_LIBGRPCPP_LIBS])
 # }}}
 
+AC_ARG_VAR([GRPC_CPP_PLUGIN], [path to the grpc_cpp_plugin binary])
+AC_PATH_PROG([GRPC_CPP_PLUGIN], [grpc_cpp_plugin])
+AM_CONDITIONAL([HAVE_GRPC_CPP], [test "x$GRPC_CPP_PLUGIN" != "x"])
+
 # --with-libiptc {{{
-AC_ARG_WITH(libiptc, [AS_HELP_STRING([--with-libiptc@<:@=PREFIX@:>@], [Path to libiptc.])],
-[
-       if test "x$withval" = "xyes"
-       then
-               with_libiptc="pkgconfig"
-       else if test "x$withval" = "xno"
-       then
-               with_libiptc="no"
-       else
-               with_libiptc="yes"
-               with_libiptc_cflags="-I$withval/include"
-               with_libiptc_libs="-L$withval/lib"
-       fi; fi
-],
-[
-       if test "x$ac_system" = "xLinux"
-       then
-               with_libiptc="pkgconfig"
-       else
-               with_libiptc="no (Linux only)"
-       fi
-])
+AC_ARG_WITH([libiptc],
+  [AS_HELP_STRING([--with-libiptc@<:@=PREFIX@:>@], [Path to libiptc.])],
+  [
+    if test "x$withval" = "xyes"; then
+      with_libiptc="pkgconfig"
+    else if test "x$withval" = "xno"; then
+      with_libiptc="no"
+    else
+      with_libiptc="yes"
+      with_libiptc_cflags="-I$withval/include"
+      with_libiptc_libs="-L$withval/lib"
+    fi; fi
+  ],
+  [
+    if test "x$ac_system" = "xLinux"; then
+      with_libiptc="pkgconfig"
+    else
+      with_libiptc="no (Linux only)"
+    fi
+  ]
+)
 
-if test "x$with_libiptc" = "xpkgconfig"
-then
-       $PKG_CONFIG --exists 'libiptc' 2>/dev/null
-       if test $? -ne 0
-       then
-               with_libiptc="no (pkg-config doesn't know libiptc)"
-       fi
+if test "x$with_libiptc" = "xpkgconfig"; then
+  $PKG_CONFIG --exists 'libiptc' 2>/dev/null
+  if test $? -ne 0; then
+    with_libiptc="no (pkg-config doesn't know libiptc)"
+  fi
 fi
-if test "x$with_libiptc" = "xpkgconfig"
-then
-       with_libiptc_cflags="`$PKG_CONFIG --cflags 'libiptc'`"
-       if test $? -ne 0
-       then
-               with_libiptc="no ($PKG_CONFIG failed)"
-       fi
-       with_libiptc_libs="`$PKG_CONFIG --libs 'libiptc'`"
-       if test $? -ne 0
-       then
-               with_libiptc="no ($PKG_CONFIG failed)"
-       fi
+
+if test "x$with_libiptc" = "xpkgconfig"; then
+  with_libiptc_cflags="`$PKG_CONFIG --cflags 'libiptc'`"
+  if test $? -ne 0; then
+    with_libiptc="no ($PKG_CONFIG failed)"
+  fi
+
+  with_libiptc_libs="`$PKG_CONFIG --libs 'libiptc'`"
+  if test $? -ne 0; then
+    with_libiptc="no ($PKG_CONFIG failed)"
+  fi
 fi
 
 SAVE_CPPFLAGS="$CPPFLAGS"
 CPPFLAGS="$CPPFLAGS $with_libiptc_cflags"
 
 # check whether the header file for libiptc is available.
-if test "x$with_libiptc" = "xpkgconfig"
-then
-       AC_CHECK_HEADERS(libiptc/libiptc.h libiptc/libip6tc.h, ,
-                       [with_libiptc="no (header file missing)"])
+if test "x$with_libiptc" = "xpkgconfig"; then
+  AC_CHECK_HEADERS([libiptc/libiptc.h libiptc/libip6tc.h],
+    [],
+    [with_libiptc="no (header file missing)"]
+  )
 fi
+
 # If the header file is available, check for the required type declaractions.
 # They may be missing in old versions of libiptc. In that case, they will be
 # declared in the iptables plugin.
-if test "x$with_libiptc" = "xpkgconfig"
-then
-       AC_CHECK_TYPES([iptc_handle_t, ip6tc_handle_t], [], [])
+if test "x$with_libiptc" = "xpkgconfig"; then
+  AC_CHECK_TYPES([iptc_handle_t, ip6tc_handle_t], [], [])
 fi
+
 # Check for the iptc_init symbol in the library.
 # This could be in iptc or ip4tc
-if test "x$with_libiptc" = "xpkgconfig"
-then
-       SAVE_LIBS="$LIBS"
-       AC_SEARCH_LIBS(iptc_init, [iptc ip4tc],
-                       [with_libiptc="pkgconfig"],
-                       [with_libiptc="no"],
-                       [$with_libiptc_libs])
-       LIBS="$SAVE_LIBS"
-fi
-if test "x$with_libiptc" = "xpkgconfig"
-then
-       with_libiptc="yes"
+if test "x$with_libiptc" = "xpkgconfig"; then
+  SAVE_LIBS="$LIBS"
+  AC_SEARCH_LIBS([iptc_init], [iptc ip4tc],
+    [with_libiptc="pkgconfig"],
+    [with_libiptc="no"],
+    [$with_libiptc_libs]
+  )
+  LIBS="$SAVE_LIBS"
+fi
+
+if test "x$with_libiptc" = "xpkgconfig"; then
+  with_libiptc="yes"
 fi
 
 CPPFLAGS="$SAVE_CPPFLAGS"
 
-AM_CONDITIONAL(BUILD_WITH_LIBIPTC, test "x$with_libiptc" = "xyes")
-if test "x$with_libiptc" = "xyes"
-then
-       BUILD_WITH_LIBIPTC_CPPFLAGS="$with_libiptc_cflags"
-       BUILD_WITH_LIBIPTC_LDFLAGS="$with_libiptc_libs"
-       AC_SUBST(BUILD_WITH_LIBIPTC_CPPFLAGS)
-       AC_SUBST(BUILD_WITH_LIBIPTC_LDFLAGS)
+if test "x$with_libiptc" = "xyes"; then
+  BUILD_WITH_LIBIPTC_CPPFLAGS="$with_libiptc_cflags"
+  BUILD_WITH_LIBIPTC_LDFLAGS="$with_libiptc_libs"
 fi
+AC_SUBST([BUILD_WITH_LIBIPTC_CPPFLAGS])
+AC_SUBST([BUILD_WITH_LIBIPTC_LDFLAGS])
 # }}}
 
 # --with-libdpdk {{{
 
 # --with-java {{{
 with_java_home="$JAVA_HOME"
-if test "x$with_java_home" = "x"
-then
-       with_java_home="/usr/lib/jvm"
+if test "x$with_java_home" = "x"; then
+  with_java_home="/usr/lib/jvm"
 fi
+
 JAVAC="$JAVAC"
 JAR="$JAR"
-AC_ARG_WITH(java, [AS_HELP_STRING([--with-java@<:@=PREFIX@:>@], [Path to Java home.])],
-[
-       if test "x$withval" = "xno"
-       then
-               with_java="no"
-       else if test "x$withval" = "xyes"
-       then
-               with_java="yes"
-       else
-               with_java_home="$withval"
-               with_java="yes"
-       fi; fi
-],
-[with_java="yes"])
-if test "x$with_java" = "xyes"
-then
-       if test -d "$with_java_home"
-       then
-               AC_MSG_CHECKING([for jni.h])
-               TMPVAR=`find -L "$with_java_home" -name jni.h -type f -exec 'dirname' '{}' ';' 2>/dev/null | LC_ALL=C sort | head -n 1`
-               if test "x$TMPVAR" != "x"
-               then
-                       AC_MSG_RESULT([found in $TMPVAR])
-                       JAVA_CPPFLAGS="$JAVA_CPPFLAGS -I$TMPVAR"
-               else
-                       AC_MSG_RESULT([not found])
-               fi
-
-               AC_MSG_CHECKING([for jni_md.h])
-               TMPVAR=`find -L "$with_java_home" -name jni_md.h -type f -exec 'dirname' '{}' ';' 2>/dev/null | LC_ALL=C sort | head -n 1`
-               if test "x$TMPVAR" != "x"
-               then
-                       AC_MSG_RESULT([found in $TMPVAR])
-                       JAVA_CPPFLAGS="$JAVA_CPPFLAGS -I$TMPVAR"
-               else
-                       AC_MSG_RESULT([not found])
-               fi
-
-               AC_MSG_CHECKING([for libjvm.so])
-               TMPVAR=`find -L "$with_java_home" -type f \( -name libjvm.so -o -name libjvm.dylib \) -exec 'dirname' '{}' ';' 2>/dev/null | LC_ALL=C sort | head -n 1`
-               if test "x$TMPVAR" != "x"
-               then
-                       AC_MSG_RESULT([found in $TMPVAR])
-                       JAVA_LDFLAGS="$JAVA_LDFLAGS -L$TMPVAR -Wl,-rpath -Wl,$TMPVAR"
-               else
-                       AC_MSG_RESULT([not found])
-               fi
-
-               if test "x$JAVAC" = "x"
-               then
-                       AC_MSG_CHECKING([for javac])
-                       TMPVAR=`find -L "$with_java_home" -name javac -type f 2>/dev/null | LC_ALL=C sort | head -n 1`
-                       if test "x$TMPVAR" != "x"
-                       then
-                               JAVAC="$TMPVAR"
-                               AC_MSG_RESULT([$JAVAC])
-                       else
-                               AC_MSG_RESULT([not found])
-                       fi
-               fi
-               if test "x$JAR" = "x"
-               then
-                       AC_MSG_CHECKING([for jar])
-                       TMPVAR=`find -L "$with_java_home" -name jar -type f 2>/dev/null | LC_ALL=C sort | head -n 1`
-                       if test "x$TMPVAR" != "x"
-                       then
-                               JAR="$TMPVAR"
-                               AC_MSG_RESULT([$JAR])
-                       else
-                               AC_MSG_RESULT([not found])
-                       fi
-               fi
-       else if test "x$with_java_home" != "x"
-       then
-               AC_MSG_WARN([JAVA_HOME: No such directory: $with_java_home])
-       fi; fi
+AC_ARG_WITH([java],
+  [AS_HELP_STRING([--with-java@<:@=PREFIX@:>@], [Path to Java home.])],
+  [
+    if test "x$withval" = "xno"; then
+      with_java="no"
+    else if test "x$withval" = "xyes"; then
+      with_java="yes"
+    else
+      with_java_home="$withval"
+      with_java="yes"
+    fi; fi
+  ],
+  [with_java="yes"]
+)
+
+if test "x$with_java" = "xyes"; then
+  if test -d "$with_java_home"; then
+    AC_MSG_CHECKING([for jni.h])
+    TMPVAR=`find -L "$with_java_home" -name jni.h -type f -exec 'dirname' '{}' ';' 2>/dev/null | LC_ALL=C sort | head -n 1`
+    if test "x$TMPVAR" != "x"; then
+      AC_MSG_RESULT([found in $TMPVAR])
+      JAVA_CPPFLAGS="$JAVA_CPPFLAGS -I$TMPVAR"
+    else
+      AC_MSG_RESULT([not found])
+    fi
+
+    AC_MSG_CHECKING([for jni_md.h])
+    TMPVAR=`find -L "$with_java_home" -name jni_md.h -type f -exec 'dirname' '{}' ';' 2>/dev/null | LC_ALL=C sort | head -n 1`
+    if test "x$TMPVAR" != "x"; then
+      AC_MSG_RESULT([found in $TMPVAR])
+      JAVA_CPPFLAGS="$JAVA_CPPFLAGS -I$TMPVAR"
+    else
+      AC_MSG_RESULT([not found])
+    fi
+
+    AC_MSG_CHECKING([for libjvm.so])
+    TMPVAR=`find -L "$with_java_home" -type f \( -name libjvm.so -o -name libjvm.dylib \) -exec 'dirname' '{}' ';' 2>/dev/null | LC_ALL=C sort | head -n 1`
+    if test "x$TMPVAR" != "x"; then
+      AC_MSG_RESULT([found in $TMPVAR])
+      JAVA_LDFLAGS="$JAVA_LDFLAGS -L$TMPVAR -Wl,-rpath -Wl,$TMPVAR"
+    else
+      AC_MSG_RESULT([not found])
+    fi
+
+    if test "x$JAVAC" = "x"; then
+      AC_MSG_CHECKING([for javac])
+      TMPVAR=`find -L "$with_java_home" -name javac -type f 2>/dev/null | LC_ALL=C sort | head -n 1`
+      if test "x$TMPVAR" != "x"; then
+        JAVAC="$TMPVAR"
+        AC_MSG_RESULT([$JAVAC])
+      else
+        AC_MSG_RESULT([not found])
+      fi
+    fi
+
+    if test "x$JAR" = "x"; then
+      AC_MSG_CHECKING([for jar])
+      TMPVAR=`find -L "$with_java_home" -name jar -type f 2>/dev/null | LC_ALL=C sort | head -n 1`
+      if test "x$TMPVAR" != "x"; then
+        JAR="$TMPVAR"
+        AC_MSG_RESULT([$JAR])
+      else
+        AC_MSG_RESULT([not found])
+      fi
+    fi
+  else if test "x$with_java_home" != "x"; then
+    AC_MSG_WARN([JAVA_HOME: No such directory: $with_java_home])
+  fi; fi
 fi
 
-if test "x$JAVA_CPPFLAGS" != "x"
-then
-       AC_MSG_NOTICE([Building with JAVA_CPPFLAGS set to: $JAVA_CPPFLAGS])
+if test "x$JAVA_CPPFLAGS" != "x"; then
+  AC_MSG_NOTICE([Building with JAVA_CPPFLAGS set to: $JAVA_CPPFLAGS])
 fi
-if test "x$JAVA_CFLAGS" != "x"
-then
-       AC_MSG_NOTICE([Building with JAVA_CFLAGS set to: $JAVA_CFLAGS])
+if test "x$JAVA_CFLAGS" != "x"; then
+  AC_MSG_NOTICE([Building with JAVA_CFLAGS set to: $JAVA_CFLAGS])
 fi
-if test "x$JAVA_LDFLAGS" != "x"
-then
-       AC_MSG_NOTICE([Building with JAVA_LDFLAGS set to: $JAVA_LDFLAGS])
+if test "x$JAVA_LDFLAGS" != "x"; then
+  AC_MSG_NOTICE([Building with JAVA_LDFLAGS set to: $JAVA_LDFLAGS])
 fi
-if test "x$JAVA_LIBS" != "x"
-then
-       AC_MSG_NOTICE([Building with JAVA_LIBS set to: $JAVA_LIBS])
+if test "x$JAVA_LIBS" != "x"; then
+  AC_MSG_NOTICE([Building with JAVA_LIBS set to: $JAVA_LIBS])
 fi
-if test "x$JAVAC" = "x"
-then
-       with_javac_path="$PATH"
-       if test "x$with_java_home" != "x"
-       then
-               with_javac_path="$with_java_home:with_javac_path"
-               if test -d "$with_java_home/bin"
-               then
-                       with_javac_path="$with_java_home/bin:with_javac_path"
-               fi
-       fi
+if test "x$JAVAC" = "x"; then
+  with_javac_path="$PATH"
+  if test "x$with_java_home" != "x"; then
+    with_javac_path="$with_java_home:with_javac_path"
+    if test -d "$with_java_home/bin"; then
+      with_javac_path="$with_java_home/bin:with_javac_path"
+    fi
+  fi
 
-       AC_PATH_PROG(JAVAC, javac, [], "$with_javac_path")
+  AC_PATH_PROG([JAVAC], [javac], [], "$with_javac_path")
 fi
-if test "x$JAVAC" = "x"
-then
-       with_java="no (javac not found)"
+
+if test "x$JAVAC" = "x"; then
+  with_java="no (javac not found)"
 fi
-if test "x$JAR" = "x"
-then
-       with_jar_path="$PATH"
-       if test "x$with_java_home" != "x"
-       then
-               with_jar_path="$with_java_home:$with_jar_path"
-               if test -d "$with_java_home/bin"
-               then
-                       with_jar_path="$with_java_home/bin:$with_jar_path"
-               fi
-       fi
 
-       AC_PATH_PROG(JAR, jar, [], "$with_jar_path")
+if test "x$JAR" = "x"; then
+  with_jar_path="$PATH"
+  if test "x$with_java_home" != "x"; then
+    with_jar_path="$with_java_home:$with_jar_path"
+    if test -d "$with_java_home/bin"; then
+      with_jar_path="$with_java_home/bin:$with_jar_path"
+    fi
+  fi
+
+  AC_PATH_PROG([JAR], [jar], [], "$with_jar_path")
 fi
-if test "x$JAR" = "x"
-then
-       with_java="no (jar not found)"
+
+if test "x$JAR" = "x"; then
+  with_java="no (jar not found)"
 fi
 
 SAVE_CPPFLAGS="$CPPFLAGS"
@@ -2787,21 +2859,23 @@ CFLAGS="$CFLAGS $JAVA_CFLAGS"
 LDFLAGS="$LDFLAGS $JAVA_LDFLAGS"
 LIBS="$LIBS $JAVA_LIBS"
 
-if test "x$with_java" = "xyes"
-then
-       AC_CHECK_HEADERS(jni.h, [], [with_java="no (jni.h not found)"])
+if test "x$with_java" = "xyes"; then
+  AC_CHECK_HEADERS([jni.h],
+    [with_jave="yes"],
+    [with_java="no (jni.h not found)"])
 fi
-if test "x$with_java" = "xyes"
-then
-       AC_CHECK_LIB(jvm, JNI_CreateJavaVM,
-       [with_java="yes"],
-       [with_java="no (Symbol 'JNI_CreateJavaVM' not found)"],
-       [$JAVA_LIBS $PTHREAD_LIBS])
+
+if test "x$with_java" = "xyes"; then
+  AC_CHECK_LIB([jvm], [JNI_CreateJavaVM],
+    [with_java="yes"],
+    [with_java="no (Symbol 'JNI_CreateJavaVM' not found)"],
+    [$JAVA_LIBS $PTHREAD_LIBS]
+  )
 fi
-if test "x$with_java" = "xyes"
-then
-       JAVA_LIBS="$JAVA_LIBS -ljvm"
-       AC_MSG_NOTICE([Building with JAVA_LIBS set to: $JAVA_LIBS])
+
+if test "x$with_java" = "xyes"; then
+  JAVA_LIBS="$JAVA_LIBS -ljvm"
+  AC_MSG_NOTICE([Building with JAVA_LIBS set to: $JAVA_LIBS])
 fi
 
 CPPFLAGS="$SAVE_CPPFLAGS"
@@ -2809,29 +2883,29 @@ CFLAGS="$SAVE_CFLAGS"
 LDFLAGS="$SAVE_LDFLAGS"
 LIBS="$SAVE_LIBS"
 
-AC_SUBST(JAVA_CPPFLAGS)
-AC_SUBST(JAVA_CFLAGS)
-AC_SUBST(JAVA_LDFLAGS)
-AC_SUBST(JAVA_LIBS)
-AM_CONDITIONAL(BUILD_WITH_JAVA, test "x$with_java" = "xyes")
+AC_SUBST([JAVA_CPPFLAGS])
+AC_SUBST([JAVA_CFLAGS])
+AC_SUBST([JAVA_LDFLAGS])
+AC_SUBST([JAVA_LIBS])
+AM_CONDITIONAL([BUILD_WITH_JAVA], [test "x$with_java" = "xyes"])
 # }}}
 
 # --with-libldap {{{
-AC_ARG_WITH(libldap, [AS_HELP_STRING([--with-libldap@<:@=PREFIX@:>@], [Path to libldap.])],
-[
- if test "x$withval" = "xyes"
- then
-        with_libldap="yes"
- else if test "x$withval" = "xno"
- then
-        with_libldap="no"
- else
-        with_libldap="yes"
-        LIBLDAP_CPPFLAGS="$LIBLDAP_CPPFLAGS -I$withval/include"
-        LIBLDAP_LDFLAGS="$LIBLDAP_LDFLAGS -L$withval/lib"
- fi; fi
-],
-[with_libldap="yes"])
+AC_ARG_WITH([libldap],
+  [AS_HELP_STRING([--with-libldap@<:@=PREFIX@:>@], [Path to libldap.])],
+  [
   if test "x$withval" = "xyes"; then
+      with_libldap="yes"
+    else if test "x$withval" = "xno"; then
+      with_libldap="no"
+    else
+      with_libldap="yes"
+      LIBLDAP_CPPFLAGS="$LIBLDAP_CPPFLAGS -I$withval/include"
+      LIBLDAP_LDFLAGS="$LIBLDAP_LDFLAGS -L$withval/lib"
+    fi; fi
+  ],
+  [with_libldap="yes"]
+)
 
 SAVE_CPPFLAGS="$CPPFLAGS"
 SAVE_LDFLAGS="$LDFLAGS"
@@ -2839,26 +2913,26 @@ SAVE_LDFLAGS="$LDFLAGS"
 CPPFLAGS="$CPPFLAGS $LIBLDAP_CPPFLAGS"
 LDFLAGS="$LDFLAGS $LIBLDAP_LDFLAGS"
 
-if test "x$with_libldap" = "xyes"
-then
-       if test "x$LIBLDAP_CPPFLAGS" != "x"
-       then
-               AC_MSG_NOTICE([libldap CPPFLAGS: $LIBLDAP_CPPFLAGS])
-       fi
-       AC_CHECK_HEADERS(ldap.h,
-       [with_libldap="yes"],
-       [with_libldap="no ('ldap.h' not found)"])
+if test "x$with_libldap" = "xyes"; then
+  if test "x$LIBLDAP_CPPFLAGS" != "x"; then
+    AC_MSG_NOTICE([libldap CPPFLAGS: $LIBLDAP_CPPFLAGS])
+  fi
+
+  AC_CHECK_HEADERS([ldap.h],
+    [with_libldap="yes"],
+    [with_libldap="no ('ldap.h' not found)"]
+  )
 fi
-if test "x$with_libldap" = "xyes"
-then
-       if test "x$LIBLDAP_LDFLAGS" != "x"
-       then
-               AC_MSG_NOTICE([libldap LDFLAGS: $LIBLDAP_LDFLAGS])
-       fi
-       AC_CHECK_LIB(ldap, ldap_initialize,
-       [with_libldap="yes"],
-       [with_libldap="no (symbol 'ldap_initialize' not found)"])
 
+if test "x$with_libldap" = "xyes"; then
+  if test "x$LIBLDAP_LDFLAGS" != "x"; then
+    AC_MSG_NOTICE([libldap LDFLAGS: $LIBLDAP_LDFLAGS])
+  fi
+
+  AC_CHECK_LIB([ldap], [ldap_initialize],
+    [with_libldap="yes"],
+    [with_libldap="no (symbol 'ldap_initialize' not found)"]
+  )
 fi
 
 CPPFLAGS="$SAVE_CPPFLAGS"
@@ -2866,12 +2940,11 @@ LDFLAGS="$SAVE_LDFLAGS"
 
 if test "x$with_libldap" = "xyes"
 then
-       BUILD_WITH_LIBLDAP_CPPFLAGS="$LIBLDAP_CPPFLAGS"
-       BUILD_WITH_LIBLDAP_LDFLAGS="$LIBLDAP_LDFLAGS"
-       AC_SUBST(BUILD_WITH_LIBLDAP_CPPFLAGS)
-       AC_SUBST(BUILD_WITH_LIBLDAP_LDFLAGS)
+  BUILD_WITH_LIBLDAP_CPPFLAGS="$LIBLDAP_CPPFLAGS"
+  BUILD_WITH_LIBLDAP_LDFLAGS="$LIBLDAP_LDFLAGS"
 fi
-AM_CONDITIONAL(BUILD_WITH_LIBLDAP, test "x$with_libldap" = "xyes")
+AC_SUBST([BUILD_WITH_LIBLDAP_CPPFLAGS])
+AC_SUBST([BUILD_WITH_LIBLDAP_LDFLAGS])
 # }}}
 
 # --with-liblua {{{
@@ -2889,7 +2962,7 @@ else
       PKG_CHECK_MODULES([LUA], [lua-5.3],
         [with_liblua="yes"],
         [
-         PKG_CHECK_MODULES([LUA], [lua5.3],
+          PKG_CHECK_MODULES([LUA], [lua5.3],
             [with_liblua="yes"],
             [
               PKG_CHECK_MODULES([LUA], [lua-5.2],
@@ -2955,114 +3028,117 @@ AC_SUBST(BUILD_WITH_LIBLUA_LIBS)
 # }}}
 
 # --with-liblvm2app {{{
-with_liblvm2app_cppflags=""
-with_liblvm2app_ldflags=""
-AC_ARG_WITH(liblvm2app, [AS_HELP_STRING([--with-liblvm2app@<:@=PREFIX@:>@], [Path to liblvm2app.])],
-[
-       if test "x$withval" = "xno"
-       then
-               with_liblvm2app="no"
-       else
-               with_liblvm2app="yes"
-               if test "x$withval" != "xyes"
-               then
-                       with_liblvm2app_cppflags="-I$withval/include"
-                       with_liblvm2app_ldflags="-L$withval/lib"
-               fi
-        fi
-],
-[
-       if test "x$ac_system" = "xLinux"
-       then
-               with_liblvm2app="yes"
-       else
-               with_liblvm2app="no (Linux only library)"
-       fi
-])
-if test "x$with_liblvm2app" = "xyes"
-then
-        SAVE_CPPFLAGS="$CPPFLAGS"
-        CPPFLAGS="$CPPFLAGS $with_liblvm2app_cppflags"
+AC_ARG_WITH([liblvm2app],
+  [AS_HELP_STRING([--with-liblvm2app@<:@=PREFIX@:>@], [Path to liblvm2app.])],
+  [
+    if test "x$withval" = "xno"; then
+      with_liblvm2app="no"
+    else
+      with_liblvm2app="yes"
+      if test "x$withval" != "xyes"; then
+        with_liblvm2app_cppflags="-I$withval/include"
+        with_liblvm2app_ldflags="-L$withval/lib"
+      fi
+    fi
+  ],
+  [
+    if test "x$ac_system" = "xLinux"; then
+      with_liblvm2app="yes"
+    else
+      with_liblvm2app="no (Linux only library)"
+    fi
+  ]
+)
 
-        AC_CHECK_HEADERS(lvm2app.h, [with_liblvm2app="yes"], [with_liblvm2app="no (lvm2app.h not found)"])
+if test "x$with_liblvm2app" = "xyes"; then
+  SAVE_CPPFLAGS="$CPPFLAGS"
+  CPPFLAGS="$CPPFLAGS $with_liblvm2app_cppflags"
 
-        CPPFLAGS="$SAVE_CPPFLAGS"
-fi
+  AC_CHECK_HEADERS([lvm2app.h],
+    [with_liblvm2app="yes"],
+    [with_liblvm2app="no (lvm2app.h not found)"]
+  )
 
-if test "x$with_liblvm2app" = "xyes"
-then
-        SAVE_CPPFLAGS="$CPPFLAGS"
-        SAVE_LDFLAGS="$LDFLAGS"
-        CPPFLAGS="$CPPFLAGS $with_liblvm2app_cppflags"
-        LDFLAGS="$LDFLAGS $with_liblvm2app_ldflags"
+  CPPFLAGS="$SAVE_CPPFLAGS"
+fi
+
+if test "x$with_liblvm2app" = "xyes"; then
+  SAVE_CPPFLAGS="$CPPFLAGS"
+  SAVE_LDFLAGS="$LDFLAGS"
+  CPPFLAGS="$CPPFLAGS $with_liblvm2app_cppflags"
+  LDFLAGS="$LDFLAGS $with_liblvm2app_ldflags"
+
+  AC_CHECK_LIB([lvm2app], [lvm_lv_get_property],
+    [with_liblvm2app="yes"],
+    [with_liblvm2app="no (Symbol 'lvm_lv_get_property' not found)"]
+  )
 
-        AC_CHECK_LIB(lvm2app, lvm_lv_get_property, [with_liblvm2app="yes"], [with_liblvm2app="no (Symbol 'lvm_lv_get_property' not found)"])
+  CPPFLAGS="$SAVE_CPPFLAGS"
+  LDFLAGS="$SAVE_LDFLAGS"
+fi
 
-        CPPFLAGS="$SAVE_CPPFLAGS"
-        LDFLAGS="$SAVE_LDFLAGS"
+if test "x$with_liblvm2app" = "xyes"; then
+  BUILD_WITH_LIBLVM2APP_CPPFLAGS="$with_liblvm2app_cppflags"
+  BUILD_WITH_LIBLVM2APP_LDFLAGS="$with_liblvm2app_ldflags"
+  BUILD_WITH_LIBLVM2APP_LIBS="-llvm2app"
 fi
-if test "x$with_liblvm2app" = "xyes"
-then
-        BUILD_WITH_LIBLVM2APP_CPPFLAGS="$with_liblvm2app_cppflags"
-        BUILD_WITH_LIBLVM2APP_LDFLAGS="$with_liblvm2app_ldflags"
-        BUILD_WITH_LIBLVM2APP_LIBS="-llvm2app"
-        AC_SUBST(BUILD_WITH_LIBLVM2APP_CPPFLAGS)
-        AC_SUBST(BUILD_WITH_LIBLVM2APP_LDFLAGS)
-        AC_SUBST(BUILD_WITH_LIBLVM2APP_LIBS)
-        AC_DEFINE(HAVE_LIBLVM2APP, 1, [Define if liblvm2app is present and usable.])
-fi
-AM_CONDITIONAL(BUILD_WITH_LIBLVM2APP, test "x$with_liblvm2app" = "xyes")
+
+AC_SUBST([BUILD_WITH_LIBLVM2APP_CPPFLAGS])
+AC_SUBST([BUILD_WITH_LIBLVM2APP_LDFLAGS])
+AC_SUBST([BUILD_WITH_LIBLVM2APP_LIBS])
 # }}}
 
 # --with-libmemcached {{{
-with_libmemcached_cppflags=""
-with_libmemcached_ldflags=""
-AC_ARG_WITH(libmemcached, [AS_HELP_STRING([--with-libmemcached@<:@=PREFIX@:>@], [Path to libmemcached.])],
-[
-       if test "x$withval" != "xno" && test "x$withval" != "xyes"
-       then
-               with_libmemcached_cppflags="-I$withval/include"
-               with_libmemcached_ldflags="-L$withval/lib"
-               with_libmemcached="yes"
-       else
-               with_libmemcached="$withval"
-       fi
-],
-[
-       with_libmemcached="yes"
-])
-if test "x$with_libmemcached" = "xyes"
-then
-       SAVE_CPPFLAGS="$CPPFLAGS"
-       CPPFLAGS="$CPPFLAGS $with_libmemcached_cppflags"
+AC_ARG_WITH([libmemcached],
+  [AS_HELP_STRING([--with-libmemcached@<:@=PREFIX@:>@], [Path to libmemcached.])],
+  [
+    if test "x$withval" != "xno" && test "x$withval" != "xyes"; then
+      with_libmemcached_cppflags="-I$withval/include"
+      with_libmemcached_ldflags="-L$withval/lib"
+      with_libmemcached="yes"
+    else
+      with_libmemcached="$withval"
+    fi
+  ],
+  [with_libmemcached="yes"]
+)
 
-       AC_CHECK_HEADERS(libmemcached/memcached.h, [with_libmemcached="yes"], [with_libmemcached="no (libmemcached/memcached.h not found)"])
+if test "x$with_libmemcached" = "xyes"; then
+  SAVE_CPPFLAGS="$CPPFLAGS"
+  CPPFLAGS="$CPPFLAGS $with_libmemcached_cppflags"
 
-       CPPFLAGS="$SAVE_CPPFLAGS"
+  AC_CHECK_HEADERS([libmemcached/memcached.h],
+    [with_libmemcached="yes"],
+    [with_libmemcached="no (libmemcached/memcached.h not found)"]
+  )
+
+  CPPFLAGS="$SAVE_CPPFLAGS"
 fi
-if test "x$with_libmemcached" = "xyes"
-then
-       SAVE_CPPFLAGS="$CPPFLAGS"
-       SAVE_LDFLAGS="$LDFLAGS"
-       CPPFLAGS="$CPPFLAGS $with_libmemcached_cppflags"
-       LDFLAGS="$LDFLAGS $with_libmemcached_ldflags"
 
-       AC_CHECK_LIB(memcached, memcached_create, [with_libmemcached="yes"], [with_libmemcached="no (Symbol 'memcached_create' not found)"])
+if test "x$with_libmemcached" = "xyes"; then
+  SAVE_CPPFLAGS="$CPPFLAGS"
+  SAVE_LDFLAGS="$LDFLAGS"
+  CPPFLAGS="$CPPFLAGS $with_libmemcached_cppflags"
+  LDFLAGS="$LDFLAGS $with_libmemcached_ldflags"
 
-       CPPFLAGS="$SAVE_CPPFLAGS"
-       LDFLAGS="$SAVE_LDFLAGS"
+  AC_CHECK_LIB([memcached], [memcached_create],
+    [with_libmemcached="yes"],
+    [with_libmemcached="no (Symbol 'memcached_create' not found)"]
+  )
+
+  CPPFLAGS="$SAVE_CPPFLAGS"
+  LDFLAGS="$SAVE_LDFLAGS"
 fi
-if test "x$with_libmemcached" = "xyes"
-then
-       BUILD_WITH_LIBMEMCACHED_CPPFLAGS="$with_libmemcached_cppflags"
-       BUILD_WITH_LIBMEMCACHED_LDFLAGS="$with_libmemcached_ldflags"
-       BUILD_WITH_LIBMEMCACHED_LIBS="-lmemcached"
-       AC_SUBST(BUILD_WITH_LIBMEMCACHED_CPPFLAGS)
-       AC_SUBST(BUILD_WITH_LIBMEMCACHED_LDFLAGS)
-       AC_SUBST(BUILD_WITH_LIBMEMCACHED_LIBS)
-       AC_DEFINE(HAVE_LIBMEMCACHED, 1, [Define if libmemcached is present and usable.])
-fi
-AM_CONDITIONAL(BUILD_WITH_LIBMEMCACHED, test "x$with_libmemcached" = "xyes")
+
+if test "x$with_libmemcached" = "xyes"; then
+  BUILD_WITH_LIBMEMCACHED_CPPFLAGS="$with_libmemcached_cppflags"
+  BUILD_WITH_LIBMEMCACHED_LDFLAGS="$with_libmemcached_ldflags"
+  BUILD_WITH_LIBMEMCACHED_LIBS="-lmemcached"
+fi
+
+AC_SUBST([BUILD_WITH_LIBMEMCACHED_CPPFLAGS])
+AC_SUBST([BUILD_WITH_LIBMEMCACHED_LDFLAGS])
+AC_SUBST([BUILD_WITH_LIBMEMCACHED_LIBS])
 # }}}
 
 # --with-libmicrohttpd {{{
@@ -3070,29 +3146,25 @@ with_libmicrohttpd_cppflags=""
 with_libmicrohttpd_ldflags=""
 AC_ARG_WITH([libmicrohttpd], [AS_HELP_STRING([--with-libmicrohttpd@<:@=PREFIX@:>@], [Path to libmicrohttpd.])],
   [
-    if test "x$withval" != "xno" && test "x$withval" != "xyes"
-    then
+    if test "x$withval" != "xno" && test "x$withval" != "xyes"; then
       with_libmicrohttpd_cppflags="-I$withval/include"
       with_libmicrohttpd_ldflags="-L$withval/lib"
       with_libmicrohttpd="yes"
     fi
-    if test "x$withval" = "xno"
-    then
+    if test "x$withval" = "xno"; then
       with_libmicrohttpd="no (disabled on command line)"
     fi
   ],
   [withval="yes"]
 )
-if test "x$withval" = "xyes"
-then
-PKG_CHECK_MODULES([MICROHTTPD], [libmicrohttpd],
-  [with_libmicrohttpd="yes"],
-  [with_libmicrohttpd="no (pkg-config could not find libmicrohttpd)"]
-)
+if test "x$withval" = "xyes"; then
+  PKG_CHECK_MODULES([MICROHTTPD], [libmicrohttpd],
+    [with_libmicrohttpd="yes"],
+    [with_libmicrohttpd="no (pkg-config could not find libmicrohttpd)"]
+  )
 fi
 
-if test "x$MICROHTTPD_LIBS" = "x"
-then
+if test "x$MICROHTTPD_LIBS" = "x"; then
   MICROHTTPD_LIBS="-lmicrohttpd"
 fi
 
@@ -3103,18 +3175,18 @@ CPPFLAGS="$with_libmicrohttpd_cppflags $MICROHTTPD_CFLAGS"
 LDFLAGS="$with_libmicrohttpd_ldflags $LDFLAGS"
 LIBS="$LIBS $MICROHTTPD_LIBS"
 
-if test "x$with_libmicrohttpd" = "xyes"
-then
+if test "x$with_libmicrohttpd" = "xyes"; then
   AC_CHECK_HEADERS([microhttpd.h],
-                   [with_libmicrohttpd="yes"],
-                   [with_libmicrohttpd="no (<microhttpd.h> not found)"])
+   [with_libmicrohttpd="yes"],
+   [with_libmicrohttpd="no (<microhttpd.h> not found)"]
+  )
 fi
 
-if test "x$with_libmicrohttpd" = "xyes"
-then
+if test "x$with_libmicrohttpd" = "xyes"; then
   AC_CHECK_LIB([microhttpd], [MHD_start_daemon],
-               [with_libmicrohttpd="yes"],
-               [with_libmicrohttpd="no (libmicrohttpd not found)"])
+    [with_libmicrohttpd="yes"],
+    [with_libmicrohttpd="no (libmicrohttpd not found)"]
+  )
 fi
 
 CPPFLAGS="$SAVE_CPPFLAGS"
@@ -3130,106 +3202,97 @@ AC_SUBST([BUILD_WITH_LIBMICROHTTPD_LIBS])
 # }}}
 
 # --with-libmodbus {{{
-with_libmodbus_config=""
-with_libmodbus_cflags=""
-with_libmodbus_libs=""
-AC_ARG_WITH(libmodbus, [AS_HELP_STRING([--with-libmodbus@<:@=PREFIX@:>@], [Path to the modbus library.])],
-[
-       if test "x$withval" = "xno"
-       then
-               with_libmodbus="no"
-       else if test "x$withval" = "xyes"
-       then
-               with_libmodbus="use_pkgconfig"
-       else if test -d "$with_libmodbus/lib"
-       then
-               AC_MSG_NOTICE([Not checking for libmodbus: Manually configured])
-               with_libmodbus_cflags="-I$withval/include"
-               with_libmodbus_libs="-L$withval/lib -lmodbus"
-               with_libmodbus="yes"
-       fi; fi; fi
-],
-[with_libmodbus="use_pkgconfig"])
+AC_ARG_WITH([libmodbus],
+  [AS_HELP_STRING([--with-libmodbus@<:@=PREFIX@:>@], [Path to the modbus library.])],
+  [
+    if test "x$withval" = "xno"; then
+      with_libmodbus="no"
+    else if test "x$withval" = "xyes"; then
+      with_libmodbus="use_pkgconfig"
+    else if test -d "$with_libmodbus/lib"; then
+      AC_MSG_NOTICE([Not checking for libmodbus: Manually configured])
+      with_libmodbus_cflags="-I$withval/include"
+      with_libmodbus_libs="-L$withval/lib -lmodbus"
+      with_libmodbus="yes"
+    fi; fi; fi
+  ],
+  [with_libmodbus="use_pkgconfig"]
+)
 
 # configure using pkg-config
-if test "x$with_libmodbus" = "xuse_pkgconfig"
-then
-       AC_MSG_NOTICE([Checking for libmodbus using $PKG_CONFIG])
-       $PKG_CONFIG --exists 'libmodbus' 2>/dev/null
-       if test $? -ne 0
-       then
-               with_libmodbus="no (pkg-config doesn't know libmodbus)"
-       fi
+if test "x$with_libmodbus" = "xuse_pkgconfig"; then
+  AC_MSG_NOTICE([Checking for libmodbus using $PKG_CONFIG])
+  $PKG_CONFIG --exists 'libmodbus' 2>/dev/null
+  if test $? -ne 0; then
+    with_libmodbus="no (pkg-config doesn't know libmodbus)"
+  fi
 fi
-if test "x$with_libmodbus" = "xuse_pkgconfig"
-then
-       with_libmodbus_cflags="`$PKG_CONFIG --cflags 'libmodbus'`"
-       if test $? -ne 0
-       then
-               with_libmodbus="no ($PKG_CONFIG failed)"
-       fi
-       with_libmodbus_libs="`$PKG_CONFIG --libs 'libmodbus'`"
-       if test $? -ne 0
-       then
-               with_libmodbus="no ($PKG_CONFIG failed)"
-       fi
+
+if test "x$with_libmodbus" = "xuse_pkgconfig"; then
+  with_libmodbus_cflags="`$PKG_CONFIG --cflags 'libmodbus'`"
+  if test $? -ne 0; then
+    with_libmodbus="no ($PKG_CONFIG failed)"
+  fi
+
+  with_libmodbus_libs="`$PKG_CONFIG --libs 'libmodbus'`"
+  if test $? -ne 0; then
+    with_libmodbus="no ($PKG_CONFIG failed)"
+  fi
 fi
-if test "x$with_libmodbus" = "xuse_pkgconfig"
-then
-       with_libmodbus="yes"
+
+if test "x$with_libmodbus" = "xuse_pkgconfig"; then
+  with_libmodbus="yes"
 fi
 
-# with_libmodbus_cflags and with_libmodbus_libs are set up now, let's do
-# the actual checks.
-if test "x$with_libmodbus" = "xyes"
-then
-       SAVE_CPPFLAGS="$CPPFLAGS"
-       CPPFLAGS="$CPPFLAGS $with_libmodbus_cflags"
+if test "x$with_libmodbus" = "xyes"; then
+  SAVE_CPPFLAGS="$CPPFLAGS"
+  CPPFLAGS="$CPPFLAGS $with_libmodbus_cflags"
 
-       AC_CHECK_HEADERS(modbus.h, [], [with_libmodbus="no (modbus.h not found)"])
+  AC_CHECK_HEADERS([modbus.h],
+    [with_libmodbus="yes"],
+    [with_libmodbus="no (modbus.h not found)"]
+  )
 
-       CPPFLAGS="$SAVE_CPPFLAGS"
+  CPPFLAGS="$SAVE_CPPFLAGS"
 fi
-if test "x$with_libmodbus" = "xyes"
-then
-       SAVE_CPPFLAGS="$CPPFLAGS"
-       SAVE_LDFLAGS="$LDFLAGS"
 
-       CPPFLAGS="$CPPFLAGS $with_libmodbus_cflags"
-       LDFLAGS="$LDFLAGS $with_libmodbus_libs"
+if test "x$with_libmodbus" = "xyes"; then
+  SAVE_LDFLAGS="$LDFLAGS"
+  LDFLAGS="$LDFLAGS $with_libmodbus_libs"
 
-       AC_CHECK_LIB(modbus, modbus_connect,
-                    [with_libmodbus="yes"],
-                    [with_libmodbus="no (symbol modbus_connect not found)"])
+  AC_CHECK_LIB([modbus], [modbus_connect],
+    [with_libmodbus="yes"],
+    [with_libmodbus="no (symbol modbus_connect not found)"]
+  )
 
-       CPPFLAGS="$SAVE_CPPFLAGS"
-       LDFLAGS="$SAVE_LDFLAGS"
+  LDFLAGS="$SAVE_LDFLAGS"
 fi
-if test "x$with_libmodbus" = "xyes"
-then
-       BUILD_WITH_LIBMODBUS_CFLAGS="$with_libmodbus_cflags"
-       BUILD_WITH_LIBMODBUS_LIBS="$with_libmodbus_libs"
-       AC_SUBST(BUILD_WITH_LIBMODBUS_CFLAGS)
-       AC_SUBST(BUILD_WITH_LIBMODBUS_LIBS)
+
+if test "x$with_libmodbus" = "xyes"; then
+  BUILD_WITH_LIBMODBUS_CFLAGS="$with_libmodbus_cflags"
+  BUILD_WITH_LIBMODBUS_LIBS="$with_libmodbus_libs"
 fi
+
+AC_SUBST([BUILD_WITH_LIBMODBUS_CFLAGS])
+AC_SUBST([BUILD_WITH_LIBMODBUS_LIBS])
 # }}}
 
 # --with-libmongoc {{{
-AC_ARG_WITH(libmongoc, [AS_HELP_STRING([--with-libmongoc@<:@=PREFIX@:>@], [Path to libmongoc.])],
-[
- if test "x$withval" = "xyes"
- then
-        with_libmongoc="yes"
- else if test "x$withval" = "xno"
- then
-        with_libmongoc="no"
- else
-        with_libmongoc="yes"
-        LIBMONGOC_CPPFLAGS="$LIBMONGOC_CPPFLAGS -I$withval/include"
-        LIBMONGOC_LDFLAGS="$LIBMONGOC_LDFLAGS -L$withval/lib"
- fi; fi
-],
-[with_libmongoc="yes"])
+AC_ARG_WITH([libmongoc],
+  [AS_HELP_STRING([--with-libmongoc@<:@=PREFIX@:>@], [Path to libmongoc.])],
+  [
   if test "x$withval" = "xyes"; then
+      with_libmongoc="yes"
+    else if test "x$withval" = "xno"; then
+      with_libmongoc="no"
+    else
+      with_libmongoc="yes"
+      LIBMONGOC_CPPFLAGS="$LIBMONGOC_CPPFLAGS -I$withval/include"
+      LIBMONGOC_LDFLAGS="$LIBMONGOC_LDFLAGS -L$withval/lib"
+    fi; fi
+  ],
+  [with_libmongoc="yes"]
+)
 
 SAVE_CPPFLAGS="$CPPFLAGS"
 SAVE_LDFLAGS="$LDFLAGS"
@@ -3237,366 +3300,346 @@ SAVE_LDFLAGS="$LDFLAGS"
 CPPFLAGS="$CPPFLAGS $LIBMONGOC_CPPFLAGS"
 LDFLAGS="$LDFLAGS $LIBMONGOC_LDFLAGS"
 
-if test "x$with_libmongoc" = "xyes"
-then
-       if test "x$LIBMONGOC_CPPFLAGS" != "x"
-       then
-               AC_MSG_NOTICE([libmongoc CPPFLAGS: $LIBMONGOC_CPPFLAGS])
-       fi
-       AC_CHECK_HEADERS(mongo.h,
-       [with_libmongoc="yes"],
-       [with_libmongoc="no ('mongo.h' not found)"],
-[#if HAVE_STDINT_H
-# define MONGO_HAVE_STDINT 1
-#else
-# define MONGO_USE_LONG_LONG_INT 1
-#endif
-])
+if test "x$with_libmongoc" = "xyes"; then
+  if test "x$LIBMONGOC_CPPFLAGS" != "x"; then
+    AC_MSG_NOTICE([libmongoc CPPFLAGS: $LIBMONGOC_CPPFLAGS])
+  fi
+
+  AC_CHECK_HEADERS([mongo.h],
+    [with_libmongoc="yes"],
+    [with_libmongoc="no ('mongo.h' not found)"],
+    [[#define MONGO_HAVE_STDINT 1]]
+  )
 fi
-if test "x$with_libmongoc" = "xyes"
-then
-       if test "x$LIBMONGOC_LDFLAGS" != "x"
-       then
-               AC_MSG_NOTICE([libmongoc LDFLAGS: $LIBMONGOC_LDFLAGS])
-       fi
-       AC_CHECK_LIB(mongoc, mongo_run_command,
-       [with_libmongoc="yes"],
-       [with_libmongoc="no (symbol 'mongo_run_command' not found)"])
+
+if test "x$with_libmongoc" = "xyes"; then
+  if test "x$LIBMONGOC_LDFLAGS" != "x"; then
+    AC_MSG_NOTICE([libmongoc LDFLAGS: $LIBMONGOC_LDFLAGS])
+  fi
+
+  AC_CHECK_LIB([mongoc], [mongo_run_command],
+    [with_libmongoc="yes"],
+    [with_libmongoc="no (symbol 'mongo_run_command' not found)"]
+  )
 fi
 
 CPPFLAGS="$SAVE_CPPFLAGS"
 LDFLAGS="$SAVE_LDFLAGS"
 
-if test "x$with_libmongoc" = "xyes"
-then
-       BUILD_WITH_LIBMONGOC_CPPFLAGS="$LIBMONGOC_CPPFLAGS"
-       BUILD_WITH_LIBMONGOC_LDFLAGS="$LIBMONGOC_LDFLAGS"
-       AC_SUBST(BUILD_WITH_LIBMONGOC_CPPFLAGS)
-       AC_SUBST(BUILD_WITH_LIBMONGOC_LDFLAGS)
+if test "x$with_libmongoc" = "xyes"; then
+  BUILD_WITH_LIBMONGOC_CPPFLAGS="$LIBMONGOC_CPPFLAGS"
+  BUILD_WITH_LIBMONGOC_LDFLAGS="$LIBMONGOC_LDFLAGS"
 fi
-AM_CONDITIONAL(BUILD_WITH_LIBMONGOC, test "x$with_libmongoc" = "xyes")
+
+AC_SUBST([BUILD_WITH_LIBMONGOC_CPPFLAGS])
+AC_SUBST([BUILD_WITH_LIBMONGOC_LDFLAGS])
 # }}}
 
 # --with-libmosquitto {{{
-with_libmosquitto_cppflags=""
-with_libmosquitto_ldflags=""
-AC_ARG_WITH(libmosquitto, [AS_HELP_STRING([--with-libmosquitto@<:@=PREFIX@:>@], [Path to libmosquitto.])],
-[
-       if test "x$withval" != "xno" && test "x$withval" != "xyes"
-       then
-               with_libmosquitto_cppflags="-I$withval/include"
-               with_libmosquitto_ldflags="-L$withval/lib"
-               with_libmosquitto="yes"
-       else
-               with_libmosquitto="$withval"
-       fi
-],
-[
-       with_libmosquitto="yes"
-])
-if test "x$with_libmosquitto" = "xyes"
-then
-       SAVE_CPPFLAGS="$CPPFLAGS"
-       CPPFLAGS="$CPPFLAGS $with_libmosquitto_cppflags"
+AC_ARG_WITH([libmosquitto],
+  [AS_HELP_STRING([--with-libmosquitto@<:@=PREFIX@:>@], [Path to libmosquitto.])],
+  [
+    if test "x$withval" != "xno" && test "x$withval" != "xyes"; then
+      with_libmosquitto_cppflags="-I$withval/include"
+      with_libmosquitto_ldflags="-L$withval/lib"
+      with_libmosquitto="yes"
+    else
+      with_libmosquitto="$withval"
+    fi
+  ],
+  [with_libmosquitto="yes"]
+)
 
-       AC_CHECK_HEADERS(mosquitto.h, [with_libmosquitto="yes"], [with_libmosquitto="no (mosquitto.h not found)"])
+if test "x$with_libmosquitto" = "xyes"; then
+  SAVE_CPPFLAGS="$CPPFLAGS"
+  CPPFLAGS="$CPPFLAGS $with_libmosquitto_cppflags"
 
-       CPPFLAGS="$SAVE_CPPFLAGS"
+  AC_CHECK_HEADERS([mosquitto.h],
+    [with_libmosquitto="yes"],
+    [with_libmosquitto="no (mosquitto.h not found)"]
+  )
+
+  CPPFLAGS="$SAVE_CPPFLAGS"
 fi
-if test "x$with_libmosquitto" = "xyes"
-then
-       SAVE_LDFLAGS="$LDFLAGS"
-       SAVE_CPPFLAGS="$CPPFLAGS"
-       LDFLAGS="$LDFLAGS $with_libmosquitto_ldflags"
-       CPPFLAGS="$CPPFLAGS $with_libmosquitto_cppflags"
 
-       AC_CHECK_LIB(mosquitto, mosquitto_connect, [with_libmosquitto="yes"], [with_libmosquitto="no (libmosquitto not found)"])
+if test "x$with_libmosquitto" = "xyes"; then
+  SAVE_LDFLAGS="$LDFLAGS"
+  LDFLAGS="$LDFLAGS $with_libmosquitto_ldflags"
 
-       LDFLAGS="$SAVE_LDFLAGS"
-       CPPFLAGS="$SAVE_CPPFLAGS"
+  AC_CHECK_LIB([mosquitto], [mosquitto_connect],
+    [with_libmosquitto="yes"],
+    [with_libmosquitto="no (libmosquitto not found)"]
+  )
+
+  LDFLAGS="$SAVE_LDFLAGS"
 fi
-if test "x$with_libmosquitto" = "xyes"
-then
-       BUILD_WITH_LIBMOSQUITTO_CPPFLAGS="$with_libmosquitto_cppflags"
-       BUILD_WITH_LIBMOSQUITTO_LDFLAGS="$with_libmosquitto_ldflags"
-       BUILD_WITH_LIBMOSQUITTO_LIBS="-lmosquitto"
-       AC_SUBST(BUILD_WITH_LIBMOSQUITTO_CPPFLAGS)
-       AC_SUBST(BUILD_WITH_LIBMOSQUITTO_LDFLAGS)
-       AC_SUBST(BUILD_WITH_LIBMOSQUITTO_LIBS)
+
+if test "x$with_libmosquitto" = "xyes"; then
+  BUILD_WITH_LIBMOSQUITTO_CPPFLAGS="$with_libmosquitto_cppflags"
+  BUILD_WITH_LIBMOSQUITTO_LDFLAGS="$with_libmosquitto_ldflags"
+  BUILD_WITH_LIBMOSQUITTO_LIBS="-lmosquitto"
 fi
+
+AC_SUBST([BUILD_WITH_LIBMOSQUITTO_CPPFLAGS])
+AC_SUBST([BUILD_WITH_LIBMOSQUITTO_LDFLAGS])
+AC_SUBST([BUILD_WITH_LIBMOSQUITTO_LIBS])
 # }}}
 
 # --with-libmysql {{{
 with_mysql_config="mysql_config"
-with_mysql_cflags=""
-with_mysql_libs=""
-AC_ARG_WITH(libmysql, [AS_HELP_STRING([--with-libmysql@<:@=PREFIX@:>@], [Path to libmysql.])],
-[
-       if test "x$withval" = "xno"
-       then
-               with_libmysql="no"
-       else if test "x$withval" = "xyes"
-       then
-               with_libmysql="yes"
-       else
-               if test -f "$withval" && test -x "$withval";
-               then
-                       with_mysql_config="$withval"
-               else if test -x "$withval/bin/mysql_config"
-               then
-                       with_mysql_config="$withval/bin/mysql_config"
-               fi; fi
-               with_libmysql="yes"
-       fi; fi
-],
-[
-       with_libmysql="yes"
-])
-if test "x$with_libmysql" = "xyes"
-then
-       with_mysql_cflags=`$with_mysql_config --include 2>/dev/null`
-       mysql_config_status=$?
+AC_ARG_WITH([libmysql],
+  [AS_HELP_STRING([--with-libmysql@<:@=PREFIX@:>@], [Path to libmysql.])],
+  [
+    if test "x$withval" = "xno"; then
+      with_libmysql="no"
+    else if test "x$withval" = "xyes"; then
+      with_libmysql="yes"
+    else
+      if test -f "$withval" && test -x "$withval"; then
+        with_mysql_config="$withval"
+      else if test -x "$withval/bin/mysql_config"; then
+        with_mysql_config="$withval/bin/mysql_config"
+      fi; fi
+      with_libmysql="yes"
+    fi; fi
+  ],
+  [with_libmysql="yes"]
+)
 
-       if test $mysql_config_status -ne 0
-       then
-               with_libmysql="no ($with_mysql_config failed)"
-       else
-               SAVE_CPPFLAGS="$CPPFLAGS"
-               CPPFLAGS="$CPPFLAGS $with_mysql_cflags"
+if test "x$with_libmysql" = "xyes"; then
+  with_mysql_cflags=`$with_mysql_config --include 2>/dev/null`
+  if test $? -ne 0; then
+    with_libmysql="no ($with_mysql_config failed)"
+  else
+    SAVE_CPPFLAGS="$CPPFLAGS"
+    CPPFLAGS="$CPPFLAGS $with_mysql_cflags"
 
-               have_mysql_h="no"
-               have_mysql_mysql_h="no"
-               AC_CHECK_HEADERS(mysql.h, [have_mysql_h="yes"])
+    AC_CHECK_HEADERS([mysql.h],
+      [have_mysql_h="yes"],
+      [have_mysql_h="no"]
+    )
 
-               if test "x$have_mysql_h" = "xno"
-               then
-                       AC_CHECK_HEADERS(mysql/mysql.h, [have_mysql_mysql_h="yes"])
-               fi
+    if test "x$have_mysql_h" != "xyes"; then
+      AC_CHECK_HEADERS([mysql/mysql.h],
+        [have_mysql_mysql_h="yes"],
+        [],
+      )
+    fi
 
-               if test "x$have_mysql_h$have_mysql_mysql_h" = "xnono"
-               then
-                       with_libmysql="no (mysql.h not found)"
-               fi
+    if test "x$have_mysql_h" != "xyes" && test "x$have_mysql_mysql_h" != "xyes"; then
+      with_libmysql="no (mysql.h not found)"
+    fi
 
-               CPPFLAGS="$SAVE_CPPFLAGS"
-       fi
+    CPPFLAGS="$SAVE_CPPFLAGS"
+  fi
 fi
-if test "x$with_libmysql" = "xyes"
-then
-       with_mysql_libs=`$with_mysql_config --libs_r 2>/dev/null`
-       mysql_config_status=$?
 
-       if test $mysql_config_status -ne 0
-       then
-               with_libmysql="no ($with_mysql_config failed)"
-       else
-               SAVE_CPPFLAGS="$CPPFLAGS"
-               CPPFLAGS="$CPPFLAGS $with_mysql_cflags"
-               SAVE_LIBS="$LIBS"
-               LIBS="$with_mysql_libs"
-               AC_SEARCH_LIBS([mysql_get_server_version],
-                [],
-                [with_libmysql="yes"],
-                [with_libmysql="no (symbol 'mysql_get_server_version' not found)"],
-                [])
-               CPPFLAGS="$SAVE_CPPFLAGS"
-               LIBS="$SAVE_LIBS"
-       fi
+if test "x$with_libmysql" = "xyes"; then
+  with_mysql_libs=`$with_mysql_config --libs_r 2>/dev/null`
+  if test $? -ne 0; then
+    with_libmysql="no ($with_mysql_config failed)"
+  else
+    SAVE_LIBS="$LIBS"
+    LIBS="$with_mysql_libs"
+
+    AC_SEARCH_LIBS([mysql_get_server_version],
+      [],
+      [with_libmysql="yes"],
+      [with_libmysql="no (symbol 'mysql_get_server_version' not found in ${LIBS})"],
+      []
+    )
+    LIBS="$SAVE_LIBS"
+  fi
 fi
-if test "x$with_libmysql" = "xyes"
-then
-       BUILD_WITH_LIBMYSQL_CFLAGS="$with_mysql_cflags"
-       BUILD_WITH_LIBMYSQL_LIBS="$with_mysql_libs"
-       AC_SUBST(BUILD_WITH_LIBMYSQL_CFLAGS)
-       AC_SUBST(BUILD_WITH_LIBMYSQL_LIBS)
+
+if test "x$with_libmysql" = "xyes"; then
+  BUILD_WITH_LIBMYSQL_CFLAGS="$with_mysql_cflags"
+  BUILD_WITH_LIBMYSQL_LIBS="$with_mysql_libs"
 fi
-AM_CONDITIONAL(BUILD_WITH_LIBMYSQL, test "x$with_libmysql" = "xyes")
+
+AC_SUBST([BUILD_WITH_LIBMYSQL_CFLAGS])
+AC_SUBST([BUILD_WITH_LIBMYSQL_LIBS])
 # }}}
 
 # --with-libmnl {{{
-with_libmnl_cflags=""
-with_libmnl_libs=""
-AC_ARG_WITH(libmnl, [AS_HELP_STRING([--with-libmnl@<:@=PREFIX@:>@], [Path to libmnl.])],
-[
- echo "libmnl: withval = $withval"
- if test "x$withval" = "xyes"
- then
-        with_libmnl="yes"
- else if test "x$withval" = "xno"
- then
-        with_libmnl="no"
- else
-        if test -d "$withval/include"
-        then
-                with_libmnl_cflags="-I$withval/include"
-                with_libmnl_libs="-L$withval/lib -lmnl"
-                with_libmnl="yes"
-        else
-                AC_MSG_ERROR("no such directory: $withval/include")
-        fi
- fi; fi
-],
-[
- if test "x$ac_system" = "xLinux"
- then
-        with_libmnl="yes"
- else
-        with_libmnl="no (Linux only library)"
- fi
-])
-if test "x$with_libmnl" = "xyes"
-then
-       if $PKG_CONFIG --exists libmnl 2>/dev/null; then
-         with_libmnl_cflags="$with_libmnl_ldflags `$PKG_CONFIG --cflags libmnl`"
-         with_libmnl_libs="$with_libmnl_libs `$PKG_CONFIG --libs libmnl`"
-       fi
+AC_ARG_WITH([libmnl],
+  [AS_HELP_STRING([--with-libmnl@<:@=PREFIX@:>@], [Path to libmnl.])],
+  [
+    if test "x$withval" = "xyes"; then
+      with_libmnl="yes"
+     else if test "x$withval" = "xno"; then
+       with_libmnl="no"
+     else
+       if test -d "$withval/include"; then
+         with_libmnl_cflags="-I$withval/include"
+         with_libmnl_libs="-L$withval/lib -lmnl"
+         with_libmnl="yes"
+       else
+         AC_MSG_ERROR("no such directory: $withval/include")
+       fi
+     fi; fi
+  ],
+  [
+    if test "x$ac_system" = "xLinux"; then
+      with_libmnl="yes"
+    else
+      with_libmnl="no (Linux only library)"
+    fi
+  ]
+)
 
-       AC_CHECK_HEADERS(libmnl.h libmnl/libmnl.h,
-       [
-        with_libmnl="yes"
-        break
-       ], [],
-[#include <stdio.h>
-#include <sys/types.h>
-#include <asm/types.h>
-#include <sys/socket.h>
-#include <linux/netlink.h>
-#include <linux/rtnetlink.h>])
-       AC_CHECK_HEADERS(linux/gen_stats.h linux/pkt_sched.h, [], [],
-[#include <stdio.h>
-#include <sys/types.h>
-#include <asm/types.h>
-#include <sys/socket.h>])
-
-        AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
-[[
-#include <stdio.h>
-#include <sys/types.h>
-#include <asm/types.h>
-#include <sys/socket.h>
-#include <linux/netlink.h>
-#include <linux/rtnetlink.h>
-]],
-[[
-int retval = TCA_STATS2;
-return (retval);
-]]
-       )],
-       [AC_DEFINE([HAVE_TCA_STATS2], [1], [True if the enum-member TCA_STATS2 exists])])
-
-       AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
-[[
-#include <stdio.h>
-#include <sys/types.h>
-#include <asm/types.h>
-#include <sys/socket.h>
-#include <linux/netlink.h>
-#include <linux/rtnetlink.h>
-]],
-[[
-int retval = TCA_STATS;
-return (retval);
-]]
-       )],
-       [AC_DEFINE([HAVE_TCA_STATS], 1, [True if the enum-member TCA_STATS exists])])
-fi
-if test "x$with_libmnl" = "xyes"
-then
-       AC_CHECK_MEMBERS([struct rtnl_link_stats64.tx_window_errors],
-       [AC_DEFINE(HAVE_RTNL_LINK_STATS64, 1, [Define if struct rtnl_link_stats64 exists and is usable.])],
-       [],
-       [
-       #include <linux/if_link.h>
-       ])
-fi
-if test "x$with_libmnl" = "xyes"
-then
-       AC_CHECK_LIB(mnl, mnl_nlmsg_get_payload,
-                    [with_libmnl="yes"],
-                    [with_libmnl="no (symbol 'mnl_nlmsg_get_payload' not found)"],
-                    [$with_libmnl_libs])
+if test "x$with_libmnl" = "xyes"; then
+  if $PKG_CONFIG --exists libmnl 2>/dev/null; then
+    with_libmnl_cflags="$with_libmnl_ldflags `$PKG_CONFIG --cflags libmnl`"
+    with_libmnl_libs="$with_libmnl_libs `$PKG_CONFIG --libs libmnl`"
+  fi
+
+  AC_CHECK_HEADERS([libmnl.h libmnl/libmnl.h],
+    [
+      with_libmnl="yes"
+      break
+    ],
+    [],
+    [[
+      #include <stdio.h>
+      #include <sys/types.h>
+      #include <asm/types.h>
+      #include <sys/socket.h>
+      #include <linux/netlink.h>
+      #include <linux/rtnetlink.h>]]
+  )
+
+  AC_CHECK_HEADERS([linux/gen_stats.h linux/pkt_sched.h],
+    [],
+    [],
+    [[
+      #include <stdio.h>
+      #include <sys/types.h>
+      #include <asm/types.h>
+      #include <sys/socket.h>
+    ]]
+  )
+
+  AC_COMPILE_IFELSE(
+    [
+      AC_LANG_PROGRAM(
+        [[
+          #include <stdio.h>
+          #include <sys/types.h>
+          #include <asm/types.h>
+          #include <sys/socket.h>
+          #include <linux/netlink.h>
+          #include <linux/rtnetlink.h>
+        ]],
+        [[
+          int retval = TCA_STATS2;
+          return (retval);
+        ]]
+      )
+    ],
+    [AC_DEFINE([HAVE_TCA_STATS2], [1], [True if the enum-member TCA_STATS2 exists])]
+  )
+
+  AC_COMPILE_IFELSE(
+    [
+      AC_LANG_PROGRAM(
+        [[
+          #include <stdio.h>
+          #include <sys/types.h>
+          #include <asm/types.h>
+          #include <sys/socket.h>
+          #include <linux/netlink.h>
+          #include <linux/rtnetlink.h>
+        ]],
+        [[
+          int retval = TCA_STATS;
+          return (retval);
+        ]]
+      )
+    ],
+    [AC_DEFINE([HAVE_TCA_STATS], 1, [True if the enum-member TCA_STATS exists])]
+  )
+
+  AC_CHECK_MEMBERS([struct rtnl_link_stats64.tx_window_errors],
+    [AC_DEFINE(HAVE_RTNL_LINK_STATS64, 1, [Define if struct rtnl_link_stats64 exists and is usable.])],
+    [],
+    [[#include <linux/if_link.h>]]
+  )
+
+  AC_CHECK_LIB([mnl], [mnl_nlmsg_get_payload],
+    [with_libmnl="yes"],
+    [with_libmnl="no (symbol 'mnl_nlmsg_get_payload' not found)"],
+    [$with_libmnl_libs]
+  )
 fi
-if test "x$with_libmnl" = "xyes"
-then
-       AC_DEFINE(HAVE_LIBMNL, 1, [Define if libmnl is present and usable.])
-       BUILD_WITH_LIBMNL_CFLAGS="$with_libmnl_cflags"
-       BUILD_WITH_LIBMNL_LIBS="$with_libmnl_libs"
-       AC_SUBST(BUILD_WITH_LIBMNL_CFLAGS)
-       AC_SUBST(BUILD_WITH_LIBMNL_LIBS)
+
+if test "x$with_libmnl" = "xyes"; then
+  BUILD_WITH_LIBMNL_CFLAGS="$with_libmnl_cflags"
+  BUILD_WITH_LIBMNL_LIBS="$with_libmnl_libs"
 fi
-AM_CONDITIONAL(BUILD_WITH_LIBMNL, test "x$with_libmnl" = "xyes")
+AC_SUBST([BUILD_WITH_LIBMNL_CFLAGS])
+AC_SUBST([BUILD_WITH_LIBMNL_LIBS])
 # }}}
 
 # --with-libnetapp {{{
 AC_ARG_VAR([LIBNETAPP_CPPFLAGS], [C preprocessor flags required to build with libnetapp])
 AC_ARG_VAR([LIBNETAPP_LDFLAGS],  [Linker flags required to build with libnetapp])
 AC_ARG_VAR([LIBNETAPP_LIBS],     [Other libraries required to link against libnetapp])
-LIBNETAPP_CPPFLAGS="$LIBNETAPP_CPPFLAGS"
-LIBNETAPP_LDFLAGS="$LIBNETAPP_LDFLAGS"
-LIBNETAPP_LIBS="$LIBNETAPP_LIBS"
-AC_ARG_WITH(libnetapp, [AS_HELP_STRING([--with-libnetapp@<:@=PREFIX@:>@], [Path to libnetapp.])],
-[
- if test -d "$withval"
- then
-        LIBNETAPP_CPPFLAGS="$LIBNETAPP_CPPFLAGS -I$withval/include"
-        LIBNETAPP_LDFLAGS="$LIBNETAPP_LDFLAGS -L$withval/lib"
-        with_libnetapp="yes"
- else
-        with_libnetapp="$withval"
- fi
-],
-[
- with_libnetapp="yes"
-])
+AC_ARG_WITH([libnetapp],
+  [AS_HELP_STRING([--with-libnetapp@<:@=PREFIX@:>@], [Path to libnetapp.])],
+  [
+   if test -d "$withval"; then
+     LIBNETAPP_CPPFLAGS="$LIBNETAPP_CPPFLAGS -I$withval/include"
+     LIBNETAPP_LDFLAGS="$LIBNETAPP_LDFLAGS -L$withval/lib"
+     with_libnetapp="yes"
+   else
+     with_libnetapp="$withval"
+   fi
+  ],
+  [with_libnetapp="yes"]
+)
 
 SAVE_CPPFLAGS="$CPPFLAGS"
 SAVE_LDFLAGS="$LDFLAGS"
 CPPFLAGS="$CPPFLAGS $LIBNETAPP_CPPFLAGS"
 LDFLAGS="$LDFLAGS $LIBNETAPP_LDFLAGS"
 
-if test "x$with_libnetapp" = "xyes"
-then
-       if test "x$LIBNETAPP_CPPFLAGS" != "x"
-       then
-               AC_MSG_NOTICE([netapp CPPFLAGS: $LIBNETAPP_CPPFLAGS])
-       fi
-       AC_CHECK_HEADERS(netapp_api.h,
-               [with_libnetapp="yes"],
-               [with_libnetapp="no (netapp_api.h not found)"])
+if test "x$with_libnetapp" = "xyes"; then
+  if test "x$LIBNETAPP_CPPFLAGS" != "x"; then
+    AC_MSG_NOTICE([netapp CPPFLAGS: $LIBNETAPP_CPPFLAGS])
+  fi
+  AC_CHECK_HEADERS([netapp_api.h],
+    [with_libnetapp="yes"],
+    [with_libnetapp="no (netapp_api.h not found)"]
+  )
 fi
 
-if test "x$with_libnetapp" = "xyes"
-then
-       if test "x$LIBNETAPP_LDFLAGS" != "x"
-       then
-               AC_MSG_NOTICE([netapp LDFLAGS: $LIBNETAPP_LDFLAGS])
-       fi
+if test "x$with_libnetapp" = "xyes"; then
+  if test "x$LIBNETAPP_LDFLAGS" != "x"; then
+    AC_MSG_NOTICE([netapp LDFLAGS: $LIBNETAPP_LDFLAGS])
+  fi
 
-       if test "x$LIBNETAPP_LIBS" = "x"
-       then
-               LIBNETAPP_LIBS="$PTHREAD_LIBS -lxml -ladt -lssl -lm -lcrypto -lz"
-       fi
-       AC_MSG_NOTICE([netapp LIBS: $LIBNETAPP_LIBS])
+  if test "x$LIBNETAPP_LIBS" = "x"; then
+    LIBNETAPP_LIBS="$PTHREAD_LIBS -lxml -ladt -lssl -lm -lcrypto -lz"
+  fi
+
+  AC_MSG_NOTICE([netapp LIBS: $LIBNETAPP_LIBS])
+
+  AC_CHECK_LIB([netapp], [na_server_invoke_elem],
+    [with_libnetapp="yes"],
+    [with_libnetapp="no (symbol na_server_invoke_elem not found)"],
+    [$LIBNETAPP_LIBS]
+  )
 
-       AC_CHECK_LIB(netapp, na_server_invoke_elem,
-               [with_libnetapp="yes"],
-               [with_libnetapp="no (symbol na_server_invoke_elem not found)"],
-               [$LIBNETAPP_LIBS])
-       LIBNETAPP_LIBS="-lnetapp $LIBNETAPP_LIBS"
+  LIBNETAPP_LIBS="-lnetapp $LIBNETAPP_LIBS"
 fi
 
 CPPFLAGS="$SAVE_CPPFLAGS"
 LDFLAGS="$SAVE_LDFLAGS"
 
-if test "x$with_libnetapp" = "xyes"
-then
-       AC_DEFINE(HAVE_LIBNETAPP, 1, [Define to 1 if you have the netapp library (-lnetapp).])
-fi
-
-AC_SUBST(LIBNETAPP_CPPFLAGS)
-AC_SUBST(LIBNETAPP_LDFLAGS)
-AC_SUBST(LIBNETAPP_LIBS)
-AM_CONDITIONAL(BUILD_WITH_LIBNETAPP, test "x$with_libnetapp" = "xyes")
+AC_SUBST([LIBNETAPP_CPPFLAGS])
+AC_SUBST([LIBNETAPP_LDFLAGS])
+AC_SUBST([LIBNETAPP_LIBS])
 # }}}
 
 # --with-libnetsnmp {{{
@@ -3620,7 +3663,10 @@ then
        SAVE_CPPFLAGS="$CPPFLAGS"
        CPPFLAGS="$CPPFLAGS $with_libnetsnmp_cppflags"
 
-       AC_CHECK_HEADERS(net-snmp/net-snmp-config.h, [], [with_libnetsnmp="no (net-snmp/net-snmp-config.h not found)"])
+    AC_CHECK_HEADERS([net-snmp/net-snmp-config.h],
+      [with_libnetsnmp="yes"],
+      [with_libnetsnmp="no (net-snmp/net-snmp-config.h not found)"]
+    )
 
        CPPFLAGS="$SAVE_CPPFLAGS"
 fi
@@ -3647,552 +3693,496 @@ AC_SUBST(BUILD_WITH_LIBNETSNMP_LDFLAGS)
 AC_SUBST(BUILD_WITH_LIBNETSNMP_LIBS)
 # }}}
 
-# --with-liboconfig {{{
-with_own_liboconfig="no"
-liboconfig_LDFLAGS="$LDFLAGS"
-liboconfig_CPPFLAGS="$CPPFLAGS"
-AC_ARG_WITH(liboconfig, [AS_HELP_STRING([--with-liboconfig@<:@=PREFIX@:>@], [Path to liboconfig.])],
-[
-       if test "x$withval" != "xno" && test "x$withval" != "xyes"
-       then
-               if test -d "$withval/lib"
-               then
-                       liboconfig_LDFLAGS="$LDFLAGS -L$withval/lib"
-               fi
-               if test -d "$withval/include"
-               then
-                       liboconfig_CPPFLAGS="$CPPFLAGS -I$withval/include"
-               fi
-       fi
-       if test "x$withval" = "xno"
-       then
-               AC_MSG_ERROR("liboconfig is required")
-       fi
-],
-[
-       with_liboconfig="yes"
-])
-
-save_LDFLAGS="$LDFLAGS"
-save_CPPFLAGS="$CPPFLAGS"
-LDFLAGS="$liboconfig_LDFLAGS"
-CPPFLAGS="$liboconfig_CPPFLAGS"
-AC_CHECK_LIB(oconfig, oconfig_parse_file,
-[
-       with_liboconfig="yes"
-       with_own_liboconfig="no"
-],
-[
-       with_liboconfig="yes"
-       with_own_liboconfig="yes"
-       LDFLAGS="$save_LDFLAGS"
-       CPPFLAGS="$save_CPPFLAGS"
-])
-
-AM_CONDITIONAL(BUILD_WITH_OWN_LIBOCONFIG, test "x$with_own_liboconfig" = "xyes")
-if test "x$with_own_liboconfig" = "xyes"
-then
-       with_liboconfig="yes (shipped version)"
-fi
-# }}}
-
 # --with-liboping {{{
-AC_ARG_WITH(liboping, [AS_HELP_STRING([--with-liboping@<:@=PREFIX@:>@], [Path to liboping.])],
-[
- if test "x$withval" = "xyes"
- then
-        with_liboping="yes"
- else if test "x$withval" = "xno"
- then
-        with_liboping="no"
- else
-        with_liboping="yes"
-        LIBOPING_CPPFLAGS="$LIBOPING_CPPFLAGS -I$withval/include"
-        LIBOPING_LDFLAGS="$LIBOPING_LDFLAGS -L$withval/lib"
- fi; fi
-],
-[with_liboping="yes"])
+AC_ARG_WITH([liboping],
+  [AS_HELP_STRING([--with-liboping@<:@=PREFIX@:>@], [Path to liboping.])],
+  [
   if test "x$withval" = "xyes"; then
+      with_liboping="yes"
+    else if test "x$withval" = "xno"; then
+      with_liboping="no"
+    else
+      with_liboping="yes"
+      LIBOPING_CPPFLAGS="-I$withval/include"
+      LIBOPING_LDFLAGS="-L$withval/lib"
+    fi; fi
+  ],
+  [with_liboping="yes"]
+)
 
 SAVE_CPPFLAGS="$CPPFLAGS"
 SAVE_LDFLAGS="$LDFLAGS"
-
 CPPFLAGS="$CPPFLAGS $LIBOPING_CPPFLAGS"
 LDFLAGS="$LDFLAGS $LIBOPING_LDFLAGS"
 
-if test "x$with_liboping" = "xyes"
-then
-       if test "x$LIBOPING_CPPFLAGS" != "x"
-       then
-               AC_MSG_NOTICE([liboping CPPFLAGS: $LIBOPING_CPPFLAGS])
-       fi
-       AC_CHECK_HEADERS(oping.h,
-       [with_liboping="yes"],
-       [with_liboping="no (oping.h not found)"])
+if test "x$with_liboping" = "xyes"; then
+  AC_CHECK_HEADERS([oping.h],
+    [with_liboping="yes"],
+    [with_liboping="no (oping.h not found)"]
+  )
 fi
-if test "x$with_liboping" = "xyes"
-then
-       if test "x$LIBOPING_LDFLAGS" != "x"
-       then
-               AC_MSG_NOTICE([liboping LDFLAGS: $LIBOPING_LDFLAGS])
-       fi
-       AC_CHECK_LIB(oping, ping_construct,
-       [with_liboping="yes"],
-       [with_liboping="no (symbol 'ping_construct' not found)"])
+
+if test "x$with_liboping" = "xyes"; then
+  AC_CHECK_LIB([oping], [ping_construct],
+    [with_liboping="yes"],
+    [with_liboping="no (symbol 'ping_construct' not found)"]
+  )
 fi
 
 CPPFLAGS="$SAVE_CPPFLAGS"
 LDFLAGS="$SAVE_LDFLAGS"
 
-if test "x$with_liboping" = "xyes"
-then
-       BUILD_WITH_LIBOPING_CPPFLAGS="$LIBOPING_CPPFLAGS"
-       BUILD_WITH_LIBOPING_LDFLAGS="$LIBOPING_LDFLAGS"
-       AC_SUBST(BUILD_WITH_LIBOPING_CPPFLAGS)
-       AC_SUBST(BUILD_WITH_LIBOPING_LDFLAGS)
+if test "x$with_liboping" = "xyes"; then
+  BUILD_WITH_LIBOPING_CPPFLAGS="$LIBOPING_CPPFLAGS"
+  BUILD_WITH_LIBOPING_LDFLAGS="$LIBOPING_LDFLAGS"
 fi
-AM_CONDITIONAL(BUILD_WITH_LIBOPING, test "x$with_liboping" = "xyes")
+
+AC_SUBST([BUILD_WITH_LIBOPING_CPPFLAGS])
+AC_SUBST([BUILD_WITH_LIBOPING_LDFLAGS])
 # }}}
 
 # --with-oracle {{{
-with_oracle_cppflags=""
-with_oracle_libs=""
-AC_ARG_WITH(oracle, [AS_HELP_STRING([--with-oracle@<:@=ORACLE_HOME@:>@], [Path to Oracle.])],
-[
-       if test "x$withval" = "xyes"
-       then
-               if test "x$ORACLE_HOME" = "x"
-               then
-                       AC_MSG_WARN([Use of the Oracle library has been forced, but the environment variable ORACLE_HOME is not set.])
-               fi
-               with_oracle="yes"
-       else if test "x$withval" = "xno"
-       then
-               with_oracle="no"
-       else
-               with_oracle="yes"
-               ORACLE_HOME="$withval"
-       fi; fi
-],
-[
-       if test "x$ORACLE_HOME" = "x"
-       then
-               with_oracle="no (ORACLE_HOME is not set)"
-       else
-               with_oracle="yes"
-       fi
-])
-if test "x$ORACLE_HOME" != "x"
-then
-       with_oracle_cppflags="-I$ORACLE_HOME/rdbms/public"
+AC_ARG_WITH([oracle],
+  [AS_HELP_STRING([--with-oracle@<:@=ORACLE_HOME@:>@], [Path to Oracle.])],
+  [
+    if test "x$withval" = "xyes"; then
+      if test "x$ORACLE_HOME" = "x"; then
+        AC_MSG_WARN([Use of the Oracle library has been forced, but the environment variable ORACLE_HOME is not set.])
+      fi
+      with_oracle="yes"
+    else if test "x$withval" = "xno"; then
+      with_oracle="no"
+    else
+      with_oracle="yes"
+      ORACLE_HOME="$withval"
+    fi; fi
+  ],
+  [
+    if test "x$ORACLE_HOME" = "x"; then
+      with_oracle="no (ORACLE_HOME is not set)"
+    else
+      with_oracle="yes"
+    fi
+  ]
+)
 
-       if test -e "$ORACLE_HOME/lib/ldflags"
-       then
-               with_oracle_libs=`cat "$ORACLE_HOME/lib/ldflags"`
-       fi
-       #with_oracle_libs="-L$ORACLE_HOME/lib $with_oracle_libs -lclntsh"
-       with_oracle_libs="-L$ORACLE_HOME/lib -lclntsh"
+if test "x$ORACLE_HOME" != "x"; then
+  with_oracle_cppflags="-I$ORACLE_HOME/rdbms/public"
+  if test -e "$ORACLE_HOME/lib/ldflags"; then
+    with_oracle_libs=`cat "$ORACLE_HOME/lib/ldflags"`
+  fi
+  with_oracle_libs="-L$ORACLE_HOME/lib -lclntsh"
 fi
-if test "x$with_oracle" = "xyes"
-then
-       SAVE_CPPFLAGS="$CPPFLAGS"
-       CPPFLAGS="$CPPFLAGS $with_oracle_cppflags"
 
-       AC_CHECK_HEADERS(oci.h, [with_oracle="yes"], [with_oracle="no (oci.h not found)"])
+if test "x$with_oracle" = "xyes"; then
+  SAVE_CPPFLAGS="$CPPFLAGS"
+  CPPFLAGS="$CPPFLAGS $with_oracle_cppflags"
 
-       CPPFLAGS="$SAVE_CPPFLAGS"
+  AC_CHECK_HEADERS([oci.h],
+    [with_oracle="yes"],
+    [with_oracle="no (oci.h not found)"]
+  )
+
+  CPPFLAGS="$SAVE_CPPFLAGS"
 fi
-if test "x$with_oracle" = "xyes"
-then
-       SAVE_CPPFLAGS="$CPPFLAGS"
-       SAVE_LIBS="$LIBS"
-       CPPFLAGS="$CPPFLAGS $with_oracle_cppflags"
-       LIBS="$LIBS $with_oracle_libs"
 
-       AC_CHECK_FUNC(OCIEnvCreate, [with_oracle="yes"], [with_oracle="no (Symbol 'OCIEnvCreate' not found)"])
+if test "x$with_oracle" = "xyes"; then
+  SAVE_CPPFLAGS="$CPPFLAGS"
+  SAVE_LIBS="$LIBS"
+  CPPFLAGS="$CPPFLAGS $with_oracle_cppflags"
+  LIBS="$LIBS $with_oracle_libs"
 
-       CPPFLAGS="$SAVE_CPPFLAGS"
-       LIBS="$SAVE_LIBS"
+  AC_CHECK_FUNC([OCIEnvCreate],
+    [with_oracle="yes"],
+    [with_oracle="no (Symbol 'OCIEnvCreate' not found)"]
+  )
+
+  CPPFLAGS="$SAVE_CPPFLAGS"
+  LIBS="$SAVE_LIBS"
 fi
-if test "x$with_oracle" = "xyes"
-then
-       BUILD_WITH_ORACLE_CPPFLAGS="$with_oracle_cppflags"
-       BUILD_WITH_ORACLE_LIBS="$with_oracle_libs"
-       AC_SUBST(BUILD_WITH_ORACLE_CPPFLAGS)
-       AC_SUBST(BUILD_WITH_ORACLE_LIBS)
+
+if test "x$with_oracle" = "xyes"; then
+  BUILD_WITH_ORACLE_CPPFLAGS="$with_oracle_cppflags"
+  BUILD_WITH_ORACLE_LIBS="$with_oracle_libs"
 fi
+
+AC_SUBST([BUILD_WITH_ORACLE_CPPFLAGS])
+AC_SUBST([BUILD_WITH_ORACLE_LIBS])
 # }}}
 
 # --with-libowcapi {{{
-with_libowcapi_cppflags=""
-with_libowcapi_ldflags=""
-AC_ARG_WITH(libowcapi, [AS_HELP_STRING([--with-libowcapi@<:@=PREFIX@:>@], [Path to libowcapi.])],
-[
-       if test "x$withval" != "xno" && test "x$withval" != "xyes"
-       then
-               with_libowcapi_cppflags="-I$withval/include"
-               with_libowcapi_ldflags="-L$withval/lib"
-               with_libowcapi="yes"
-       else
-               with_libowcapi="$withval"
-       fi
-],
-[
-       with_libowcapi="yes"
-])
-if test "x$with_libowcapi" = "xyes"
-then
-       SAVE_CPPFLAGS="$CPPFLAGS"
-       CPPFLAGS="$CPPFLAGS $with_libowcapi_cppflags"
+AC_ARG_WITH([libowcapi],
+  [AS_HELP_STRING([--with-libowcapi@<:@=PREFIX@:>@], [Path to libowcapi.])],
+  [
+    if test "x$withval" != "xno" && test "x$withval" != "xyes"; then
+      with_libowcapi_cppflags="-I$withval/include"
+      with_libowcapi_ldflags="-L$withval/lib"
+      with_libowcapi="yes"
+    else
+      with_libowcapi="$withval"
+    fi
+  ],
+  [with_libowcapi="yes"]
+)
 
-       AC_CHECK_HEADERS(owcapi.h, [with_libowcapi="yes"], [with_libowcapi="no (owcapi.h not found)"])
+if test "x$with_libowcapi" = "xyes"; then
+  SAVE_CPPFLAGS="$CPPFLAGS"
+  CPPFLAGS="$CPPFLAGS $with_libowcapi_cppflags"
 
-       CPPFLAGS="$SAVE_CPPFLAGS"
+  AC_CHECK_HEADERS([owcapi.h],
+    [with_libowcapi="yes"],
+    [with_libowcapi="no (owcapi.h not found)"]
+  )
+
+  CPPFLAGS="$SAVE_CPPFLAGS"
 fi
-if test "x$with_libowcapi" = "xyes"
-then
-       SAVE_LDFLAGS="$LDFLAGS"
-       SAVE_CPPFLAGS="$CPPFLAGS"
-       LDFLAGS="$LDFLAGS $with_libowcapi_ldflags"
-       CPPFLAGS="$with_libowcapi_cppflags"
 
-       AC_CHECK_LIB(owcapi, OW_get, [with_libowcapi="yes"], [with_libowcapi="no (libowcapi not found)"])
+if test "x$with_libowcapi" = "xyes"; then
+  SAVE_LDFLAGS="$LDFLAGS"
+  LDFLAGS="$LDFLAGS $with_libowcapi_ldflags"
 
-       LDFLAGS="$SAVE_LDFLAGS"
-       CPPFLAGS="$SAVE_CPPFLAGS"
+  AC_CHECK_LIB([owcapi], [OW_get],
+    [with_libowcapi="yes"],
+    [with_libowcapi="no (libowcapi not found)"]
+  )
+
+  LDFLAGS="$SAVE_LDFLAGS"
 fi
-if test "x$with_libowcapi" = "xyes"
-then
-       BUILD_WITH_LIBOWCAPI_CPPFLAGS="$with_libowcapi_cppflags"
-       BUILD_WITH_LIBOWCAPI_LDFLAGS="$with_libowcapi_ldflags"
-       BUILD_WITH_LIBOWCAPI_LIBS="-lowcapi"
-       AC_SUBST(BUILD_WITH_LIBOWCAPI_CPPFLAGS)
-       AC_SUBST(BUILD_WITH_LIBOWCAPI_LDFLAGS)
-       AC_SUBST(BUILD_WITH_LIBOWCAPI_LIBS)
+
+if test "x$with_libowcapi" = "xyes"; then
+  BUILD_WITH_LIBOWCAPI_CPPFLAGS="$with_libowcapi_cppflags"
+  BUILD_WITH_LIBOWCAPI_LDFLAGS="$with_libowcapi_ldflags"
+  BUILD_WITH_LIBOWCAPI_LIBS="-lowcapi"
 fi
+
+AC_SUBST([BUILD_WITH_LIBOWCAPI_CPPFLAGS])
+AC_SUBST([BUILD_WITH_LIBOWCAPI_LDFLAGS])
+AC_SUBST([BUILD_WITH_LIBOWCAPI_LIBS])
 # }}}
 
 # --with-libpcap {{{
-AC_ARG_WITH(libpcap, [AS_HELP_STRING([--with-libpcap@<:@=PREFIX@:>@], [Path to libpcap.])],
-[
-       if test "x$withval" != "xno" && test "x$withval" != "xyes"
-       then
-               LDFLAGS="$LDFLAGS -L$withval/lib"
-               CPPFLAGS="$CPPFLAGS -I$withval/include"
-               with_libpcap="yes"
-       else
-               with_libpcap="$withval"
-       fi
-],
-[
-       with_libpcap="yes"
-])
-if test "x$with_libpcap" = "xyes"
-then
-       AC_CHECK_LIB(pcap, pcap_open_live,
-       [
-               AC_DEFINE(HAVE_LIBPCAP, 1, [Define to 1 if you have the pcap library (-lpcap).])
-       ], [with_libpcap="no (libpcap not found)"])
+AC_ARG_WITH([libpcap],
+  [AS_HELP_STRING([--with-libpcap@<:@=PREFIX@:>@], [Path to libpcap.])],
+  [
+    if test "x$withval" != "xno" && test "x$withval" != "xyes"; then
+      with_libpcap_cppflags="-I$withval/include"
+      with_libpcap_ldflags="$LDFLAGS -L$withval/lib"
+      with_libpcap="yes"
+    else
+      with_libpcap="$withval"
+    fi
+  ],
+  [with_libpcap="yes"]
+)
+
+if test "x$with_libpcap" = "xyes"; then
+  SAVE_CPPFLAGS="$CPPFLAGS"
+  CPPFLAGS="$CPPFLAGS $with_libpcap_cppflags"
+
+  AC_CHECK_HEADERS([pcap.h],
+    [with_libpcap="yes"],
+    [with_libpcap="no (pcap.h not found)"]
+  )
+
+  CPPFLAGS="$SAVE_CPPFLAGS"
 fi
-if test "x$with_libpcap" = "xyes"
-then
-       AC_CHECK_HEADERS(pcap.h,,
-                        [with_libpcap="no (pcap.h not found)"])
+
+if test "x$with_libpcap" = "xyes"; then
+  SAVE_LDFLAGS="$LDFLAGS"
+  LDFLAGS="$LDFLAGS $with_libpcap_ldflags"
+
+  AC_CHECK_LIB([pcap], [pcap_open_live],
+    [with_libpcap="yes"],
+    [with_libpcap="no (libpcap not found)"]
+  )
+
+  LDFLAGS="$SAVE_LDFLAGS"
 fi
-if test "x$with_libpcap" = "xyes"
-then
-       AC_CACHE_CHECK([whether libpcap has PCAP_ERROR_IFACE_NOT_UP],
-                      [c_cv_libpcap_have_pcap_error_iface_not_up],
-                      AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
-[[[
-#include <pcap.h>
-]]],
-[[[
-  int val = PCAP_ERROR_IFACE_NOT_UP;
-  return(val);
-]]]
-                      )],
-                      [c_cv_libpcap_have_pcap_error_iface_not_up="yes"],
-                      [c_cv_libpcap_have_pcap_error_iface_not_up="no"]))
-fi
-if test "x$c_cv_libpcap_have_pcap_error_iface_not_up" != "xyes"
-then
-               with_libpcap="no (pcap.h misses PCAP_ERROR_IFACE_NOT_UP)"
+
+if test "x$with_libpcap" = "xyes"; then
+  AC_CACHE_CHECK([whether libpcap has PCAP_ERROR_IFACE_NOT_UP],
+    [c_cv_libpcap_have_pcap_error_iface_not_up],
+    [
+      AC_COMPILE_IFELSE(
+        [
+          AC_LANG_PROGRAM(
+            [[#include <pcap.h>]],
+            [[
+              int val = PCAP_ERROR_IFACE_NOT_UP;
+              return(val);
+            ]]
+          )
+        ],
+        [c_cv_libpcap_have_pcap_error_iface_not_up="yes"],
+        [c_cv_libpcap_have_pcap_error_iface_not_up="no"]
+      )
+    ]
+  )
+fi
+
+if test "x$c_cv_libpcap_have_pcap_error_iface_not_up" != "xyes"; then
+  with_libpcap="no (pcap.h misses PCAP_ERROR_IFACE_NOT_UP)"
+fi
+
+if test "x$with_libpcap" = "xyes"; then
+  BUILD_WITH_LIBPCAP_CPPFLAGS="$with_libpcap_cppflags"
+  BUILD_WITH_LIBPCAP_LDFLAGS="$with_libpcap_ldflags"
+  BUILD_WITH_LIBPCAP_LIBS="-lpcap"
 fi
-AM_CONDITIONAL(BUILD_WITH_LIBPCAP, test "x$with_libpcap" = "xyes")
+
+AC_SUBST([BUILD_WITH_LIBPCAP_CPPFLAGS])
+AC_SUBST([BUILD_WITH_LIBPCAP_LDFLAGS])
+AC_SUBST([BUILD_WITH_LIBPCAP_LIBS])
 # }}}
 
 # --with-libperl {{{
-perl_interpreter="perl"
-AC_ARG_WITH(libperl, [AS_HELP_STRING([--with-libperl@<:@=PREFIX@:>@], [Path to libperl.])],
-[
-       if test -f "$withval" && test -x "$withval"
-       then
-               perl_interpreter="$withval"
-               with_libperl="yes"
-       else if test "x$withval" != "xno" && test "x$withval" != "xyes"
-       then
-               LDFLAGS="$LDFLAGS -L$withval/lib"
-               CPPFLAGS="$CPPFLAGS -I$withval/include"
-               perl_interpreter="$withval/bin/perl"
-               with_libperl="yes"
-       else
-               with_libperl="$withval"
-       fi; fi
-],
-[
-       with_libperl="yes"
-])
+AC_ARG_WITH([libperl],
+  [AS_HELP_STRING([--with-libperl@<:@=PREFIX@:>@], [Path to libperl.])],
+  [
+    if test "x$withval" != "xno" && test "x$withval" != "xyes"; then
+      LDFLAGS="$LDFLAGS -L$withval/lib"
+      CPPFLAGS="$CPPFLAGS -I$withval/include"
+      with_libperl="yes"
+    else
+      with_libperl="$withval"
+    fi
+  ],
+  [with_libperl="yes"]
+)
 
-AC_MSG_CHECKING([for perl])
-perl_interpreter=`which "$perl_interpreter" 2> /dev/null`
-if test -x "$perl_interpreter"
-then
-       AC_MSG_RESULT([yes ($perl_interpreter)])
-else
-       perl_interpreter=""
-       AC_MSG_RESULT([no])
-fi
+AC_ARG_VAR([PERL], [path to Perl interpreter])
+AC_PATH_PROG([PERL], [perl])
 
-AC_SUBST(PERL, "$perl_interpreter")
+if test "x$PERL" = "x"; then
+  with_libperl="no (no Perl interpreter found)"
+fi
 
-if test "x$with_libperl" = "xyes" \
-       && test -n "$perl_interpreter"
-then
+if test "x$with_libperl" = "xyes"; then
   SAVE_CFLAGS="$CFLAGS"
   SAVE_LIBS="$LIBS"
-dnl ARCHFLAGS="" -> disable multi -arch on OSX (see Config_heavy.pl:fetch_string)
-  PERL_CFLAGS=`ARCHFLAGS="" $perl_interpreter -MExtUtils::Embed -e perl_inc`
-  PERL_LIBS=`ARCHFLAGS="" $perl_interpreter -MExtUtils::Embed -e ldopts`
+  dnl ARCHFLAGS="" -> disable multi -arch on OSX (see Config_heavy.pl:fetch_string)
+  PERL_CFLAGS=`ARCHFLAGS="" $PERL -MExtUtils::Embed -e perl_inc`
+  PERL_LIBS=`ARCHFLAGS="" $PERL -MExtUtils::Embed -e ldopts`
   CFLAGS="$CFLAGS $PERL_CFLAGS"
   LIBS="$LIBS $PERL_LIBS"
 
   AC_CACHE_CHECK([for libperl],
     [c_cv_have_libperl],
-    AC_LINK_IFELSE([AC_LANG_PROGRAM(
-[[[
-#define PERL_NO_GET_CONTEXT
-#include <EXTERN.h>
-#include <perl.h>
-#include <XSUB.h>
-]]],
-[[[
-       dTHX;
-       load_module (PERL_LOADMOD_NOIMPORT,
-                        newSVpv ("Collectd::Plugin::FooBar", 24),
-                        Nullsv);
-]]]
-      )],
-      [c_cv_have_libperl="yes"],
-      [c_cv_have_libperl="no"]
-    )
+    [
+      AC_LINK_IFELSE(
+        [
+          AC_LANG_PROGRAM(
+            [[
+              #define PERL_NO_GET_CONTEXT
+              #include <EXTERN.h>
+              #include <perl.h>
+              #include <XSUB.h>
+            ]],
+            [[
+              dTHX;
+              load_module (PERL_LOADMOD_NOIMPORT,
+                newSVpv ("Collectd::Plugin::FooBar", 24),
+                Nullsv);
+            ]]
+          )
+        ],
+        [c_cv_have_libperl="yes"],
+        [c_cv_have_libperl="no"]
+      )
+    ]
   )
 
-  if test "x$c_cv_have_libperl" = "xyes"
-  then
-         AC_DEFINE(HAVE_LIBPERL, 1, [Define if libperl is present and usable.])
-         AC_SUBST(PERL_CFLAGS)
-         AC_SUBST(PERL_LIBS)
-  else
-         with_libperl="no"
+  CFLAGS="$SAVE_CFLAGS"
+  LIBS="$SAVE_LIBS"
+
+  if test "x$c_cv_have_libperl" = "xno"; then
+    with_libperl="no"
   fi
+fi
+
+if test "x$with_libperl" = "xyes"; then
+  SAVE_CFLAGS="$CFLAGS"
+  SAVE_LIBS="$LIBS"
+  CFLAGS="$CFLAGS $PERL_CFLAGS"
+  LIBS="$LIBS $PERL_LIBS"
+
+  AC_CACHE_CHECK([if Perl supports ithreads],
+    [c_cv_have_perl_ithreads],
+    [
+      AC_LINK_IFELSE(
+        [
+          AC_LANG_PROGRAM(
+            [[
+              #include <EXTERN.h>
+              #include <perl.h>
+              #include <XSUB.h>
+
+              #if !defined(USE_ITHREADS)
+              # error "Perl does not support ithreads!"
+              #endif /* !defined(USE_ITHREADS) */
+            ]],
+            []
+          )
+        ],
+        [c_cv_have_perl_ithreads="yes"],
+        [c_cv_have_perl_ithreads="no"]
+      )
+    ]
+  )
 
   CFLAGS="$SAVE_CFLAGS"
   LIBS="$SAVE_LIBS"
-else if test -z "$perl_interpreter"; then
-  with_libperl="no (no perl interpreter found)"
-  c_cv_have_libperl="no"
-fi; fi
-AM_CONDITIONAL(BUILD_WITH_LIBPERL, test "x$with_libperl" = "xyes")
+fi
 
-if test "x$with_libperl" = "xyes"
-then
-       SAVE_CFLAGS="$CFLAGS"
-       SAVE_LIBS="$LIBS"
-       CFLAGS="$CFLAGS $PERL_CFLAGS"
-       LIBS="$LIBS $PERL_LIBS"
-
-       AC_CACHE_CHECK([if perl supports ithreads],
-               [c_cv_have_perl_ithreads],
-               AC_LINK_IFELSE([AC_LANG_PROGRAM(
-[[[
-#include <EXTERN.h>
-#include <perl.h>
-#include <XSUB.h>
-
-#if !defined(USE_ITHREADS)
-# error "Perl does not support ithreads!"
-#endif /* !defined(USE_ITHREADS) */
-]]],
-[[[ ]]]
-                       )],
-                       [c_cv_have_perl_ithreads="yes"],
-                       [c_cv_have_perl_ithreads="no"]
-               )
-       )
+if test "x$with_libperl" = "xyes"; then
+  # trigger an error if Perl_load_module*() uses __attribute__nonnull__(3)
+  # (see issues #41 and #42)
+  SAVE_CFLAGS="$CFLAGS"
+  SAVE_LIBS="$LIBS"
+  CFLAGS="$CFLAGS $PERL_CFLAGS -Wall -Werror"
+  LIBS="$LIBS $PERL_LIBS"
 
-       if test "x$c_cv_have_perl_ithreads" = "xyes"
-       then
-               AC_DEFINE(HAVE_PERL_ITHREADS, 1, [Define if Perl supports ithreads.])
-       fi
+  AC_CACHE_CHECK([for broken Perl_load_module()],
+    [c_cv_have_broken_perl_load_module],
+    [
+      AC_LINK_IFELSE(
+        [
+          AC_LANG_PROGRAM(
+            [[
+              #define PERL_NO_GET_CONTEXT
+              #include <EXTERN.h>
+              #include <perl.h>
+              #include <XSUB.h>
+            ]],
+            [[
+              dTHX;
+              load_module (PERL_LOADMOD_NOIMPORT,
+                newSVpv ("Collectd::Plugin::FooBar", 24),
+                Nullsv);
+            ]]
+          )
+        ],
+        [c_cv_have_broken_perl_load_module="no"],
+        [c_cv_have_broken_perl_load_module="yes"]
+      )
+    ]
+  )
+
+  CFLAGS="$SAVE_CFLAGS"
+  LIBS="$SAVE_LIBS"
+fi
 
-       CFLAGS="$SAVE_CFLAGS"
-       LIBS="$SAVE_LIBS"
+if test "x$c_cv_have_broken_perl_load_module" = "xyes"; then
+  PERL_CFLAGS="$PERL_CFLAGS -Wno-nonnull"
 fi
 
-if test "x$with_libperl" = "xyes"
-then
-       SAVE_CFLAGS="$CFLAGS"
-       SAVE_LIBS="$LIBS"
-       # trigger an error if Perl_load_module*() uses __attribute__nonnull__(3)
-       # (see issues #41 and #42)
-       CFLAGS="$CFLAGS $PERL_CFLAGS -Wall -Werror"
-       LIBS="$LIBS $PERL_LIBS"
-
-       AC_CACHE_CHECK([for broken Perl_load_module()],
-               [c_cv_have_broken_perl_load_module],
-               AC_LINK_IFELSE([AC_LANG_PROGRAM(
-[[[
-#define PERL_NO_GET_CONTEXT
-#include <EXTERN.h>
-#include <perl.h>
-#include <XSUB.h>
-]]],
-[[[
-                        dTHX;
-                        load_module (PERL_LOADMOD_NOIMPORT,
-                            newSVpv ("Collectd::Plugin::FooBar", 24),
-                            Nullsv);
-]]]
-                       )],
-                       [c_cv_have_broken_perl_load_module="no"],
-                       [c_cv_have_broken_perl_load_module="yes"]
-               )
-       )
+if test "x$with_libperl" = "xyes"; then
+  SAVE_CFLAGS="$CFLAGS"
+  SAVE_LIBS="$LIBS"
+  CFLAGS="$CFLAGS $PERL_CFLAGS"
+  LIBS="$LIBS $PERL_LIBS"
 
-       CFLAGS="$SAVE_CFLAGS"
-       LIBS="$SAVE_LIBS"
-fi
-AM_CONDITIONAL(HAVE_BROKEN_PERL_LOAD_MODULE,
-               test "x$c_cv_have_broken_perl_load_module" = "xyes")
+  AC_CHECK_MEMBER(
+    [struct mgvtbl.svt_local],
+    [have_struct_mgvtbl_svt_local="yes"],
+    [have_struct_mgvtbl_svt_local="no"],
+    [[
+      #include <EXTERN.h>
+      #include <perl.h>
+      #include <XSUB.h>
+    ]]
+  )
 
-if test "x$with_libperl" = "xyes"
-then
-       SAVE_CFLAGS="$CFLAGS"
-       SAVE_LIBS="$LIBS"
-       CFLAGS="$CFLAGS $PERL_CFLAGS"
-       LIBS="$LIBS $PERL_LIBS"
-
-       AC_CHECK_MEMBER(
-               [struct mgvtbl.svt_local],
-               [have_struct_mgvtbl_svt_local="yes"],
-               [have_struct_mgvtbl_svt_local="no"],
-               [
-#include <EXTERN.h>
-#include <perl.h>
-#include <XSUB.h>
-               ])
-
-       if test "x$have_struct_mgvtbl_svt_local" = "xyes"
-       then
-               AC_DEFINE(HAVE_PERL_STRUCT_MGVTBL_SVT_LOCAL, 1,
-                                 [Define if Perl's struct mgvtbl has member svt_local.])
-       fi
+  if test "x$have_struct_mgvtbl_svt_local" = "xyes"; then
+    AC_DEFINE([HAVE_PERL_STRUCT_MGVTBL_SVT_LOCAL], [1], [Define if Perls struct mgvtbl has member svt_local.])
+  fi
 
-       CFLAGS="$SAVE_CFLAGS"
-       LIBS="$SAVE_LIBS"
+  CFLAGS="$SAVE_CFLAGS"
+  LIBS="$SAVE_LIBS"
 fi
+AC_SUBST([PERL_CFLAGS])
+AC_SUBST([PERL_LIBS])
+
 # }}}
 
 # --with-libpq {{{
 with_pg_config="pg_config"
-with_libpq_includedir=""
-with_libpq_libdir=""
-with_libpq_cppflags=""
-with_libpq_ldflags=""
-AC_ARG_WITH(libpq, [AS_HELP_STRING([--with-libpq@<:@=PREFIX@:>@],
-       [Path to libpq.])],
-[
-       if test "x$withval" = "xno"
-       then
-               with_libpq="no"
-       else if test "x$withval" = "xyes"
-       then
-               with_libpq="yes"
-       else
-               if test -f "$withval" && test -x "$withval";
-               then
-                       with_pg_config="$withval"
-               else if test -x "$withval/bin/pg_config"
-               then
-                       with_pg_config="$withval/bin/pg_config"
-               fi; fi
-               with_libpq="yes"
-       fi; fi
-],
-[
-       with_libpq="yes"
-])
-if test "x$with_libpq" = "xyes"
-then
-       with_libpq_includedir=`$with_pg_config --includedir 2> /dev/null`
-       pg_config_status=$?
-
-       if test $pg_config_status -eq 0
-       then
-               if test -n "$with_libpq_includedir"; then
-                       for dir in $with_libpq_includedir; do
-                               with_libpq_cppflags="$with_libpq_cppflags -I$dir"
-                       done
-               fi
-       else
-               AC_MSG_WARN([$with_pg_config returned with status $pg_config_status])
-       fi
+AC_ARG_WITH([libpq],
+  [AS_HELP_STRING([--with-libpq@<:@=PREFIX@:>@], [Path to libpq.])],
+  [
+    if test "x$withval" = "xno" || test "x$withval" = "xyes"; then
+      with_libpq="$withval"
+    else
+      if test -f "$withval" && test -x "$withval"; then
+        with_pg_config="$withval"
+      else if test -x "$withval/bin/pg_config"; then
+        with_pg_config="$withval/bin/pg_config"
+      fi; fi
+      with_libpq="yes"
+    fi
+  ],
+  [with_libpq="yes"]
+)
 
-       SAVE_CPPFLAGS="$CPPFLAGS"
-       CPPFLAGS="$CPPFLAGS $with_libpq_cppflags"
+if test "x$with_libpq" = "xyes"; then
+  with_libpq_includedir=`$with_pg_config --includedir 2> /dev/null`
+  pg_config_status=$?
+
+  if test $pg_config_status -eq 0; then
+    if test -n "$with_libpq_includedir"; then
+      for dir in $with_libpq_includedir; do
+        with_libpq_cppflags="$with_libpq_cppflags -I$dir"
+      done
+    fi
+  else
+    AC_MSG_WARN([$with_pg_config returned with status $pg_config_status])
+  fi
+
+  SAVE_CPPFLAGS="$CPPFLAGS"
+  CPPFLAGS="$CPPFLAGS $with_libpq_cppflags"
 
-       AC_CHECK_HEADERS(libpq-fe.h, [],
-               [with_libpq="no (libpq-fe.h not found)"], [])
+  AC_CHECK_HEADERS([libpq-fe.h],
+    [with_libpq="yes"],
+    [with_libpq="no (libpq-fe.h not found)"]
+  )
 
-       CPPFLAGS="$SAVE_CPPFLAGS"
+  CPPFLAGS="$SAVE_CPPFLAGS"
 fi
-if test "x$with_libpq" = "xyes"
-then
-       with_libpq_libdir=`$with_pg_config --libdir 2> /dev/null`
-       pg_config_status=$?
 
-       if test $pg_config_status -eq 0
-       then
-               if test -n "$with_libpq_libdir"; then
-                       for dir in $with_libpq_libdir; do
-                               with_libpq_ldflags="$with_libpq_ldflags -L$dir"
-                       done
-               fi
-       else
-               AC_MSG_WARN([$with_pg_config returned with status $pg_config_status])
-       fi
+if test "x$with_libpq" = "xyes"; then
+  with_libpq_libdir=`$with_pg_config --libdir 2> /dev/null`
+  pg_config_status=$?
 
-       SAVE_LDFLAGS="$LDFLAGS"
-       LDFLAGS="$LDFLAGS $with_libpq_ldflags"
+  if test $pg_config_status -eq 0
+  then
+    if test -n "$with_libpq_libdir"; then
+      for dir in $with_libpq_libdir; do
+        with_libpq_ldflags="$with_libpq_ldflags -L$dir"
+      done
+    fi
+  else
+    AC_MSG_WARN([$with_pg_config returned with status $pg_config_status])
+  fi
 
-       AC_CHECK_LIB(pq, PQconnectdb,
-               [with_libpq="yes"],
-               [with_libpq="no (symbol 'PQconnectdb' not found)"])
+  SAVE_LDFLAGS="$LDFLAGS"
+  LDFLAGS="$LDFLAGS $with_libpq_ldflags"
 
-       AC_CHECK_LIB(pq, PQserverVersion,
-               [with_libpq="yes"],
-               [with_libpq="no (symbol 'PQserverVersion' not found)"])
+  AC_CHECK_LIB([pq], [PQserverVersion],
+    [with_libpq="yes"],
+    [with_libpq="no (symbol 'PQserverVersion' not found)"])
 
-       LDFLAGS="$SAVE_LDFLAGS"
+  LDFLAGS="$SAVE_LDFLAGS"
 fi
-if test "x$with_libpq" = "xyes"
-then
-       BUILD_WITH_LIBPQ_CPPFLAGS="$with_libpq_cppflags"
-       BUILD_WITH_LIBPQ_LDFLAGS="$with_libpq_ldflags"
-       AC_SUBST(BUILD_WITH_LIBPQ_CPPFLAGS)
-       AC_SUBST(BUILD_WITH_LIBPQ_LDFLAGS)
+
+if test "x$with_libpq" = "xyes"; then
+  BUILD_WITH_LIBPQ_CPPFLAGS="$with_libpq_cppflags"
+  BUILD_WITH_LIBPQ_LDFLAGS="$with_libpq_ldflags"
+  BUILD_WITH_LIBPQ_LIBS="-lpq"
 fi
-AM_CONDITIONAL(BUILD_WITH_LIBPQ, test "x$with_libpq" = "xyes")
+
+AC_SUBST([BUILD_WITH_LIBPQ_CPPFLAGS])
+AC_SUBST([BUILD_WITH_LIBPQ_LDFLAGS])
+AC_SUBST([BUILD_WITH_LIBPQ_LIBS])
 # }}}
 
 # --with-libpqos {{{
@@ -4247,31 +4237,29 @@ fi
 # --with-libprotobuf {{{
 with_libprotobuf_cppflags=""
 with_libprotobuf_ldflags=""
-AC_ARG_WITH([libprotobuf], [AS_HELP_STRING([--with-libprotobuf@<:@=PREFIX@:>@], [Path to libprotobuf.])],
+AC_ARG_WITH([libprotobuf],
+  [AS_HELP_STRING([--with-libprotobuf@<:@=PREFIX@:>@], [Path to libprotobuf.])],
   [
-    if test "x$withval" != "xno" && test "x$withval" != "xyes"
-    then
+    if test "x$withval" != "xno" && test "x$withval" != "xyes"; then
       with_libprotobuf_cppflags="-I$withval/include"
       with_libprotobuf_ldflags="-L$withval/lib"
       with_libprotobuf="yes"
     fi
-    if test "x$withval" = "xno"
-    then
+    if test "x$withval" = "xno"; then
       with_libprotobuf="no (disabled on command line)"
     fi
   ],
   [withval="yes"]
 )
-if test "x$withval" = "xyes"
-then
-PKG_CHECK_MODULES([PROTOBUF], [protobuf],
-  [with_libprotobuf="yes"],
-  [with_libprotobuf="no (pkg-config could not find libprotobuf)"]
-)
+
+if test "x$withval" = "xyes"; then
+  PKG_CHECK_MODULES([PROTOBUF], [protobuf],
+    [with_libprotobuf="yes"],
+    [with_libprotobuf="no (pkg-config could not find libprotobuf)"]
+  )
 fi
 
-if test "x$withval" != "xno"
-then
+if test "x$withval" != "xno"; then
   SAVE_LDFLAGS="$LDFLAGS"
   SAVE_LIBS="$LIBS"
   LDFLAGS="$with_libprotobuf_ldflags"
@@ -4297,6 +4285,7 @@ then
   LDFLAGS="$SAVE_LDFLAGS"
   LIBS="$SAVE_LIBS"
 fi
+
 BUILD_WITH_LIBPROTOBUF_CPPFLAGS="$with_libprotobuf_cppflags $PROTOBUF_CFLAGS"
 BUILD_WITH_LIBPROTOBUF_LDFLAGS="$with_libprotobuf_ldflags"
 BUILD_WITH_LIBPROTOBUF_LIBS="$PROTOBUF_LIBS"
@@ -4305,34 +4294,46 @@ AC_SUBST([BUILD_WITH_LIBPROTOBUF_LDFLAGS])
 AC_SUBST([BUILD_WITH_LIBPROTOBUF_LIBS])
 # }}}
 
+AC_ARG_VAR([PROTOC], [path to the protoc binary])
+AC_PATH_PROG([PROTOC], [protoc])
+have_protoc3="no"
+if test "x$PROTOC" != "x"; then
+  AC_MSG_CHECKING([for protoc 3.0.0+])
+  if $PROTOC --version | $EGREP libprotoc.3 >/dev/null; then
+    protoc3="yes (`$PROTOC --version`)"
+    have_protoc3="yes"
+  else
+    protoc3="no (`$PROTOC --version`)"
+  fi
+  AC_MSG_RESULT([$protoc3])
+fi
+AM_CONDITIONAL([HAVE_PROTOC3], [test "x$have_protoc3" = "xyes"])
+
 # --with-libprotobuf-c {{{
-with_libprotobuf_c_cppflags=""
-with_libprotobuf_c_ldflags=""
-AC_ARG_WITH([libprotobuf-c], [AS_HELP_STRING([--with-libprotobuf-c@<:@=PREFIX@:>@], [Path to libprotobuf-c.])],
+AC_ARG_WITH([libprotobuf-c],
+  [AS_HELP_STRING([--with-libprotobuf-c@<:@=PREFIX@:>@], [Path to libprotobuf-c.])],
   [
-    if test "x$withval" != "xno" && test "x$withval" != "xyes"
-    then
+    if test "x$withval" != "xno" && test "x$withval" != "xyes"; then
       with_libprotobuf_c_cppflags="-I$withval/include"
       with_libprotobuf_c_ldflags="-L$withval/lib"
       with_libprotobuf_c="yes"
     fi
-    if test "x$withval" = "xno"
-    then
+
+    if test "x$withval" = "xno"; then
       with_libprotobuf_c="no (disabled on command line)"
     fi
   ],
   [withval="yes"]
 )
-if test "x$withval" = "xyes"
-then
-PKG_CHECK_MODULES([PROTOBUF_C], [libprotobuf-c],
-  [with_libprotobuf_c="yes"],
-  [with_libprotobuf_c="no (pkg-config could not find libprotobuf-c)"]
-)
+
+if test "x$withval" = "xyes"; then
+  PKG_CHECK_MODULES([PROTOBUF_C], [libprotobuf-c],
+    [with_libprotobuf_c="yes"],
+    [with_libprotobuf_c="no (pkg-config could not find libprotobuf-c)"]
+  )
 fi
 
-if test "x$withval" != "xno"
-then
+if test "x$withval" != "xno"; then
   SAVE_LDFLAGS="$LDFLAGS"
   SAVE_LIBS="$LIBS"
   LDFLAGS="$with_libprotobuf_c_ldflags"
@@ -4341,10 +4342,10 @@ then
     [
       SAVE_CPPFLAGS="$CPPFLAGS"
       CPPFLAGS="$with_libprotobuf_c_cppflags $PROTOBUF_C_CFLAGS"
-      if test "x$PROTOBUF_C_LIBS" = "x"
-      then
+      if test "x$PROTOBUF_C_LIBS" = "x"; then
         PROTOBUF_C_LIBS="-lprotobuf-c"
       fi
+
       AC_CHECK_HEADERS([protobuf-c/protobuf-c.h google/protobuf-c/protobuf-c.h],
         [
           with_libprotobuf_c="yes"
@@ -4352,6 +4353,7 @@ then
         ],
         [with_libprotobuf_c="no (<protobuf-c.h> not found)"]
       )
+
       CPPFLAGS="$SAVE_CPPFLAGS"
     ],
     [with_libprotobuf_c="no (libprotobuf-c not found)"]
@@ -4359,6 +4361,7 @@ then
   LDFLAGS="$SAVE_LDFLAGS"
   LIBS="$SAVE_LIBS"
 fi
+
 BUILD_WITH_LIBPROTOBUF_C_CPPFLAGS="$with_libprotobuf_c_cppflags $PROTOBUF_C_CFLAGS"
 BUILD_WITH_LIBPROTOBUF_C_LDFLAGS="$with_libprotobuf_c_ldflags"
 BUILD_WITH_LIBPROTOBUF_C_LIBS="$PROTOBUF_C_LIBS"
@@ -4367,18 +4370,26 @@ AC_SUBST([BUILD_WITH_LIBPROTOBUF_C_LDFLAGS])
 AC_SUBST([BUILD_WITH_LIBPROTOBUF_C_LIBS])
 # }}}
 
+AC_ARG_VAR([PROTOC_C], [path to the protoc-c binary])
+AC_PATH_PROG([PROTOC_C], [protoc-c])
+if test "x$PROTOC_C" = "x"
+then
+  have_protoc_c="no (protoc-c compiler not found)"
+else
+  have_protoc_c="yes"
+fi
+
 # --with-libpython {{{
 AC_ARG_VAR([LIBPYTHON_CPPFLAGS], [Preprocessor flags for libpython])
 AC_ARG_VAR([LIBPYTHON_LDFLAGS], [Linker flags for libpython])
 AC_ARG_VAR([LIBPYTHON_LIBS], [Libraries for libpython])
 
 AC_ARG_WITH([libpython],
-  [AS_HELP_STRING([--with-libpython],
-    [if we should build with libpython @<:@default=yes@:>@])
-  ],
+  [AS_HELP_STRING([--with-libpython], [if we should build with libpython @<:@default=yes@:>@])],
   [with_libpython="$withval"],
   [with_libpython="check"]
 )
+
 if test "$with_libpython" != "no"; then
   if test "$LIBPYTHON_CPPFLAGS" = "" && test "$LIBPYTHON_LDFLAGS" = ""; then
     AC_ARG_VAR([PYTHON_CONFIG], [path to python-config])
@@ -4416,6 +4427,7 @@ if test "$with_libpython" != "xno"; then
   CPPFLAGS="$LIBPYTHON_CPPFLAGS $CPPFLAGS"
   LDFLAGS="$LIBPYTHON_LDFLAGS $LDFLAGS"
   LIBS="$LIBPYTHON_LIBS $LIBS"
+
   AC_CHECK_HEADERS([Python.h],
     [
       AC_MSG_CHECKING([for libpython])
@@ -4430,6 +4442,7 @@ if test "$with_libpython" != "xno"; then
     ],
     [with_libpython="no"]
   )
+
   CPPFLAGS="$SAVE_CPPFLAGS"
   LDFLAGS="$SAVE_LDFLAGS"
   LIBS="$SAVE_LIBS"
 # }}} --with-libpython
 
 # --with-librabbitmq {{{
-with_librabbitmq_cppflags=""
-with_librabbitmq_ldflags=""
-AC_ARG_WITH(librabbitmq, [AS_HELP_STRING([--with-librabbitmq@<:@=PREFIX@:>@], [Path to librabbitmq.])],
-[
-       if test "x$withval" != "xno" && test "x$withval" != "xyes"
-       then
-               with_librabbitmq_cppflags="-I$withval/include"
-               with_librabbitmq_ldflags="-L$withval/lib"
-               with_librabbitmq="yes"
-       else
-               with_librabbitmq="$withval"
-       fi
-],
-[
-       with_librabbitmq="yes"
-])
-SAVE_CPPFLAGS="$CPPFLAGS"
-SAVE_LDFLAGS="$LDFLAGS"
-CPPFLAGS="$CPPFLAGS $with_librabbitmq_cppflags"
-LDFLAGS="$LDFLAGS $with_librabbitmq_ldflags"
-if test "x$with_librabbitmq" = "xyes"
-then
-       AC_CHECK_HEADERS(amqp.h, [with_librabbitmq="yes"], [with_librabbitmq="no (amqp.h not found)"])
-fi
-if test "x$with_librabbitmq" = "xyes"
-then
-       # librabbitmq up to version 0.9.1 provides "library_errno", later
-       # versions use "library_error". The library does not provide a version
-       # macro :( Use "AC_CHECK_MEMBERS" (plural) for automatic defines.
-       AC_CHECK_MEMBERS([amqp_rpc_reply_t.library_errno],,,
-                        [
-#if HAVE_STDLIB_H
-# include <stdlib.h>
-#endif
-#if HAVE_STDIO_H
-# include <stdio.h>
-#endif
-#if HAVE_STDINT_H
-# include <stdint.h>
-#endif
-#if HAVE_INTTYPES_H
-# include <inttypes.h>
-#endif
-#include <amqp.h>
-                         ])
-fi
-if test "x$with_librabbitmq" = "xyes"
-then
-       AC_CHECK_LIB(rabbitmq, amqp_basic_publish, [with_librabbitmq="yes"], [with_librabbitmq="no (Symbol 'amqp_basic_publish' not found)"])
+AC_ARG_WITH([librabbitmq],
+  [AS_HELP_STRING([--with-librabbitmq@<:@=PREFIX@:>@], [Path to librabbitmq.])],
+  [
+    if test "x$withval" != "xno" && test "x$withval" != "xyes"; then
+      with_librabbitmq_cppflags="-I$withval/include"
+      with_librabbitmq_ldflags="-L$withval/lib"
+      with_librabbitmq="yes"
+    else
+      with_librabbitmq="$withval"
+    fi
+  ],
+  [with_librabbitmq="yes"]
+)
+
+if test "x$with_librabbitmq" = "xyes"; then
+  SAVE_CPPFLAGS="$CPPFLAGS"
+  CPPFLAGS="$CPPFLAGS $with_librabbitmq_cppflags"
+
+  AC_CHECK_HEADERS([amqp.h],
+    [with_librabbitmq="yes"],
+    [with_librabbitmq="no (amqp.h not found)"]
+  )
+
+  CPPFLAGS="$SAVE_CPPFLAGS"
 fi
-if test "x$with_librabbitmq" = "xyes"
-then
-       BUILD_WITH_LIBRABBITMQ_CPPFLAGS="$with_librabbitmq_cppflags"
-       BUILD_WITH_LIBRABBITMQ_LDFLAGS="$with_librabbitmq_ldflags"
-       BUILD_WITH_LIBRABBITMQ_LIBS="-lrabbitmq"
-       AC_SUBST(BUILD_WITH_LIBRABBITMQ_CPPFLAGS)
-       AC_SUBST(BUILD_WITH_LIBRABBITMQ_LDFLAGS)
-       AC_SUBST(BUILD_WITH_LIBRABBITMQ_LIBS)
-       AC_DEFINE(HAVE_LIBRABBITMQ, 1, [Define if librabbitmq is present and usable.])
+
+if test "x$with_librabbitmq" = "xyes"; then
+  # librabbitmq up to version 0.9.1 provides "library_errno", later
+  # versions use "library_error". The library does not provide a version
+  # macro :(.
+
+  SAVE_CPPFLAGS="$CPPFLAGS"
+  CPPFLAGS="$CPPFLAGS $with_librabbitmq_cppflags"
+
+  AC_CHECK_MEMBERS([amqp_rpc_reply_t.library_errno],
+    [],
+    [],
+    [[
+      #include <stdlib.h>
+      #include <stdio.h>
+      #include <stdint.h>
+      #include <inttypes.h>
+      #include <amqp.h>
+    ]]
+  )
+  CPPFLAGS="$SAVE_CPPFLAGS"
+
+  SAVE_LDFLAGS="$LDFLAGS"
+  LDFLAGS="$LDFLAGS $with_librabbitmq_ldflags"
+
+  AC_CHECK_LIB([rabbitmq], [amqp_basic_publish],
+    [with_librabbitmq="yes"],
+    [with_librabbitmq="no (Symbol 'amqp_basic_publish' not found)"]
+  )
+
+  LDFLAGS="$SAVE_LDFLAGS"
 fi
-CPPFLAGS="$SAVE_CPPFLAGS"
-LDFLAGS="$SAVE_LDFLAGS"
-AM_CONDITIONAL(BUILD_WITH_LIBRABBITMQ, test "x$with_librabbitmq" = "xyes")
 
-with_amqp_tcp_socket="no"
-if test "x$with_librabbitmq" = "xyes"
-then
-       SAVE_CPPFLAGS="$CPPFLAGS"
-       SAVE_LDFLAGS="$LDFLAGS"
-       SAVE_LIBS="$LIBS"
-       CPPFLAGS="$CPPFLAGS $with_librabbitmq_cppflags"
-       LDFLAGS="$LDFLAGS $with_librabbitmq_ldflags"
-       LIBS="-lrabbitmq"
-
-       AC_CHECK_HEADERS(amqp_tcp_socket.h amqp_socket.h)
-       AC_CHECK_FUNC(amqp_tcp_socket_new, [with_amqp_tcp_socket="yes"], [with_amqp_tcp_socket="no"])
-       if test "x$with_amqp_tcp_socket" = "xyes"
-       then
-               AC_DEFINE(HAVE_AMQP_TCP_SOCKET, 1,
-                               [Define if librabbitmq provides the new TCP socket interface.])
-       fi
+if test "x$with_librabbitmq" = "xyes"; then
+  SAVE_CPPFLAGS="$CPPFLAGS"
+  SAVE_LDFLAGS="$LDFLAGS"
+  SAVE_LIBS="$LIBS"
+  CPPFLAGS="$CPPFLAGS $with_librabbitmq_cppflags"
+  LDFLAGS="$LDFLAGS $with_librabbitmq_ldflags"
+  LIBS="-lrabbitmq"
+
+  AC_CHECK_HEADERS([amqp_tcp_socket.h amqp_socket.h])
+  AC_CHECK_FUNC([amqp_tcp_socket_new],
+    [
+      AC_DEFINE([HAVE_AMQP_TCP_SOCKET], [1],
+        [Define if librabbitmq provides the new TCP socket interface.])
+    ]
+  )
 
-       AC_CHECK_DECLS(amqp_socket_close,
-                               [amqp_socket_close_decl="yes"], [amqp_socket_close_decl="no"],
-                               [[
-#include <amqp.h>
-#ifdef HAVE_AMQP_TCP_SOCKET_H
-# include <amqp_tcp_socket.h>
-#endif
-#ifdef HAVE_AMQP_SOCKET_H
-# include <amqp_socket.h>
-#endif
-                               ]])
+  AC_CHECK_DECLS([amqp_socket_close],
+    [],
+    [],
+    [[
+      #include <amqp.h>
+      #ifdef HAVE_AMQP_TCP_SOCKET_H
+      # include <amqp_tcp_socket.h>
+      #endif
+      #ifdef HAVE_AMQP_SOCKET_H
+      # include <amqp_socket.h>
+      #endif
+    ]]
+  )
 
-       CPPFLAGS="$SAVE_CPPFLAGS"
-       LDFLAGS="$SAVE_LDFLAGS"
-       LIBS="$SAVE_LIBS"
+  CPPFLAGS="$SAVE_CPPFLAGS"
+  LDFLAGS="$SAVE_LDFLAGS"
+  LIBS="$SAVE_LIBS"
+fi
+
+if test "x$with_librabbitmq" = "xyes"; then
+  BUILD_WITH_LIBRABBITMQ_CPPFLAGS="$with_librabbitmq_cppflags"
+  BUILD_WITH_LIBRABBITMQ_LDFLAGS="$with_librabbitmq_ldflags"
+  BUILD_WITH_LIBRABBITMQ_LIBS="-lrabbitmq"
 fi
+
+AC_SUBST(BUILD_WITH_LIBRABBITMQ_CPPFLAGS)
+AC_SUBST(BUILD_WITH_LIBRABBITMQ_LDFLAGS)
+AC_SUBST(BUILD_WITH_LIBRABBITMQ_LIBS)
+
 # }}}
 
 # --with-librdkafka {{{
-AC_ARG_WITH(librdkafka, [AS_HELP_STRING([--with-librdkafka@<:@=PREFIX@:>@], [Path to librdkafka.])],
-[
-  if test "x$withval" != "xno" && test "x$withval" != "xyes"
-  then
-    with_librdkafka_cppflags="-I$withval/include"
-    with_librdkafka_ldflags="-L$withval/lib"
-    with_librdkafka_rpath="$withval/lib"
-    with_librdkafka="yes"
-  else
-    with_librdkafka="$withval"
-  fi
-],
-[
-  with_librdkafka="yes"
-])
-SAVE_CPPFLAGS="$CPPFLAGS"
-SAVE_LDFLAGS="$LDFLAGS"
+AC_ARG_WITH([librdkafka],
+  [AS_HELP_STRING([--with-librdkafka@<:@=PREFIX@:>@], [Path to librdkafka.])],
+  [
+    if test "x$withval" != "xno" && test "x$withval" != "xyes"; then
+      with_librdkafka_cppflags="-I$withval/include"
+      with_librdkafka_ldflags="-L$withval/lib"
+      with_librdkafka_rpath="$withval/lib"
+      with_librdkafka="yes"
+    else
+      with_librdkafka="$withval"
+    fi
+  ],
+  [with_librdkafka="yes"]
+)
 
-CPPFLAGS="$CPPFLAGS $with_librdkafka_cppflags"
-LDFLAGS="$LDFLAGS $with_librdkafka_ldflags"
+if test "x$with_librdkafka" = "xyes"; then
+  SAVE_CPPFLAGS="$CPPFLAGS"
+  CPPFLAGS="$CPPFLAGS $with_librdkafka_cppflags"
 
-if test "x$with_librdkafka" = "xyes"
-then
-       AC_CHECK_HEADERS(librdkafka/rdkafka.h, [with_librdkafka="yes"], [with_librdkafka="no (librdkafka/rdkafka.h not found)"])
+  AC_CHECK_HEADERS([librdkafka/rdkafka.h],
+    [with_librdkafka="yes"],
+    [with_librdkafka="no (librdkafka/rdkafka.h not found)"]
+  )
+
+  CPPFLAGS="$SAVE_CPPFLAGS"
 fi
 
-if test "x$with_librdkafka" = "xyes"
-then
-       AC_CHECK_LIB(rdkafka, rd_kafka_new, [with_librdkafka="yes"], [with_librdkafka="no (Symbol 'rd_kafka_new' not found)"])
-  AC_CHECK_LIB(rdkafka, rd_kafka_conf_set_log_cb, [with_librdkafka_log_cb="yes"], [with_librdkafka_log_cb="no"])
-  AC_CHECK_LIB(rdkafka, rd_kafka_set_logger, [with_librdkafka_logger="yes"], [with_librdkafka_logger="no"])
+if test "x$with_librdkafka" = "xyes"; then
+  SAVE_LDFLAGS="$LDFLAGS"
+  LDFLAGS="$LDFLAGS $with_librdkafka_ldflags"
+
+  AC_CHECK_LIB([rdkafka], [rd_kafka_new],
+    [with_librdkafka="yes"],
+    [with_librdkafka="no (Symbol 'rd_kafka_new' not found)"])
+
+  AC_CHECK_LIB([rdkafka], [rd_kafka_conf_set_log_cb],
+    [with_librdkafka_log_cb="yes"],
+    [with_librdkafka_log_cb="no"])
+
+  AC_CHECK_LIB([rdkafka], [rd_kafka_set_logger],
+    [with_librdkafka_logger="yes"],
+    [with_librdkafka_logger="no"]
+  )
+
+  LDFLAGS="$SAVE_LDFLAGS"
 fi
-if test "x$with_librdkafka" = "xyes"
-then
-       BUILD_WITH_LIBRDKAFKA_CPPFLAGS="$with_librdkafka_cppflags"
-       BUILD_WITH_LIBRDKAFKA_LDFLAGS="$with_librdkafka_ldflags"
-       if test "x$with_librdkafka_rpath" != "x"
-       then
-               BUILD_WITH_LIBRDKAFKA_LIBS="-Wl,-rpath,$with_librdkafka_rpath -lrdkafka"
-       else
-               BUILD_WITH_LIBRDKAFKA_LIBS="-lrdkafka"
-       fi
-       AC_SUBST(BUILD_WITH_LIBRDKAFKA_CPPFLAGS)
-       AC_SUBST(BUILD_WITH_LIBRDKAFKA_LDFLAGS)
-       AC_SUBST(BUILD_WITH_LIBRDKAFKA_LIBS)
-       AC_DEFINE(HAVE_LIBRDKAFKA, 1, [Define if librdkafka is present and usable.])
-  if test "x$with_librdkafka_log_cb" = "xyes"
-  then
-        AC_DEFINE(HAVE_LIBRDKAFKA_LOG_CB, 1, [Define if librdkafka log facility is present and usable.])
-  else if test "x$with_librdkafka_logger" = "xyes"
-  then
-        AC_DEFINE(HAVE_LIBRDKAFKA_LOGGER, 1, [Define if librdkafka log facility is present and usable.])
+
+if test "x$with_librdkafka" = "xyes"; then
+  BUILD_WITH_LIBRDKAFKA_CPPFLAGS="$with_librdkafka_cppflags"
+  BUILD_WITH_LIBRDKAFKA_LDFLAGS="$with_librdkafka_ldflags"
+
+  if test "x$with_librdkafka_rpath" != "x"; then
+    BUILD_WITH_LIBRDKAFKA_LIBS="-Wl,-rpath,$with_librdkafka_rpath -lrdkafka"
+  else
+    BUILD_WITH_LIBRDKAFKA_LIBS="-lrdkafka"
+  fi
+
+  if test "x$with_librdkafka_log_cb" = "xyes"; then
+    AC_DEFINE(HAVE_LIBRDKAFKA_LOG_CB, 1, [Define if librdkafka log facility is present and usable.])
+  else if test "x$with_librdkafka_logger" = "xyes"; then
+    AC_DEFINE(HAVE_LIBRDKAFKA_LOGGER, 1, [Define if librdkafka log facility is present and usable.])
   fi; fi
 fi
-CPPFLAGS="$SAVE_CPPFLAGS"
-LDFLAGS="$SAVE_LDFLAGS"
-AM_CONDITIONAL(BUILD_WITH_LIBRDKAFKA, test "x$with_librdkafka" = "xyes")
 
+AC_SUBST([BUILD_WITH_LIBRDKAFKA_CPPFLAGS])
+AC_SUBST([BUILD_WITH_LIBRDKAFKA_LDFLAGS])
+AC_SUBST([BUILD_WITH_LIBRDKAFKA_LIBS])
 # }}}
 
 # --with-librouteros {{{
-AC_ARG_WITH(librouteros, [AS_HELP_STRING([--with-librouteros@<:@=PREFIX@:>@], [Path to librouteros.])],
-[
- if test "x$withval" = "xyes"
- then
-        with_librouteros="yes"
- else if test "x$withval" = "xno"
- then
-        with_librouteros="no"
- else
-        with_librouteros="yes"
-        LIBROUTEROS_CPPFLAGS="$LIBROUTEROS_CPPFLAGS -I$withval/include"
-        LIBROUTEROS_LDFLAGS="$LIBROUTEROS_LDFLAGS -L$withval/lib"
- fi; fi
-],
-[with_librouteros="yes"])
+AC_ARG_WITH([librouteros],
+  [AS_HELP_STRING([--with-librouteros@<:@=PREFIX@:>@], [Path to librouteros.])],
+  [
+    if test "x$withval" = "xyes" || test "x$withval" = "xno"; then
+      with_librouteros="$witval"
+    else
+      with_librouteros_cppflags="-I$withval/include"
+      with_librouteros_ldflags="-L$withval/lib"
+      with_librouteros="yes"
+   fi
+  ],
+  [with_librouteros="yes"]
+)
 
-SAVE_CPPFLAGS="$CPPFLAGS"
-SAVE_LDFLAGS="$LDFLAGS"
+if test "x$with_librouteros" = "xyes"; then
+  SAVE_CPPFLAGS="$CPPFLAGS"
+  CPPFLAGS="$CPPFLAGS $with_librouteros_cppflags"
 
-CPPFLAGS="$CPPFLAGS $LIBROUTEROS_CPPFLAGS"
-LDFLAGS="$LDFLAGS $LIBROUTEROS_LDFLAGS"
+  AC_CHECK_HEADERS([routeros_api.h],
+    [with_librouteros="yes"],
+    [with_librouteros="no (routeros_api.h not found)"]
+  )
 
-if test "x$with_librouteros" = "xyes"
-then
-       if test "x$LIBROUTEROS_CPPFLAGS" != "x"
-       then
-               AC_MSG_NOTICE([librouteros CPPFLAGS: $LIBROUTEROS_CPPFLAGS])
-       fi
-       AC_CHECK_HEADERS(routeros_api.h,
-       [with_librouteros="yes"],
-       [with_librouteros="no (routeros_api.h not found)"])
-fi
-if test "x$with_librouteros" = "xyes"
-then
-       if test "x$LIBROUTEROS_LDFLAGS" != "x"
-       then
-               AC_MSG_NOTICE([librouteros LDFLAGS: $LIBROUTEROS_LDFLAGS])
-       fi
-       AC_CHECK_LIB(routeros, ros_interface,
-       [with_librouteros="yes"],
-       [with_librouteros="no (symbol 'ros_interface' not found)"])
+  CPPFLAGS="$SAVE_CPPFLAGS"
 fi
 
-CPPFLAGS="$SAVE_CPPFLAGS"
-LDFLAGS="$SAVE_LDFLAGS"
+if test "x$with_librouteros" = "xyes"; then
+  SAVE_LDFLAGS="$LDFLAGS"
+  LDFLAGS="$LDFLAGS $with_librouteros_ldflags"
 
-if test "x$with_librouteros" = "xyes"
-then
-       BUILD_WITH_LIBROUTEROS_CPPFLAGS="$LIBROUTEROS_CPPFLAGS"
-       BUILD_WITH_LIBROUTEROS_LDFLAGS="$LIBROUTEROS_LDFLAGS"
-       AC_SUBST(BUILD_WITH_LIBROUTEROS_CPPFLAGS)
-       AC_SUBST(BUILD_WITH_LIBROUTEROS_LDFLAGS)
+  AC_CHECK_LIB([routeros], [ros_interface],
+    [with_librouteros="yes"],
+    [with_librouteros="no (symbol 'ros_interface' not found)"]
+  )
+
+  LDFLAGS="$SAVE_LDFLAGS"
 fi
-AM_CONDITIONAL(BUILD_WITH_LIBROUTEROS, test "x$with_librouteros" = "xyes")
+
+if test "x$with_librouteros" = "xyes"; then
+  BUILD_WITH_LIBROUTEROS_CPPFLAGS="$with_librouteros_cppflags"
+  BUILD_WITH_LIBROUTEROS_LDFLAGS="$with_librouteros_ldflags"
+fi
+
+AC_SUBST([BUILD_WITH_LIBROUTEROS_CPPFLAGS])
+AC_SUBST([BUILD_WITH_LIBROUTEROS_LDFLAGS])
 # }}}
 
 # --with-librrd {{{
-librrd_cflags=""
-librrd_ldflags=""
 librrd_threadsafe="no"
 librrd_rrdc_update="no"
-AC_ARG_WITH(librrd,
+AC_ARG_WITH([librrd],
   [AS_HELP_STRING([--with-librrd@<:@=PREFIX@:>@], [Path to rrdtool.])],
   [
-    if test "x$withval" != "xno" && test "x$withval" != "xyes"
-    then
+    if test "x$withval" != "xno" && test "x$withval" != "xyes"; then
       librrd_cflags="-I$withval/include"
       librrd_ldflags="-L$withval/lib"
       with_librrd="yes"
@@ -4675,8 +4690,7 @@ AC_ARG_WITH(librrd,
   [with_librrd="yes"]
 )
 
-if test "x$with_librrd" = "xyes"
-then
+if test "x$with_librrd" = "xyes"; then
   SAVE_LDFLAGS="$LDFLAGS"
   LDFLAGS="$LDFLAGS $librrd_ldflags"
   PKG_CHECK_MODULES([RRD], [librrd >= 1.6.0],
@@ -4701,8 +4715,7 @@ then
   CPPFLAGS="$SAVE_CPPFLAGS"
 fi
 
-if test "x$with_librrd" = "xyes" && test "x$librrd_threadsafe" = "xno"
-then
+if test "x$with_librrd" = "xyes" && test "x$librrd_threadsafe" = "xno"; then
   SAVE_LDFLAGS="$LDFLAGS"
   LDFLAGS="$LDFLAGS $librrd_ldflags"
 
@@ -4720,8 +4733,7 @@ then
   LDFLAGS="$SAVE_LDFLAGS"
 fi
 
-if test "x$with_librrd" = "xyes" && test "x$librrd_threadsafe" = "xno"
-then
+if test "x$with_librrd" = "xyes" && test "x$librrd_threadsafe" = "xno"; then
   SAVE_LDFLAGS="$LDFLAGS"
   LDFLAGS="$LDFLAGS $librrd_ldflags"
 
@@ -4738,82 +4750,78 @@ then
   LDFLAGS="$SAVE_LDFLAGS"
 fi
 
-if test "x$with_librrd" = "xyes"
-then
+if test "x$with_librrd" = "xyes"; then
   BUILD_WITH_LIBRRD_CFLAGS="$RRD_CFLAGS $librrd_cflags"
   BUILD_WITH_LIBRRD_LDFLAGS="$librrd_ldflags"
   BUILD_WITH_LIBRRD_LIBS="$RRD_LIBS"
-  AC_SUBST(BUILD_WITH_LIBRRD_CFLAGS)
-  AC_SUBST(BUILD_WITH_LIBRRD_LDFLAGS)
-  AC_SUBST(BUILD_WITH_LIBRRD_LIBS)
 fi
-if test "x$librrd_threadsafe" = "xyes"
-then
+
+if test "x$librrd_threadsafe" = "xyes"; then
   AC_DEFINE([HAVE_THREADSAFE_LIBRRD], [1],
     [Define to 1 if the rrd library is thread-safe]
   )
 fi
+
+AC_SUBST([BUILD_WITH_LIBRRD_CFLAGS])
+AC_SUBST([BUILD_WITH_LIBRRD_LDFLAGS])
+AC_SUBST([BUILD_WITH_LIBRRD_LIBS])
 # }}}
 
 # --with-libsensors {{{
-with_sensors_cflags=""
-with_sensors_ldflags=""
-AC_ARG_WITH(libsensors, [AS_HELP_STRING([--with-libsensors@<:@=PREFIX@:>@], [Path to lm_sensors.])],
-[
-       if test "x$withval" = "xno"
-       then
-               with_libsensors="no"
-       else
-               with_libsensors="yes"
-               if test "x$withval" != "xyes"
-               then
-                       with_sensors_cflags="-I$withval/include"
-                       with_sensors_ldflags="-L$withval/lib"
-                       with_libsensors="yes"
-               fi
-       fi
-],
-[
-       if test "x$ac_system" = "xLinux"
-       then
-               with_libsensors="yes"
-       else
-               with_libsensors="no (Linux only library)"
-       fi
-])
-if test "x$with_libsensors" = "xyes"
-then
-       SAVE_CPPFLAGS="$CPPFLAGS"
-       CPPFLAGS="$CPPFLAGS $with_sensors_cflags"
+AC_ARG_WITH([libsensors],
+  [AS_HELP_STRING([--with-libsensors@<:@=PREFIX@:>@], [Path to lm_sensors.])],
+  [
+    if test "x$withval" = "xno" || test "x$withval" = "xyes"; then
+      with_libsensors="$withval"
+    else
+      with_sensors_cppflags="-I$withval/include"
+      with_sensors_ldflags="-L$withval/lib"
+      with_libsensors="yes"
+    fi
+  ],
+  [
+    if test "x$ac_system" = "xLinux"; then
+      with_libsensors="yes"
+    else
+      with_libsensors="no (Linux only library)"
+    fi
+  ]
+)
 
-       AC_CHECK_HEADERS(sensors/sensors.h, [], [with_libsensors="no (sensors/sensors.h not found)"])
+if test "x$with_libsensors" = "xyes"; then
+  SAVE_CPPFLAGS="$CPPFLAGS"
+  CPPFLAGS="$CPPFLAGS $with_sensors_cppflags"
 
-       CPPFLAGS="$SAVE_CPPFLAGS"
+  AC_CHECK_HEADERS([sensors/sensors.h],
+    [with_libsensors="yes"],
+    [with_libsensors="no (sensors/sensors.h not found)"]
+  )
+
+  CPPFLAGS="$SAVE_CPPFLAGS"
 fi
-if test "x$with_libsensors" = "xyes"
-then
-       SAVE_CPPFLAGS="$CPPFLAGS"
-       SAVE_LDFLAGS="$LDFLAGS"
-       CPPFLAGS="$CPPFLAGS $with_sensors_cflags"
-       LDFLAGS="$LDFLAGS $with_sensors_ldflags"
 
-       AC_CHECK_LIB(sensors, sensors_init,
-       [
-               AC_DEFINE(HAVE_LIBSENSORS, 1, [Define to 1 if you have the sensors library (-lsensors).])
-       ],
-       [with_libsensors="no (libsensors not found)"])
+if test "x$with_libsensors" = "xyes"; then
+  SAVE_LDFLAGS="$LDFLAGS"
+  LDFLAGS="$LDFLAGS $with_sensors_ldflags"
 
-       CPPFLAGS="$SAVE_CPPFLAGS"
-       LDFLAGS="$SAVE_LDFLAGS"
+  AC_CHECK_LIB([sensors], [sensors_init],
+    [with_libsensors="yes"],
+    [with_libsensors="no (libsensors not found)"]
+  )
+
+  LDFLAGS="$SAVE_LDFLAGS"
 fi
-if test "x$with_libsensors" = "xyes"
-then
-       BUILD_WITH_LIBSENSORS_CFLAGS="$with_sensors_cflags"
-       BUILD_WITH_LIBSENSORS_LDFLAGS="$with_sensors_ldflags"
-       AC_SUBST(BUILD_WITH_LIBSENSORS_CFLAGS)
-       AC_SUBST(BUILD_WITH_LIBSENSORS_LDFLAGS)
+
+if test "x$with_libsensors" = "xyes"; then
+  BUILD_WITH_LIBSENSORS_CPPFLAGS="$with_sensors_cppflags"
+  BUILD_WITH_LIBSENSORS_LDFLAGS="$with_sensors_ldflags"
+  BUILD_WITH_LIBSENSORS_LIBS="-lsensors"
 fi
-AM_CONDITIONAL(BUILD_WITH_LM_SENSORS, test "x$with_libsensors" = "xyes")
+
+AC_SUBST([BUILD_WITH_LIBSENSORS_CPPFLAGS])
+AC_SUBST([BUILD_WITH_LIBSENSORS_LDFLAGS])
+AC_SUBST([BUILD_WITH_LIBSENSORS_LIBS])
+
 # }}}
 
 # libsigrok {{{
@@ -4826,35 +4834,29 @@ PKG_CHECK_MODULES([LIBSIGROK], [libsigrok < 0.4],
 # }}}
 
 # --with-libstatgrab {{{
-with_libstatgrab_cflags=""
-with_libstatgrab_ldflags=""
-AC_ARG_WITH(libstatgrab, [AS_HELP_STRING([--with-libstatgrab@<:@=PREFIX@:>@], [Path to libstatgrab.])],
-[
- if test "x$withval" != "xno" \
-   && test "x$withval" != "xyes"
- then
-   with_libstatgrab_cflags="-I$withval/include"
-   with_libstatgrab_ldflags="-L$withval/lib -lstatgrab"
-   with_libstatgrab="yes"
-   with_libstatgrab_pkg_config="no"
- else
-   with_libstatgrab="$withval"
-   with_libstatgrab_pkg_config="yes"
- fi
- ],
-[
- with_libstatgrab="yes"
- with_libstatgrab_pkg_config="yes"
-])
-
-if test "x$with_libstatgrab" = "xyes" \
-  && test "x$with_libstatgrab_pkg_config" = "xyes"
-then
-  AC_MSG_CHECKING([pkg-config for libstatgrab])
+AC_ARG_WITH([libstatgrab],
+  [AS_HELP_STRING([--with-libstatgrab@<:@=PREFIX@:>@], [Path to libstatgrab.])],
+  [
+    if test "x$withval" != "xno" && test "x$withval" != "xyes"; then
+      with_libstatgrab_cflags="-I$withval/include"
+      with_libstatgrab_ldflags="-L$withval/lib -lstatgrab"
+      with_libstatgrab="yes"
+      with_libstatgrab_pkg_config="no"
+    else
+      with_libstatgrab="$withval"
+      with_libstatgrab_pkg_config="yes"
+    fi
+  ],
+  [
+    with_libstatgrab="yes"
+    with_libstatgrab_pkg_config="yes"
+  ])
+
+if test "x$with_libstatgrab" = "xyes" && test "x$with_libstatgrab_pkg_config" = "xyes"; then
+  AC_MSG_CHECKING([pkg-config for libstatgrab])
   temp_result="found"
   $PKG_CONFIG --exists libstatgrab 2>/dev/null
-  if test "$?" != "0"
-  then
+  if test "$?" != "0"; then
     with_libstatgrab_pkg_config="no"
     with_libstatgrab="no (pkg-config doesn't know libstatgrab)"
     temp_result="not found"
@@ -4862,14 +4864,10 @@ then
   AC_MSG_RESULT([$temp_result])
 fi
 
-if test "x$with_libstatgrab" = "xyes" \
-  && test "x$with_libstatgrab_pkg_config" = "xyes" \
-  && test "x$with_libstatgrab_cflags" = "x"
-then
+if test "x$with_libstatgrab" = "xyes" && test "x$with_libstatgrab_pkg_config" = "xyes" && test "x$with_libstatgrab_cflags" = "x"; then
   AC_MSG_CHECKING([for libstatgrab CFLAGS])
   temp_result="`$PKG_CONFIG --cflags libstatgrab`"
-  if test "$?" = "0"
-  then
+  if test "$?" = "0"; then
     with_libstatgrab_cflags="$temp_result"
   else
     with_libstatgrab="no ($PKG_CONFIG --cflags libstatgrab failed)"
@@ -4878,10 +4876,7 @@ then
   AC_MSG_RESULT([$temp_result])
 fi
 
-if test "x$with_libstatgrab" = "xyes" \
-  && test "x$with_libstatgrab_pkg_config" = "xyes" \
-  && test "x$with_libstatgrab_ldflags" = "x"
-then
+if test "x$with_libstatgrab" = "xyes" && test "x$with_libstatgrab_pkg_config" = "xyes" && test "x$with_libstatgrab_ldflags" = "x"; then
   AC_MSG_CHECKING([for libstatgrab LDFLAGS])
   temp_result="`$PKG_CONFIG --libs libstatgrab`"
   if test "$?" = "0"
@@ -4894,36 +4889,31 @@ then
   AC_MSG_RESULT([$temp_result])
 fi
 
-if test "x$with_libstatgrab" = "xyes"
-then
+if test "x$with_libstatgrab" = "xyes"; then
   SAVE_CPPFLAGS="$CPPFLAGS"
   CPPFLAGS="$CPPFLAGS $with_libstatgrab_cflags"
 
-  AC_CHECK_HEADERS(statgrab.h,
-                  [with_libstatgrab="yes"],
-                  [with_libstatgrab="no (statgrab.h not found)"])
+  AC_CHECK_HEADERS([statgrab.h],
+    [with_libstatgrab="yes"],
+    [with_libstatgrab="no (statgrab.h not found)"]
+  )
 
   CPPFLAGS="$SAVE_CPPFLAGS"
 fi
 
-if test "x$with_libstatgrab" = "xyes"
-then
-  SAVE_CFLAGS="$CFLAGS"
+if test "x$with_libstatgrab" = "xyes"; then
   SAVE_LDFLAGS="$LDFLAGS"
-
-  CFLAGS="$CFLAGS $with_libstatgrab_cflags"
   LDFLAGS="$LDFLAGS $with_libstatgrab_ldflags"
 
-  AC_CHECK_LIB(statgrab, sg_init,
-              [with_libstatgrab="yes"],
-              [with_libstatgrab="no (symbol sg_init not found)"])
+  AC_CHECK_LIB([statgrab], [sg_init],
+    [with_libstatgrab="yes"],
+    [with_libstatgrab="no (symbol sg_init not found)"]
+  )
 
-  CFLAGS="$SAVE_CFLAGS"
   LDFLAGS="$SAVE_LDFLAGS"
 fi
 
-if test "x$with_libstatgrab" = "xyes"
-then
+if test "x$with_libstatgrab" = "xyes"; then
   SAVE_CFLAGS="$CFLAGS"
   SAVE_LDFLAGS="$LDFLAGS"
   SAVE_LIBS="$LIBS"
@@ -4933,19 +4923,24 @@ then
   LIBS="-lstatgrab $LIBS"
 
   AC_CACHE_CHECK([if libstatgrab >= 0.90],
-          [c_cv_have_libstatgrab_0_90],
-          AC_LINK_IFELSE([AC_LANG_PROGRAM(
-[[[
-#include <stdio.h>
-#include <statgrab.h>
-]]],
-[[[
-      if (sg_init()) return 0;
-]]]
-    )],
-    [c_cv_have_libstatgrab_0_90="no"],
-    [c_cv_have_libstatgrab_0_90="yes"]
+    [c_cv_have_libstatgrab_0_90],
+    [
+      AC_LINK_IFELSE(
+        [
+          AC_LANG_PROGRAM(
+            [[
+              #include <stdio.h>
+              #include <statgrab.h>
+            ]],
+            [[
+              if (sg_init()) return 0;
+            ]]
           )
+        ],
+        [c_cv_have_libstatgrab_0_90="no"],
+        [c_cv_have_libstatgrab_0_90="yes"]
+      )
+    ]
   )
 
   CFLAGS="$SAVE_CFLAGS"
@@ -4953,832 +4948,782 @@ then
   LIBS="$SAVE_LIBS"
 fi
 
-AM_CONDITIONAL(BUILD_WITH_LIBSTATGRAB, test "x$with_libstatgrab" = "xyes")
-if test "x$with_libstatgrab" = "xyes"
-then
-  AC_DEFINE(HAVE_LIBSTATGRAB, 1, [Define to 1 if you have the 'statgrab' library (-lstatgrab)])
+AM_CONDITIONAL([BUILD_WITH_LIBSTATGRAB], [test "x$with_libstatgrab" = "xyes"])
+
+if test "x$with_libstatgrab" = "xyes"; then
+  AC_DEFINE([HAVE_LIBSTATGRAB], [1],
+    [Define to 1 if you have the 'statgrab' library (-lstatgrab)]
+  )
+
+  if test "x$c_cv_have_libstatgrab_0_90" = "xyes"; then
+    AC_DEFINE([HAVE_LIBSTATGRAB_0_90], [1],
+      [Define to 1 if libstatgrab version >= 0.90]
+    )
+  fi
+
   BUILD_WITH_LIBSTATGRAB_CFLAGS="$with_libstatgrab_cflags"
   BUILD_WITH_LIBSTATGRAB_LDFLAGS="$with_libstatgrab_ldflags"
-  AC_SUBST(BUILD_WITH_LIBSTATGRAB_CFLAGS)
-  AC_SUBST(BUILD_WITH_LIBSTATGRAB_LDFLAGS)
-  if test "x$c_cv_have_libstatgrab_0_90" = "xyes"
-  then
-        AC_DEFINE(HAVE_LIBSTATGRAB_0_90, 1, [Define to 1 if libstatgrab version >= 0.90])
-  fi
+
 fi
+
+AC_SUBST([BUILD_WITH_LIBSTATGRAB_CFLAGS])
+AC_SUBST([BUILD_WITH_LIBSTATGRAB_LDFLAGS])
 # }}}
 
 # --with-libtokyotyrant {{{
-with_libtokyotyrant_cppflags=""
-with_libtokyotyrant_ldflags=""
-with_libtokyotyrant_libs=""
-AC_ARG_WITH(libtokyotyrant, [AS_HELP_STRING([--with-libtokyotyrant@<:@=PREFIX@:>@], [Path to libtokyotyrant.])],
-[
-  if test "x$withval" = "xno"
-  then
-    with_libtokyotyrant="no"
-  else if test "x$withval" = "xyes"
-  then
-    with_libtokyotyrant="yes"
-  else
-    with_libtokyotyrant_cppflags="-I$withval/include"
-    with_libtokyotyrant_ldflags="-L$withval/include"
-    with_libtokyotyrant_libs="-ltokyotyrant"
-    with_libtokyotyrant="yes"
-  fi; fi
-],
-[
-  with_libtokyotyrant="yes"
-])
+AC_ARG_WITH([libtokyotyrant],
+  [AS_HELP_STRING([--with-libtokyotyrant@<:@=PREFIX@:>@], [Path to libtokyotyrant.])],
+  [
+    if test "x$withval" = "xno" || test "x$withval" = "xyes"; then
+      with_libtokyotyrant="$withval"
+    else
+      with_libtokyotyrant_cppflags="-I$withval/include"
+      with_libtokyotyrant_ldflags="-L$withval/include"
+      with_libtokyotyrant_libs="-ltokyotyrant"
+      with_libtokyotyrant="yes"
+    fi
+  ],
+  [with_libtokyotyrant="yes"]
+)
 
-if test "x$with_libtokyotyrant" = "xyes"
-then
-  if $PKG_CONFIG --exists tokyotyrant
-  then
+if test "x$with_libtokyotyrant" = "xyes"; then
+  if $PKG_CONFIG --exists tokyotyrant; then
     with_libtokyotyrant_cppflags="$with_libtokyotyrant_cppflags `$PKG_CONFIG --cflags tokyotyrant`"
     with_libtokyotyrant_ldflags="$with_libtokyotyrant_ldflags `$PKG_CONFIG --libs-only-L tokyotyrant`"
     with_libtokyotyrant_libs="$with_libtokyotyrant_libs `$PKG_CONFIG --libs-only-l tokyotyrant`"
   fi
 fi
 
-SAVE_CPPFLAGS="$CPPFLAGS"
-SAVE_LDFLAGS="$LDFLAGS"
-CPPFLAGS="$CPPFLAGS $with_libtokyotyrant_cppflags"
-LDFLAGS="$LDFLAGS $with_libtokyotyrant_ldflags"
+if test "x$with_libtokyotyrant" = "xyes"; then
+  SAVE_CPPFLAGS="$CPPFLAGS"
+  CPPFLAGS="$CPPFLAGS $with_libtokyotyrant_cppflags"
 
-if test "x$with_libtokyotyrant" = "xyes"
-then
-  AC_CHECK_HEADERS(tcrdb.h,
-  [
-          AC_DEFINE(HAVE_TCRDB_H, 1,
-                    [Define to 1 if you have the <tcrdb.h> header file.])
-  ], [with_libtokyotyrant="no (tcrdb.h not found)"])
-fi
+  AC_CHECK_HEADERS([tcrdb.h],
+    [with_libtokyotyrant="yes"],
+    [with_libtokyotyrant="no (tcrdb.h not found)"]
+  )
 
-if test "x$with_libtokyotyrant" = "xyes"
-then
-  AC_CHECK_LIB(tokyotyrant, tcrdbrnum,
-  [
-          AC_DEFINE(HAVE_LIBTOKYOTYRANT, 1,
-                    [Define to 1 if you have the tokyotyrant library (-ltokyotyrant).])
-  ],
-  [with_libtokyotyrant="no (symbol tcrdbrnum not found)"],
-  [$with_libtokyotyrant_libs])
+  CPPFLAGS="$SAVE_CPPFLAGS"
 fi
 
-CPPFLAGS="$SAVE_CPPFLAGS"
-LDFLAGS="$SAVE_LDFLAGS"
+if test "x$with_libtokyotyrant" = "xyes"; then
+  SAVE_LDFLAGS="$LDFLAGS"
+  LDFLAGS="$LDFLAGS $with_libtokyotyrant_ldflags"
 
-if test "x$with_libtokyotyrant" = "xyes"
-then
+  AC_CHECK_LIB([tokyotyrant], [tcrdbrnum],
+    [with_libtokyotyrant="yes"],
+    [with_libtokyotyrant="no (symbol tcrdbrnum not found)"],
+    [$with_libtokyotyrant_libs]
+  )
+
+  LDFLAGS="$SAVE_LDFLAGS"
+fi
+
+if test "x$with_libtokyotyrant" = "xyes"; then
   BUILD_WITH_LIBTOKYOTYRANT_CPPFLAGS="$with_libtokyotyrant_cppflags"
   BUILD_WITH_LIBTOKYOTYRANT_LDFLAGS="$with_libtokyotyrant_ldflags"
   BUILD_WITH_LIBTOKYOTYRANT_LIBS="$with_libtokyotyrant_libs"
-  AC_SUBST(BUILD_WITH_LIBTOKYOTYRANT_CPPFLAGS)
-  AC_SUBST(BUILD_WITH_LIBTOKYOTYRANT_LDFLAGS)
-  AC_SUBST(BUILD_WITH_LIBTOKYOTYRANT_LIBS)
 fi
-AM_CONDITIONAL(BUILD_WITH_LIBTOKYOTYRANT, test "x$with_libtokyotyrant" = "xyes")
+AC_SUBST([BUILD_WITH_LIBTOKYOTYRANT_CPPFLAGS])
+AC_SUBST([BUILD_WITH_LIBTOKYOTYRANT_LDFLAGS])
+AC_SUBST([BUILD_WITH_LIBTOKYOTYRANT_LIBS])
 # }}}
 
 # --with-libudev {{{
-with_libudev_cflags=""
-with_libudev_ldflags=""
-AC_ARG_WITH(libudev, [AS_HELP_STRING([--with-libudev@<:@=PREFIX@:>@], [Path to libudev.])],
-[
-       if test "x$withval" = "xno"
-       then
-               with_libudev="no"
-       else
-               with_libudev="yes"
-               if test "x$withval" != "xyes"
-               then
-                       with_libudev_cflags="-I$withval/include"
-                       with_libudev_ldflags="-L$withval/lib"
-                       with_libudev="yes"
-               fi
-       fi
-],
-[
-       if test "x$ac_system" = "xLinux"
-       then
-               with_libudev="yes"
-       else
-               with_libudev="no (Linux only library)"
-       fi
-])
-if test "x$with_libudev" = "xyes"
-then
-       SAVE_CPPFLAGS="$CPPFLAGS"
-       CPPFLAGS="$CPPFLAGS $with_libudev_cflags"
+AC_ARG_WITH([libudev],
+  [AS_HELP_STRING([--with-libudev@<:@=PREFIX@:>@], [Path to libudev.])],
+  [
+    if test "x$withval" = "xno" || test "x$withval" = "xyes"; then
+      with_libudev="$withval"
+    else
+      with_libudev_cppflags="-I$withval/include"
+      with_libudev_ldflags="-L$withval/lib"
+      with_libudev="yes"
+    fi
+  ],
+  [
+    if test "x$ac_system" = "xLinux"; then
+      with_libudev="yes"
+    else
+      with_libudev="no (Linux only library)"
+    fi
+  ]
+)
 
-       AC_CHECK_HEADERS(libudev.h, [], [with_libudev="no (libudev.h not found)"])
+if test "x$with_libudev" = "xyes"; then
+  SAVE_CPPFLAGS="$CPPFLAGS"
+  CPPFLAGS="$CPPFLAGS $with_libudev_cppflags"
 
-       CPPFLAGS="$SAVE_CPPFLAGS"
+  AC_CHECK_HEADERS([libudev.h],
+    [with_libudev="yes"],
+    [with_libudev="no (libudev.h not found)"]
+  )
+
+  CPPFLAGS="$SAVE_CPPFLAGS"
 fi
-if test "x$with_libudev" = "xyes"
-then
-       SAVE_CPPFLAGS="$CPPFLAGS"
-       SAVE_LDFLAGS="$LDFLAGS"
-       CPPFLAGS="$CPPFLAGS $with_libudev_cflags"
-       LDFLAGS="$LDFLAGS $with_libudev_ldflags"
 
-       AC_CHECK_LIB(udev, udev_new,
-       [
-               AC_DEFINE(HAVE_LIBUDEV, 1, [Define to 1 if you have the udev library (-ludev).])
-       ],
-       [with_libudev="no (libudev not found)"])
+if test "x$with_libudev" = "xyes"; then
+  SAVE_LDFLAGS="$LDFLAGS"
+  LDFLAGS="$LDFLAGS $with_libudev_ldflags"
 
-       CPPFLAGS="$SAVE_CPPFLAGS"
-       LDFLAGS="$SAVE_LDFLAGS"
+  AC_CHECK_LIB([udev], [udev_new],
+    [with_libudev="yes"],
+    [with_libudev="no (libudev not found)"]
+  )
+
+  LDFLAGS="$SAVE_LDFLAGS"
 fi
-if test "x$with_libudev" = "xyes"
-then
-       BUILD_WITH_LIBUDEV_CFLAGS="$with_libudev_cflags"
-       BUILD_WITH_LIBUDEV_LDFLAGS="$with_libudev_ldflags"
-       BUILD_WITH_LIBUDEV_LIBS="-ludev"
-       AC_SUBST(BUILD_WITH_LIBUDEV_CFLAGS)
-       AC_SUBST(BUILD_WITH_LIBUDEV_LDFLAGS)
-       AC_SUBST(BUILD_WITH_LIBUDEV_LIBS)
-fi
-AM_CONDITIONAL(BUILD_WITH_LIBUDEV, test "x$with_libudev" = "xyes")
+
+if test "x$with_libudev" = "xyes"; then
+  BUILD_WITH_LIBUDEV_CPPFLAGS="$with_libudev_cppflags"
+  BUILD_WITH_LIBUDEV_LDFLAGS="$with_libudev_ldflags"
+  BUILD_WITH_LIBUDEV_LIBS="-ludev"
+fi
+
+AC_SUBST([BUILD_WITH_LIBUDEV_CPPFLAGS])
+AC_SUBST([BUILD_WITH_LIBUDEV_LDFLAGS])
+AC_SUBST([BUILD_WITH_LIBUDEV_LIBS])
+
+AM_CONDITIONAL([BUILD_WITH_LIBUDEV], [test "x$with_libudev" = "xyes"])
 # }}}
 
 # --with-libupsclient {{{
 with_libupsclient_config=""
-with_libupsclient_cflags=""
-with_libupsclient_libs=""
-AC_ARG_WITH(libupsclient, [AS_HELP_STRING([--with-libupsclient@<:@=PREFIX@:>@], [Path to the upsclient library.])],
-[
-       if test "x$withval" = "xno"
-       then
-               with_libupsclient="no"
-       else if test "x$withval" = "xyes"
-       then
-               with_libupsclient="use_pkgconfig"
-       else
-               if test -x "$withval"
-               then
-                       with_libupsclient_config="$withval"
-                       with_libupsclient="use_libupsclient_config"
-               else if test -x "$withval/bin/libupsclient-config"
-               then
-                       with_libupsclient_config="$withval/bin/libupsclient-config"
-                       with_libupsclient="use_libupsclient_config"
-               else
-                       AC_MSG_NOTICE([Not checking for libupsclient: Manually configured])
-                       with_libupsclient_cflags="-I$withval/include"
-                       with_libupsclient_libs="-L$withval/lib -lupsclient"
-                       with_libupsclient="yes"
-               fi; fi
-       fi; fi
-],
-[with_libupsclient="use_pkgconfig"])
+AC_ARG_WITH([libupsclient],
+  [AS_HELP_STRING([--with-libupsclient@<:@=PREFIX@:>@], [Path to the upsclient library.])],
+  [
+    if test "x$withval" = "xno"; then
+      with_libupsclient="no"
+    else if test "x$withval" = "xyes"; then
+      with_libupsclient="use_pkgconfig"
+    else
+      if test -x "$withval"; then
+        with_libupsclient_config="$withval"
+        with_libupsclient="use_libupsclient_config"
+      else if test -x "$withval/bin/libupsclient-config"; then
+        with_libupsclient_config="$withval/bin/libupsclient-config"
+        with_libupsclient="use_libupsclient_config"
+      else
+        AC_MSG_NOTICE([Not checking for libupsclient: Manually configured])
+        with_libupsclient_cflags="-I$withval/include"
+        with_libupsclient_libs="-L$withval/lib -lupsclient"
+        with_libupsclient="yes"
+      fi; fi
+    fi; fi
+  ],
+  [with_libupsclient="use_pkgconfig"]
+)
 
 # configure using libupsclient-config
-if test "x$with_libupsclient" = "xuse_libupsclient_config"
-then
-       AC_MSG_NOTICE([Checking for libupsclient using $with_libupsclient_config])
-       with_libupsclient_cflags="`$with_libupsclient_config --cflags`"
-       if test $? -ne 0
-       then
-               with_libupsclient="no ($with_libupsclient_config failed)"
-       fi
-       with_libupsclient_libs="`$with_libupsclient_config --libs`"
-       if test $? -ne 0
-       then
-               with_libupsclient="no ($with_libupsclient_config failed)"
-       fi
+if test "x$with_libupsclient" = "xuse_libupsclient_config"; then
+  with_libupsclient_cflags="`$with_libupsclient_config --cflags`"
+  if test $? -ne 0; then
+    with_libupsclient="no ($with_libupsclient_config failed)"
+  fi
+  with_libupsclient_libs="`$with_libupsclient_config --libs`"
+  if test $? -ne 0; then
+    with_libupsclient="no ($with_libupsclient_config failed)"
+  fi
 fi
-if test "x$with_libupsclient" = "xuse_libupsclient_config"
-then
-       with_libupsclient="yes"
+
+if test "x$with_libupsclient" = "xuse_libupsclient_config"; then
+  with_libupsclient="yes"
 fi
 
 # configure using pkg-config
-if test "x$with_libupsclient" = "xuse_pkgconfig"
-then
-       AC_MSG_NOTICE([Checking for libupsclient using $PKG_CONFIG])
-       $PKG_CONFIG --exists 'libupsclient' 2>/dev/null
-       if test $? -ne 0
-       then
-               with_libupsclient="no (pkg-config doesn't know libupsclient)"
-       fi
+if test "x$with_libupsclient" = "xuse_pkgconfig"; then
+  AC_MSG_NOTICE([Checking for libupsclient using $PKG_CONFIG])
+  $PKG_CONFIG --exists 'libupsclient' 2>/dev/null
+  if test $? -ne 0; then
+    with_libupsclient="no (pkg-config doesn't know libupsclient)"
+  fi
 fi
-if test "x$with_libupsclient" = "xuse_pkgconfig"
-then
-       with_libupsclient_cflags="`$PKG_CONFIG --cflags 'libupsclient'`"
-       if test $? -ne 0
-       then
-               with_libupsclient="no ($PKG_CONFIG failed)"
-       fi
-       with_libupsclient_libs="`$PKG_CONFIG --libs 'libupsclient'`"
-       if test $? -ne 0
-       then
-               with_libupsclient="no ($PKG_CONFIG failed)"
-       fi
+
+if test "x$with_libupsclient" = "xuse_pkgconfig"; then
+  with_libupsclient_cflags="`$PKG_CONFIG --cflags 'libupsclient'`"
+  if test $? -ne 0; then
+    with_libupsclient="no ($PKG_CONFIG failed)"
+  fi
+
+  with_libupsclient_libs="`$PKG_CONFIG --libs 'libupsclient'`"
+  if test $? -ne 0; then
+    with_libupsclient="no ($PKG_CONFIG failed)"
+  fi
 fi
-if test "x$with_libupsclient" = "xuse_pkgconfig"
-then
-       with_libupsclient="yes"
+
+if test "x$with_libupsclient" = "xuse_pkgconfig"; then
+  with_libupsclient="yes"
 fi
 
-# with_libupsclient_cflags and with_libupsclient_libs are set up now, let's do
-# the actual checks.
-if test "x$with_libupsclient" = "xyes"
-then
-       SAVE_CPPFLAGS="$CPPFLAGS"
-       CPPFLAGS="$CPPFLAGS $with_libupsclient_cflags"
+if test "x$with_libupsclient" = "xyes"; then
+  SAVE_CPPFLAGS="$CPPFLAGS"
+  CPPFLAGS="$CPPFLAGS $with_libupsclient_cflags"
 
-       AC_CHECK_HEADERS(upsclient.h, [], [with_libupsclient="no (upsclient.h not found)"])
+  AC_CHECK_HEADERS([upsclient.h],
+    [with_libupsclient="yes"],
+    [with_libupsclient="no (upsclient.h not found)"]
+  )
 
-       CPPFLAGS="$SAVE_CPPFLAGS"
+  CPPFLAGS="$SAVE_CPPFLAGS"
 fi
-if test "x$with_libupsclient" = "xyes"
-then
-       SAVE_CPPFLAGS="$CPPFLAGS"
-       SAVE_LDFLAGS="$LDFLAGS"
 
-       CPPFLAGS="$CPPFLAGS $with_libupsclient_cflags"
-       LDFLAGS="$LDFLAGS $with_libupsclient_libs"
+if test "x$with_libupsclient" = "xyes"; then
+  SAVE_LDFLAGS="$LDFLAGS"
+  LDFLAGS="$LDFLAGS $with_libupsclient_libs"
 
-       AC_CHECK_LIB(upsclient, upscli_connect,
-                    [with_libupsclient="yes"],
-                    [with_libupsclient="no (symbol upscli_connect not found)"])
+  AC_CHECK_LIB([upsclient], [upscli_connect],
+    [with_libupsclient="yes"],
+    [with_libupsclient="no (symbol upscli_connect not found)"]
+  )
 
-       CPPFLAGS="$SAVE_CPPFLAGS"
-       LDFLAGS="$SAVE_LDFLAGS"
+  LDFLAGS="$SAVE_LDFLAGS"
 fi
-if test "x$with_libupsclient" = "xyes"
-then
-       SAVE_CPPFLAGS="$CPPFLAGS"
-       CPPFLAGS="$CPPFLAGS $with_libupsclient_cflags"
 
-       AC_CHECK_TYPES([UPSCONN_t, UPSCONN], [], [],
-[#include <stdlib.h>
-#include <stdio.h>
-#include <upsclient.h>])
+if test "x$with_libupsclient" = "xyes"; then
+  SAVE_CPPFLAGS="$CPPFLAGS"
+  CPPFLAGS="$CPPFLAGS $with_libupsclient_cflags"
 
-       CPPFLAGS="$SAVE_CPPFLAGS"
+  AC_CHECK_TYPES([UPSCONN_t, UPSCONN],
+    [],
+    [],
+    [[
+      #include <stdlib.h>
+      #include <stdio.h>
+      #include <upsclient.h>
+    ]]
+  )
+
+  CPPFLAGS="$SAVE_CPPFLAGS"
 fi
-if test "x$with_libupsclient" = "xyes"
-then
-       BUILD_WITH_LIBUPSCLIENT_CFLAGS="$with_libupsclient_cflags"
-       BUILD_WITH_LIBUPSCLIENT_LIBS="$with_libupsclient_libs"
-       AC_SUBST(BUILD_WITH_LIBUPSCLIENT_CFLAGS)
-       AC_SUBST(BUILD_WITH_LIBUPSCLIENT_LIBS)
+
+if test "x$with_libupsclient" = "xyes"; then
+  BUILD_WITH_LIBUPSCLIENT_CFLAGS="$with_libupsclient_cflags"
+  BUILD_WITH_LIBUPSCLIENT_LIBS="$with_libupsclient_libs"
 fi
+
+AC_SUBST([BUILD_WITH_LIBUPSCLIENT_CFLAGS])
+AC_SUBST([BUILD_WITH_LIBUPSCLIENT_LIBS])
 # }}}
 
 # --with-libxenctrl {{{
-with_libxenctrl_cppflags=""
-with_libxenctrl_ldflags=""
-AC_ARG_WITH(libxenctrl, [AS_HELP_STRING([--with-libxenctrl@<:@=PREFIX@:>@], [Path to libxenctrl.])],
-[
-       if test "x$withval" != "xno" && test "x$withval" != "xyes"
-       then
-               with_libxenctrl_cppflags="-I$withval/include"
-               with_libxenctrl_ldflags="-L$withval/lib"
-               with_libxenctrl="yes"
-       else
-               with_libxenctrl="$withval"
-       fi
-],
-[
-       with_libxenctrl="yes"
-])
-if test "x$with_libxenctrl" = "xyes"
-then
-       SAVE_CPPFLAGS="$CPPFLAGS"
-       CPPFLAGS="$CPPFLAGS $with_libxenctrl_cppflags"
+AC_ARG_WITH([libxenctrl],
+  [AS_HELP_STRING([--with-libxenctrl@<:@=PREFIX@:>@], [Path to libxenctrl.])],
+  [
+    if test "x$withval" != "xno" && test "x$withval" != "xyes"; then
+      with_libxenctrl_cppflags="-I$withval/include"
+      with_libxenctrl_ldflags="-L$withval/lib"
+      with_libxenctrl="yes"
+    else
+      with_libxenctrl="$withval"
+    fi
+  ],
+  [with_libxenctrl="yes"]
+)
 
-       AC_CHECK_HEADERS(xenctrl.h, [with_libxenctrl="yes"], [with_libxenctrl="no (xenctrl.h not found)"])
+if test "x$with_libxenctrl" = "xyes"; then
+  SAVE_CPPFLAGS="$CPPFLAGS"
+  CPPFLAGS="$CPPFLAGS $with_libxenctrl_cppflags"
 
-       CPPFLAGS="$SAVE_CPPFLAGS"
+  AC_CHECK_HEADERS([xenctrl.h],
+    [with_libxenctrl="yes"],
+    [with_libxenctrl="no (xenctrl.h not found)"]
+  )
+
+  CPPFLAGS="$SAVE_CPPFLAGS"
 fi
-if test "x$with_libxenctrl" = "xyes"
-then
-       SAVE_CPPFLAGS="$CPPFLAGS"
-       SAVE_LDFLAGS="$LDFLAGS"
-       CPPFLAGS="$CPPFLAGS $with_libxenctrl_cppflags"
-       LDFLAGS="$LDFLAGS $with_libxenctrl_ldflags"
 
-       #Xen versions older than 3.4 has no xc_getcpuinfo()
-       AC_CHECK_LIB(xenctrl, xc_getcpuinfo, [with_libxenctrl="yes"], [with_libxenctrl="no (symbol 'xc_getcpuinfo' not found)"], [])
+if test "x$with_libxenctrl" = "xyes"; then
+  SAVE_LDFLAGS="$LDFLAGS"
+  LDFLAGS="$LDFLAGS $with_libxenctrl_ldflags"
 
-       CPPFLAGS="$SAVE_CPPFLAGS"
-       LDFLAGS="$SAVE_LDFLAGS"
-       LIBXENCTL_CPPFLAGS="$with_libxenctl_cppflags"
-       LIBXENCTL_LDFLAGS="$with_libxenctl_ldflags"
-       AC_SUBST(LIBXENCTL_CPPFLAGS)
-       AC_SUBST(LIBXENCTL_LDFLAGS)
+  #Xen versions older than 3.4 has no xc_getcpuinfo()
+  AC_CHECK_LIB([xenctrl], [xc_getcpuinfo],
+    [with_libxenctrl="yes"],
+    [with_libxenctrl="no (symbol 'xc_getcpuinfo' not found)"]
+  )
+
+  LDFLAGS="$SAVE_LDFLAGS"
 fi
+
+LIBXENCTL_CPPFLAGS="$with_libxenctl_cppflags"
+LIBXENCTL_LDFLAGS="$with_libxenctl_ldflags"
+AC_SUBST([LIBXENCTL_CPPFLAGS])
+AC_SUBST([LIBXENCTL_LDFLAGS])
 # }}}
 
 # --with-libxmms {{{
 with_xmms_config="xmms-config"
-with_xmms_cflags=""
-with_xmms_libs=""
-AC_ARG_WITH(libxmms, [AS_HELP_STRING([--with-libxmms@<:@=PREFIX@:>@], [Path to libxmms.])],
-[
-       if test "x$withval" != "xno" \
-               && test "x$withval" != "xyes"
-       then
-               if test -f "$withval" && test -x "$withval";
-               then
-                       with_xmms_config="$withval"
-               else if test -x "$withval/bin/xmms-config"
-               then
-                       with_xmms_config="$withval/bin/xmms-config"
-               fi; fi
-               with_libxmms="yes"
-       else if test "x$withval" = "xno"
-       then
-               with_libxmms="no"
-       else
-               with_libxmms="yes"
-       fi; fi
-],
-[
-       with_libxmms="yes"
-])
-if test "x$with_libxmms" = "xyes"
-then
-       with_xmms_cflags=`$with_xmms_config --cflags 2>/dev/null`
-       xmms_config_status=$?
+AC_ARG_WITH([libxmms],
+  [AS_HELP_STRING([--with-libxmms@<:@=PREFIX@:>@], [Path to libxmms.])],
+  [
+    if test "x$withval" = "xno" || test "x$withval" = "xyes"; then
+      with_libxmms="$withval"
+    else
+      if test -f "$withval" && test -x "$withval"; then
+        with_xmms_config="$withval"
+      else if test -x "$withval/bin/xmms-config"; then
+        with_xmms_config="$withval/bin/xmms-config"
+      fi; fi
+      with_libxmms="yes"
+    fi
+  ],
+  [with_libxmms="yes"]
+)
 
-       if test $xmms_config_status -ne 0
-       then
-               with_libxmms="no"
-       fi
+if test "x$with_libxmms" = "xyes"; then
+  with_xmms_cflags=`$with_xmms_config --cflags 2>/dev/null`
+  if test $? -ne 0; then
+    with_libxmms="no"
+  fi
 fi
-if test "x$with_libxmms" = "xyes"
-then
-       with_xmms_libs=`$with_xmms_config --libs 2>/dev/null`
-       xmms_config_status=$?
 
-       if test $xmms_config_status -ne 0
-       then
-               with_libxmms="no"
-       fi
+if test "x$with_libxmms" = "xyes"; then
+  with_xmms_libs=`$with_xmms_config --libs 2>/dev/null`
+  if test $? -ne 0; then
+    with_libxmms="no"
+  fi
 fi
-if test "x$with_libxmms" = "xyes"
-then
-       AC_CHECK_LIB(xmms, xmms_remote_get_info,
-       [
-               BUILD_WITH_LIBXMMS_CFLAGS="$with_xmms_cflags"
-               BUILD_WITH_LIBXMMS_LIBS="$with_xmms_libs"
-               AC_SUBST(BUILD_WITH_LIBXMMS_CFLAGS)
-               AC_SUBST(BUILD_WITH_LIBXMMS_LIBS)
-       ],
-       [
-               with_libxmms="no"
-       ],
-       [$with_xmms_libs])
-fi
-with_libxmms_numeric=0
-if test "x$with_libxmms" = "xyes"
-then
-       with_libxmms_numeric=1
+
+if test "x$with_libxmms" = "xyes"; then
+  SAVE_CFLAGS="$CFLAGS"
+  CFLAGS="$with_xmms_cflags"
+
+  AC_CHECK_HEADER([xmmsctrl.h],
+    [with_libxmms="yes"],
+    [with_libxmms="no"],
+  )
+
+  CFLAGS="$SAVE_CFLAGS"
 fi
-AC_DEFINE_UNQUOTED(HAVE_LIBXMMS, [$with_libxmms_numeric], [Define to 1 if you have the 'xmms' library (-lxmms).])
-AM_CONDITIONAL(BUILD_WITH_LIBXMMS, test "x$with_libxmms" = "xyes")
+
+if test "x$with_libxmms" = "xyes"; then
+  SAVE_LIBS="$LIBS"
+  LIBS="$with_xmms_libs"
+
+  AC_CHECK_LIB([xmms], [xmms_remote_get_info],
+    [with_libxmss="yes"],
+    [with_libxmms="no"],
+    [$with_xmms_libs]
+
+  )
+
+  LIBS="$SAVE_LIBS"
+fi
+
+BUILD_WITH_LIBXMMS_CFLAGS="$with_xmms_cflags"
+BUILD_WITH_LIBXMMS_LIBS="$with_xmms_libs"
+
+AC_SUBST([BUILD_WITH_LIBXMMS_CFLAGS])
+AC_SUBST([BUILD_WITH_LIBXMMS_LIBS])
 # }}}
 
 # --with-libyajl {{{
-with_libyajl_cppflags=""
-with_libyajl_ldflags=""
-AC_ARG_WITH(libyajl, [AS_HELP_STRING([--with-libyajl@<:@=PREFIX@:>@], [Path to libyajl.])],
-[
-       if test "x$withval" != "xno" && test "x$withval" != "xyes"
-       then
-               with_libyajl_cppflags="-I$withval/include"
-               with_libyajl_ldflags="-L$withval/lib"
-               with_libyajl="yes"
-       else
-               with_libyajl="$withval"
-       fi
-],
-[
-       with_libyajl="yes"
-])
-if test "x$with_libyajl" = "xyes"
-then
-       SAVE_CPPFLAGS="$CPPFLAGS"
-       CPPFLAGS="$CPPFLAGS $with_libyajl_cppflags"
+AC_ARG_WITH([libyajl],
+  [AS_HELP_STRING([--with-libyajl@<:@=PREFIX@:>@], [Path to libyajl.])],
+  [
+    if test "x$withval" != "xno" && test "x$withval" != "xyes"; then
+      with_libyajl_cppflags="-I$withval/include"
+      with_libyajl_ldflags="-L$withval/lib"
+      with_libyajl="yes"
+    else
+      with_libyajl="$withval"
+    fi
+  ],
+  [with_libyajl="yes"]
+)
 
-       AC_CHECK_HEADERS(yajl/yajl_parse.h, [with_libyajl="yes"], [with_libyajl="no (yajl/yajl_parse.h not found)"])
-       AC_CHECK_HEADERS(yajl/yajl_version.h)
+if test "x$with_libyajl" = "xyes"; then
+  SAVE_CPPFLAGS="$CPPFLAGS"
+  CPPFLAGS="$CPPFLAGS $with_libyajl_cppflags"
 
-       CPPFLAGS="$SAVE_CPPFLAGS"
+  AC_CHECK_HEADERS([yajl/yajl_parse.h],
+    [with_libyajl="yes"],
+    [with_libyajl="no (yajl/yajl_parse.h not found)"]
+  )
+
+  AC_CHECK_HEADERS([yajl/yajl_version.h])
+
+  CPPFLAGS="$SAVE_CPPFLAGS"
 fi
-if test "x$with_libyajl" = "xyes"
-then
-       SAVE_CPPFLAGS="$CPPFLAGS"
-       SAVE_LDFLAGS="$LDFLAGS"
-       CPPFLAGS="$CPPFLAGS $with_libyajl_cppflags"
-       LDFLAGS="$LDFLAGS $with_libyajl_ldflags"
 
-       AC_CHECK_LIB(yajl, yajl_alloc, [with_libyajl="yes"], [with_libyajl="no (Symbol 'yajl_alloc' not found)"])
+if test "x$with_libyajl" = "xyes"; then
+  SAVE_LDFLAGS="$LDFLAGS"
+  LDFLAGS="$LDFLAGS $with_libyajl_ldflags"
 
-       CPPFLAGS="$SAVE_CPPFLAGS"
-       LDFLAGS="$SAVE_LDFLAGS"
+  AC_CHECK_LIB([yajl], [yajl_alloc],
+    [with_libyajl="yes"],
+    [with_libyajl="no (Symbol 'yajl_alloc' not found)"]
+  )
+
+  LDFLAGS="$SAVE_LDFLAGS"
 fi
-if test "x$with_libyajl" = "xyes"
-then
-       BUILD_WITH_LIBYAJL_CPPFLAGS="$with_libyajl_cppflags"
-       BUILD_WITH_LIBYAJL_LDFLAGS="$with_libyajl_ldflags"
-       BUILD_WITH_LIBYAJL_LIBS="-lyajl"
-       AC_SUBST(BUILD_WITH_LIBYAJL_CPPFLAGS)
-       AC_SUBST(BUILD_WITH_LIBYAJL_LDFLAGS)
-       AC_SUBST(BUILD_WITH_LIBYAJL_LIBS)
-       AC_DEFINE(HAVE_LIBYAJL, 1, [Define if libyajl is present and usable.])
-fi
-AM_CONDITIONAL(BUILD_WITH_LIBYAJL, test "x$with_libyajl" = "xyes")
+
+if test "x$with_libyajl" = "xyes"; then
+  BUILD_WITH_LIBYAJL_CPPFLAGS="$with_libyajl_cppflags"
+  BUILD_WITH_LIBYAJL_LDFLAGS="$with_libyajl_ldflags"
+  BUILD_WITH_LIBYAJL_LIBS="-lyajl"
+  AC_DEFINE([HAVE_LIBYAJL], [1], [Define if libyajl is present and usable.])
+fi
+
+AC_SUBST([BUILD_WITH_LIBYAJL_CPPFLAGS])
+AC_SUBST([BUILD_WITH_LIBYAJL_LDFLAGS])
+AC_SUBST([BUILD_WITH_LIBYAJL_LIBS])
+
+AM_CONDITIONAL([BUILD_WITH_LIBYAJL], [test "x$with_libyajl" = "xyes"])
 # }}}
 
 # --with-mic {{{
-with_mic_cflags="-I/opt/intel/mic/sysmgmt/sdk/include"
-with_mic_ldpath="-L/opt/intel/mic/sysmgmt/sdk/lib/Linux"
-with_mic_libs=""
-AC_ARG_WITH(mic,[AS_HELP_STRING([--with-mic@<:@=PREFIX@:>@], [Path to Intel MIC Access API.])],
-[
-       if test "x$withval" = "xno"
-       then
-               with_mic="no"
-       else if test "x$withval" = "xyes"
-       then
-               with_mic="yes"
-       else if test -d "$with_mic/lib"
-       then
-               AC_MSG_NOTICE([Not checking for Intel Mic: Manually configured])
-               with_mic_cflags="-I$withval/include"
-               with_mic_ldpath="-L$withval/lib/Linux"
-               with_mic_libs="$PTHREAD_LIBS -lMicAccessSDK -lscif"
-               with_mic="yes"
-       fi; fi; fi
-],
-[with_mic="yes"])
-if test "x$with_mic" = "xyes"
-then
-       SAVE_CPPFLAGS="$CPPFLAGS"
-       CPPFLAGS="$CPPFLAGS $with_mic_cflags"
-       AC_CHECK_HEADERS(MicAccessApi.h,[],[with_mic="no (MicAccessApi not found)"])
-       CPPFLAGS="$SAVE_CPPFLAGS"
+with_mic_cppflags="-I/opt/intel/mic/sysmgmt/sdk/include"
+with_mic_ldflags="-L/opt/intel/mic/sysmgmt/sdk/lib/Linux"
+with_mic_libs="-lMicAccessSDK -scif"
+AC_ARG_WITH([mic],
+  [AS_HELP_STRING([--with-mic@<:@=PREFIX@:>@], [Path to Intel MIC Access API.])],
+  [
+    if test "x$withval" = "xno" || test "x$withval" = "xyes"; then
+      with_mic="$withval"
+    else if test -d "$with_mic/lib"; then
+      with_mic_cppflags="-I$withval/include"
+      with_mic_ldflags="-L$withval/lib/Linux"
+      with_mic="yes"
+    fi; fi
+  ],
+  [with_mic="yes"]
+)
+
+if test "x$with_mic" = "xyes"; then
+  SAVE_CPPFLAGS="$CPPFLAGS"
+  CPPFLAGS="$CPPFLAGS $with_mic_cppflags"
+
+  AC_CHECK_HEADERS([MicAccessApi.h],
+    [with_mic="yes"],
+    [with_mic="no (MicAccessApi not found)"]
+  )
+
+  CPPFLAGS="$SAVE_CPPFLAGS"
 fi
-if test "x$with_mic" = "xyes"
-then
-       SAVE_CPPFLAGS="$CPPFLAGS"
-       SAVE_LDFLAGS="$LDFLAGS"
 
-       CPPFLAGS="$CPPFLAGS $with_mic_cflags"
-       LDFLAGS="$LDFLAGS $with_mic_ldpath"
+if test "x$with_mic" = "xyes"; then
+  SAVE_LDFLAGS="$LDFLAGS"
+  LDFLAGS="$LDFLAGS $with_mic_ldflags"
 
-       AC_CHECK_LIB(MicAccessSDK, MicInitAPI,
-                       [with_mic_ldpath="$with_mic_ldpath"
-                       with_mic_libs="$PTHREAD_LIBS -lMicAccessSDK -lscif"],
-                       [with_mic="no (symbol MicInitAPI not found)"],[$PTHREAD_LIBS -lscif])
+  AC_CHECK_LIB([MicAccessSDK], [MicInitAPI],
+    [with_mic="yes"],
+    [with_mic="no (symbol MicInitAPI not found)"],
+    [$PTHREAD_LIBS -lscif]
+  )
 
-       CPPFLAGS="$SAVE_CPPFLAGS"
-       LDFLAGS="$SAVE_LDFLAGS"
+  LDFLAGS="$SAVE_LDFLAGS"
 fi
 
-if test "x$with_mic" = "xyes"
-then
-       BUILD_WITH_MIC_CPPFLAGS="$with_mic_cflags"
-       BUILD_WITH_MIC_LIBPATH="$with_mic_ldpath"
-       BUILD_WITH_MIC_LDADD="$with_mic_libs"
-       AC_SUBST(BUILD_WITH_MIC_CPPFLAGS)
-       AC_SUBST(BUILD_WITH_MIC_LIBPATH)
-       AC_SUBST(BUILD_WITH_MIC_LDADD)
+if test "x$with_mic" = "xyes"; then
+  BUILD_WITH_MIC_CPPFLAGS="$with_mic_cppflags"
+  BUILD_WITH_MIC_LDFLAGS="$with_mic_ldflags"
+  BUILD_WITH_MIC_LIBS="$with_mic_libs"
 fi
+AC_SUBST([BUILD_WITH_MIC_CPPFLAGS])
+AC_SUBST([BUILD_WITH_MIC_LDFLAGS])
+AC_SUBST([BUILD_WITH_MIC_LIBS])
 #}}}
 
 # --with-libvarnish {{{
-with_libvarnish_cppflags=""
-with_libvarnish_cflags=""
-with_libvarnish_libs=""
-AC_ARG_WITH(libvarnish, [AS_HELP_STRING([--with-libvarnish@<:@=PREFIX@:>@], [Path to libvarnish.])],
-[
-       if test "x$withval" = "xno"
-       then
-               with_libvarnish="no"
-       else if test "x$withval" = "xyes"
-       then
-               with_libvarnish="use_pkgconfig"
-       else if test -d "$with_libvarnish/lib"
-       then
-               AC_MSG_NOTICE([Not checking for libvarnish: Manually configured])
-               with_libvarnish_cflags="-I$withval/include"
-               with_libvarnish_libs="-L$withval/lib -lvarnishapi"
-               with_libvarnish="yes"
-       fi; fi; fi
-],
-[with_libvarnish="use_pkgconfig"])
+AC_ARG_WITH([libvarnish],
+  [AS_HELP_STRING([--with-libvarnish@<:@=PREFIX@:>@], [Path to libvarnish.])],
+  [
+    if test "x$withval" = "xno"; then
+      with_libvarnish="no"
+    else if test "x$withval" = "xyes"; then
+      with_libvarnish="use_pkgconfig"
+    else if test -d "$with_libvarnish/lib"; then
+      with_libvarnish_cflags="-I$withval/include"
+      with_libvarnish_libs="-L$withval/lib -lvarnishapi"
+      with_libvarnish="yes"
+    fi; fi; fi
+  ],
+  [with_libvarnish="use_pkgconfig"]
+)
 
 # configure using pkg-config
-if test "x$with_libvarnish" = "xuse_pkgconfig"
-then
-       AC_MSG_NOTICE([Checking for varnishapi using $PKG_CONFIG])
-       $PKG_CONFIG --exists 'varnishapi' 2>/dev/null
-       if test $? -ne 0
-       then
-               with_libvarnish="no (pkg-config doesn't know varnishapi)"
-       fi
+if test "x$with_libvarnish" = "xuse_pkgconfig"; then
+  $PKG_CONFIG --exists 'varnishapi' 2>/dev/null
+  if test $? -ne 0; then
+    with_libvarnish="no (pkg-config doesn't know varnishapi)"
+  fi
 fi
-if test "x$with_libvarnish" = "xuse_pkgconfig"
-then
-       with_libvarnish_cflags="`$PKG_CONFIG --cflags 'varnishapi'`"
-       if test $? -ne 0
-       then
-               with_libvarnish="no ($PKG_CONFIG failed)"
-       fi
-       with_libvarnish_libs="`$PKG_CONFIG --libs 'varnishapi'`"
-       if test $? -ne 0
-       then
-               with_libvarnish="no ($PKG_CONFIG failed)"
-       fi
+
+if test "x$with_libvarnish" = "xuse_pkgconfig"; then
+  with_libvarnish_cflags="`$PKG_CONFIG --cflags 'varnishapi'`"
+  if test $? -ne 0; then
+    with_libvarnish="no ($PKG_CONFIG failed)"
+  fi
+
+  with_libvarnish_libs="`$PKG_CONFIG --libs 'varnishapi'`"
+  if test $? -ne 0; then
+    with_libvarnish="no ($PKG_CONFIG failed)"
+  fi
 fi
-if test "x$with_libvarnish" = "xuse_pkgconfig"
-then
-       with_libvarnish="yes"
+if test "x$with_libvarnish" = "xuse_pkgconfig"; then
+  with_libvarnish="yes"
 fi
 
-# with_libvarnish_cflags and with_libvarnish_libs are set up now, let's do
-# the actual checks.
-if test "x$with_libvarnish" = "xyes"
-then
-       SAVE_CPPFLAGS="$CPPFLAGS"
-
-       CPPFLAGS="$CPPFLAGS $with_libvarnish_cflags"
+if test "x$with_libvarnish" = "xyes"; then
+  SAVE_CPPFLAGS="$CPPFLAGS"
+  CPPFLAGS="$CPPFLAGS $with_libvarnish_cflags"
 
-       AC_CHECK_HEADERS(vapi/vsc.h,
-               [AC_DEFINE([HAVE_VARNISH_V4], [1], [Varnish 4 API support])],
-               [AC_CHECK_HEADERS(vsc.h,
-                       [AC_DEFINE([HAVE_VARNISH_V3], [1], [Varnish 3 API support])],
-                       [AC_CHECK_HEADERS(varnishapi.h,
-                               [AC_DEFINE([HAVE_VARNISH_V2], [1], [Varnish 2 API support])],
-                               [with_libvarnish="no (found none of the varnish header files)"])])])
+  AC_CHECK_HEADERS([vapi/vsc.h],
+    [AC_DEFINE([HAVE_VARNISH_V4], [1], [Varnish 4 API support])],
+    [
+      AC_CHECK_HEADERS([vsc.h],
+        [AC_DEFINE([HAVE_VARNISH_V3], [1], [Varnish 3 API support]) ],
+        [
+          AC_CHECK_HEADERS([varnishapi.h],
+            [AC_DEFINE([HAVE_VARNISH_V2], [1], [Varnish 2 API support])],
+            [with_libvarnish="no (found none of the varnish header files)"]
+          )
+        ]
+      )
+    ]
+  )
 
-       CPPFLAGS="$SAVE_CPPFLAGS"
+  CPPFLAGS="$SAVE_CPPFLAGS"
 fi
-if test "x$with_libvarnish" = "xyes"
-then
-       BUILD_WITH_LIBVARNISH_CFLAGS="$with_libvarnish_cflags"
-       BUILD_WITH_LIBVARNISH_LIBS="$with_libvarnish_libs"
-       AC_SUBST(BUILD_WITH_LIBVARNISH_CFLAGS)
-       AC_SUBST(BUILD_WITH_LIBVARNISH_LIBS)
+
+if test "x$with_libvarnish" = "xyes"; then
+  BUILD_WITH_LIBVARNISH_CFLAGS="$with_libvarnish_cflags"
+  BUILD_WITH_LIBVARNISH_LIBS="$with_libvarnish_libs"
 fi
+
+AC_SUBST([BUILD_WITH_LIBVARNISH_CFLAGS])
+AC_SUBST([BUILD_WITH_LIBVARNISH_LIBS])
 # }}}
 
 # pkg-config --exists 'libxml-2.0'; pkg-config --exists libvirt {{{
-with_libxml2="no (pkg-config isn't available)"
-with_libxml2_cflags=""
-with_libxml2_ldflags=""
-with_libvirt="no (pkg-config isn't available)"
-with_libvirt_cflags=""
-with_libvirt_ldflags=""
 $PKG_CONFIG --exists 'libxml-2.0' 2>/dev/null
-if test "$?" = "0"
-then
-       with_libxml2="yes"
+if test $? -eq 0; then
+  with_libxml2="yes"
 else
-       with_libxml2="no (pkg-config doesn't know libxml-2.0)"
+  with_libxml2="no (pkg-config doesn't know libxml-2.0)"
 fi
 
 $PKG_CONFIG --exists libvirt 2>/dev/null
-if test "$?" = "0"
-then
-       with_libvirt="yes"
+if test $? = 0; then
+  with_libvirt="yes"
 else
-       with_libvirt="no (pkg-config doesn't know libvirt)"
+  with_libvirt="no (pkg-config doesn't know libvirt)"
 fi
-if test "x$with_libxml2" = "xyes"
-then
-       with_libxml2_cflags="`$PKG_CONFIG --cflags libxml-2.0`"
-       if test $? -ne 0
-       then
-               with_libxml2="no"
-       fi
-       with_libxml2_ldflags="`$PKG_CONFIG --libs libxml-2.0`"
-       if test $? -ne 0
-       then
-               with_libxml2="no"
-       fi
+
+if test "x$with_libxml2" = "xyes"; then
+  with_libxml2_cflags="`$PKG_CONFIG --cflags libxml-2.0`"
+  if test $? -ne 0; then
+    with_libxml2="no"
+  fi
+
+  with_libxml2_ldflags="`$PKG_CONFIG --libs libxml-2.0`"
+  if test $? -ne 0; then
+    with_libxml2="no"
+  fi
 fi
-if test "x$with_libxml2" = "xyes"
-then
-       SAVE_CPPFLAGS="$CPPFLAGS"
-       CPPFLAGS="$CPPFLAGS $with_libxml2_cflags"
 
-       AC_CHECK_HEADERS(libxml/parser.h, [],
-                     [with_libxml2="no (libxml/parser.h not found)"])
+if test "x$with_libxml2" = "xyes"; then
+  SAVE_CPPFLAGS="$CPPFLAGS"
+  CPPFLAGS="$CPPFLAGS $with_libxml2_cflags"
 
-       CPPFLAGS="$SAVE_CPPFLAGS"
+  AC_CHECK_HEADERS([libxml/parser.h],
+    [with_libxml2="yes"],
+    [with_libxml2="no (libxml/parser.h not found)"]
+  )
+
+  CPPFLAGS="$SAVE_CPPFLAGS"
 fi
-if test "x$with_libxml2" = "xyes"
-then
-       SAVE_CFLAGS="$CFLAGS"
-       SAVE_LDFLAGS="$LDFLAGS"
 
-       CFLAGS="$CFLAGS $with_libxml2_cflags"
-       LDFLAGS="$LDFLAGS $with_libxml2_ldflags"
+if test "x$with_libxml2" = "xyes"; then
+  SAVE_LDFLAGS="$LDFLAGS"
+  LDFLAGS="$LDFLAGS $with_libxml2_ldflags"
 
-       AC_CHECK_LIB(xml2, xmlXPathEval,
-                    [with_libxml2="yes"],
-                    [with_libxml2="no (symbol xmlXPathEval not found)"])
+  AC_CHECK_LIB([xml2], [xmlXPathEval],
+    [with_libxml2="yes"],
+    [with_libxml2="no (symbol xmlXPathEval not found)"]
+  )
 
-       CFLAGS="$SAVE_CFLAGS"
-       LDFLAGS="$SAVE_LDFLAGS"
+  LDFLAGS="$SAVE_LDFLAGS"
 fi
-dnl Add the right compiler flags and libraries.
+
 if test "x$with_libxml2" = "xyes"; then
-       BUILD_WITH_LIBXML2_CFLAGS="$with_libxml2_cflags"
-       BUILD_WITH_LIBXML2_LIBS="$with_libxml2_ldflags"
-       AC_SUBST(BUILD_WITH_LIBXML2_CFLAGS)
-       AC_SUBST(BUILD_WITH_LIBXML2_LIBS)
+  BUILD_WITH_LIBXML2_CFLAGS="$with_libxml2_cflags"
+  BUILD_WITH_LIBXML2_LIBS="$with_libxml2_ldflags"
 fi
-if test "x$with_libvirt" = "xyes"
-then
-       with_libvirt_cflags="`$PKG_CONFIG --cflags libvirt`"
-       if test $? -ne 0
-       then
-               with_libvirt="no"
-       fi
-       with_libvirt_ldflags="`$PKG_CONFIG --libs libvirt`"
-       if test $? -ne 0
-       then
-               with_libvirt="no"
-       fi
+
+AC_SUBST([BUILD_WITH_LIBXML2_CFLAGS])
+AC_SUBST([BUILD_WITH_LIBXML2_LIBS])
+
+if test "x$with_libvirt" = "xyes"; then
+  with_libvirt_cflags="`$PKG_CONFIG --cflags libvirt`"
+  if test $? -ne 0; then
+    with_libvirt="no"
+  fi
+
+  with_libvirt_ldflags="`$PKG_CONFIG --libs libvirt`"
+  if test $? -ne 0; then
+    with_libvirt="no"
+  fi
 fi
-if test "x$with_libvirt" = "xyes"
-then
-       SAVE_CPPFLAGS="$CPPFLAGS"
-       CPPFLAGS="$CPPFLAGS $with_libvirt_cflags"
 
-       AC_CHECK_HEADERS(libvirt/libvirt.h, [],
-                     [with_libvirt="no (libvirt/libvirt.h not found)"])
+if test "x$with_libvirt" = "xyes"; then
+  SAVE_CPPFLAGS="$CPPFLAGS"
+  CPPFLAGS="$CPPFLAGS $with_libvirt_cflags"
 
-       CPPFLAGS="$SAVE_CPPFLAGS"
+  AC_CHECK_HEADERS([libvirt/libvirt.h],
+    [with_libvirt="yes"],
+    [with_libvirt="no (libvirt/libvirt.h not found)"]
+  )
+
+  CPPFLAGS="$SAVE_CPPFLAGS"
 fi
-if test "x$with_libvirt" = "xyes"
-then
-       SAVE_CFLAGS="$CFLAGS"
-       SAVE_LDFLAGS="$LDFLAGS"
 
-       CFLAGS="$CFLAGS $with_libvirt_cflags"
-       LDFLAGS="$LDFLAGS $with_libvirt_ldflags"
+if test "x$with_libvirt" = "xyes"; then
+  SAVE_LDFLAGS="$LDFLAGS"
+  LDFLAGS="$LDFLAGS $with_libvirt_ldflags"
 
-       AC_CHECK_LIB(virt, virDomainBlockStats,
-                    [with_libvirt="yes"],
-                    [with_libvirt="no (symbol virDomainBlockStats not found)"])
+  AC_CHECK_LIB([virt], [virDomainBlockStats],
+    [with_libvirt="yes"],
+    [with_libvirt="no (symbol virDomainBlockStats not found)"]
+  )
 
-       CFLAGS="$SAVE_CFLAGS"
-       LDFLAGS="$SAVE_LDFLAGS"
+  LDFLAGS="$SAVE_LDFLAGS"
 fi
-dnl Add the right compiler flags and libraries.
+
 if test "x$with_libvirt" = "xyes"; then
-       BUILD_WITH_LIBVIRT_CFLAGS="$with_libvirt_cflags"
-       BUILD_WITH_LIBVIRT_LIBS="$with_libvirt_ldflags"
-       AC_SUBST(BUILD_WITH_LIBVIRT_CFLAGS)
-       AC_SUBST(BUILD_WITH_LIBVIRT_LIBS)
+  BUILD_WITH_LIBVIRT_CFLAGS="$with_libvirt_cflags"
+  BUILD_WITH_LIBVIRT_LIBS="$with_libvirt_ldflags"
 fi
+
+AC_SUBST([BUILD_WITH_LIBVIRT_CFLAGS])
+AC_SUBST([BUILD_WITH_LIBVIRT_LIBS])
 # }}}
 
 # $PKG_CONFIG --exists OpenIPMIpthread {{{
 with_libopenipmipthread="yes"
-with_libopenipmipthread_cflags=""
-with_libopenipmipthread_libs=""
-
-if test "x$with_libopenipmipthread" = "xyes"
-then
-       AC_MSG_CHECKING([for libOpenIPMIpthread])
-       $PKG_CONFIG --exists OpenIPMIpthread 2>/dev/null
-       if test "$?" != "0"
-       then
-               with_libopenipmipthread="no (pkg-config doesn't know OpenIPMIpthread)"
-       fi
-       AC_MSG_RESULT([$with_libopenipmipthread])
-fi
-
-if test "x$with_libopenipmipthread" = "xyes"
-then
-       AC_MSG_CHECKING([for libOpenIPMIpthread CFLAGS])
-       temp_result="`$PKG_CONFIG --cflags OpenIPMIpthread`"
-       if test "$?" = "0"
-       then
-               with_libopenipmipthread_cflags="$temp_result"
-       else
-               with_libopenipmipthread="no ($PKG_CONFIG --cflags OpenIPMIpthread failed)"
-               temp_result="$PKG_CONFIG --cflags OpenIPMIpthread failed"
-       fi
-       AC_MSG_RESULT([$temp_result])
+AC_MSG_CHECKING([for libOpenIPMIpthread])
+$PKG_CONFIG --exists OpenIPMIpthread 2>/dev/null
+if test $? -ne 0; then
+  with_libopenipmipthread="no (pkg-config doesn't know OpenIPMIpthread)"
+fi
+AC_MSG_RESULT([$with_libopenipmipthread])
+
+if test "x$with_libopenipmipthread" = "xyes"; then
+  AC_MSG_CHECKING([for libOpenIPMIpthread CFLAGS])
+  temp_result="`$PKG_CONFIG --cflags OpenIPMIpthread`"
+  if test $? -eq 0; then
+    with_libopenipmipthread_cflags="$temp_result"
+  else
+    with_libopenipmipthread="no ($PKG_CONFIG --cflags OpenIPMIpthread failed)"
+    temp_result="$PKG_CONFIG --cflags OpenIPMIpthread failed"
+  fi
+  AC_MSG_RESULT([$temp_result])
 fi
 
-if test "x$with_libopenipmipthread" = "xyes"
-then
-       AC_MSG_CHECKING([for libOpenIPMIpthread LDFLAGS])
-       temp_result="`$PKG_CONFIG --libs OpenIPMIpthread`"
-       if test "$?" = "0"
-       then
-               with_libopenipmipthread_ldflags="$temp_result"
-       else
-               with_libopenipmipthread="no ($PKG_CONFIG --libs OpenIPMIpthread failed)"
-               temp_result="$PKG_CONFIG --libs OpenIPMIpthread failed"
-       fi
-       AC_MSG_RESULT([$temp_result])
+if test "x$with_libopenipmipthread" = "xyes"; then
+  AC_MSG_CHECKING([for libOpenIPMIpthread LDFLAGS])
+  temp_result="`$PKG_CONFIG --libs OpenIPMIpthread`"
+  if test $? -eq 0; then
+    with_libopenipmipthread_ldflags="$temp_result"
+  else
+    with_libopenipmipthread="no ($PKG_CONFIG --libs OpenIPMIpthread failed)"
+    temp_result="$PKG_CONFIG --libs OpenIPMIpthread failed"
+  fi
+  AC_MSG_RESULT([$temp_result])
 fi
 
-if test "x$with_libopenipmipthread" = "xyes"
-then
-       SAVE_CPPFLAGS="$CPPFLAGS"
-       CPPFLAGS="$CPPFLAGS $with_libopenipmipthread_cflags"
-
-       AC_CHECK_HEADERS(OpenIPMI/ipmi_smi.h,
-                        [with_libopenipmipthread="yes"],
-                        [with_libopenipmipthread="no (OpenIPMI/ipmi_smi.h not found)"],
-[#include <OpenIPMI/ipmiif.h>
-#include <OpenIPMI/ipmi_err.h>
-#include <OpenIPMI/ipmi_posix.h>
-#include <OpenIPMI/ipmi_conn.h>
-])
+if test "x$with_libopenipmipthread" = "xyes"; then
+  SAVE_CPPFLAGS="$CPPFLAGS"
+  CPPFLAGS="$CPPFLAGS $with_libopenipmipthread_cflags"
+
+  AC_CHECK_HEADERS([OpenIPMI/ipmi_smi.h],
+    [with_libopenipmipthread="yes"],
+    [with_libopenipmipthread="no (OpenIPMI/ipmi_smi.h not found)"],
+    [[
+      #include <OpenIPMI/ipmiif.h>
+      #include <OpenIPMI/ipmi_err.h>
+      #include <OpenIPMI/ipmi_posix.h>
+      #include <OpenIPMI/ipmi_conn.h>
+    ]]
+  )
 
-       CPPFLAGS="$SAVE_CPPFLAGS"
+  CPPFLAGS="$SAVE_CPPFLAGS"
 fi
 
-if test "x$with_libopenipmipthread" = "xyes"
-then
-       BUILD_WITH_OPENIPMI_CFLAGS="$with_libopenipmipthread_cflags"
-       BUILD_WITH_OPENIPMI_LIBS="$with_libopenipmipthread_ldflags"
-       AC_SUBST(BUILD_WITH_OPENIPMI_CFLAGS)
-       AC_SUBST(BUILD_WITH_OPENIPMI_LIBS)
+if test "x$with_libopenipmipthread" = "xyes"; then
+  BUILD_WITH_OPENIPMI_CFLAGS="$with_libopenipmipthread_cflags"
+  BUILD_WITH_OPENIPMI_LIBS="$with_libopenipmipthread_ldflags"
 fi
+
+AC_SUBST([BUILD_WITH_OPENIPMI_CFLAGS])
+AC_SUBST([BUILD_WITH_OPENIPMI_LIBS])
 # }}}
 
 # --with-libatasmart {{{
-with_libatasmart_cppflags=""
-with_libatasmart_ldflags=""
-AC_ARG_WITH(libatasmart, [AS_HELP_STRING([--with-libatasmart@<:@=PREFIX@:>@], [Path to libatasmart.])],
-[
-       if test "x$withval" != "xno" && test "x$withval" != "xyes"
-       then
-               with_libatasmart_cppflags="-I$withval/include"
-               with_libatasmart_ldflags="-L$withval/lib"
-               with_libatasmart="yes"
-       else
-               with_libatasmart="$withval"
-       fi
-],
-[
-       if test "x$ac_system" = "xLinux"
-       then
-               with_libatasmart="yes"
-       else
-               with_libatasmart="no (Linux only library)"
-       fi
-])
-if test "x$with_libatasmart" = "xyes"
-then
-       SAVE_CPPFLAGS="$CPPFLAGS"
-       CPPFLAGS="$CPPFLAGS $with_libatasmart_cppflags"
+AC_ARG_WITH([libatasmart],
+  [AS_HELP_STRING([--with-libatasmart@<:@=PREFIX@:>@], [Path to libatasmart.])],
+  [
+    if test "x$withval" != "xno" && test "x$withval" != "xyes"; then
+      with_libatasmart_cppflags="-I$withval/include"
+      with_libatasmart_ldflags="-L$withval/lib"
+      with_libatasmart="yes"
+    else
+      with_libatasmart="$withval"
+    fi
+  ],
+  [
+    if test "x$ac_system" = "xLinux"; then
+      with_libatasmart="yes"
+    else
+      with_libatasmart="no (Linux only library)"
+    fi
+  ]
+)
 
-       AC_CHECK_HEADERS(atasmart.h, [with_libatasmart="yes"], [with_libatasmart="no (atasmart.h not found)"])
+if test "x$with_libatasmart" = "xyes"; then
+  SAVE_CPPFLAGS="$CPPFLAGS"
+  CPPFLAGS="$CPPFLAGS $with_libatasmart_cppflags"
 
-       CPPFLAGS="$SAVE_CPPFLAGS"
+  AC_CHECK_HEADERS([atasmart.h],
+    [with_libatasmart="yes"],
+    [with_libatasmart="no (atasmart.h not found)"])
+
+  CPPFLAGS="$SAVE_CPPFLAGS"
 fi
-if test "x$with_libatasmart" = "xyes"
-then
-       SAVE_CPPFLAGS="$CPPFLAGS"
-       SAVE_LDFLAGS="$LDFLAGS"
-       CPPFLAGS="$CPPFLAGS $with_libatasmart_cppflags"
-       LDFLAGS="$LDFLAGS $with_libatasmart_ldflags"
 
-       AC_CHECK_LIB(atasmart, sk_disk_open, [with_libatasmart="yes"], [with_libatasmart="no (Symbol 'sk_disk_open' not found)"])
+if test "x$with_libatasmart" = "xyes"; then
+  SAVE_LDFLAGS="$LDFLAGS"
+  LDFLAGS="$LDFLAGS $with_libatasmart_ldflags"
 
-       CPPFLAGS="$SAVE_CPPFLAGS"
-       LDFLAGS="$SAVE_LDFLAGS"
+  AC_CHECK_LIB([atasmart], [sk_disk_open],
+    [with_libatasmart="yes"],
+    [with_libatasmart="no (Symbol 'sk_disk_open' not found)"]
+  )
+
+  LDFLAGS="$SAVE_LDFLAGS"
 fi
-if test "x$with_libatasmart" = "xyes"
-then
-       BUILD_WITH_LIBATASMART_CPPFLAGS="$with_libatasmart_cppflags"
-       BUILD_WITH_LIBATASMART_LDFLAGS="$with_libatasmart_ldflags"
-       BUILD_WITH_LIBATASMART_LIBS="-latasmart"
-       AC_SUBST(BUILD_WITH_LIBATASMART_CPPFLAGS)
-       AC_SUBST(BUILD_WITH_LIBATASMART_LDFLAGS)
-       AC_SUBST(BUILD_WITH_LIBATASMART_LIBS)
-       AC_DEFINE(HAVE_LIBATASMART, 1, [Define if libatasmart is present and usable.])
-fi
-AM_CONDITIONAL(BUILD_WITH_LIBATASMART, test "x$with_libatasmart" = "xyes")
+
+if test "x$with_libatasmart" = "xyes"; then
+  BUILD_WITH_LIBATASMART_CPPFLAGS="$with_libatasmart_cppflags"
+  BUILD_WITH_LIBATASMART_LDFLAGS="$with_libatasmart_ldflags"
+  BUILD_WITH_LIBATASMART_LIBS="-latasmart"
+fi
+
+AC_SUBST([BUILD_WITH_LIBATASMART_CPPFLAGS])
+AC_SUBST([BUILD_WITH_LIBATASMART_LDFLAGS])
+AC_SUBST([BUILD_WITH_LIBATASMART_LIBS])
 # }}}
 
 PKG_CHECK_MODULES([LIBNOTIFY], [libnotify],
-               [with_libnotify="yes"],
-               [with_libnotify="no (pkg-config doesn't know libnotify)"]
+  [with_libnotify="yes"],
+  [with_libnotify="no (pkg-config doesn't know libnotify)"]
 )
 
 PKG_CHECK_MODULES([LIBRIEMANN_CLIENT], [riemann-client >= 1.6.0],
  [with_libriemann_client="yes"],
- [with_libriemann_client="no (pkg-config doesn't know libriemann-client)"])
+ [with_libriemann_client="no (pkg-config doesn't know libriemann-client)"]
+)
 
 # Check for enabled/disabled features
 #
@@ -5786,61 +5731,59 @@ PKG_CHECK_MODULES([LIBRIEMANN_CLIENT], [riemann-client >= 1.6.0],
 # AC_COLLECTD(name, enable/disable, info-text, feature/module)
 # ------------------------------------------------------------
 dnl
-m4_define([my_toupper], [m4_translit([$1], m4_defn([m4_cr_letters]), m4_defn([m4_cr_LETTERS]))])
+m4_define([my_toupper],[m4_translit([$1], m4_defn([m4_cr_letters]), m4_defn([m4_cr_LETTERS]))])
 dnl
 AC_DEFUN(
-       [AC_COLLECTD],
-       [
-       m4_if([$1], [], [AC_FATAL([AC_COLLECTD([$1], [$2], [$3], [$4]): 1st argument must not be empty])])dnl
-       m4_if(
-               [$2],
-               [enable],
-               [dnl
-               m4_define([EnDis],[disabled])dnl
-               m4_define([YesNo],[no])dnl
-               ],dnl
-               [m4_if(
-                       [$2],
-                       [disable],
-                       [dnl
-                       m4_define([EnDis],[enabled])dnl
-                       m4_define([YesNo],[yes])dnl
-                       ],
-                       [dnl
-                       AC_FATAL([AC_COLLECTD([$1], [$2], [$3], [$4]): 2nd argument must be either enable or disable])dnl
-                       ]dnl
-               )]dnl
-       )dnl
-       m4_if([$3], [feature], [],
-               [m4_if(
-                       [$3], [module], [],
-                       [dnl
-                       AC_FATAL([AC_COLLECTD([$1], [$2], [$3], [$4]): 3rd argument must be either feature or disable])dnl
-                       ]dnl
-               )]dnl
-       )dnl
-       AC_ARG_ENABLE(
-               [$1],
-               AS_HELP_STRING([--$2-$1], [$2 $4 (EnDis by def)]),
-               [],
-               enable_$1='[YesNo]'dnl
-       )# AC_ARG_ENABLE
-if test "x$enable_$1" = "xno"
-then
-       collectd_$1=0
-else
-       if test "x$enable_$1" = "xyes"
-       then
-               collectd_$1=1
-       else
-               AC_MSG_NOTICE([please specify either --enable-$1 or --disable-$1; enabling $1.])
-               collectd_$1=1
-               enable_$1='yes'
-       fi
-fi
-       AC_DEFINE_UNQUOTED([COLLECT_]my_toupper([$1]), [$collectd_$1], [wether or not to enable $3 $4])
-       AM_CONDITIONAL([BUILD_]my_toupper([$3])[_]my_toupper([$1]), [test "x$enable_$1" = "xyes"])dnl
-       ]dnl
+  [AC_COLLECTD],
+  [
+  m4_if([$1], [], [AC_FATAL([AC_COLLECTD([$1], [$2], [$3], [$4]): 1st argument must not be empty])])dnl
+  m4_if(
+    [$2],
+    [enable],
+    [dnl
+    m4_define([EnDis],[disabled])dnl
+    m4_define([YesNo],[no])dnl
+    ],dnl
+    [m4_if(
+      [$2],
+      [disable],
+      [dnl
+      m4_define([EnDis],[enabled])dnl
+      m4_define([YesNo],[yes])dnl
+      ],
+      [dnl
+      AC_FATAL([AC_COLLECTD([$1], [$2], [$3], [$4]): 2nd argument must be either enable or disable])dnl
+      ]dnl
+    )]dnl
+  )dnl
+  m4_if([$3], [feature], [],
+    [m4_if(
+      [$3], [module], [],
+      [dnl
+      AC_FATAL([AC_COLLECTD([$1], [$2], [$3], [$4]): 3rd argument must be either feature or disable])dnl
+      ]dnl
+    )]dnl
+  )dnl
+  AC_ARG_ENABLE(
+    [$1],
+    AS_HELP_STRING([--$2-$1], [$2 $4 (EnDis by def)]),
+    [],
+    enable_$1='[YesNo]'dnl
+  )# AC_ARG_ENABLE
+  if test "x$enable_$1" = "xno"; then
+    collectd_$1=0
+  else
+    if test "x$enable_$1" = "xyes"; then
+      collectd_$1=1
+    else
+      AC_MSG_NOTICE([please specify either --enable-$1 or --disable-$1; enabling $1.])
+      collectd_$1=1
+      enable_$1='yes'
+    fi
+  fi
+  AC_DEFINE_UNQUOTED([COLLECT_]my_toupper([$1]), [$collectd_$1], [whether or not to enable $3 $4])
+  AM_CONDITIONAL([BUILD_]my_toupper([$3])[_]my_toupper([$1]), [test "x$enable_$1" = "xyes"])dnl
+  ]dnl
 )# AC_COLLECTD(name, enable/disable, info-text, feature/module)
 
 # AC_PLUGIN(name, default, info)
@@ -5851,47 +5794,42 @@ AC_DEFUN(
   [
     enable_plugin="no"
     force="no"
-    AC_ARG_ENABLE([$1], AS_HELP_STRING([--enable-$1],[$3]),
-    [
-     if test "x$enableval" = "xyes"
-     then
-            enable_plugin="yes"
-     else if test "x$enableval" = "xforce"
-     then
-            enable_plugin="yes"
-            force="yes"
-     else
-            enable_plugin="no (disabled on command line)"
-     fi; fi
-    ],
-    [
-        if test "x$enable_all_plugins" = "xauto"
-        then
-            if test "x$2" = "xyes"
-            then
-                    enable_plugin="yes"
-            else
-                    enable_plugin="$2"
-            fi
-        else
-            enable_plugin="$enable_all_plugins"
-        fi
-    ])
-    if test "x$enable_plugin" = "xyes"
-    then
-           if test "x$2" = "xyes" || test "x$force" = "xyes"
-           then
-                   AC_DEFINE([HAVE_PLUGIN_]my_toupper([$1]), 1, [Define to 1 if the $1 plugin is enabled.])
-                   if test "x$2" != "xyes"
-                   then
-                           dependency_warning="yes"
-                   fi
-           else # User passed "yes" but dependency checking yielded "no" => Dependency problem.
-                   dependency_error="yes"
-                   enable_plugin="$2 (dependency error)"
-           fi
+    AC_ARG_ENABLE([$1],
+      [AS_HELP_STRING([--enable-$1],[$3])],
+      [
+        if test "x$enableval" = "xyes"; then
+          enable_plugin="yes"
+        else if test "x$enableval" = "xforce"; then
+          enable_plugin="yes"
+          force="yes"
+        else
+          enable_plugin="no (disabled on command line)"
+        fi; fi
+      ],
+      [
+        if test "x$enable_all_plugins" = "xauto"; then
+          if test "x$2" = "xyes"; then
+            enable_plugin="yes"
+          else
+            enable_plugin="$2"
+          fi
+        else
+          enable_plugin="$enable_all_plugins"
+        fi
+      ]
+    )
+    if test "x$enable_plugin" = "xyes"; then
+      if test "x$2" = "xyes" || test "x$force" = "xyes"; then
+        AC_DEFINE([HAVE_PLUGIN_]my_toupper([$1]), 1, [Define to 1 if the $1 plugin is enabled.])
+        if test "x$2" != "xyes"; then
+          dependency_warning="yes"
+        fi
+      else # User passed "yes" but dependency checking yielded "no" => Dependency problem.
+        dependency_error="yes"
+        enable_plugin="$2 (dependency error)"
+      fi
     fi
-    AM_CONDITIONAL([BUILD_PLUGIN_]my_toupper([$1]), test "x$enable_plugin" = "xyes")
+    AM_CONDITIONAL([BUILD_PLUGIN_]my_toupper([$1]), [test "x$enable_plugin" = "xyes"])
     enable_$1="$enable_plugin"
   ]
 )# AC_PLUGIN(name, default, info)
@@ -5933,6 +5871,7 @@ plugin_grpc="no"
 plugin_hugepages="no"
 plugin_intel_rdt="no"
 plugin_interface="no"
+plugin_ipc="no"
 plugin_ipmi="no"
 plugin_ipvs="no"
 plugin_irq="no"
@@ -5968,369 +5907,297 @@ plugin_zone="no"
 plugin_zookeeper="no"
 
 # Linux
-if test "x$ac_system" = "xLinux"
-then
-       plugin_battery="yes"
-       plugin_cgroups="yes"
-       plugin_conntrack="yes"
-       plugin_contextswitch="yes"
-       plugin_cpu="yes"
-       plugin_cpufreq="yes"
-       plugin_disk="yes"
-       plugin_drbd="yes"
-       plugin_entropy="yes"
-       plugin_fhcount="yes"
-       plugin_fscache="yes"
-       plugin_hugepages="yes"
-       plugin_interface="yes"
-       plugin_ipc="yes"
-       plugin_irq="yes"
-       plugin_load="yes"
-       plugin_lvm="yes"
-       plugin_memory="yes"
-       plugin_nfs="yes"
-       plugin_numa="yes"
-       plugin_processes="yes"
-       plugin_protocols="yes"
-       plugin_serial="yes"
-       plugin_swap="yes"
-       plugin_tcpconns="yes"
-       plugin_thermal="yes"
-       plugin_uptime="yes"
-       plugin_vmem="yes"
-       plugin_vserver="yes"
-       plugin_wireless="yes"
-       plugin_zfs_arc="yes"
-
-       if test "x$have_linux_ip_vs_h" = "xyes" || test "x$have_net_ip_vs_h" = "xyes" || test "x$have_ip_vs_h" = "xyes"
-       then
-               plugin_ipvs="yes"
-       fi
-       if test "x$c_cv_have_usable_asm_msrindex_h" = "xyes" && test "x$have_cpuid_h" = "xyes"
-       then
-               plugin_turbostat="yes"
-       fi
-       
-       if test "x$c_cv_have_clock_boottime_monotonic" = "xyes"
-       then
-               plugin_cpusleep="yes"
-       fi
+if test "x$ac_system" = "xLinux"; then
+  plugin_battery="yes"
+  plugin_cgroups="yes"
+  plugin_conntrack="yes"
+  plugin_contextswitch="yes"
+  plugin_cpu="yes"
+  plugin_cpufreq="yes"
+  plugin_disk="yes"
+  plugin_drbd="yes"
+  plugin_entropy="yes"
+  plugin_fhcount="yes"
+  plugin_fscache="yes"
+  plugin_hugepages="yes"
+  plugin_interface="yes"
+  plugin_ipc="yes"
+  plugin_irq="yes"
+  plugin_load="yes"
+  plugin_lvm="yes"
+  plugin_memory="yes"
+  plugin_nfs="yes"
+  plugin_numa="yes"
+  plugin_processes="yes"
+  plugin_protocols="yes"
+  plugin_serial="yes"
+  plugin_swap="yes"
+  plugin_tcpconns="yes"
+  plugin_thermal="yes"
+  plugin_uptime="yes"
+  plugin_vmem="yes"
+  plugin_vserver="yes"
+  plugin_wireless="yes"
+  plugin_zfs_arc="yes"
+
+  if test "x$have_linux_ip_vs_h" = "xyes" || test "x$have_net_ip_vs_h" = "xyes" || test "x$have_ip_vs_h" = "xyes"; then
+    plugin_ipvs="yes"
+  fi
+
+  if test "x$c_cv_have_usable_asm_msrindex_h" = "xyes" && test "x$have_cpuid_h" = "xyes"; then
+    plugin_turbostat="yes"
+  fi
+  
+  if test "x$c_cv_have_clock_boottime_monotonic" = "xyes"; then
+    plugin_cpusleep="yes"
+  fi
 fi
 
-if test "x$ac_system" = "xOpenBSD"
-then
-       plugin_tcpconns="yes"
+if test "x$ac_system" = "xOpenBSD"; then
+  plugin_tcpconns="yes"
 fi
 
-if test "x$ac_system" = "xNetBSD"
-then
-       plugin_disk="yes"
-       plugin_entropy="yes"
-       plugin_irq="yes"
-       plugin_processes="yes"
+if test "x$ac_system" = "xNetBSD"; then
+  plugin_disk="yes"
+  plugin_entropy="yes"
+  plugin_irq="yes"
+  plugin_processes="yes"
 fi
 
 # Mac OS X devices
-if test "x$with_libiokit" = "xyes"
-then
-       plugin_battery="yes"
-       plugin_disk="yes"
+if test "x$with_libiokit" = "xyes"; then
+  plugin_battery="yes"
+  plugin_disk="yes"
 fi
 
 # AIX
 
-if test "x$ac_system" = "xAIX"
-then
-       plugin_ipc="yes"
-       plugin_tcpconns="yes"
+if test "x$ac_system" = "xAIX"; then
+  plugin_ipc="yes"
+  plugin_tcpconns="yes"
 fi
 
 # FreeBSD
 
-if test "x$ac_system" = "xFreeBSD"
-then
-       plugin_disk="yes"
-       plugin_zfs_arc="yes"
+if test "x$ac_system" = "xFreeBSD"; then
+  plugin_disk="yes"
+  plugin_zfs_arc="yes"
 fi
 
 
-if test "x$with_perfstat" = "xyes"
-then
-       plugin_contextswitch="yes"
-       plugin_cpu="yes"
-       plugin_disk="yes"
-       plugin_interface="yes"
-       plugin_load="yes"
-       plugin_memory="yes"
-       plugin_swap="yes"
-       plugin_uptime="yes"
+if test "x$with_perfstat" = "xyes"; then
+  plugin_contextswitch="yes"
+  plugin_cpu="yes"
+  plugin_disk="yes"
+  plugin_interface="yes"
+  plugin_load="yes"
+  plugin_memory="yes"
+  plugin_swap="yes"
+  plugin_uptime="yes"
 fi
 
-if test "x$with_procinfo" = "xyes"
-then
-       plugin_processes="yes"
+if test "x$with_procinfo" = "xyes"; then
+  plugin_processes="yes"
 fi
 
 # Solaris
-if test "x$with_kstat" = "xyes"
-then
-       plugin_nfs="yes"
-       plugin_processes="yes"
-       plugin_uptime="yes"
-       plugin_zfs_arc="yes"
-       plugin_zone="yes"
+if test "x$with_kstat" = "xyes"; then
+  plugin_nfs="yes"
+  plugin_processes="yes"
+  plugin_uptime="yes"
+  plugin_zfs_arc="yes"
+  plugin_zone="yes"
 fi
 
-if test "x$with_devinfo$with_kstat" = "xyesyes"
-then
-       plugin_cpu="yes"
-       plugin_disk="yes"
-       plugin_interface="yes"
-       plugin_memory="yes"
-       plugin_tape="yes"
-fi
-
-# libi2c-dev
-if test "x$ac_system" = "xLinux"
-then
-AC_CHECK_DECL(i2c_smbus_read_i2c_block_data,
-       [with_libi2c="yes"],
-       [with_libi2c="no (symbol i2c_smbus_read_i2c_block_data not found - have you installed libi2c-dev ?)"],
-       [[#include <stdlib.h>
-       #include <linux/i2c-dev.h>]])
-else
-       with_libi2c="no (Linux only)"
+if test "x$with_devinfo" = "xyes" && test "x$with_kstat" = "xyes"; then
+  plugin_cpu="yes"
+  plugin_disk="yes"
+  plugin_interface="yes"
+  plugin_memory="yes"
+  plugin_tape="yes"
 fi
 
-if test "x$with_libi2c" = "xyes"
-then
-       plugin_barometer="yes"
+if test "x$with_libi2c" = "xyes"; then
+  plugin_barometer="yes"
 fi
 
 
 # libstatgrab
-if test "x$with_libstatgrab" = "xyes"
-then
-       plugin_cpu="yes"
-       plugin_disk="yes"
-       plugin_interface="yes"
-       plugin_load="yes"
-       plugin_memory="yes"
-       plugin_swap="yes"
-       plugin_users="yes"
+if test "x$with_libstatgrab" = "xyes"; then
+  plugin_cpu="yes"
+  plugin_disk="yes"
+  plugin_interface="yes"
+  plugin_load="yes"
+  plugin_memory="yes"
+  plugin_swap="yes"
+  plugin_users="yes"
+fi
+
+if test "x$with_libcurl" = "xyes" && test "x$with_libxml2" = "xyes"; then
+  plugin_ascent="yes"
+  if test "x$have_strptime" = "xyes"; then
+    plugin_bind="yes"
+  fi
 fi
 
-if test "x$with_libcurl" = "xyes" && test "x$with_libxml2" = "xyes"
-then
-       plugin_ascent="yes"
-       if test "x$have_strptime" = "xyes"
-       then
-               plugin_bind="yes"
-       fi
+if test "x$with_libopenipmipthread" = "xyes"; then
+  plugin_ipmi="yes"
 fi
 
-if test "x$with_libopenipmipthread" = "xyes"
-then
-       plugin_ipmi="yes"
+if test "x$with_libcurl" = "xyes" && test "x$with_libyajl" = "xyes"; then
+  plugin_curl_json="yes"
 fi
 
-if test "x$with_libcurl" = "xyes" && test "x$with_libyajl" = "xyes"
-then
-       plugin_curl_json="yes"
+if test "x$with_libcurl" = "xyes" && test "x$with_libxml2" = "xyes"; then
+  plugin_curl_xml="yes"
 fi
 
-if test "x$with_libcurl" = "xyes" && test "x$with_libxml2" = "xyes"
-then
-       plugin_curl_xml="yes"
+if test "x$with_libyajl" = "xyes"; then
+  plugin_ceph="yes"
 fi
 
-if test "x$with_libyajl" = "xyes"
-then
-       plugin_ceph="yes"
+if test "x$have_processor_info" = "xyes"; then
+  plugin_cpu="yes"
 fi
 
-if test "x$have_processor_info" = "xyes"
-then
-       plugin_cpu="yes"
-fi
-if test "x$have_sysctl" = "xyes"
-then
-       plugin_cpu="yes"
-       plugin_memory="yes"
-       plugin_uptime="yes"
-       if test "x$ac_system" = "xDarwin"
-       then
-               plugin_swap="yes"
-       fi
+if test "x$have_sysctl" = "xyes"; then
+  plugin_cpu="yes"
+  plugin_memory="yes"
+  plugin_uptime="yes"
+  if test "x$ac_system" = "xDarwin"; then
+    plugin_swap="yes"
+  fi
 fi
-if test "x$have_sysctlbyname" = "xyes"
-then
-       plugin_contextswitch="yes"
-       plugin_cpu="yes"
-       plugin_memory="yes"
-       plugin_tcpconns="yes"
+if test "x$have_sysctlbyname" = "xyes"; then
+  plugin_contextswitch="yes"
+  plugin_cpu="yes"
+  plugin_memory="yes"
+  plugin_tcpconns="yes"
 fi
 
-# Df plugin: Check if we know how to determine mount points first.
-#if test "x$have_listmntent" = "xyes"; then
-#      plugin_df="yes"
-#fi
-if test "x$have_getvfsstat" = "xyes" || test "x$have_getfsstat" = "xyes"
-then
-       plugin_df="yes"
+if test "x$have_getvfsstat" = "xyes" || test "x$have_getfsstat" = "xyes"; then
+  plugin_df="yes"
 fi
-if test "x$c_cv_have_two_getmntent" = "xyes" || test "x$have_getmntent" = "xgen" || test "x$have_getmntent" = "xsun"
-then
-       plugin_df="yes"
+
+if test "x$c_cv_have_two_getmntent" = "xyes" || test "x$have_getmntent" = "xgen" || test "x$have_getmntent" = "xsun"; then
+  plugin_df="yes"
 fi
-#if test "x$have_getmntent" = "xseq"
-#then
-#      plugin_df="yes"
-#fi
-if test "x$c_cv_have_one_getmntent" = "xyes"
-then
-       plugin_df="yes"
+
+if test "x$c_cv_have_one_getmntent" = "xyes"; then
+  plugin_df="yes"
 fi
 
-if test "x$c_cv_have_getmntent_r" = "xyes"
-then
-       plugin_df="yes"
+if test "x$c_cv_have_getmntent_r" = "xyes"; then
+  plugin_df="yes"
 fi
 
-# Df plugin: Check if we have either `statfs' or `statvfs' second.
-if test "x$plugin_df" = "xyes"
-then
-       plugin_df="no"
-       if test "x$have_statfs" = "xyes"
-       then
-               plugin_df="yes"
-       fi
-       if test "x$have_statvfs" = "xyes"
-       then
-               plugin_df="yes"
-       fi
+if test "x$plugin_df" = "xyes"; then
+  plugin_df="no"
+  if test "x$have_statfs" = "xyes"; then
+    plugin_df="yes"
+  fi
+
+  if test "x$have_statvfs" = "xyes"; then
+    plugin_df="yes"
+  fi
 fi
 
-if test "x$have_linux_sockios_h$have_linux_ethtool_h" = "xyesyes"
-then
-       plugin_ethstat="yes"
+if test "x$have_linux_sockios_h" = "xyes" && test "x$have_linux_ethtool_h" = "xyes"; then
+  plugin_ethstat="yes"
 fi
 
-if test "x$with_libgrpcpp" = "xyes" && test "x$with_libprotobuf" = "xyes" && test "x$have_protoc3" = "xyes" && test "x$GRPC_CPP_PLUGIN" != "x"
-then
-       plugin_grpc="yes"
+if test "x$with_libgps" = "xyes"; then
+  plugin_gps="yes"
 fi
 
-if test "x$have_getifaddrs" = "xyes"
-then
-       plugin_interface="yes"
+if test "x$with_libgrpcpp" = "xyes" && test "x$with_libprotobuf" = "xyes" && test "x$have_protoc3" = "xyes" && test "x$GRPC_CPP_PLUGIN" != "x"; then
+  plugin_grpc="yes"
 fi
 
-if test "x$with_libgps" = "xyes"
-then
-       plugin_gps="yes"
+if test "x$have_getifaddrs" = "xyes"; then
+  plugin_interface="yes"
 fi
 
-if test "x$have_getloadavg" = "xyes"
-then
-       plugin_load="yes"
+if test "x$have_getloadavg" = "xyes"; then
+  plugin_load="yes"
 fi
 
-if test "x$with_libyajl" = "xyes"
-then
-       plugin_log_logstash="yes"
+if test "x$with_libyajl" = "xyes"; then
+  plugin_log_logstash="yes"
 fi
 
-if test "x$c_cv_have_libperl$c_cv_have_perl_ithreads" = "xyesyes"
-then
-       plugin_perl="yes"
+if test "x$with_libperl" = "xyes" && test "x$c_cv_have_perl_ithreads" = "xyes"; then
+  plugin_perl="yes"
 fi
 
-if test "x$have_protoc_c" = "xyes" && test "x$with_libprotobuf_c" = "xyes"
-then
-       plugin_pinba="yes"
-       if test "x$with_libmicrohttpd" = "xyes"
-       then
-               plugin_write_prometheus="yes"
-       fi
+if test "x$have_protoc_c" = "xyes" && test "x$with_libprotobuf_c" = "xyes"; then
+  plugin_pinba="yes"
+  if test "x$with_libmicrohttpd" = "xyes"; then
+    plugin_write_prometheus="yes"
+  fi
 fi
 
 # Mac OS X memory interface
-if test "x$have_host_statistics" = "xyes"
-then
-       plugin_memory="yes"
+if test "x$have_host_statistics" = "xyes"; then
+  plugin_memory="yes"
 fi
 
-if test "x$have_termios_h" = "xyes"
-then
-       if test "x$ac_system" != "xAIX"
-       then
-               plugin_multimeter="yes"
-       fi
-       plugin_ted="yes"
+if test "x$have_termios_h" = "xyes"; then
+  if test "x$ac_system" != "xAIX"; then
+    plugin_multimeter="yes"
+  fi
+  plugin_ted="yes"
 fi
 
-if test "x$have_thread_info" = "xyes"
-then
-       plugin_processes="yes"
+if test "x$have_thread_info" = "xyes"; then
+  plugin_processes="yes"
 fi
 
-if test "x$with_kvm_getprocs" = "xyes" && test "x$have_struct_kinfo_proc_freebsd" = "xyes"
-then
-       plugin_processes="yes"
+if test "x$with_kvm_getprocs" = "xyes" && test "x$have_struct_kinfo_proc_freebsd" = "xyes"; then
+  plugin_processes="yes"
 fi
 
-if test "x$with_kvm_getprocs" = "xyes" && test "x$have_struct_kinfo_proc_openbsd" = "xyes"
-then
-       plugin_processes="yes"
+if test "x$with_kvm_getprocs" = "xyes" && test "x$have_struct_kinfo_proc_openbsd" = "xyes"; then
+  plugin_processes="yes"
 fi
 
-if test "x$with_libpython" != "xno"
-then
-       plugin_python="yes"
+if test "x$with_libpython" != "xno"; then
+  plugin_python="yes"
 fi
 
-if test "x$with_libatasmart" = "xyes" && test "x$with_libudev" = "xyes"
-then
-       plugin_smart="yes"
+if test "x$with_libatasmart" = "xyes" && test "x$with_libudev" = "xyes"; then
+  plugin_smart="yes"
 fi
 
-if test "x$with_kvm_getswapinfo" = "xyes"
-then
-       plugin_swap="yes"
+if test "x$with_kvm_getswapinfo" = "xyes"; then
+  plugin_swap="yes"
 fi
 
-if test "x$have_swapctl" = "xyes" && test "x$c_cv_have_swapctl_two_args" = "xyes"
-then
-       plugin_swap="yes"
+if test "x$have_swapctl" = "xyes" && test "x$c_cv_have_swapctl_two_args" = "xyes"; then
+  plugin_swap="yes"
 fi
 
-if test "x$have_swapctl" = "xyes" && test "x$c_cv_have_swapctl_three_args" = "xyes"
-then
-       plugin_swap="yes"
+if test "x$have_swapctl" = "xyes" && test "x$c_cv_have_swapctl_three_args" = "xyes"; then
+  plugin_swap="yes"
 fi
 
-if test "x$with_kvm_openfiles$with_kvm_nlist" = "xyesyes"
-then
-       plugin_tcpconns="yes"
+if test "x$with_kvm_openfiles = "xyes" && $with_kvm_nlist" = "xyes"; then
+  plugin_tcpconns="yes"
 fi
 
-if test "x$have_getutent" = "xyes"
-then
-       plugin_users="yes"
+if test "x$have_getutent" = "xyes"; then
+  plugin_users="yes"
 fi
-if test "x$have_getutxent" = "xyes"
-then
-       plugin_users="yes"
+
+if test "x$have_getutxent" = "xyes"; then
+  plugin_users="yes"
 fi
 
-if test "x$with_libxml2" = "xyes" && test "x$with_libvirt" = "xyes"
-then
-       plugin_virt="yes"
+if test "x$with_libxml2" = "xyes" && test "x$with_libvirt" = "xyes"; then
+  plugin_virt="yes"
 fi
 
-if test "x$with_libxenctrl" = "xyes"
-then
+if test "x$with_libxenctrl" = "xyes"; then
   plugin_xencpu="yes"
 fi
 
@@ -6343,19 +6210,18 @@ m4_divert_once([HELP_ENABLE], [
 collectd plugins:])
 
 AC_ARG_ENABLE([all-plugins],
-               AS_HELP_STRING([--enable-all-plugins],[enable all plugins (auto by def)]),
-               [
-                if test "x$enableval" = "xyes"
-                then
-                        enable_all_plugins="yes"
-                else if test "x$enableval" = "xauto"
-                then
-                        enable_all_plugins="auto"
-                else
-                        enable_all_plugins="no"
-                fi; fi
-               ],
-               [enable_all_plugins="auto"])
+  [AS_HELP_STRING([--enable-all-plugins], [enable all plugins @<:@default=yes@:>@])],
+  [
+     if test "x$enableval" = "xyes"; then
+       enable_all_plugins="yes"
+     else if test "x$enableval" = "xauto"; then
+       enable_all_plugins="auto"
+     else
+       enable_all_plugins="no"
+     fi; fi
+  ],
+  [enable_all_plugins="auto"]
+)
 
 m4_divert_once([HELP_ENABLE], [])
 
@@ -6516,45 +6382,41 @@ LOAD_PLUGIN_LOG_LOGSTASH=""
 
 AC_MSG_CHECKING([which default log plugin to load])
 default_log_plugin="none"
-if test "x$enable_syslog" = "xyes"
-then
-       default_log_plugin="syslog"
+if test "x$enable_syslog" = "xyes"; then
+  default_log_plugin="syslog"
 else
-       LOAD_PLUGIN_SYSLOG="##"
+  LOAD_PLUGIN_SYSLOG="##"
 fi
 
-if test "x$enable_logfile" = "xyes"
-then
-       if test "x$default_log_plugin" = "xnone"
-       then
-               default_log_plugin="logfile"
-       else
-               LOAD_PLUGIN_LOGFILE="#"
-       fi
+if test "x$enable_logfile" = "xyes"; then
+  if test "x$default_log_plugin" = "xnone"; then
+    default_log_plugin="logfile"
+  else
+    LOAD_PLUGIN_LOGFILE="#"
+  fi
 else
-       LOAD_PLUGIN_LOGFILE="##"
+  LOAD_PLUGIN_LOGFILE="##"
 fi
 
-if test "x$enable_log_logstash" = "xyes"
-then
+if test "x$enable_log_logstash" = "xyes"; then
   LOAD_PLUGIN_LOG_LOGSTASH="#"
 else
   LOAD_PLUGIN_LOG_LOGSTASH="##"
 fi
 
-
 AC_MSG_RESULT([$default_log_plugin])
 
-AC_SUBST(LOAD_PLUGIN_SYSLOG)
-AC_SUBST(LOAD_PLUGIN_LOGFILE)
-AC_SUBST(LOAD_PLUGIN_LOG_LOGSTASH)
+AC_SUBST([LOAD_PLUGIN_SYSLOG])
+AC_SUBST([LOAD_PLUGIN_LOGFILE])
+AC_SUBST([LOAD_PLUGIN_LOG_LOGSTASH])
 
-DEFAULT_LOG_LEVEL="info"
 if test "x$enable_debug" = "xyes"
 then
-       DEFAULT_LOG_LEVEL="debug"
+  DEFAULT_LOG_LEVEL="debug"
+else
+  DEFAULT_LOG_LEVEL="info"
 fi
-AC_SUBST(DEFAULT_LOG_LEVEL)
+AC_SUBST([DEFAULT_LOG_LEVEL])
 
 # Load only one of rrdtool, network, csv in the default config.
 LOAD_PLUGIN_RRDTOOL=""
@@ -6563,73 +6425,65 @@ LOAD_PLUGIN_CSV=""
 
 AC_MSG_CHECKING([which default write plugin to load])
 default_write_plugin="none"
-if test "x$enable_rrdtool" = "xyes"
-then
-       default_write_plugin="rrdtool"
+if test "x$enable_rrdtool" = "xyes"; then
+  default_write_plugin="rrdtool"
 else
-       LOAD_PLUGIN_RRDTOOL="##"
+  LOAD_PLUGIN_RRDTOOL="##"
 fi
 
-if test "x$enable_network" = "xyes"
-then
-       if test "x$default_write_plugin" = "xnone"
-       then
-               default_write_plugin="network"
-       else
-               LOAD_PLUGIN_NETWORK="#"
-       fi
+if test "x$enable_network" = "xyes"; then
+  if test "x$default_write_plugin" = "xnone"; then
+    default_write_plugin="network"
+  else
+    LOAD_PLUGIN_NETWORK="#"
+  fi
 else
-       LOAD_PLUGIN_NETWORK="##"
+  LOAD_PLUGIN_NETWORK="##"
 fi
 
-if test "x$enable_csv" = "xyes"
-then
-       if test "x$default_write_plugin" = "xnone"
-       then
-               default_write_plugin="csv"
-       else
-               LOAD_PLUGIN_CSV="#"
-       fi
+if test "x$enable_csv" = "xyes"; then
+  if test "x$default_write_plugin" = "xnone"; then
+    default_write_plugin="csv"
+  else
+    LOAD_PLUGIN_CSV="#"
+  fi
 else
-       LOAD_PLUGIN_CSV="##"
+  LOAD_PLUGIN_CSV="##"
 fi
 AC_MSG_RESULT([$default_write_plugin])
 
-AC_SUBST(LOAD_PLUGIN_RRDTOOL)
-AC_SUBST(LOAD_PLUGIN_NETWORK)
-AC_SUBST(LOAD_PLUGIN_CSV)
+AC_SUBST([LOAD_PLUGIN_RRDTOOL])
+AC_SUBST([LOAD_PLUGIN_NETWORK])
+AC_SUBST([LOAD_PLUGIN_CSV])
 
 dnl ip_vs.h
-if test "x$ac_system" = "xLinux" \
-       && test "x$have_linux_ip_vs_h$have_net_ip_vs_h$have_ip_vs_h" = "xnonono"
-then
-       enable_ipvs="$enable_ipvs (ip_vs.h not found)"
+if test "x$ac_system" = "xLinux" && test "x$have_linux_ip_vs_h" = "xno" && "x$have_net_ip_vs_h" = "xno" && "x$have_ip_vs_h" = "xno"; then
+  enable_ipvs="$enable_ipvs (ip_vs.h not found)"
 fi
 
-if test "x$ip_vs_h_needs_kernel_cflags" = "xyes"
-then
-       enable_ipvs="$enable_ipvs (needs $KERNEL_CFLAGS)"
+if test "x$ip_vs_h_needs_kernel_cflags" = "xyes"; then
+  enable_ipvs="$enable_ipvs (needs $KERNEL_CFLAGS)"
 fi
 
 dnl Perl bindings
 PERL_BINDINGS_OPTIONS="PREFIX=${prefix}"
 AC_ARG_WITH(perl-bindings, [AS_HELP_STRING([--with-perl-bindings@<:@=OPTIONS@:>@], [Options passed to "perl Makefile.PL".])],
 [
-       if test "x$withval" != "xno" && test "x$withval" != "xyes"
-       then
-               PERL_BINDINGS_OPTIONS="$withval"
-               with_perl_bindings="yes"
-       else
-               with_perl_bindings="$withval"
-       fi
+  if test "x$withval" != "xno" && test "x$withval" != "xyes"
+  then
+    PERL_BINDINGS_OPTIONS="$withval"
+    with_perl_bindings="yes"
+  else
+    with_perl_bindings="$withval"
+  fi
 ],
 [
-       if test -n "$perl_interpreter"
-       then
-               with_perl_bindings="yes"
-       else
-               with_perl_bindings="no (no perl interpreter found)"
-       fi
+  if test "x$PERL" != "x"
+  then
+    with_perl_bindings="yes"
+  else
+    with_perl_bindings="no (no perl interpreter found)"
+  fi
 ])
 
 if test "x$with_perl_bindings" = "xyes"
@@ -6645,12 +6499,13 @@ fi
 
 if test "x$with_perl_bindings" = "xyes"
 then
-       PERL_BINDINGS="perl"
+  PERL_BINDINGS="perl"
 else
-       PERL_BINDINGS=""
+  PERL_BINDINGS=""
 fi
-AC_SUBST(PERL_BINDINGS)
-AC_SUBST(PERL_BINDINGS_OPTIONS)
+
+AC_SUBST([PERL_BINDINGS])
+AC_SUBST([PERL_BINDINGS_OPTIONS])
 
 dnl libcollectdclient
 LCC_VERSION_MAJOR=`echo $PACKAGE_VERSION | cut -d'.' -f1`
@@ -6661,49 +6516,55 @@ LCC_VERSION_EXTRA=`echo $PACKAGE_VERSION | cut -d'.' -f4-`
 
 LCC_VERSION_STRING="$LCC_VERSION_MAJOR.$LCC_VERSION_MINOR.$LCC_VERSION_PATCH"
 
-AC_SUBST(LCC_VERSION_MAJOR)
-AC_SUBST(LCC_VERSION_MINOR)
-AC_SUBST(LCC_VERSION_PATCH)
-AC_SUBST(LCC_VERSION_EXTRA)
-AC_SUBST(LCC_VERSION_STRING)
+AC_SUBST([LCC_VERSION_MAJOR])
+AC_SUBST([LCC_VERSION_MINOR])
+AC_SUBST([LCC_VERSION_PATCH])
+AC_SUBST([LCC_VERSION_EXTRA])
+AC_SUBST([LCC_VERSION_STRING])
 
-AC_CONFIG_FILES(src/libcollectdclient/collectd/lcc_features.h)
+AC_CONFIG_FILES([src/libcollectdclient/collectd/lcc_features.h])
 
 AM_CFLAGS="-Wall"
 AM_CXXFLAGS="-Wall"
-if test "x$enable_werror" != "xno"
-then
-        AM_CFLAGS="$AM_CFLAGS -Werror"
-        AM_CXXFLAGS="$AM_CXXFLAGS -Werror"
+if test "x$enable_werror" != "xno"; then
+  AM_CFLAGS="$AM_CFLAGS -Werror"
+  AM_CXXFLAGS="$AM_CXXFLAGS -Werror"
 fi
+
 AC_SUBST([AM_CFLAGS])
 AC_SUBST([AM_CXXFLAGS])
 
-AC_CONFIG_FILES([Makefile proto/Makefile src/Makefile src/daemon/Makefile src/collectd.conf src/libcollectdclient/Makefile src/libcollectdclient/libcollectdclient.pc src/liboconfig/Makefile bindings/Makefile bindings/java/Makefile])
+AC_CONFIG_FILES([ \
+  Makefile \
+  bindings/Makefile \
+  bindings/java/Makefile \
+  proto/Makefile \
+  src/Makefile \
+  src/collectd.conf \
+  src/daemon/Makefile \
+  src/libcollectdclient/Makefile \
+  src/libcollectdclient/libcollectdclient.pc \
+  src/liboconfig/Makefile \
+])
+
 AC_OUTPUT
 
-if test "x$with_librrd" = "xyes" \
-       && test "x$librrd_threadsafe" != "xyes"
-then
-       with_librrd="yes (warning: librrd is not thread-safe)"
+if test "x$with_librrd" = "xyes" && test "x$librrd_threadsafe" != "xyes"; then
+  with_librrd="yes (warning: librrd is not thread-safe)"
 fi
 
-if test "x$with_libperl" = "xyes"
-then
-       with_libperl="yes (version `$perl_interpreter -MConfig -e 'print $Config{version};'`)"
+if test "x$with_libperl" = "xyes"; then
+  with_libperl="yes (version `$PERL -MConfig -e 'print $Config{version};'`)"
 else
-       enable_perl="no (needs libperl)"
+  enable_perl="no (needs libperl)"
 fi
 
-if test "x$enable_perl" = "xno" && test "x$c_cv_have_perl_ithreads" = "xno"
-then
-       enable_perl="no (libperl doesn't support ithreads)"
+if test "x$enable_perl" = "xno" && test "x$c_cv_have_perl_ithreads" = "xno"; then
+  enable_perl="no (libperl doesn't support ithreads)"
 fi
 
-if test "x$with_perl_bindings" = "xyes" \
-       && test "x$PERL_BINDINGS_OPTIONS" != "x"
-then
-       with_perl_bindings="yes ($PERL_BINDINGS_OPTIONS)"
+if test "x$with_perl_bindings" = "xyes" && test "x$PERL_BINDINGS_OPTIONS" != "x"; then
+  with_perl_bindings="yes ($PERL_BINDINGS_OPTIONS)"
 fi
 
 AC_MSG_RESULT()
@@ -6734,7 +6595,6 @@ AC_MSG_RESULT([    libganglia  . . . . . $with_libganglia])
 AC_MSG_RESULT([    libgcrypt . . . . . . $with_libgcrypt])
 AC_MSG_RESULT([    libgps  . . . . . . . $with_libgps])
 AC_MSG_RESULT([    libgrpc++ . . . . . . $with_libgrpcpp])
-AC_MSG_RESULT([    libhal  . . . . . . . $with_libhal])
 AC_MSG_RESULT([    libhiredis  . . . . . $with_libhiredis])
 AC_MSG_RESULT([    libi2c-dev  . . . . . $with_libi2c])
 AC_MSG_RESULT([    libiokit  . . . . . . $with_libiokit])
@@ -6755,7 +6615,6 @@ AC_MSG_RESULT([    libmysql  . . . . . . $with_libmysql])
 AC_MSG_RESULT([    libnetapp . . . . . . $with_libnetapp])
 AC_MSG_RESULT([    libnetsnmp  . . . . . $with_libnetsnmp])
 AC_MSG_RESULT([    libnotify . . . . . . $with_libnotify])
-AC_MSG_RESULT([    liboconfig  . . . . . $with_liboconfig])
 AC_MSG_RESULT([    libopenipmi . . . . . $with_libopenipmipthread])
 AC_MSG_RESULT([    liboping  . . . . . . $with_liboping])
 AC_MSG_RESULT([    libowcapi . . . . . . $with_libowcapi])
@@ -6836,7 +6695,7 @@ AC_MSG_RESULT([    gps . . . . . . . . . $enable_gps])
 AC_MSG_RESULT([    grpc  . . . . . . . . $enable_grpc])
 AC_MSG_RESULT([    hddtemp . . . . . . . $enable_hddtemp])
 AC_MSG_RESULT([    hugepages . . . . . . $enable_hugepages])
-AC_MSG_RESULT([    intel_rdt. . . . .  . $enable_intel_rdt])
+AC_MSG_RESULT([    intel_rdt . . . . . . $enable_intel_rdt])
 AC_MSG_RESULT([    interface . . . . . . $enable_interface])
 AC_MSG_RESULT([    ipc . . . . . . . . . $enable_ipc])
 AC_MSG_RESULT([    ipmi  . . . . . . . . $enable_ipmi])
@@ -6946,11 +6805,11 @@ AC_MSG_RESULT([    zookeeper . . . . . . $enable_zookeeper])
 AC_MSG_RESULT()
 
 if test "x$dependency_error" = "xyes"; then
-       AC_MSG_ERROR("Some plugins are missing dependencies - see the summary above for details")
+  AC_MSG_ERROR("Some plugins are missing dependencies - see the summary above for details")
 fi
 
 if test "x$dependency_warning" = "xyes"; then
-       AC_MSG_WARN("Some plugins seem to have missing dependencies but have been enabled forcibly - see the summary above for details")
+  AC_MSG_WARN("Some plugins seem to have missing dependencies but have been enabled forcibly - see the summary above for details")
 fi
 
-# vim: set fdm=marker :
+# vim: set fdm=marker sw=2 sts=2 ts=2 et :
index 5f401f0..6e2ea19 100644 (file)
@@ -49,6 +49,21 @@ should look something like this:
   datadir: "/var/lib/collectd/rrd/"
   libdir: "/usr/lib/collectd/"
 
+docker/
+-------
+Sample docker setup using an LD_PRELOAD wrapper to redirect system calls
+accessing /proc and /sys to prefixed bind-mounts inside the container.
+
+Drop your collectd configuration snippets in the
+contrib/docker/collectd.conf.d/ directory, and build an image including them:
+ $ docker build -t my_collectd ./contrib/docker/
+
+Then run it with the required bind-mounts:
+ $ docker run -it --rm \
+    -v /proc:/rootfs/proc:ro -v /sys:/rootfs/sys:ro \
+    --name collectd my_collectd
+ $ docker exec -it collectd collectdctl listval
+
 exec-munin.px
 -------------
   Script to be used with the exec-plugin (see collectd-exec(5) for details)
diff --git a/contrib/docker/50docker-apt-conf b/contrib/docker/50docker-apt-conf
new file mode 100644 (file)
index 0000000..3f898b3
--- /dev/null
@@ -0,0 +1,4 @@
+APT::Install-Recommends "0";
+APT::Install-Suggests "0";
+APT::Get::Assume-Yes "1";
+APT::Get::AutomaticRemove "1";
diff --git a/contrib/docker/Dockerfile b/contrib/docker/Dockerfile
new file mode 100644 (file)
index 0000000..a691f2e
--- /dev/null
@@ -0,0 +1,24 @@
+FROM debian:stable
+
+ENV DEBIAN_FRONTEND noninteractive
+COPY 50docker-apt-conf /etc/apt/apt.conf.d/
+
+COPY rootfs_prefix/ /usr/src/rootfs_prefix/
+
+RUN apt-get update \
+ && apt-get upgrade \
+ && apt-get install \
+    collectd-core \
+    collectd-utils \
+    build-essential \
+ && make -C /usr/src/rootfs_prefix/ \
+ && apt-get --purge remove build-essential \
+ && apt-get clean \
+ && rm -rf /var/lib/apt/lists/*
+
+COPY collectd.conf /etc/collectd/collectd.conf
+COPY collectd.conf.d /etc/collectd/collectd.conf.d
+
+ENV LD_PRELOAD /usr/src/rootfs_prefix/rootfs_prefix.so
+
+CMD [ "/usr/sbin/collectd", "-f"]
diff --git a/contrib/docker/collectd.conf b/contrib/docker/collectd.conf
new file mode 100644 (file)
index 0000000..bbcd079
--- /dev/null
@@ -0,0 +1,16 @@
+LoadPlugin logfile
+<Plugin logfile>
+       LogLevel "info"
+       File STDOUT
+       Timestamp true
+       PrintSeverity true
+</Plugin>
+
+LoadPlugin unixsock
+<Plugin unixsock>
+        SocketGroup "nogroup"
+</Plugin>
+
+<Include "/etc/collectd/collectd.conf.d">
+        Filter "*.conf"
+</Include>
diff --git a/contrib/docker/collectd.conf.d/sample.conf b/contrib/docker/collectd.conf.d/sample.conf
new file mode 100644 (file)
index 0000000..cbd7ce1
--- /dev/null
@@ -0,0 +1,4 @@
+LoadPlugin cpu
+LoadPlugin memory
+LoadPlugin disk
+LoadPlugin df
diff --git a/contrib/docker/rootfs_prefix/.gitignore b/contrib/docker/rootfs_prefix/.gitignore
new file mode 100644 (file)
index 0000000..c95ccf8
--- /dev/null
@@ -0,0 +1 @@
+rootprefix.so
diff --git a/contrib/docker/rootfs_prefix/Makefile b/contrib/docker/rootfs_prefix/Makefile
new file mode 100644 (file)
index 0000000..f26bebd
--- /dev/null
@@ -0,0 +1,2 @@
+rootfs_prefix.so: rootfs_prefix.c
+       $(CC) -Wall -Werror -fPIC -shared -o rootfs_prefix.so rootfs_prefix.c -ldl
diff --git a/contrib/docker/rootfs_prefix/rootfs_prefix.c b/contrib/docker/rootfs_prefix/rootfs_prefix.c
new file mode 100644 (file)
index 0000000..2b83151
--- /dev/null
@@ -0,0 +1,58 @@
+#define _GNU_SOURCE
+
+#include <dirent.h>
+#include <dlfcn.h>
+#include <errno.h>
+#include <error.h>
+#include <stdio.h>
+#include <string.h>
+
+#define PREFIX "/rootfs"
+#define BUFSIZE 256
+
+const char *add_prefix(const char *orig, char *prefixed) {
+  if ((strncmp(orig, "/proc", strlen("/proc")) != 0) &&
+      (strncmp(orig, "/sys", strlen("/sys")) != 0))
+    return orig;
+
+  int status = snprintf(prefixed, BUFSIZE, "%s%s", PREFIX, orig);
+  if (status < 1) {
+    error(status, errno, "adding '%s' prefix to file path failed: '%s' -> '%s'",
+          PREFIX, orig, prefixed);
+    return orig;
+  } else if ((unsigned int)status >= BUFSIZE) {
+    error(status, ENAMETOOLONG,
+          "'%s' got truncated when adding '%s' prefix: '%s'", orig, PREFIX,
+          prefixed);
+    return orig;
+  } else {
+    return (const char *)prefixed;
+  }
+}
+
+FILE *fopen(const char *path, const char *mode) {
+  char filename[BUFSIZE] = "\0";
+
+  FILE *(*original_fopen)(const char *, const char *);
+  original_fopen = dlsym(RTLD_NEXT, "fopen");
+
+  return (*original_fopen)(add_prefix(path, filename), mode);
+}
+
+DIR *opendir(const char *name) {
+  char filename[BUFSIZE] = "\0";
+
+  DIR *(*original_opendir)(const char *);
+  original_opendir = dlsym(RTLD_NEXT, "opendir");
+
+  return (*original_opendir)(add_prefix(name, filename));
+}
+
+int *open(const char *pathname, int flags) {
+  char filename[BUFSIZE] = "\0";
+
+  int *(*original_open)(const char *, int);
+  original_open = dlsym(RTLD_NEXT, "open");
+
+  return (*original_open)(add_prefix(pathname, filename), flags);
+}
index 4fc76e1..09cc3b1 100644 (file)
@@ -242,7 +242,7 @@ Source:             https://collectd.org/files/%{name}-%{version}.tar.bz2
 License:       GPLv2
 Group:         System Environment/Daemons
 BuildRoot:     %{_tmppath}/%{name}-%{version}-root
-BuildRequires: libgcrypt-devel, kernel-headers, libtool-ltdl-devel, libcap-devel, which
+BuildRequires: libgcrypt-devel, kernel-headers, libcap-devel, which
 Vendor:                collectd development team <collectd@verplant.org>
 
 %if 0%{?fedora} || 0%{?rhel} >= 7
@@ -1767,7 +1767,6 @@ Collectd utilities
 %configure CFLAGS="%{optflags} -DLT_LAZY_OR_NOW=\"RTLD_LAZY|RTLD_GLOBAL\"" \
        %{?_python_config} \
        --disable-static \
-       --without-included-ltdl \
        --enable-all-plugins=yes \
        --enable-match_empty_counter \
        --enable-match_hashed \
diff --git a/docs/README.virt.md b/docs/README.virt.md
new file mode 100644 (file)
index 0000000..a80e9ea
--- /dev/null
@@ -0,0 +1,240 @@
+Inside the virt plugin
+======================
+
+Originally written: 20161111
+
+Last updated: 20161124
+
+This document will explain the new domain tag support introduced
+in the virt plugin, and will provide one important use case for this feature.
+In the reminder of this document, we consider
+
+* libvirt <= 2.0.0
+* QEMU <= 2.6.0
+
+
+Domain tags and domains partitioning across virt reader instances
+-----------------------------------------------------------------
+
+The virt plugin gained the `Instances` option. It allows to start
+more than one reader instance, so the the libvirt domains could be queried
+by more than one reader thread.
+The default value for `Instances` is `1`.
+With default settings, the plugin will behave in a fully transparent,
+backward compatible way.
+It is recommended to set this value to one multiple of the
+daemon `ReadThreads` value.
+
+Each reader instance will query only a subset of the libvirt domain.
+The subset is identified as follows:
+
+1. Each virt reader instance is named `virt-$NUM`, where `NUM` is
+   the progressive order of instances. If you configure `Instances 3`
+   you will have `virt-0`, `virt-1`, `virt-2`. Please note: the `virt-0`
+   instance is special, and will always be available.
+2. Each virt reader instance will iterate over all the libvirt active domains,
+   and will look for one `tag` attribute (see below) in the domain metadata section.
+3. Each virt reader instance will take care *only* of the libvirt domains whose
+   tag matches with its own
+4. The special `virt-0` instance will take care of all the libvirt domains with
+   no tags, or with tags which are not in the set \[virt-0 ... virt-$NUM\]
+
+Collectd will just use the domain tags, but never enforces or requires them.
+It is up to an external entity, like a software management system,
+to attach and manage the tags to the domain.
+
+Please note that unless you have such tag-aware management sofware,
+it most likely make no sense to enable more than one reader instance on your
+setup.
+
+
+Libvirt tag metadata format
+----------------------------
+
+This is the snipped to be added to libvirt domains:
+
+    <ovirtmap:tag xmlns:ovirtmap="http://ovirt.org/ovirtmap/tag/1.0">
+      $TAG
+    </ovirtmap:tag>
+
+it must be included in the <metadata> section.
+
+Check the `src/virt_test.c` file for really minimal example of libvirt domains.
+
+
+Examples
+--------
+
+### Example one: 10 libvirt domains named "domain-A" ... "domain-J", virt plugin with instances=5, using 5 different tags
+
+
+    libvirt domain name -    tag    - read instance - reason
+    domain-A                virt-0         0          tag match
+    domain-B                virt-1         1          tag match
+    domain-C                virt-2         2          tag match
+    domain-D                virt-3         3          tag match
+    domain-E                virt-4         4          tag match
+    domain-F                virt-0         0          tag match
+    domain-G                virt-1         1          tag match
+    domain-H                virt-2         2          tag match
+    domain-I                virt-3         3          tag match
+    domain-J                virt-4         4          tag match
+
+
+  Because the domain where properly tagged, all the read instances have even load. Please note that the the virt plugin
+  knows nothing, and should know nothing, about *how* the libvirt domain are tagged. This is entirely up to the
+  management system.
+
+
+Example two: 10 libvirt domains named "domain-A" ... "domain-J", virt plugin with instances=3, using 5 different tags
+
+
+    libvirt domain name -    tag    - read instance - reason
+    domain-A                virt-0         0          tag match
+    domain-B                virt-1         1          tag match
+    domain-C                virt-2         2          tag match
+    domain-D                virt-3         0          adopted by instance #0
+    domain-E                virt-4         0          adopted by instance #0
+    domain-F                virt-0         0          rag match
+    domain-G                virt-1         1          tag match
+    domain-H                virt-2         2          tag match
+    domain-I                virt-3         0          adopted by instance #0
+    domain-J                virt-4         0          adopted by instance #0
+
+
+  In this case we have uneven load, but no domain is ignored.
+
+
+### Example three: 10 libvirt domains named "domain-A" ... "domain-J", virt plugin with instances=5, using 3 different tags
+
+
+    libvirt domain name -    tag    - read instance - reason
+    domain-A                virt-0         0          tag match
+    domain-B                virt-1         1          tag match
+    domain-C                virt-2         2          tag match
+    domain-D                virt-0         0          tag match
+    domain-E                virt-1         1          tag match
+    domain-F                virt-2         2          tag match
+    domain-G                virt-0         0          tag match
+    domain-H                virt-1         1          tag match
+    domain-I                virt-2         2          tag match
+    domain-J                virt-0         0          tag match
+
+
+  Once again we have uneven load and two idle read instances, but besides that no domain is left unmonitored
+
+
+### Example four: 10 libvirt domains named "domain-A" ... "domain-J", virt plugin with instances=5, partial tagging
+
+
+    libvirt domain name -    tag    - read instance - reason
+    domain-A                virt-0         0          tag match
+    domain-B                virt-1         1          tag match
+    domain-C                virt-2         2          tag match
+    domain-D                virt-0         0          tag match
+    domain-E                               0          adopted by instance #0
+    domain-F                               0          adopted by instance #0
+    domain-G                               0          adopted by instance #0
+    domain-H                               0          adopted by instance #0
+    domain-I                               0          adopted by instance #0
+    domain-J                               0          adopted by instance #0
+
+
+The lack of tags causes uneven load, but no domain are unmonitored.
+
+
+Possible extensions - custom tag format
+---------------------------------------
+
+The aformentioned approach relies on fixed tag format, `virt-$N`. The algorithm works fine with any tag, which
+is just one string, compared for equality. However, using custom strings for tags creates the need for a mapping
+between tags and the read instances.
+This mapping needs to be updated as long as domain are created or destroyed, and the virt plugin needs to be
+notified of the changes.
+
+This adds a significant amount of complexity, with little gain with respect to the fixed schema adopted initially.
+For this reason, the introdution of dynamic, custom mapping was not implemented.
+
+
+Dealing with datacenters: libvirt, qemu, shared storage
+-------------------------------------------------------
+
+When used in a datacenter, QEMU is most often configured to use shared storage. This is
+the default configuration of datacenter management solutions like [oVirt](http://www.ovirt.org).
+The actual shared storage could be implemented on top of NFS for small installations, or most likely
+ISCSI or Fiber Channel. The key takeaway is that the storage is accessed over the network,
+not using e.g. the SATA or PCI bus of any given host, so any network issue could cause
+one or more storage operations to delay, or to be lost entirely.
+
+In that case, the userspace process that requested the operation can end up in the D state,
+and become unresponsive, and unkillable.
+
+
+Dealing with unresponsive domains
+---------------------------------
+
+All the above considered, one robust management or monitoring application must deal with the fact that
+the libvirt API can block for a long time, or forever. This is not an issue or a bug of one specific
+API, but it is rather a byproduct of how libvirt and QEMU interact.
+
+Whenever we query more than one VM, we should take care to avoid that one blocked VM prevent other,
+well behaving VMs to be queried. We don't want one rogue VM to disrupt well-behaving VMs.
+Unfortunately, any way we enumerate VMs, either implicitely, using the libvirt bulk stats API,
+or explicitely, listing all libvirt domains and query each one in turn, we may unpredictably encounter
+one unresponsive VM.
+
+There are many possible approaches to deal with this issue. The virt plugin supports
+a simple but effective approach partitioning the domains, as follows.
+
+1. The virt plugin always register one or more `read` callbacks. The `zero` read callback is guaranteed to
+   be always present, so it performs special duties (more details later)
+   Each callback will be named 'virt-$N', where `N` ranges from 0 (zero) to M-1, where M is the number of instances configured.
+   `M` equals to `5` by default, because this is the same default number of threads in the libvirt worker pool.
+2. Each of the read callbacks queries libvirt for the list of all the active domains, and retrieves the libvirt domain metadata.
+   Both of those operations are safe wrt domain blocked in I/O (they affect only the libvirtd daemon).
+3. Each of the read callbacks extracts the `tag` from the domain metadata using a well-known format (see below).
+   Each of the read callbacks discards any domain which has no tag, or whose tag doesn't match with the read callback tag.
+3.a. The read callback tag equals to the read callback name, thus `virt-$N`. Remember that `virt-0` is guaranteed to be
+     always present.
+3.b. Since the `virt-0` reader is always present, it will take care of domains with no tag, or with unrecognized tag.
+     One unrecognized tag is any tag which has not the scheme `virt-$N`.
+4. Each read callback only samples the subset of domains with matching tag. The `virt-0` reader will possibly do more,
+   but worst case the load will be unbalanced, no domain will be left unsampled.
+
+To make this approach work, some entity must attach the tags to the libvirt domains, in such a way that all
+the domains which run on a given host and insist on the same network-based storage share the same tag.
+This minimizes the disruption, because when using the shared storage, if one domain becomes unresponsive because
+of unavailable storage, the most likely thing to happen is that others domain using the same storage will soon become
+unavailable; should the box run other libvirt domains using other network-based storage, they could be monitored
+safely.
+
+In case of [oVirt](http://www.ovirt.org), the aforementioned tagging is performed by the host agent.
+
+Please note that this approach is ineffective if the host completely lose network access to the storage network.
+In this case, however, no recovery is possible and no damage limitation is possible.
+
+Lastly, please note that if the virt plugin is configured with instances=1, it behaves exactly like before.
+
+
+Addendum: high level overview: libvirt client, libvirt daemon, qemu
+--------------------------------------------------------------------
+
+Let's review how the client application (collectd + virt plugin), the libvirtd daemon and the
+QEMU processes interact with each other.
+
+The libvirt daemon talks to QEMU using the JSON QMP protcol over one unix domain socket.
+The details of the protocol are not important now, but the key part is that the protocol
+is a simple request/response, meaning that libvirtd must serialize all the interactions
+with the QEMU monitor, and must protects its endpoint with a lock.
+No out of order request/responses are possible (e.g. no pipelining or async replies).
+This means that if for any reason one QMP request could not be completed, any other caller
+trying to access the QEMU monitor will block until the blocked caller returns.
+
+To retrieve some key informations, most notably about the block device state or the balloon
+device state, the libvirtd daemon *must* use the QMP protocol.
+
+The QEMU core, including the handling of the QMP protocol, is single-threaded.
+All the above combined make it possible for a client to block forever waiting for one QMP
+request, if QEMU itself is blocked. The most likely cause of block is I/O, and this is especially
+true considering how QEMU is used in a datacenter.
+
index bec7ca9..9355c78 100644 (file)
@@ -1,8 +1,4 @@
-SUBDIRS = libcollectdclient
-if BUILD_WITH_OWN_LIBOCONFIG
-SUBDIRS += liboconfig
-endif
-SUBDIRS += daemon
+SUBDIRS = libcollectdclient liboconfig daemon
 
 PLUGIN_LDFLAGS = -module -avoid-version -export-symbols-regex '\<module_register\>'
 
@@ -380,6 +376,7 @@ if BUILD_PLUGIN_DISK
 pkglib_LTLIBRARIES += disk.la
 disk_la_SOURCES = disk.c
 disk_la_CFLAGS = $(AM_CFLAGS)
+disk_la_CPPFLAGS = $(AM_CPPFLAGS)
 disk_la_LDFLAGS = $(PLUGIN_LDFLAGS)
 disk_la_LIBADD =
 if BUILD_WITH_LIBKSTAT
@@ -396,7 +393,7 @@ disk_la_CFLAGS += $(BUILD_WITH_LIBSTATGRAB_CFLAGS)
 disk_la_LIBADD += $(BUILD_WITH_LIBSTATGRAB_LDFLAGS)
 endif
 if BUILD_WITH_LIBUDEV
-disk_la_CFLAGS += $(BUILD_WITH_LIBUDEV_CFLAGS)
+disk_la_CPPFLAGS += $(BUILD_WITH_LIBUDEV_CPPFLAGS)
 disk_la_LDFLAGS += $(BUILD_WITH_LIBUDEV_LDFLAGS)
 disk_la_LIBADD += $(BUILD_WITH_LIBUDEV_LIBS)
 endif
@@ -411,8 +408,9 @@ endif
 if BUILD_PLUGIN_DNS
 pkglib_LTLIBRARIES += dns.la
 dns_la_SOURCES = dns.c utils_dns.c utils_dns.h
-dns_la_LDFLAGS = $(PLUGIN_LDFLAGS)
-dns_la_LIBADD = -lpcap
+dns_la_CPPFLAGS = $(AM_CPPFLAGS) $(BUILD_WITH_LIBPCAP_CPPFLAGS)
+dns_la_LDFLAGS = $(PLUGIN_LDFLAGS) $(BUILD_WITH_LIBPCAP_LDFLAGS)
+dns_la_LIBADD = $(BUILD_WITH_LIBPCAP_LIBS)
 endif
 
 if BUILD_PLUGIN_DPDKSTAT
@@ -724,9 +722,9 @@ endif
 if BUILD_PLUGIN_MIC
 pkglib_LTLIBRARIES += mic.la
 mic_la_SOURCES = mic.c
-mic_la_LDFLAGS = $(PLUGIN_LDFLAGS) $(BUILD_WITH_MIC_LIBPATH)
-mic_la_CFLAGS = $(AM_CFLAGS) $(BUILD_WITH_MIC_CPPFLAGS)
-mic_la_LIBADD = $(BUILD_WITH_MIC_LDADD)
+mic_la_CPPFLAGS = $(AM_CPPFLAGS) $(BUILD_WITH_MIC_CPPFLAGS)
+mic_la_LDFLAGS = $(PLUGIN_LDFLAGS) $(BUILD_WITH_MIC_LDFLAGS)
+mic_la_LIBADD = $(BUILD_WITH_MIC_LIBS)
 endif
 
 if BUILD_PLUGIN_MODBUS
@@ -823,8 +821,9 @@ endif
 if BUILD_PLUGIN_NOTIFY_EMAIL
 pkglib_LTLIBRARIES += notify_email.la
 notify_email_la_SOURCES = notify_email.c
-notify_email_la_LDFLAGS = $(PLUGIN_LDFLAGS)
-notify_email_la_LIBADD = -lesmtp -lssl -lcrypto
+notify_email_la_CPPFLAGS = $(AM_CPPFLAGS) $(BUILD_WITH_LIBESMTP_CPPFLAGS)
+notify_email_la_LDFLAGS = $(PLUGIN_LDFLAGS) $(BUILD_WITH_LIBESMTP_LDFLAGS)
+notify_email_la_LIBADD = $(BUILD_WITH_LIBESMTP_LIBS)
 endif
 
 if BUILD_PLUGIN_NOTIFY_NAGIOS
@@ -911,11 +910,6 @@ perl_la_CPPFLAGS += -D_GNU_SOURCE
 perl_la_CFLAGS  = $(AM_CFLAGS) \
                $(PERL_CFLAGS) \
                -DXS_VERSION=\"$(VERSION)\" -DVERSION=\"$(VERSION)\"
-# Work-around for issues #41 and #42 - Perl 5.10 incorrectly introduced
-# __attribute__nonnull__(3) for Perl_load_module().
-if HAVE_BROKEN_PERL_LOAD_MODULE
-perl_la_CFLAGS += -Wno-nonnull
-endif
 perl_la_LDFLAGS = $(PLUGIN_LDFLAGS) \
                $(PERL_LDFLAGS)
 perl_la_LIBADD = $(PERL_LIBS)
@@ -951,7 +945,7 @@ postgresql_la_SOURCES = postgresql.c \
 postgresql_la_CPPFLAGS = $(AM_CPPFLAGS) $(BUILD_WITH_LIBPQ_CPPFLAGS)
 postgresql_la_LDFLAGS = $(PLUGIN_LDFLAGS) \
                $(BUILD_WITH_LIBPQ_LDFLAGS)
-postgresql_la_LIBADD = -lpq
+postgresql_la_LIBADD = $(BUILD_WITH_LIBPQ_LIBS)
 endif
 
 if BUILD_PLUGIN_POWERDNS
@@ -1029,9 +1023,9 @@ endif
 if BUILD_PLUGIN_SENSORS
 pkglib_LTLIBRARIES += sensors.la
 sensors_la_SOURCES = sensors.c
-sensors_la_CFLAGS = $(AM_CFLAGS) $(BUILD_WITH_LIBSENSORS_CFLAGS)
+sensors_la_CPPFLAGS = $(AM_CPPFLAGS) $(BUILD_WITH_LIBSENSORS_CPPFLAGS)
 sensors_la_LDFLAGS = $(PLUGIN_LDFLAGS) $(BUILD_WITH_LIBSENSORS_LDFLAGS)
-sensors_la_LIBADD = -lsensors
+sensors_la_LIBADD = $(BUILD_WITH_LIBSENSORS_LIBS)
 endif
 
 if BUILD_PLUGIN_SERIAL
@@ -1052,7 +1046,7 @@ if BUILD_PLUGIN_SMART
 if BUILD_WITH_LIBUDEV
 pkglib_LTLIBRARIES += smart.la
 smart_la_SOURCES = smart.c
-smart_la_CFLAGS = $(AM_CFLAGS) $(BUILD_WITH_LIBATASMART_CPPFLAGS) $(BUILD_WITH_LIBUDEV_CFLAGS)
+smart_la_CPPFLAGS = $(AM_CPPFLAGS) $(BUILD_WITH_LIBATASMART_CPPFLAGS) $(BUILD_WITH_LIBUDEV_CPPFLAGS)
 smart_la_LDFLAGS = $(PLUGIN_LDFLAGS) $(BUILD_WITH_LIBATASMART_LDFLAGS) $(BUILD_WITH_LIBUDEV_LDFLAGS)
 smart_la_LIBADD = $(BUILD_WITH_LIBATASMART_LIBS) $(BUILD_WITH_LIBUDEV_LIBS)
 endif
@@ -1251,8 +1245,6 @@ endif
 if BUILD_PLUGIN_UUID
 pkglib_LTLIBRARIES += uuid.la
 uuid_la_SOURCES = uuid.c
-uuid_la_CFLAGS  = $(AM_CFLAGS) $(BUILD_WITH_LIBHAL_CFLAGS)
-uuid_la_LIBADD  = $(BUILD_WITH_LIBHAL_LIBS)
 uuid_la_LDFLAGS = $(PLUGIN_LDFLAGS)
 endif
 
@@ -1271,6 +1263,19 @@ virt_la_CFLAGS = $(AM_CFLAGS) \
                $(BUILD_WITH_LIBVIRT_CFLAGS) $(BUILD_WITH_LIBXML2_CFLAGS)
 virt_la_LIBADD = $(BUILD_WITH_LIBVIRT_LIBS) $(BUILD_WITH_LIBXML2_LIBS)
 virt_la_LDFLAGS = $(PLUGIN_LDFLAGS)
+
+# TODO: enable once we support only modern libvirts which depends on libnl-3
+# the libvirt on wheezy is linked in libnl v1, and there is a small leak here,
+# triggered by the library initialization. There are no means to avoid it,
+# and libvirt switched to libnl3 anyway
+#test_plugin_virt_SOURCES = virt_test.c
+#test_plugin_virt_CPPFLAGS = $(AM_CPPFLAGS) \
+#              $(BUILD_WITH_LIBVIRT_CFLAGS) $(BUILD_WITH_LIBXML2_CFLAGS)
+#test_plugin_virt_LDFLAGS = $(PLUGIN_LDFLAGS)
+#test_plugin_virt_LDADD = daemon/libplugin_mock.la \
+#              $(BUILD_WITH_LIBVIRT_LIBS) $(BUILD_WITH_LIBXML2_LIBS)
+#check_PROGRAMS += test_plugin_virt
+#TESTS += test_plugin_virt
 endif
 
 if BUILD_PLUGIN_VMEM
index 4e20d0c..8d501f6 100644 (file)
@@ -752,5 +752,3 @@ void module_register(void) {
   plugin_register_read("aggregation", agg_read);
   plugin_register_write("aggregation", agg_write, /* user_data = */ NULL);
 }
-
-/* vim: set sw=2 sts=2 tw=78 et fdm=marker : */
index cd07023..4870107 100644 (file)
@@ -1022,5 +1022,3 @@ void module_register(void) {
   plugin_register_complex_config("amqp", camqp_config);
   plugin_register_shutdown("amqp", camqp_shutdown);
 } /* void module_register */
-
-/* vim: set sw=4 sts=4 et fdm=marker : */
index eaef61b..547d745 100644 (file)
@@ -573,5 +573,3 @@ void module_register(void) {
   plugin_register_complex_config("apache", config);
   plugin_register_init("apache", apache_init);
 } /* void module_register */
-
-/* vim: set sw=8 noet fdm=marker : */
index 2f8cccd..902b5f9 100644 (file)
 #include "common.h"
 #include "plugin.h"
 
-#if HAVE_CTYPE_H
-#include <ctype.h>
-#endif
-
 #if HAVE_MACH_MACH_TYPES_H
 #include <mach/mach_types.h>
 #endif
index 4a78f68..22278e0 100644 (file)
@@ -161,5 +161,3 @@ void module_register(void) {
   plugin_register_read("aquaero", aquaero_read);
   plugin_register_shutdown("aquaero", aquaero_shutdown);
 } /* void module_register */
-
-/* vim: set sw=8 sts=8 noet : */
index 840fe8b..5f0d85e 100644 (file)
@@ -571,5 +571,3 @@ void module_register(void) {
   plugin_register_init("ascent", ascent_init);
   plugin_register_read("ascent", ascent_read);
 } /* void module_register */
-
-/* vim: set sw=2 sts=2 ts=8 et fdm=marker : */
index 4b9baf4..4f6a8c1 100644 (file)
@@ -87,9 +87,9 @@ int battery_read_statefs(void) {
   }
 
   struct {
-    char *path;
-    char *type;
-    char *type_instance;
+    const char *path;
+    const char *type;
+    const char *type_instance;
     gauge_t factor;
   } metrics[] = {
       {STATEFS_ROOT "Current", "current", NULL, 1e-6},        // from uA to A
index 9bb662f..3876177 100644 (file)
@@ -1613,5 +1613,3 @@ void module_register(void) {
   plugin_register_read("bind", bind_read);
   plugin_register_shutdown("bind", bind_shutdown);
 } /* void module_register */
-
-/* vim: set sw=2 sts=2 ts=8 et fdm=marker : */
index 4e435b3..2331e33 100644 (file)
@@ -1446,4 +1446,3 @@ void module_register(void) {
   plugin_register_read("ceph", ceph_read);
   plugin_register_shutdown("ceph", ceph_shutdown);
 }
-/* vim: set sw=4 sts=4 et : */
index 3da4098..2f65b50 100644 (file)
@@ -187,5 +187,3 @@ int main(void) {
 
   END_TEST;
 }
-
-/* vim: set sw=2 sts=2 et : */
index 7ded64d..3bde325 100644 (file)
@@ -423,5 +423,3 @@ int main(int argc, char **argv) /* {{{ */
   lcc_network_destroy(net);
   exit(EXIT_SUCCESS);
 } /* }}} int main */
-
-/* vim: set sw=2 sts=2 et fdm=marker : */
index e5b9643..8c1b10d 100644 (file)
 #      HostnameFormat name
 #      InterfaceFormat name
 #      PluginInstanceFormat name
+#      Instances 1
 #</Plugin>
 
 #<Plugin vmem>
index 11cfaeb..6a76e45 100644 (file)
@@ -7973,6 +7973,12 @@ You can also specify combinations of the B<name> and B<uuid> fields.
 For example B<name uuid> means to concatenate the guest name and UUID
 (with a literal colon character between, thus I<"foo:1234-1234-1234-1234">).
 
+=item B<Instances> B<integer>
+
+How many read instances you want to use for this plugin. The default is one,
+and the sensible setting is a multiple of the B<ReadThreads> value.
+If you are not sure, just use the default setting.
+
 =back
 
 =head2 Plugin C<vmem>
index 30d1cdc..248baad 100644 (file)
@@ -585,5 +585,3 @@ int main(int argc, char **argv) {
     return (status);
   return (0);
 } /* main */
-
-/* vim: set sw=2 ts=2 tw=78 expandtab : */
index 9040f8d..4a7d1a6 100644 (file)
@@ -386,5 +386,3 @@ int main(int argc, char **argv) {
   free(collectd_argv);
   return 0;
 } /* main */
-
-/* vim: set sw=4 ts=4 tw=78 noexpandtab : */
index 9091fef..c0bdd56 100644 (file)
--- a/src/cpu.c
+++ b/src/cpu.c
@@ -862,5 +862,3 @@ void module_register(void) {
   plugin_register_config("cpu", cpu_config, config_keys, config_keys_num);
   plugin_register_read("cpu", cpu_read);
 } /* void module_register */
-
-/* vim: set sw=8 sts=8 noet fdm=marker : */
index c6f0b60..4906d92 100644 (file)
@@ -679,5 +679,3 @@ void module_register(void) {
   plugin_register_read("curl", cc_read);
   plugin_register_shutdown("curl", cc_shutdown);
 } /* void module_register */
-
-/* vim: set sw=2 sts=2 et fdm=marker : */
index aa1ae79..8e09bd8 100644 (file)
@@ -940,5 +940,3 @@ void module_register(void) {
   plugin_register_complex_config("curl_json", cj_config);
   plugin_register_init("curl_json", cj_init);
 } /* void module_register */
-
-/* vim: set sw=2 sts=2 et fdm=marker : */
index 4e4c6f9..1c28227 100644 (file)
@@ -1026,5 +1026,3 @@ void module_register(void) {
   plugin_register_complex_config("curl_xml", cx_config);
   plugin_register_init("curl_xml", cx_init);
 } /* void module_register */
-
-/* vim: set sw=2 sts=2 et fdm=marker : */
index 5207943..9a0ba8f 100644 (file)
@@ -23,9 +23,6 @@ endif
 if BUILD_WITH_LIBSOCKET
 COMMON_LIBS += -lsocket
 endif
-if BUILD_WITH_LIBRESOLV
-COMMON_LIBS += -lresolv
-endif
 if BUILD_WITH_LIBKSTAT
 COMMON_LIBS += -lkstat
 endif
@@ -47,6 +44,8 @@ libheap_la_SOURCES = utils_heap.c utils_heap.h
 libmetadata_la_SOURCES = meta_data.c meta_data.h
 
 libplugin_mock_la_SOURCES = plugin_mock.c utils_cache_mock.c \
+                           utils_complain.c utils_complain.h \
+                           utils_ignorelist.c utils_ignorelist.h \
                            utils_time.c utils_time.h
 libplugin_mock_la_CPPFLAGS = $(AM_CPPFLAGS) -DMOCK_TIME
 libplugin_mock_la_LIBADD = $(COMMON_LIBS) libcommon.la
@@ -67,10 +66,9 @@ collectd_SOURCES = collectd.c collectd.h \
                   utils_threshold.c utils_threshold.h
 
 
-collectd_CPPFLAGS =  $(AM_CPPFLAGS) $(LTDLINCL)
 collectd_CFLAGS = $(AM_CFLAGS)
 collectd_LDFLAGS = -export-dynamic
-collectd_LDADD = libavltree.la libcommon.la libheap.la -lm $(COMMON_LIBS)
+collectd_LDADD = libavltree.la libcommon.la libheap.la -lm $(COMMON_LIBS) $(DLOPEN_LIBS)
 collectd_DEPENDENCIES = libavltree.la libcommon.la libheap.la libmetadata.la
 
 # The daemon needs to call sg_init, so we need to link it against libstatgrab,
@@ -80,12 +78,8 @@ collectd_CFLAGS += $(BUILD_WITH_LIBSTATGRAB_CFLAGS)
 collectd_LDADD += $(BUILD_WITH_LIBSTATGRAB_LDFLAGS)
 endif
 
-if BUILD_WITH_OWN_LIBOCONFIG
-collectd_LDADD += $(LIBLTDL) $(top_builddir)/src/liboconfig/liboconfig.la
+collectd_LDADD += $(top_builddir)/src/liboconfig/liboconfig.la
 collectd_DEPENDENCIES += $(top_builddir)/src/liboconfig/liboconfig.la
-else
-collectd_LDADD += -loconfig
-endif
 
 LOG_COMPILER = env VALGRIND="@VALGRIND@" $(abs_top_srcdir)/testwrapper.sh
 
index 4ec002d..38ffd0f 100644 (file)
 #include "config.h"
 #endif
 
+#include <assert.h>
+#include <ctype.h>
+#include <errno.h>
+#include <inttypes.h>
+#include <limits.h>
+#include <signal.h>
+#include <stdarg.h>
+#include <stddef.h>
+#include <stdint.h>
 #include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
 #if HAVE_SYS_TYPES_H
 #include <sys/types.h>
 #endif
 #if HAVE_SYS_STAT_H
 #include <sys/stat.h>
 #endif
-#if STDC_HEADERS
-#include <stddef.h>
-#include <stdlib.h>
-#else
-#if HAVE_STDLIB_H
-#include <stdlib.h>
-#endif
-#endif
-#if HAVE_STRING_H
-#if !STDC_HEADERS && HAVE_MEMORY_H
-#include <memory.h>
-#endif
-#include <string.h>
-#endif
 #if HAVE_STRINGS_H
 #include <strings.h>
 #endif
-#if HAVE_INTTYPES_H
-#include <inttypes.h>
-#endif
-#if HAVE_STDINT_H
-#include <stdint.h>
-#endif
 #if HAVE_UNISTD_H
 #include <unistd.h>
 #endif
 #ifndef WIFEXITED
 #define WIFEXITED(stat_val) (((stat_val)&255) == 0)
 #endif
-#if HAVE_SIGNAL_H
-#include <signal.h>
-#endif
 #if HAVE_FCNTL_H
 #include <fcntl.h>
 #endif
-#if HAVE_ERRNO_H
-#include <errno.h>
-#endif
-#if HAVE_LIMITS_H
-#include <limits.h>
-#endif
 #if TIME_WITH_SYS_TIME
 #include <sys/time.h>
 #include <time.h>
 #include <sys/socket.h>
 #endif
 
-#if HAVE_ASSERT_H
-#include <assert.h>
-#else
-#define assert(...) /* nop */
-#endif
-
-#if !defined(HAVE__BOOL) || !HAVE__BOOL
-typedef int _Bool;
-#undef HAVE__BOOL
-#define HAVE__BOOL 1
-#endif
-
 #if NAN_STATIC_DEFAULT
 #include <math.h>
 /* #endif NAN_STATIC_DEFAULT*/
@@ -212,12 +182,6 @@ typedef int _Bool;
 #endif
 #endif
 
-#if HAVE_STDARG_H
-#include <stdarg.h>
-#endif
-#if HAVE_CTYPE_H
-#include <ctype.h>
-#endif
 #if HAVE_SYS_PARAM_H
 #include <sys/param.h>
 #endif
index 0aa5345..40822d0 100644 (file)
 #include "plugin.h"
 #include "utils_cache.h"
 
-#ifdef HAVE_MATH_H
-#include <math.h>
-#endif
-
 /* for getaddrinfo */
 #include <netdb.h>
 #include <sys/types.h>
index 0c96945..f18d9fd 100644 (file)
@@ -392,5 +392,3 @@ int main(void) {
 
   END_TEST;
 }
-
-/* vim: set sw=2 sts=2 et : */
index d5f01e0..b57aadc 100644 (file)
@@ -245,7 +245,7 @@ static int dispatch_value_plugindir(oconfig_item_t *ci) {
 
 static int dispatch_loadplugin(oconfig_item_t *ci) {
   const char *name;
-  unsigned int flags = 0;
+  _Bool global = 0;
   plugin_ctx_t ctx = {0};
   plugin_ctx_t old_ctx;
   int ret_val;
@@ -270,7 +270,7 @@ static int dispatch_loadplugin(oconfig_item_t *ci) {
     oconfig_item_t *child = ci->children + i;
 
     if (strcasecmp("Globals", child->key) == 0)
-      cf_util_get_flag(child, &flags, PLUGIN_FLAGS_GLOBAL);
+      cf_util_get_boolean(child, &global);
     else if (strcasecmp("Interval", child->key) == 0)
       cf_util_get_cdtime(child, &ctx.interval);
     else if (strcasecmp("FlushInterval", child->key) == 0)
@@ -285,7 +285,7 @@ static int dispatch_loadplugin(oconfig_item_t *ci) {
   }
 
   old_ctx = plugin_set_ctx(ctx);
-  ret_val = plugin_load(name, (uint32_t)flags);
+  ret_val = plugin_load(name, global);
   /* reset to the "global" context */
   plugin_set_ctx(old_ctx);
 
index 9c4a89c..f21ea32 100644 (file)
@@ -942,5 +942,3 @@ int fc_configure(const oconfig_item_t *ci) /* {{{ */
 
   return (-1);
 } /* }}} int fc_configure */
-
-/* vim: set sw=2 sts=2 et fdm=marker : */
index 36ccbae..5cc06fc 100644 (file)
@@ -101,4 +101,3 @@ int fc_default_action(const data_set_t *ds, value_list_t *vl);
 int fc_configure(const oconfig_item_t *ci);
 
 #endif /* FILTER_CHAIN_H */
-/* vim: set sw=2 sts=2 et : */
index 583d819..3ac5370 100644 (file)
@@ -690,7 +690,7 @@ int meta_data_get_boolean(meta_data_t *md, /* {{{ */
 int meta_data_as_string(meta_data_t *md, /* {{{ */
                         const char *key, char **value) {
   meta_entry_t *e;
-  char *actual;
+  const char *actual;
   char buffer[MD_MAX_NONSTRING_CHARS]; /* For non-string types. */
   char *temp;
   int type;
@@ -746,5 +746,3 @@ int meta_data_as_string(meta_data_t *md, /* {{{ */
 
   return (0);
 } /* }}} int meta_data_as_string */
-
-/* vim: set sw=2 sts=2 et fdm=marker : */
index 3ef3360..50fdb8d 100644 (file)
@@ -69,4 +69,3 @@ int meta_data_get_boolean(meta_data_t *md, const char *key, _Bool *value);
 int meta_data_as_string(meta_data_t *md, const char *key, char **value);
 
 #endif /* META_DATA_H */
-/* vim: set sw=2 sts=2 et : */
index 803c745..bcd457d 100644 (file)
@@ -114,5 +114,3 @@ int main(void) {
 
   END_TEST;
 }
-
-/* vim: set sw=2 sts=2 et : */
index f313f36..c8fc15a 100644 (file)
@@ -46,7 +46,7 @@
 #include <pthread_np.h> /* for pthread_set_name_np(3) */
 #endif
 
-#include <ltdl.h>
+#include <dlfcn.h>
 
 /*
  * Private structures
@@ -389,40 +389,25 @@ static int plugin_unregister(llist_t *list, const char *name) /* {{{ */
  * object, but it will bitch about a shared object not having a
  * ``module_register'' symbol..
  */
-static int plugin_load_file(char *file, uint32_t flags) {
-  lt_dlhandle dlh;
+static int plugin_load_file(const char *file, _Bool global) {
   void (*reg_handle)(void);
 
-  lt_dlinit();
-  lt_dlerror(); /* clear errors */
+  int flags = RTLD_NOW;
+  if (global)
+    flags |= RTLD_GLOBAL;
 
-#if LIBTOOL_VERSION == 2
-  if (flags & PLUGIN_FLAGS_GLOBAL) {
-    lt_dladvise advise;
-    lt_dladvise_init(&advise);
-    lt_dladvise_global(&advise);
-    dlh = lt_dlopenadvise(file, advise);
-    lt_dladvise_destroy(&advise);
-  } else {
-    dlh = lt_dlopen(file);
-  }
-#else /* if LIBTOOL_VERSION == 1 */
-  if (flags & PLUGIN_FLAGS_GLOBAL)
-    WARNING("plugin_load_file: The global flag is not supported, "
-            "libtool 2 is required for this.");
-  dlh = lt_dlopen(file);
-#endif
+  void *dlh = dlopen(file, flags);
 
   if (dlh == NULL) {
     char errbuf[1024] = "";
 
     ssnprintf(errbuf, sizeof(errbuf),
-              "lt_dlopen (\"%s\") failed: %s. "
+              "dlopen (\"%s\") failed: %s. "
               "The most common cause for this problem is "
               "missing dependencies. Use ldd(1) to check "
               "the dependencies of the plugin "
               "/ shared object.",
-              file, lt_dlerror());
+              file, dlerror());
 
     ERROR("%s", errbuf);
     /* Make sure this is printed to STDERR in any case, but also
@@ -433,10 +418,11 @@ static int plugin_load_file(char *file, uint32_t flags) {
     return (1);
   }
 
-  if ((reg_handle = (void (*)(void))lt_dlsym(dlh, "module_register")) == NULL) {
+  reg_handle = (void (*)(void))dlsym(dlh, "module_register");
+  if (reg_handle == NULL) {
     WARNING("Couldn't find symbol \"module_register\" in \"%s\": %s\n", file,
-            lt_dlerror());
-    lt_dlclose(dlh);
+            dlerror());
+    dlclose(dlh);
     return (-1);
   }
 
@@ -973,7 +959,7 @@ static void plugin_free_loaded(void) {
 }
 
 #define BUFSIZE 512
-int plugin_load(char const *plugin_name, uint32_t flags) {
+int plugin_load(char const *plugin_name, _Bool global) {
   DIR *dh;
   const char *dir;
   char filename[BUFSIZE] = "";
@@ -1007,7 +993,7 @@ int plugin_load(char const *plugin_name, uint32_t flags) {
    */
   if ((strcasecmp("perl", plugin_name) == 0) ||
       (strcasecmp("python", plugin_name) == 0))
-    flags |= PLUGIN_FLAGS_GLOBAL;
+    global = 1;
 
   /* `cpu' should not match `cpufreq'. To solve this we add `.so' to the
    * type when matching the filename */
@@ -1045,7 +1031,7 @@ int plugin_load(char const *plugin_name, uint32_t flags) {
       continue;
     }
 
-    status = plugin_load_file(filename, flags);
+    status = plugin_load_file(filename, global);
     if (status == 0) {
       /* success */
       plugin_mark_loaded(plugin_name);
@@ -2592,5 +2578,3 @@ int plugin_thread_create(pthread_t *thread, const pthread_attr_t *attr,
 
   return 0;
 } /* int plugin_thread_create */
-
-/* vim: set sw=8 ts=8 noet fdm=marker : */
index f6448a5..4f877e0 100644 (file)
@@ -36,8 +36,6 @@
 
 #include <pthread.h>
 
-#define PLUGIN_FLAGS_GLOBAL 0x0001
-
 #ifndef DATA_MAX_NAME_LEN
 #define DATA_MAX_NAME_LEN 128
 #endif
@@ -226,7 +224,7 @@ void plugin_set_dir(const char *dir);
  *
  * ARGUMENTS
  *  `name'      Name of the plugin to load.
- *  `flags'     Hints on how to handle this plugin.
+ *  `global'    Make this plugins symbols available for other shared libraries.
  *
  * RETURN VALUE
  *  Returns zero upon success, a value greater than zero if no plugin was found
@@ -236,7 +234,7 @@ void plugin_set_dir(const char *dir);
  *  Re-loading an already loaded module is detected and zero is returned in
  *  this case.
  */
-int plugin_load(const char *name, uint32_t flags);
+int plugin_load(const char *name, _Bool global);
 
 int plugin_init_all(void);
 void plugin_read_all(void);
index ddfc789..9e7ba39 100644 (file)
@@ -32,6 +32,12 @@ kstat_ctl_t *kc = NULL;
 
 char hostname_g[] = "example.com";
 
+int plugin_register_config(const char *name,
+                           int (*callback)(const char *key, const char *val),
+                           const char **keys, int keys_num) {
+  return ENOTSUP;
+}
+
 int plugin_register_complex_config(const char *type,
                                    int (*callback)(oconfig_item_t *)) {
   return ENOTSUP;
@@ -45,6 +51,13 @@ int plugin_register_read(const char *name, int (*callback)(void)) {
   return ENOTSUP;
 }
 
+int plugin_register_complex_read(const char *group, const char *name,
+                                 int (*callback)(user_data_t *),
+                                 cdtime_t interval,
+                                 user_data_t const *user_data) {
+  return ENOTSUP;
+}
+
 int plugin_register_shutdown(const char *name, int (*callback)(void)) {
   return ENOTSUP;
 }
@@ -76,5 +89,3 @@ void plugin_log(int level, char const *format, ...) {
 }
 
 cdtime_t plugin_get_interval(void) { return TIME_T_TO_CDTIME_T(10); }
-
-/* vim: set sw=2 sts=2 et : */
index b1a7203..b053157 100644 (file)
@@ -191,7 +191,3 @@ int read_types_list(const char *file) {
 
   return (0);
 } /* int read_types_list */
-
-/*
- * vim: shiftwidth=2:softtabstop=2:tabstop=8
- */
index 0a84f6f..345f97b 100644 (file)
@@ -135,5 +135,3 @@ int main(void) {
 
   END_TEST;
 }
-
-/* vim: set sw=2 sts=2 et : */
index fe0e083..0caf22c 100644 (file)
@@ -938,5 +938,3 @@ int uc_meta_data_exists(const value_list_t *vl,
                                                 const char *key, _Bool *value)
                                                 UC_WRAP(meta_data_get_boolean)
 #undef UC_WRAP
-
-    /* vim: set sw=2 ts=8 sts=2 tw=78 : */
index 2f40873..24c58ff 100644 (file)
@@ -133,5 +133,4 @@ int uc_meta_data_get_double(const value_list_t *vl, const char *key,
 int uc_meta_data_get_boolean(const value_list_t *vl, const char *key,
                              _Bool *value);
 
-/* vim: set shiftwidth=2 softtabstop=2 tabstop=8 : */
 #endif /* !UTILS_CACHE_H */
index fb45243..d2162ba 100644 (file)
@@ -97,5 +97,3 @@ void c_do_release(int level, c_complain_t *c, const char *format, ...) {
 
   plugin_log(level, "%s", message);
 } /* c_release */
-
-/* vim: set sw=4 ts=4 tw=78 noexpandtab : */
index fbeea90..46d3a19 100644 (file)
@@ -113,5 +113,3 @@ c_do_release(int level, c_complain_t *c, const char *format, ...);
   } while (0)
 
 #endif /* UTILS_COMPLAIN_H */
-
-/* vim: set sw=4 ts=4 tw=78 noexpandtab : */
index 8dd501d..3bae48e 100644 (file)
@@ -203,5 +203,3 @@ void *c_heap_get_root(c_heap_t *h) {
 
   return (ret);
 } /* void *c_heap_get_root */
-
-/* vim: set sw=2 sts=2 et fdm=marker : */
index 2f77cc4..d2d70cd 100644 (file)
@@ -97,4 +97,3 @@ int c_heap_insert(c_heap_t *h, void *ptr);
 void *c_heap_get_root(c_heap_t *h);
 
 #endif /* UTILS_HEAP_H */
-/* vim: set sw=2 sts=2 et : */
index 8443b60..dec84f9 100644 (file)
@@ -76,5 +76,3 @@ int main(void) {
 
   END_TEST;
 }
-
-/* vim: set sw=2 sts=2 et : */
index d490986..77b500f 100644 (file)
@@ -50,7 +50,7 @@ static void cdrand_seed(void) {
   have_seed = 1;
 }
 
-double cdrand_d() {
+double cdrand_d(void) {
   double r;
 
   pthread_mutex_lock(&lock);
@@ -61,7 +61,7 @@ double cdrand_d() {
   return (r);
 }
 
-uint32_t cdrand_u() {
+uint32_t cdrand_u(void) {
   long r;
 
   pthread_mutex_lock(&lock);
index e25ae9b..75bdc12 100644 (file)
@@ -29,7 +29,7 @@
  *
  * This function is thread- and reentrant-safe.
  */
-double cdrand_d();
+double cdrand_d(void);
 
 /**
  * cdrand_u returns a random uint32_t value uniformly distributed in the range
@@ -37,7 +37,7 @@ double cdrand_d();
  *
  * This function is thread- and reentrant-safe.
  */
-uint32_t cdrand_u();
+uint32_t cdrand_u(void);
 
 /**
  * Returns a random long between min and max, inclusively.
index 7056c5f..5235343 100644 (file)
@@ -159,5 +159,3 @@ char *subst_string(char *buf, size_t buflen, const char *string,
 
   return (buf);
 } /* char *subst_string */
-
-/* vim: set sw=4 ts=4 tw=78 noexpandtab : */
index 025f8d4..a10b258 100644 (file)
@@ -100,5 +100,3 @@ char *subst_string(char *buf, size_t buflen, const char *string,
                    const char *needle, const char *replacement);
 
 #endif /* UTILS_SUBST_H */
-
-/* vim: set sw=4 ts=4 tw=78 noexpandtab : */
index e335b50..00ea0ea 100644 (file)
@@ -132,5 +132,3 @@ int main(void) {
 
   END_TEST;
 }
-
-/* vim: set sw=2 sts=2 et : */
index 585ad12..cefc6e2 100644 (file)
@@ -61,5 +61,3 @@ threshold_t *threshold_search(const value_list_t *vl);
 int ut_search_threshold(const value_list_t *vl, threshold_t *ret_threshold);
 
 #endif /* UTILS_THRESHOLD_H */
-
-/* vim: set sw=2 sts=2 ts=8 : */
index 9ba2b5a..815d969 100644 (file)
@@ -240,5 +240,3 @@ int rfc3339nano_local(char *buffer, size_t buffer_size, cdtime_t t) /* {{{ */
 
   return format_rfc3339_local(buffer, buffer_size, t, 1);
 } /* }}} int rfc3339nano */
-
-/* vim: set sw=2 sts=2 et fdm=marker : */
index db510af..60a6ea9 100644 (file)
@@ -130,4 +130,3 @@ int rfc3339_local(char *buffer, size_t buffer_size, cdtime_t t);
 int rfc3339nano_local(char *buffer, size_t buffer_size, cdtime_t t);
 
 #endif /* UTILS_TIME_H */
-/* vim: set sw=2 sts=2 et : */
index c1c60a2..c0179cc 100644 (file)
@@ -167,5 +167,3 @@ int main(void) {
 
   END_TEST;
 }
-
-/* vim: set sw=2 sts=2 et : */
index 7cab1d5..2b374e9 100644 (file)
--- a/src/dbi.c
+++ b/src/dbi.c
@@ -780,7 +780,3 @@ void module_register(void) /* {{{ */
   plugin_register_init("dbi", cdbi_init);
   plugin_register_shutdown("dbi", cdbi_shutdown);
 } /* }}} void module_register */
-
-/*
- * vim: shiftwidth=2 softtabstop=2 et fdm=marker
- */
index e01e150..58a1c18 100644 (file)
@@ -139,7 +139,7 @@ static int pnumdisk;
 #error "No applicable input method."
 #endif
 
-#if HAVE_LIBUDEV
+#if HAVE_UDEV_H
 #include <libudev.h>
 
 static char *conf_udev_name_attr = NULL;
@@ -173,7 +173,7 @@ static int disk_config(const char *key, const char *value) {
             "on Mach / Mac OS X and will be ignored.");
 #endif
   } else if (strcasecmp("UdevNameAttr", key) == 0) {
-#if HAVE_LIBUDEV
+#if HAVE_UDEV_H
     if (conf_udev_name_attr != NULL) {
       free(conf_udev_name_attr);
       conf_udev_name_attr = NULL;
@@ -209,7 +209,7 @@ static int disk_init(void) {
 /* #endif HAVE_IOKIT_IOKITLIB_H */
 
 #elif KERNEL_LINUX
-#if HAVE_LIBUDEV
+#if HAVE_UDEV_H
   if (conf_udev_name_attr != NULL) {
     handle_udev = udev_new();
     if (handle_udev == NULL) {
@@ -217,7 +217,7 @@ static int disk_init(void) {
       return (-1);
     }
   }
-#endif /* HAVE_LIBUDEV */
+#endif /* HAVE_UDEV_H */
 /* #endif KERNEL_LINUX */
 
 #elif KERNEL_FREEBSD
@@ -260,10 +260,10 @@ static int disk_init(void) {
 
 static int disk_shutdown(void) {
 #if KERNEL_LINUX
-#if HAVE_LIBUDEV
+#if HAVE_UDEV_H
   if (handle_udev != NULL)
     udev_unref(handle_udev);
-#endif /* HAVE_LIBUDEV */
+#endif /* HAVE_UDEV_H */
 #endif /* KERNEL_LINUX */
   return (0);
 } /* int disk_shutdown */
@@ -325,7 +325,7 @@ static counter_t disk_calc_time_incr(counter_t delta_time,
 }
 #endif
 
-#if HAVE_LIBUDEV
+#if HAVE_UDEV_H
 /**
  * Attempt to provide an rename disk instance from an assigned udev attribute.
  *
@@ -842,7 +842,7 @@ static int disk_read(void) {
 
     output_name = disk_name;
 
-#if HAVE_LIBUDEV
+#if HAVE_UDEV_H
     char *alt_name = NULL;
     if (conf_udev_name_attr != NULL) {
       alt_name =
@@ -853,7 +853,7 @@ static int disk_read(void) {
 #endif
 
     if (ignorelist_match(ignorelist, output_name) != 0) {
-#if HAVE_LIBUDEV
+#if HAVE_UDEV_H
       /* release udev-based alternate name, if allocated */
       sfree(alt_name);
 #endif
@@ -879,7 +879,7 @@ static int disk_read(void) {
         submit_io_time(output_name, io_time, weighted_time);
     } /* if (is_disk) */
 
-#if HAVE_LIBUDEV
+#if HAVE_UDEV_H
     /* release udev-based alternate name, if allocated */
     sfree(alt_name);
 #endif
index 34e9998..72a8d6e 100644 (file)
@@ -719,5 +719,3 @@ void module_register(void) {
   plugin_register_read("email", email_read);
   plugin_register_shutdown("email", email_shutdown);
 } /* void module_register */
-
-/* vim: set sw=4 ts=4 tw=78 noexpandtab : */
index bd55252..4b05300 100644 (file)
@@ -325,5 +325,3 @@ void module_register(void) {
   plugin_register_read("ethstat", ethstat_read);
   plugin_register_shutdown("ethstat", ethstat_shutdown);
 }
-
-/* vim: set sw=2 sts=2 et fdm=marker : */
index d34f9d9..df05718 100644 (file)
@@ -866,7 +866,3 @@ void module_register(void) {
                                /* user_data = */ NULL);
   plugin_register_shutdown("exec", exec_shutdown);
 } /* void module_register */
-
-/*
- * vim:shiftwidth=2:softtabstop=2:tabstop=8:fdm=marker
- */
index a78b880..608218d 100644 (file)
@@ -511,7 +511,3 @@ void module_register(void) {
   plugin_register_init("filecount", fc_init);
   plugin_register_read("filecount", fc_read);
 } /* void module_register */
-
-/*
- * vim: set sw=2 sts=2 et :
- */
index c410ea3..618bb22 100644 (file)
@@ -217,5 +217,3 @@ static int fscache_read(void) {
 void module_register(void) {
   plugin_register_read("fscache", fscache_read);
 } /* void module_register */
-
-/* vim: set sw=4 sts=4 et : */
index fc9a232..7bfb18d 100644 (file)
@@ -1030,5 +1030,3 @@ void module_register(void) {
   plugin_register_init("gmond", gmond_init);
   plugin_register_shutdown("gmond", gmond_shutdown);
 }
-
-/* vim: set sw=2 sts=2 et fdm=marker : */
index 0ae80bb..2f16dbc 100644 (file)
@@ -26,8 +26,8 @@
  *   Florian octo Forster <octo at collectd.org>
  **/
 
-#include <grpc++/grpc++.h>
 #include <google/protobuf/util/time_util.h>
+#include <grpc++/grpc++.h>
 
 #include <fstream>
 #include <iostream>
@@ -61,10 +61,10 @@ using google::protobuf::util::TimeUtil;
  */
 
 struct Listener {
-       grpc::string addr;
-       grpc::string port;
+  grpc::string addr;
+  grpc::string port;
 
-       grpc::SslServerCredentialsOptions *ssl;
+  grpc::SslServerCredentialsOptions *ssl;
 };
 static std::vector<Listener> listeners;
 static grpc::string default_addr("0.0.0.0:50051");
@@ -73,189 +73,187 @@ static grpc::string default_addr("0.0.0.0:50051");
  * helper functions
  */
 
-static bool ident_matches(const value_list_t *vl, const value_list_t *matcher)
-{
-       if (fnmatch(matcher->host, vl->host, 0))
-               return false;
+static bool ident_matches(const value_list_t *vl, const value_list_t *matcher) {
+  if (fnmatch(matcher->host, vl->host, 0))
+    return false;
 
-       if (fnmatch(matcher->plugin, vl->plugin, 0))
-               return false;
-       if (fnmatch(matcher->plugin_instance, vl->plugin_instance, 0))
-               return false;
+  if (fnmatch(matcher->plugin, vl->plugin, 0))
+    return false;
+  if (fnmatch(matcher->plugin_instance, vl->plugin_instance, 0))
+    return false;
 
-       if (fnmatch(matcher->type, vl->type, 0))
-               return false;
-       if (fnmatch(matcher->type_instance, vl->type_instance, 0))
-               return false;
+  if (fnmatch(matcher->type, vl->type, 0))
+    return false;
+  if (fnmatch(matcher->type_instance, vl->type_instance, 0))
+    return false;
 
-       return true;
+  return true;
 } /* ident_matches */
 
-static grpc::string read_file(const char *filename)
-{
-       std::ifstream f;
-       grpc::string s, content;
-
-       f.open(filename);
-       if (!f.is_open()) {
-               ERROR("grpc: Failed to open '%s'", filename);
-               return "";
-       }
-
-       while (std::getline(f, s)) {
-               content += s;
-               content.push_back('\n');
-       }
-       f.close();
-       return content;
+static grpc::string read_file(const char *filename) {
+  std::ifstream f;
+  grpc::string s, content;
+
+  f.open(filename);
+  if (!f.is_open()) {
+    ERROR("grpc: Failed to open '%s'", filename);
+    return "";
+  }
+
+  while (std::getline(f, s)) {
+    content += s;
+    content.push_back('\n');
+  }
+  f.close();
+  return content;
 } /* read_file */
 
 /*
  * proto conversion
  */
 
-static void marshal_ident(const value_list_t *vl, collectd::types::Identifier *msg)
-{
-       msg->set_host(vl->host);
-       msg->set_plugin(vl->plugin);
-       if (vl->plugin_instance[0] != '\0')
-               msg->set_plugin_instance(vl->plugin_instance);
-       msg->set_type(vl->type);
-       if (vl->type_instance[0] != '\0')
-               msg->set_type_instance(vl->type_instance);
+static void marshal_ident(const value_list_t *vl,
+                          collectd::types::Identifier *msg) {
+  msg->set_host(vl->host);
+  msg->set_plugin(vl->plugin);
+  if (vl->plugin_instance[0] != '\0')
+    msg->set_plugin_instance(vl->plugin_instance);
+  msg->set_type(vl->type);
+  if (vl->type_instance[0] != '\0')
+    msg->set_type_instance(vl->type_instance);
 } /* marshal_ident */
 
-static grpc::Status unmarshal_ident(const collectd::types::Identifier &msg, value_list_t *vl,
-               bool require_fields)
-{
-       std::string s;
+static grpc::Status unmarshal_ident(const collectd::types::Identifier &msg,
+                                    value_list_t *vl, bool require_fields) {
+  std::string s;
 
-       s = msg.host();
-       if (!s.length() && require_fields)
-               return grpc::Status(grpc::StatusCode::INVALID_ARGUMENT,
-                               grpc::string("missing host name"));
-       sstrncpy(vl->host, s.c_str(), sizeof(vl->host));
+  s = msg.host();
+  if (!s.length() && require_fields)
+    return grpc::Status(grpc::StatusCode::INVALID_ARGUMENT,
+                        grpc::string("missing host name"));
+  sstrncpy(vl->host, s.c_str(), sizeof(vl->host));
 
-       s = msg.plugin();
-       if (!s.length() && require_fields)
-               return grpc::Status(grpc::StatusCode::INVALID_ARGUMENT,
-                               grpc::string("missing plugin name"));
-       sstrncpy(vl->plugin, s.c_str(), sizeof(vl->plugin));
+  s = msg.plugin();
+  if (!s.length() && require_fields)
+    return grpc::Status(grpc::StatusCode::INVALID_ARGUMENT,
+                        grpc::string("missing plugin name"));
+  sstrncpy(vl->plugin, s.c_str(), sizeof(vl->plugin));
 
-       s = msg.type();
-       if (!s.length() && require_fields)
-               return grpc::Status(grpc::StatusCode::INVALID_ARGUMENT,
-                               grpc::string("missing type name"));
-       sstrncpy(vl->type, s.c_str(), sizeof(vl->type));
+  s = msg.type();
+  if (!s.length() && require_fields)
+    return grpc::Status(grpc::StatusCode::INVALID_ARGUMENT,
+                        grpc::string("missing type name"));
+  sstrncpy(vl->type, s.c_str(), sizeof(vl->type));
 
-       s = msg.plugin_instance();
-       sstrncpy(vl->plugin_instance, s.c_str(), sizeof(vl->plugin_instance));
+  s = msg.plugin_instance();
+  sstrncpy(vl->plugin_instance, s.c_str(), sizeof(vl->plugin_instance));
 
-       s = msg.type_instance();
-       sstrncpy(vl->type_instance, s.c_str(), sizeof(vl->type_instance));
+  s = msg.type_instance();
+  sstrncpy(vl->type_instance, s.c_str(), sizeof(vl->type_instance));
 
-       return grpc::Status::OK;
+  return grpc::Status::OK;
 } /* unmarshal_ident() */
 
-static grpc::Status marshal_value_list(const value_list_t *vl, collectd::types::ValueList *msg)
-{
-       auto id = msg->mutable_identifier();
-       marshal_ident(vl, id);
-
-       auto ds = plugin_get_ds(vl->type);
-       if ((ds == NULL) || (ds->ds_num != vl->values_len)) {
-               return grpc::Status(grpc::StatusCode::INTERNAL,
-                               grpc::string("failed to retrieve data-set for values"));
-       }
-
-       auto t = TimeUtil::NanosecondsToTimestamp(CDTIME_T_TO_NS(vl->time));
-       auto d = TimeUtil::NanosecondsToDuration(CDTIME_T_TO_NS(vl->interval));
-       msg->set_allocated_time(new google::protobuf::Timestamp(t));
-       msg->set_allocated_interval(new google::protobuf::Duration(d));
-
-       for (size_t i = 0; i < vl->values_len; ++i) {
-               auto v = msg->add_values();
-               switch (ds->ds[i].type) {
-                       case DS_TYPE_COUNTER:
-                               v->set_counter(vl->values[i].counter);
-                               break;
-                       case DS_TYPE_GAUGE:
-                               v->set_gauge(vl->values[i].gauge);
-                               break;
-                       case DS_TYPE_DERIVE:
-                               v->set_derive(vl->values[i].derive);
-                               break;
-                       case DS_TYPE_ABSOLUTE:
-                               v->set_absolute(vl->values[i].absolute);
-                               break;
-                       default:
-                               return grpc::Status(grpc::StatusCode::INTERNAL,
-                                               grpc::string("unknown value type"));
-               }
-
-               auto name = msg->add_ds_names();
-               name->assign(ds->ds[i].name);
-       }
-
-       return grpc::Status::OK;
+static grpc::Status marshal_value_list(const value_list_t *vl,
+                                       collectd::types::ValueList *msg) {
+  auto id = msg->mutable_identifier();
+  marshal_ident(vl, id);
+
+  auto ds = plugin_get_ds(vl->type);
+  if ((ds == NULL) || (ds->ds_num != vl->values_len)) {
+    return grpc::Status(grpc::StatusCode::INTERNAL,
+                        grpc::string("failed to retrieve data-set for values"));
+  }
+
+  auto t = TimeUtil::NanosecondsToTimestamp(CDTIME_T_TO_NS(vl->time));
+  auto d = TimeUtil::NanosecondsToDuration(CDTIME_T_TO_NS(vl->interval));
+  msg->set_allocated_time(new google::protobuf::Timestamp(t));
+  msg->set_allocated_interval(new google::protobuf::Duration(d));
+
+  for (size_t i = 0; i < vl->values_len; ++i) {
+    auto v = msg->add_values();
+    switch (ds->ds[i].type) {
+    case DS_TYPE_COUNTER:
+      v->set_counter(vl->values[i].counter);
+      break;
+    case DS_TYPE_GAUGE:
+      v->set_gauge(vl->values[i].gauge);
+      break;
+    case DS_TYPE_DERIVE:
+      v->set_derive(vl->values[i].derive);
+      break;
+    case DS_TYPE_ABSOLUTE:
+      v->set_absolute(vl->values[i].absolute);
+      break;
+    default:
+      return grpc::Status(grpc::StatusCode::INTERNAL,
+                          grpc::string("unknown value type"));
+    }
+
+    auto name = msg->add_ds_names();
+    name->assign(ds->ds[i].name);
+  }
+
+  return grpc::Status::OK;
 } /* marshal_value_list */
 
-static grpc::Status unmarshal_value_list(const collectd::types::ValueList &msg, value_list_t *vl)
-{
-       vl->time = NS_TO_CDTIME_T(TimeUtil::TimestampToNanoseconds(msg.time()));
-       vl->interval = NS_TO_CDTIME_T(TimeUtil::DurationToNanoseconds(msg.interval()));
-
-       auto status = unmarshal_ident(msg.identifier(), vl, true);
-       if (!status.ok())
-               return status;
-
-       value_t *values = NULL;
-       size_t values_len = 0;
-
-       status = grpc::Status::OK;
-       for (auto v : msg.values()) {
-               value_t *val = (value_t *)realloc(values, (values_len + 1) * sizeof(*values));
-               if (!val) {
-                       status = grpc::Status(grpc::StatusCode::RESOURCE_EXHAUSTED,
-                                       grpc::string("failed to allocate values array"));
-                       break;
-               }
-
-               values = val;
-               val = values + values_len;
-               values_len++;
-
-               switch (v.value_case()) {
-               case collectd::types::Value::ValueCase::kCounter:
-                       val->counter = counter_t(v.counter());
-                       break;
-               case collectd::types::Value::ValueCase::kGauge:
-                       val->gauge = gauge_t(v.gauge());
-                       break;
-               case collectd::types::Value::ValueCase::kDerive:
-                       val->derive = derive_t(v.derive());
-                       break;
-               case collectd::types::Value::ValueCase::kAbsolute:
-                       val->absolute = absolute_t(v.absolute());
-                       break;
-               default:
-                       status = grpc::Status(grpc::StatusCode::INVALID_ARGUMENT,
-                                       grpc::string("unknown value type"));
-                       break;
-               }
-
-               if (!status.ok())
-                       break;
-       }
-       if (status.ok()) {
-               vl->values = values;
-               vl->values_len = values_len;
-       }
-       else if (values) {
-               free(values);
-       }
-
-       return status;
+static grpc::Status unmarshal_value_list(const collectd::types::ValueList &msg,
+                                         value_list_t *vl) {
+  vl->time = NS_TO_CDTIME_T(TimeUtil::TimestampToNanoseconds(msg.time()));
+  vl->interval =
+      NS_TO_CDTIME_T(TimeUtil::DurationToNanoseconds(msg.interval()));
+
+  auto status = unmarshal_ident(msg.identifier(), vl, true);
+  if (!status.ok())
+    return status;
+
+  value_t *values = NULL;
+  size_t values_len = 0;
+
+  status = grpc::Status::OK;
+  for (auto v : msg.values()) {
+    value_t *val =
+        (value_t *)realloc(values, (values_len + 1) * sizeof(*values));
+    if (!val) {
+      status = grpc::Status(grpc::StatusCode::RESOURCE_EXHAUSTED,
+                            grpc::string("failed to allocate values array"));
+      break;
+    }
+
+    values = val;
+    val = values + values_len;
+    values_len++;
+
+    switch (v.value_case()) {
+    case collectd::types::Value::ValueCase::kCounter:
+      val->counter = counter_t(v.counter());
+      break;
+    case collectd::types::Value::ValueCase::kGauge:
+      val->gauge = gauge_t(v.gauge());
+      break;
+    case collectd::types::Value::ValueCase::kDerive:
+      val->derive = derive_t(v.derive());
+      break;
+    case collectd::types::Value::ValueCase::kAbsolute:
+      val->absolute = absolute_t(v.absolute());
+      break;
+    default:
+      status = grpc::Status(grpc::StatusCode::INVALID_ARGUMENT,
+                            grpc::string("unknown value type"));
+      break;
+    }
+
+    if (!status.ok())
+      break;
+  }
+  if (status.ok()) {
+    vl->values = values;
+    vl->values_len = values_len;
+  } else if (values) {
+    free(values);
+  }
+
+  return status;
 } /* unmarshal_value_list() */
 
 /*
@@ -263,200 +261,200 @@ static grpc::Status unmarshal_value_list(const collectd::types::ValueList &msg,
  */
 class CollectdImpl : public collectd::Collectd::Service {
 public:
-       grpc::Status QueryValues(grpc::ServerContext *ctx, QueryValuesRequest const *req, grpc::ServerWriter<QueryValuesResponse> *writer) override {
-               value_list_t match;
-               auto status = unmarshal_ident(req->identifier(), &match, false);
-               if (!status.ok()) {
-                       return status;
-               }
-
-               std::queue<value_list_t> value_lists;
-               status = this->queryValuesRead(&match, &value_lists);
-               if (status.ok()) {
-                       status = this->queryValuesWrite(ctx, writer, &value_lists);
-               }
-
-               while (!value_lists.empty()) {
-                       auto vl = value_lists.front();
-                       value_lists.pop();
-                       sfree(vl.values);
-               }
-
-               return status;
-       }
-
-       grpc::Status PutValues(grpc::ServerContext *ctx,
-                                                  grpc::ServerReader<PutValuesRequest> *reader,
-                                                  PutValuesResponse *res) override {
-               PutValuesRequest req;
-
-               while (reader->Read(&req)) {
-                       value_list_t vl = {0};
-                       auto status = unmarshal_value_list(req.value_list(), &vl);
-                       if (!status.ok())
-                               return status;
-
-                       if (plugin_dispatch_values(&vl))
-                               return grpc::Status(grpc::StatusCode::INTERNAL,
-                                                                       grpc::string("failed to enqueue values for writing"));
-               }
-
-               res->Clear();
-               return grpc::Status::OK;
-       }
+  grpc::Status
+  QueryValues(grpc::ServerContext *ctx, QueryValuesRequest const *req,
+              grpc::ServerWriter<QueryValuesResponse> *writer) override {
+    value_list_t match;
+    auto status = unmarshal_ident(req->identifier(), &match, false);
+    if (!status.ok()) {
+      return status;
+    }
+
+    std::queue<value_list_t> value_lists;
+    status = this->queryValuesRead(&match, &value_lists);
+    if (status.ok()) {
+      status = this->queryValuesWrite(ctx, writer, &value_lists);
+    }
+
+    while (!value_lists.empty()) {
+      auto vl = value_lists.front();
+      value_lists.pop();
+      sfree(vl.values);
+    }
+
+    return status;
+  }
+
+  grpc::Status PutValues(grpc::ServerContext *ctx,
+                         grpc::ServerReader<PutValuesRequest> *reader,
+                         PutValuesResponse *res) override {
+    PutValuesRequest req;
+
+    while (reader->Read(&req)) {
+      value_list_t vl = {0};
+      auto status = unmarshal_value_list(req.value_list(), &vl);
+      if (!status.ok())
+        return status;
+
+      if (plugin_dispatch_values(&vl))
+        return grpc::Status(
+            grpc::StatusCode::INTERNAL,
+            grpc::string("failed to enqueue values for writing"));
+    }
+
+    res->Clear();
+    return grpc::Status::OK;
+  }
 
 private:
-       grpc::Status queryValuesRead(value_list_t const *match, std::queue<value_list_t> *value_lists) {
-               uc_iter_t *iter;
-               if ((iter = uc_get_iterator()) == NULL) {
-                       return grpc::Status(grpc::StatusCode::INTERNAL,
-                                                               grpc::string("failed to query values: cannot create iterator"));
-               }
-
-               grpc::Status status = grpc::Status::OK;
-               char *name = NULL;
-               while (uc_iterator_next(iter, &name) == 0) {
-                       value_list_t vl;
-                       if (parse_identifier_vl(name, &vl) != 0) {
-                               status = grpc::Status(grpc::StatusCode::INTERNAL,
-                                                                         grpc::string("failed to parse identifier"));
-                               break;
-                       }
-
-                       if (!ident_matches(&vl, match))
-                               continue;
-
-                       if (uc_iterator_get_time(iter, &vl.time) < 0) {
-                               status = grpc::Status(grpc::StatusCode::INTERNAL,
-                                                                         grpc::string("failed to retrieve value timestamp"));
-                               break;
-                       }
-                       if (uc_iterator_get_interval(iter, &vl.interval) < 0) {
-                               status = grpc::Status(grpc::StatusCode::INTERNAL,
-                                                                         grpc::string("failed to retrieve value interval"));
-                               break;
-                       }
-                       if (uc_iterator_get_values(iter, &vl.values, &vl.values_len) < 0) {
-                               status = grpc::Status(grpc::StatusCode::INTERNAL,
-                                                                         grpc::string("failed to retrieve values"));
-                               break;
-                       }
-
-                       value_lists->push(vl);
-               } // while (uc_iterator_next(iter, &name) == 0)
-
-               uc_iterator_destroy(iter);
-               return status;
-       }
-
-       grpc::Status queryValuesWrite(grpc::ServerContext *ctx,
-                                          grpc::ServerWriter<QueryValuesResponse> *writer,
-                                          std::queue<value_list_t> *value_lists) {
-               while (!value_lists->empty()) {
-                       auto vl = value_lists->front();
-                       QueryValuesResponse res;
-                       res.Clear();
-
-                       auto status = marshal_value_list(&vl, res.mutable_value_list());
-                       if (!status.ok()) {
-                               return status;
-                       }
-
-                       if (!writer->Write(res)) {
-                               return grpc::Status::CANCELLED;
-                       }
-
-                       value_lists->pop();
-                       sfree(vl.values);
-               }
-
-               return grpc::Status::OK;
-       }
+  grpc::Status queryValuesRead(value_list_t const *match,
+                               std::queue<value_list_t> *value_lists) {
+    uc_iter_t *iter;
+    if ((iter = uc_get_iterator()) == NULL) {
+      return grpc::Status(
+          grpc::StatusCode::INTERNAL,
+          grpc::string("failed to query values: cannot create iterator"));
+    }
+
+    grpc::Status status = grpc::Status::OK;
+    char *name = NULL;
+    while (uc_iterator_next(iter, &name) == 0) {
+      value_list_t vl;
+      if (parse_identifier_vl(name, &vl) != 0) {
+        status = grpc::Status(grpc::StatusCode::INTERNAL,
+                              grpc::string("failed to parse identifier"));
+        break;
+      }
+
+      if (!ident_matches(&vl, match))
+        continue;
+
+      if (uc_iterator_get_time(iter, &vl.time) < 0) {
+        status =
+            grpc::Status(grpc::StatusCode::INTERNAL,
+                         grpc::string("failed to retrieve value timestamp"));
+        break;
+      }
+      if (uc_iterator_get_interval(iter, &vl.interval) < 0) {
+        status =
+            grpc::Status(grpc::StatusCode::INTERNAL,
+                         grpc::string("failed to retrieve value interval"));
+        break;
+      }
+      if (uc_iterator_get_values(iter, &vl.values, &vl.values_len) < 0) {
+        status = grpc::Status(grpc::StatusCode::INTERNAL,
+                              grpc::string("failed to retrieve values"));
+        break;
+      }
+
+      value_lists->push(vl);
+    } // while (uc_iterator_next(iter, &name) == 0)
+
+    uc_iterator_destroy(iter);
+    return status;
+  }
+
+  grpc::Status queryValuesWrite(grpc::ServerContext *ctx,
+                                grpc::ServerWriter<QueryValuesResponse> *writer,
+                                std::queue<value_list_t> *value_lists) {
+    while (!value_lists->empty()) {
+      auto vl = value_lists->front();
+      QueryValuesResponse res;
+      res.Clear();
+
+      auto status = marshal_value_list(&vl, res.mutable_value_list());
+      if (!status.ok()) {
+        return status;
+      }
+
+      if (!writer->Write(res)) {
+        return grpc::Status::CANCELLED;
+      }
+
+      value_lists->pop();
+      sfree(vl.values);
+    }
+
+    return grpc::Status::OK;
+  }
 };
 
 /*
  * gRPC server implementation
  */
-class CollectdServer final
-{
+class CollectdServer final {
 public:
-       void Start()
-       {
-               auto auth = grpc::InsecureServerCredentials();
-
-               grpc::ServerBuilder builder;
-
-               if (listeners.empty()) {
-                       builder.AddListeningPort(default_addr, auth);
-                       INFO("grpc: Listening on %s", default_addr.c_str());
-               }
-               else {
-                       for (auto l : listeners) {
-                               grpc::string addr = l.addr + ":" + l.port;
-
-                               auto use_ssl = grpc::string("");
-                               auto a = auth;
-                               if (l.ssl != nullptr) {
-                                       use_ssl = grpc::string(" (SSL enabled)");
-                                       a = grpc::SslServerCredentials(*l.ssl);
-                               }
-
-                               builder.AddListeningPort(addr, a);
-                               INFO("grpc: Listening on %s%s", addr.c_str(), use_ssl.c_str());
-                       }
-               }
-
-               builder.RegisterService(&collectd_service_);
-
-               server_ = builder.BuildAndStart();
-       } /* Start() */
-
-       void Shutdown()
-       {
-               server_->Shutdown();
-       } /* Shutdown() */
+  void Start() {
+    auto auth = grpc::InsecureServerCredentials();
+
+    grpc::ServerBuilder builder;
+
+    if (listeners.empty()) {
+      builder.AddListeningPort(default_addr, auth);
+      INFO("grpc: Listening on %s", default_addr.c_str());
+    } else {
+      for (auto l : listeners) {
+        grpc::string addr = l.addr + ":" + l.port;
+
+        auto use_ssl = grpc::string("");
+        auto a = auth;
+        if (l.ssl != nullptr) {
+          use_ssl = grpc::string(" (SSL enabled)");
+          a = grpc::SslServerCredentials(*l.ssl);
+        }
+
+        builder.AddListeningPort(addr, a);
+        INFO("grpc: Listening on %s%s", addr.c_str(), use_ssl.c_str());
+      }
+    }
+
+    builder.RegisterService(&collectd_service_);
+
+    server_ = builder.BuildAndStart();
+  } /* Start() */
+
+  void Shutdown() { server_->Shutdown(); } /* Shutdown() */
 
 private:
-       CollectdImpl collectd_service_;
+  CollectdImpl collectd_service_;
 
-       std::unique_ptr<grpc::Server> server_;
+  std::unique_ptr<grpc::Server> server_;
 }; /* class CollectdServer */
 
-class CollectdClient final
-{
+class CollectdClient final {
 public:
-       CollectdClient(std::shared_ptr<grpc::ChannelInterface> channel) : stub_(Collectd::NewStub(channel)) {
-       }
-
-       int PutValues(value_list_t const *vl) {
-               grpc::ClientContext ctx;
-
-               PutValuesRequest req;
-               auto status = marshal_value_list(vl, req.mutable_value_list());
-               if (!status.ok()) {
-                       ERROR("grpc: Marshalling value_list_t failed.");
-                       return -1;
-               }
-
-               PutValuesResponse res;
-               auto stream = stub_->PutValues(&ctx, &res);
-               if (!stream->Write(req)) {
-                       NOTICE("grpc: Broken stream.");
-                       /* intentionally not returning. */
-               }
-
-               stream->WritesDone();
-               status = stream->Finish();
-               if (!status.ok()) {
-                       ERROR ("grpc: Error while closing stream.");
-                       return -1;
-               }
-
-               return 0;
-       } /* int PutValues */
+  CollectdClient(std::shared_ptr<grpc::ChannelInterface> channel)
+      : stub_(Collectd::NewStub(channel)) {}
+
+  int PutValues(value_list_t const *vl) {
+    grpc::ClientContext ctx;
+
+    PutValuesRequest req;
+    auto status = marshal_value_list(vl, req.mutable_value_list());
+    if (!status.ok()) {
+      ERROR("grpc: Marshalling value_list_t failed.");
+      return -1;
+    }
+
+    PutValuesResponse res;
+    auto stream = stub_->PutValues(&ctx, &res);
+    if (!stream->Write(req)) {
+      NOTICE("grpc: Broken stream.");
+      /* intentionally not returning. */
+    }
+
+    stream->WritesDone();
+    status = stream->Finish();
+    if (!status.ok()) {
+      ERROR("grpc: Error while closing stream.");
+      return -1;
+    }
+
+    return 0;
+  } /* int PutValues */
 
 private:
-       std::unique_ptr<Collectd::Stub> stub_;
+  std::unique_ptr<Collectd::Stub> stub_;
 };
 
 static CollectdServer *server = nullptr;
@@ -465,216 +463,194 @@ static CollectdServer *server = nullptr;
  * collectd plugin interface
  */
 extern "C" {
-       static void c_grpc_destroy_write_callback (void *ptr) {
-               delete (CollectdClient *) ptr;
-       }
-
-       static int c_grpc_write(__attribute__((unused)) data_set_t const *ds,
-                       value_list_t const *vl,
-                       user_data_t *ud) {
-               CollectdClient *c = (CollectdClient *) ud->data;
-               return c->PutValues(vl);
-       }
-
-       static int c_grpc_config_listen(oconfig_item_t *ci)
-       {
-               if ((ci->values_num != 2)
-                               || (ci->values[0].type != OCONFIG_TYPE_STRING)
-                               || (ci->values[1].type != OCONFIG_TYPE_STRING)) {
-                       ERROR("grpc: The `%s` config option needs exactly "
-                                       "two string argument (address and port).", ci->key);
-                       return -1;
-               }
-
-               auto listener = Listener();
-               listener.addr = grpc::string(ci->values[0].value.string);
-               listener.port = grpc::string(ci->values[1].value.string);
-               listener.ssl = nullptr;
-
-               auto ssl_opts = new(grpc::SslServerCredentialsOptions);
-               grpc::SslServerCredentialsOptions::PemKeyCertPair pkcp = {};
-               bool use_ssl = false;
-
-               for (int i = 0; i < ci->children_num; i++) {
-                       oconfig_item_t *child = ci->children + i;
-
-                       if (!strcasecmp("EnableSSL", child->key)) {
-                               if (cf_util_get_boolean(child, &use_ssl)) {
-                                       ERROR("grpc: Option `%s` expects a boolean value",
-                                                       child->key);
-                                       return -1;
-                               }
-                       }
-                       else if (!strcasecmp("SSLCACertificateFile", child->key)) {
-                               char *certs = NULL;
-                               if (cf_util_get_string(child, &certs)) {
-                                       ERROR("grpc: Option `%s` expects a string value",
-                                                       child->key);
-                                       return -1;
-                               }
-                               ssl_opts->pem_root_certs = read_file(certs);
-                       }
-                       else if (!strcasecmp("SSLCertificateKeyFile", child->key)) {
-                               char *key = NULL;
-                               if (cf_util_get_string(child, &key)) {
-                                       ERROR("grpc: Option `%s` expects a string value",
-                                                       child->key);
-                                       return -1;
-                               }
-                               pkcp.private_key = read_file(key);
-                       }
-                       else if (!strcasecmp("SSLCertificateFile", child->key)) {
-                               char *cert = NULL;
-                               if (cf_util_get_string(child, &cert)) {
-                                       ERROR("grpc: Option `%s` expects a string value",
-                                                       child->key);
-                                       return -1;
-                               }
-                               pkcp.cert_chain = read_file(cert);
-                       }
-                       else {
-                               WARNING("grpc: Option `%s` not allowed in <%s> block.",
-                                               child->key, ci->key);
-                       }
-               }
-
-               ssl_opts->pem_key_cert_pairs.push_back(pkcp);
-               if (use_ssl)
-                       listener.ssl = ssl_opts;
-               else
-                       delete(ssl_opts);
-
-               listeners.push_back(listener);
-               return 0;
-       } /* c_grpc_config_listen() */
-
-       static int c_grpc_config_server(oconfig_item_t *ci)
-       {
-               if ((ci->values_num != 2)
-                               || (ci->values[0].type != OCONFIG_TYPE_STRING)
-                               || (ci->values[1].type != OCONFIG_TYPE_STRING)) {
-                       ERROR("grpc: The `%s` config option needs exactly "
-                                       "two string argument (address and port).", ci->key);
-                       return -1;
-               }
-
-               grpc::SslCredentialsOptions ssl_opts;
-               bool use_ssl = false;
-
-               for (int i = 0; i < ci->children_num; i++) {
-                       oconfig_item_t *child = ci->children + i;
-
-                       if (!strcasecmp("EnableSSL", child->key)) {
-                               if (cf_util_get_boolean(child, &use_ssl)) {
-                                       return -1;
-                               }
-                       }
-                       else if (!strcasecmp("SSLCACertificateFile", child->key)) {
-                               char *certs = NULL;
-                               if (cf_util_get_string(child, &certs)) {
-                                       return -1;
-                               }
-                               ssl_opts.pem_root_certs = read_file(certs);
-                       }
-                       else if (!strcasecmp("SSLCertificateKeyFile", child->key)) {
-                               char *key = NULL;
-                               if (cf_util_get_string(child, &key)) {
-                                       return -1;
-                               }
-                               ssl_opts.pem_private_key = read_file(key);
-                       }
-                       else if (!strcasecmp("SSLCertificateFile", child->key)) {
-                               char *cert = NULL;
-                               if (cf_util_get_string(child, &cert)) {
-                                       return -1;
-                               }
-                               ssl_opts.pem_cert_chain = read_file(cert);
-                       }
-                       else {
-                               WARNING("grpc: Option `%s` not allowed in <%s> block.",
-                                               child->key, ci->key);
-                       }
-               }
-
-               auto node    = grpc::string(ci->values[0].value.string);
-               auto service = grpc::string(ci->values[1].value.string);
-               auto addr    = node + ":" + service;
-
-               CollectdClient *client;
-               if (use_ssl) {
-                       auto channel_creds = grpc::SslCredentials(ssl_opts);
-                       auto channel = grpc::CreateChannel(addr, channel_creds);
-                       client = new CollectdClient(channel);
-               } else {
-                       auto channel = grpc::CreateChannel(addr, grpc::InsecureChannelCredentials());
-                       client = new CollectdClient(channel);
-               }
-
-               auto callback_name = grpc::string("grpc/") + addr;
-               user_data_t ud = {
-                       .data = client,
-                       .free_func = c_grpc_destroy_write_callback,
-               };
-
-               plugin_register_write (callback_name.c_str(), c_grpc_write, &ud);
-               return 0;
-       } /* c_grpc_config_server() */
-
-       static int c_grpc_config(oconfig_item_t *ci)
-       {
-               int i;
-
-               for (i = 0; i < ci->children_num; i++) {
-                       oconfig_item_t *child = ci->children + i;
-
-                       if (!strcasecmp("Listen", child->key)) {
-                               if (c_grpc_config_listen(child))
-                                       return -1;
-                       }
-                       else if (!strcasecmp("Server", child->key)) {
-                               if (c_grpc_config_server(child))
-                                       return -1;
-                       }
-
-                       else {
-                               WARNING("grpc: Option `%s` not allowed here.", child->key);
-                       }
-               }
-
-               return 0;
-       } /* c_grpc_config() */
-
-       static int c_grpc_init(void)
-       {
-               server = new CollectdServer();
-               if (!server) {
-                       ERROR("grpc: Failed to create server");
-                       return -1;
-               }
-
-               server->Start();
-               return 0;
-       } /* c_grpc_init() */
-
-       static int c_grpc_shutdown(void)
-       {
-               if (!server)
-                       return 0;
-
-               server->Shutdown();
-
-               delete server;
-               server = nullptr;
-
-               return 0;
-       } /* c_grpc_shutdown() */
-
-       void module_register(void)
-       {
-               plugin_register_complex_config("grpc", c_grpc_config);
-               plugin_register_init("grpc", c_grpc_init);
-               plugin_register_shutdown("grpc", c_grpc_shutdown);
-       } /* module_register() */
-} /* extern "C" */
+static void c_grpc_destroy_write_callback(void *ptr) {
+  delete (CollectdClient *)ptr;
+}
 
-/* vim: set sw=4 ts=4 tw=78 noexpandtab : */
+static int c_grpc_write(__attribute__((unused)) data_set_t const *ds,
+                        value_list_t const *vl, user_data_t *ud) {
+  CollectdClient *c = (CollectdClient *)ud->data;
+  return c->PutValues(vl);
+}
+
+static int c_grpc_config_listen(oconfig_item_t *ci) {
+  if ((ci->values_num != 2) || (ci->values[0].type != OCONFIG_TYPE_STRING) ||
+      (ci->values[1].type != OCONFIG_TYPE_STRING)) {
+    ERROR("grpc: The `%s` config option needs exactly "
+          "two string argument (address and port).",
+          ci->key);
+    return -1;
+  }
+
+  auto listener = Listener();
+  listener.addr = grpc::string(ci->values[0].value.string);
+  listener.port = grpc::string(ci->values[1].value.string);
+  listener.ssl = nullptr;
+
+  auto ssl_opts = new (grpc::SslServerCredentialsOptions);
+  grpc::SslServerCredentialsOptions::PemKeyCertPair pkcp = {};
+  bool use_ssl = false;
+
+  for (int i = 0; i < ci->children_num; i++) {
+    oconfig_item_t *child = ci->children + i;
+
+    if (!strcasecmp("EnableSSL", child->key)) {
+      if (cf_util_get_boolean(child, &use_ssl)) {
+        ERROR("grpc: Option `%s` expects a boolean value", child->key);
+        return -1;
+      }
+    } else if (!strcasecmp("SSLCACertificateFile", child->key)) {
+      char *certs = NULL;
+      if (cf_util_get_string(child, &certs)) {
+        ERROR("grpc: Option `%s` expects a string value", child->key);
+        return -1;
+      }
+      ssl_opts->pem_root_certs = read_file(certs);
+    } else if (!strcasecmp("SSLCertificateKeyFile", child->key)) {
+      char *key = NULL;
+      if (cf_util_get_string(child, &key)) {
+        ERROR("grpc: Option `%s` expects a string value", child->key);
+        return -1;
+      }
+      pkcp.private_key = read_file(key);
+    } else if (!strcasecmp("SSLCertificateFile", child->key)) {
+      char *cert = NULL;
+      if (cf_util_get_string(child, &cert)) {
+        ERROR("grpc: Option `%s` expects a string value", child->key);
+        return -1;
+      }
+      pkcp.cert_chain = read_file(cert);
+    } else {
+      WARNING("grpc: Option `%s` not allowed in <%s> block.", child->key,
+              ci->key);
+    }
+  }
+
+  ssl_opts->pem_key_cert_pairs.push_back(pkcp);
+  if (use_ssl)
+    listener.ssl = ssl_opts;
+  else
+    delete (ssl_opts);
+
+  listeners.push_back(listener);
+  return 0;
+} /* c_grpc_config_listen() */
+
+static int c_grpc_config_server(oconfig_item_t *ci) {
+  if ((ci->values_num != 2) || (ci->values[0].type != OCONFIG_TYPE_STRING) ||
+      (ci->values[1].type != OCONFIG_TYPE_STRING)) {
+    ERROR("grpc: The `%s` config option needs exactly "
+          "two string argument (address and port).",
+          ci->key);
+    return -1;
+  }
+
+  grpc::SslCredentialsOptions ssl_opts;
+  bool use_ssl = false;
+
+  for (int i = 0; i < ci->children_num; i++) {
+    oconfig_item_t *child = ci->children + i;
+
+    if (!strcasecmp("EnableSSL", child->key)) {
+      if (cf_util_get_boolean(child, &use_ssl)) {
+        return -1;
+      }
+    } else if (!strcasecmp("SSLCACertificateFile", child->key)) {
+      char *certs = NULL;
+      if (cf_util_get_string(child, &certs)) {
+        return -1;
+      }
+      ssl_opts.pem_root_certs = read_file(certs);
+    } else if (!strcasecmp("SSLCertificateKeyFile", child->key)) {
+      char *key = NULL;
+      if (cf_util_get_string(child, &key)) {
+        return -1;
+      }
+      ssl_opts.pem_private_key = read_file(key);
+    } else if (!strcasecmp("SSLCertificateFile", child->key)) {
+      char *cert = NULL;
+      if (cf_util_get_string(child, &cert)) {
+        return -1;
+      }
+      ssl_opts.pem_cert_chain = read_file(cert);
+    } else {
+      WARNING("grpc: Option `%s` not allowed in <%s> block.", child->key,
+              ci->key);
+    }
+  }
+
+  auto node = grpc::string(ci->values[0].value.string);
+  auto service = grpc::string(ci->values[1].value.string);
+  auto addr = node + ":" + service;
+
+  CollectdClient *client;
+  if (use_ssl) {
+    auto channel_creds = grpc::SslCredentials(ssl_opts);
+    auto channel = grpc::CreateChannel(addr, channel_creds);
+    client = new CollectdClient(channel);
+  } else {
+    auto channel =
+        grpc::CreateChannel(addr, grpc::InsecureChannelCredentials());
+    client = new CollectdClient(channel);
+  }
+
+  auto callback_name = grpc::string("grpc/") + addr;
+  user_data_t ud = {
+      .data = client, .free_func = c_grpc_destroy_write_callback,
+  };
+
+  plugin_register_write(callback_name.c_str(), c_grpc_write, &ud);
+  return 0;
+} /* c_grpc_config_server() */
+
+static int c_grpc_config(oconfig_item_t *ci) {
+  int i;
+
+  for (i = 0; i < ci->children_num; i++) {
+    oconfig_item_t *child = ci->children + i;
+
+    if (!strcasecmp("Listen", child->key)) {
+      if (c_grpc_config_listen(child))
+        return -1;
+    } else if (!strcasecmp("Server", child->key)) {
+      if (c_grpc_config_server(child))
+        return -1;
+    }
+
+    else {
+      WARNING("grpc: Option `%s` not allowed here.", child->key);
+    }
+  }
+
+  return 0;
+} /* c_grpc_config() */
+
+static int c_grpc_init(void) {
+  server = new CollectdServer();
+  if (!server) {
+    ERROR("grpc: Failed to create server");
+    return -1;
+  }
+
+  server->Start();
+  return 0;
+} /* c_grpc_init() */
+
+static int c_grpc_shutdown(void) {
+  if (!server)
+    return 0;
+
+  server->Shutdown();
+
+  delete server;
+  server = nullptr;
+
+  return 0;
+} /* c_grpc_shutdown() */
+
+void module_register(void) {
+  plugin_register_complex_config("grpc", c_grpc_config);
+  plugin_register_init("grpc", c_grpc_init);
+  plugin_register_shutdown("grpc", c_grpc_shutdown);
+} /* module_register() */
+} /* extern "C" */
index 2ef65f5..6beac7b 100644 (file)
@@ -460,6 +460,10 @@ static int rdt_config_cgroups(oconfig_item_t *item) {
   return (0);
 }
 
+static void rdt_pqos_log(void *context, const size_t size, const char *msg) {
+  DEBUG(RDT_PLUGIN ": %s", msg);
+}
+
 static int rdt_preinit(void) {
   int ret;
 
@@ -474,15 +478,12 @@ static int rdt_preinit(void) {
     return (-ENOMEM);
   }
 
-  /* In case previous instance of the application was not closed properly
-   * call fini and ignore return code. */
-  pqos_fini();
+  struct pqos_config pqos = {.fd_log = -1,
+                             .callback_log = rdt_pqos_log,
+                             .context_log = NULL,
+                             .verbose = 0};
 
-  /* TODO:
-   * stdout should not be used here. Will be reworked when support of log
-   * callback is added to PQoS library.
-  */
-  ret = pqos_init(&(struct pqos_config){.fd_log = STDOUT_FILENO});
+  ret = pqos_init(&pqos);
   if (ret != PQOS_RETVAL_OK) {
     ERROR(RDT_PLUGIN ": Error initializing PQoS library!");
     goto rdt_preinit_error1;
@@ -507,6 +508,9 @@ static int rdt_preinit(void) {
     goto rdt_preinit_error2;
   }
 
+  /* Reset pqos monitoring groups registers */
+  pqos_mon_reset();
+
   return (0);
 
 rdt_preinit_error2:
index c9fb003..8222efb 100644 (file)
--- a/src/ipc.c
+++ b/src/ipc.c
@@ -319,5 +319,3 @@ void module_register(void) /* {{{ */
   plugin_register_read("ipc", ipc_read);
 }
 /* }}} */
-
-/* vim: set sw=2 sts=2 et fdm=marker : */
index 1bbaf41..f3636fc 100644 (file)
@@ -621,5 +621,3 @@ void module_register(void) {
   plugin_register_read("ipmi", c_ipmi_read);
   plugin_register_shutdown("ipmi", c_ipmi_shutdown);
 } /* void module_register */
-
-/* vim: set sw=2 sts=2 ts=8 fdm=marker et : */
index 2446bd1..a8c4a1d 100644 (file)
@@ -321,5 +321,3 @@ void module_register(void) {
   plugin_register_shutdown("ipvs", cipvs_shutdown);
   return;
 } /* module_register */
-
-/* vim: set sw=4 ts=4 tw=78 noexpandtab : */
index 63b5e31..2e4d88a 100644 (file)
@@ -2841,5 +2841,3 @@ void module_register(void) {
   plugin_register_init("java", cjni_init);
   plugin_register_shutdown("java", cjni_shutdown);
 } /* void module_register (void) */
-
-/* vim: set sw=2 sts=2 et fdm=marker : */
index f61e967..a8f5d0d 100644 (file)
@@ -1021,5 +1021,3 @@ int lcc_sort_identifiers(lcc_connection_t *c, /* {{{ */
   qsort(idents, idents_num, sizeof(*idents), lcc_identifier_compare);
   return (0);
 } /* }}} int lcc_sort_identifiers */
-
-/* vim: set sw=2 sts=2 et fdm=marker : */
index 36aaf92..8604ff6 100644 (file)
@@ -39,9 +39,7 @@
 /*
  * Includes (for data types)
  */
-#if HAVE_STDINT_H
 #include <stdint.h>
-#endif
 #include <inttypes.h>
 #include <time.h>
 
@@ -141,5 +139,4 @@ int lcc_sort_identifiers(lcc_connection_t *c, lcc_identifier_t *idents,
 
 LCC_END_DECLS
 
-/* vim: set sw=2 sts=2 et : */
 #endif /* LIBCOLLECTD_COLLECTDCLIENT_H */
index 0e6fcd4..304845e 100644 (file)
@@ -62,6 +62,3 @@ const char *lcc_version_extra (void);
 LCC_END_DECLS
 
 #endif /* ! LIBCOLLECTD_LCC_FEATURES_H */
-
-/* vim: set sw=4 ts=4 tw=78 noexpandtab : */
-
index fdb9b33..35fd7d6 100644 (file)
@@ -73,5 +73,4 @@ int lcc_network_notification_send (lcc_network_t *net,
     const lcc_notification_t *notif);
 #endif
 
-/* vim: set sw=2 sts=2 et : */
 #endif /* LIBCOLLECTDCLIENT_NETWORK_H */
index 5612458..9f39310 100644 (file)
@@ -55,4 +55,3 @@ int lcc_network_buffer_get(lcc_network_buffer_t *nb, void *buffer,
                            size_t *buffer_size);
 
 #endif /* LIBCOLLECTDCLIENT_NETWORK_BUFFER_H */
-/* vim: set sw=2 sts=2 et : */
index a21799c..d096f18 100644 (file)
@@ -446,5 +446,3 @@ int lcc_network_values_send(lcc_network_t *net, /* {{{ */
 
   return (0);
 } /* }}} int lcc_network_values_send */
-
-/* vim: set sw=2 sts=2 et fdm=marker : */
index aa4941d..866c4cc 100644 (file)
@@ -35,7 +35,7 @@
 
 #include <pthread.h>
 
-#if HAVE_LIBGCRYPT
+#if HAVE_GCRYPT_H
 #if defined __APPLE__
 /* default xcode compiler throws warnings even when deprecated functionality
  * is not used. -Werror breaks the build because of erroneous warnings.
@@ -106,7 +106,7 @@ struct lcc_network_buffer_s {
   char *username;
   char *password;
 
-#if HAVE_LIBGCRYPT
+#if HAVE_GCRYPT_H
   gcry_cipher_hd_t encr_cypher;
   size_t encr_header_len;
   char encr_iv[16];
@@ -131,7 +131,7 @@ static _Bool have_gcrypt(void) /* {{{ */
     return (result);
   need_init = 0;
 
-#if HAVE_LIBGCRYPT
+#if HAVE_GCRYPT_H
 #if GCRYPT_VERSION_NUMBER < 0x010600
   if (gcry_control(GCRYCTL_SET_THREAD_CBS, &gcry_threads_pthread))
     return (0);
@@ -475,7 +475,7 @@ static int nb_add_value_list(lcc_network_buffer_t *nb, /* {{{ */
   return (0);
 } /* }}} int nb_add_value_list */
 
-#if HAVE_LIBGCRYPT
+#if HAVE_GCRYPT_H
 static int nb_add_signature(lcc_network_buffer_t *nb) /* {{{ */
 {
   char *buffer;
@@ -688,7 +688,7 @@ int lcc_network_buffer_initialize(lcc_network_buffer_t *nb) /* {{{ */
   nb->ptr = nb->buffer;
   nb->free = nb->size;
 
-#if HAVE_LIBGCRYPT
+#if HAVE_GCRYPT_H
   if (nb->seclevel == SIGN) {
     size_t username_len;
     uint16_t pkg_type = htons(TYPE_SIGN_SHA256);
@@ -739,7 +739,7 @@ int lcc_network_buffer_finalize(lcc_network_buffer_t *nb) /* {{{ */
   if (nb == NULL)
     return (EINVAL);
 
-#if HAVE_LIBGCRYPT
+#if HAVE_GCRYPT_H
   if (nb->seclevel == SIGN)
     return nb_add_signature(nb);
   else if (nb->seclevel == ENCRYPT)
@@ -779,5 +779,3 @@ int lcc_network_buffer_get(lcc_network_buffer_t *nb, /* {{{ */
 
   return (0);
 } /* }}} int lcc_network_buffer_get */
-
-/* vim: set sw=2 sts=2 et fdm=marker : */
index 76134db..079adcf 100644 (file)
@@ -196,7 +196,3 @@ void oconfig_free(oconfig_item_t *ci) {
   oconfig_free_all(ci);
   free(ci);
 }
-
-/*
- * vim:shiftwidth=2:tabstop=8:softtabstop=2:fdm=marker
- */
index d27f6f5..3b81062 100644 (file)
@@ -67,7 +67,4 @@ oconfig_item_t *oconfig_clone(const oconfig_item_t *ci);
 
 void oconfig_free(oconfig_item_t *ci);
 
-/*
- * vim: shiftwidth=2:tabstop=8:softtabstop=2
- */
 #endif /* OCONFIG_H */
index 303976b..8df32a8 100644 (file)
@@ -343,5 +343,3 @@ void module_register(void) {
   plugin_register_notification("log_logstash", log_logstash_notification,
                                /* user_data = */ NULL);
 } /* void module_register (void) */
-
-/* vim: set sw=4 ts=4 tw=78 noexpandtab : */
index db12291..0de639e 100644 (file)
@@ -208,5 +208,3 @@ void module_register(void) {
   plugin_register_notification("logfile", logfile_notification,
                                /* user_data = */ NULL);
 } /* void module_register (void) */
-
-/* vim: set sw=4 ts=4 tw=78 noexpandtab : */
index df4424c..c019227 100644 (file)
@@ -243,5 +243,3 @@ void module_register(void) {
   plugin_register_init("lpar", lpar_init);
   plugin_register_read("lpar", lpar_read);
 } /* void module_register */
-
-/* vim: set sw=8 noet : */
index 2bd56a1..9eda7d5 100644 (file)
--- a/src/lua.c
+++ b/src/lua.c
@@ -583,5 +583,3 @@ void module_register(void) {
   plugin_register_complex_config("lua", lua_config);
   plugin_register_shutdown("lua", lua_shutdown);
 }
-
-/* vim: set sw=2 sts=2 et fdm=marker : */
index 67c5578..0b2ab12 100644 (file)
@@ -79,5 +79,3 @@ void module_register(void) {
           .create = mec_create, .destroy = mec_destroy, .match = mec_match,
       });
 } /* module_register */
-
-/* vim: set sw=2 sts=2 tw=78 et fdm=marker : */
index fad5271..9c8d34f 100644 (file)
@@ -166,5 +166,3 @@ void module_register(void) {
   mproc.match = mh_match;
   fc_register_match("hashed", mproc);
 } /* module_register */
-
-/* vim: set sw=2 sts=2 tw=78 et fdm=marker : */
index 209f773..ea7fcf0 100644 (file)
@@ -364,5 +364,3 @@ void module_register(void) {
   mproc.match = mr_match;
   fc_register_match("regex", mproc);
 } /* module_register */
-
-/* vim: set sw=4 ts=4 tw=78 noexpandtab fdm=marker : */
index 6d00ed2..f0a456b 100644 (file)
@@ -141,5 +141,3 @@ void module_register(void) {
   mproc.match = mt_match;
   fc_register_match("timediff", mproc);
 } /* module_register */
-
-/* vim: set sw=2 sts=2 tw=78 et fdm=marker : */
index 3c94375..45745ba 100644 (file)
@@ -316,5 +316,3 @@ void module_register(void) {
   mproc.match = mv_match;
   fc_register_match("value", mproc);
 } /* module_register */
-
-/* vim: set sw=2 sts=2 tw=78 et fdm=marker : */
index bebbe40..19228ef 100644 (file)
@@ -479,5 +479,3 @@ void module_register(void) {
   plugin_register_read("memcachec", cmc_read);
   plugin_register_shutdown("memcachec", cmc_shutdown);
 } /* void module_register */
-
-/* vim: set sw=2 sts=2 et fdm=marker : */
index ab5ffd1..bc99e67 100644 (file)
--- a/src/mic.c
+++ b/src/mic.c
@@ -366,7 +366,3 @@ void module_register(void) {
   plugin_register_read("mic", mic_read);
   plugin_register_config("mic", mic_config, config_keys, config_keys_num);
 } /* void module_register */
-
-/*
- * vim: set shiftwidth=8 softtabstop=8 noet textwidth=78 :
- */
index 5d29791..80a2aca 100644 (file)
@@ -982,5 +982,3 @@ void module_register(void) {
   plugin_register_complex_config("modbus", mb_config);
   plugin_register_shutdown("modbus", mb_shutdown);
 } /* void module_register */
-
-/* vim: set sw=2 sts=2 et fdm=marker : */
index b578b99..33785c8 100644 (file)
@@ -751,5 +751,3 @@ void module_register(void) {
   plugin_register_complex_config("mqtt", mqtt_config);
   plugin_register_init("mqtt", mqtt_init);
 } /* void module_register */
-
-/* vim: set sw=4 sts=4 et fdm=marker : */
index 913e277..93ab3d2 100644 (file)
@@ -27,8 +27,7 @@
 #include "common.h"
 #include "plugin.h"
 
-#if HAVE_TERMIOS_H && HAVE_SYS_IOCTL_H && HAVE_MATH_H
-#include <math.h>
+#if HAVE_TERMIOS_H && HAVE_SYS_IOCTL_H
 #include <sys/ioctl.h>
 #include <termios.h>
 #else
index 4d45879..5b0827c 100644 (file)
@@ -3111,5 +3111,3 @@ void module_register(void) {
   plugin_register_init("netapp", cna_init);
   plugin_register_shutdown("netapp", cna_shutdown);
 }
-
-/* vim: set sw=2 ts=2 noet fdm=marker : */
index 8076c1f..ddae5f2 100644 (file)
@@ -85,6 +85,11 @@ typedef struct ir_ignorelist_s {
   struct ir_ignorelist_s *next;
 } ir_ignorelist_t;
 
+struct qos_stats {
+  struct gnet_stats_basic *bs;
+  struct gnet_stats_queue *qs;
+};
+
 static int ir_ignorelist_invert = 1;
 static ir_ignorelist_t *ir_ignorelist_head = NULL;
 
@@ -387,20 +392,30 @@ static int link_filter_cb(const struct nlmsghdr *nlh,
 
 #if HAVE_TCA_STATS2
 static int qos_attr_cb(const struct nlattr *attr, void *data) {
-  struct gnet_stats_basic **bs = (struct gnet_stats_basic **)data;
+  struct qos_stats *q_stats = (struct qos_stats *)data;
 
   /* skip unsupported attribute in user-space */
   if (mnl_attr_type_valid(attr, TCA_STATS_MAX) < 0)
     return MNL_CB_OK;
 
   if (mnl_attr_get_type(attr) == TCA_STATS_BASIC) {
-    if (mnl_attr_validate2(attr, MNL_TYPE_UNSPEC, sizeof(**bs)) < 0) {
+    if (mnl_attr_validate2(attr, MNL_TYPE_UNSPEC, sizeof(*q_stats->bs)) < 0) {
       ERROR("netlink plugin: qos_attr_cb: TCA_STATS_BASIC mnl_attr_validate2 "
             "failed.");
       return MNL_CB_ERROR;
     }
-    *bs = mnl_attr_get_payload(attr);
-    return MNL_CB_STOP;
+    q_stats->bs = mnl_attr_get_payload(attr);
+    return MNL_CB_OK;
+  }
+
+  if (mnl_attr_get_type(attr) == TCA_STATS_QUEUE) {
+    if (mnl_attr_validate2(attr, MNL_TYPE_UNSPEC, sizeof(*q_stats->qs)) < 0) {
+      ERROR("netlink plugin: qos_attr_cb: TCA_STATS_QUEUE mnl_attr_validate2 "
+            "failed.");
+      return MNL_CB_ERROR;
+    }
+    q_stats->qs = mnl_attr_get_payload(attr);
+    return MNL_CB_OK;
   }
 
   return MNL_CB_OK;
@@ -492,7 +507,9 @@ static int qos_filter_cb(const struct nlmsghdr *nlh, void *args) {
 
 #if HAVE_TCA_STATS2
   mnl_attr_for_each(attr, nlh, sizeof(*tm)) {
-    struct gnet_stats_basic *bs = NULL;
+    struct qos_stats q_stats;
+
+    memset(&q_stats, 0x0, sizeof(q_stats));
 
     if (mnl_attr_get_type(attr) != TCA_STATS2)
       continue;
@@ -503,9 +520,9 @@ static int qos_filter_cb(const struct nlmsghdr *nlh, void *args) {
       return MNL_CB_ERROR;
     }
 
-    mnl_attr_parse_nested(attr, qos_attr_cb, &bs);
+    mnl_attr_parse_nested(attr, qos_attr_cb, &q_stats);
 
-    if (bs != NULL) {
+    if (q_stats.bs != NULL || q_stats.qs != NULL) {
       char type_instance[DATA_MAX_NAME_LEN];
 
       stats_submitted = 1;
@@ -513,8 +530,13 @@ static int qos_filter_cb(const struct nlmsghdr *nlh, void *args) {
       ssnprintf(type_instance, sizeof(type_instance), "%s-%s", tc_type,
                 tc_inst);
 
-      submit_one(dev, "ipt_bytes", type_instance, bs->bytes);
-      submit_one(dev, "ipt_packets", type_instance, bs->packets);
+      if (q_stats.bs != NULL) {
+        submit_one(dev, "ipt_bytes", type_instance, q_stats.bs->bytes);
+        submit_one(dev, "ipt_packets", type_instance, q_stats.bs->packets);
+      }
+      if (q_stats.qs != NULL) {
+        submit_one(dev, "if_tx_dropped", type_instance, q_stats.qs->drops);
+      }
     }
 
     break;
@@ -736,7 +758,3 @@ void module_register(void) {
   plugin_register_read("netlink", ir_read);
   plugin_register_shutdown("netlink", ir_shutdown);
 } /* void module_register */
-
-/*
- * vim: set shiftwidth=2 softtabstop=2 tabstop=8 :
- */
index 8eab08b..e1214cf 100644 (file)
@@ -51,7 +51,7 @@
 #include <net/if.h>
 #endif
 
-#if HAVE_LIBGCRYPT
+#if HAVE_GCRYPT_H
 #if defined __APPLE__
 /* default xcode compiler throws warnings even when deprecated functionality
  * is not used. -Werror breaks the build because of erroneous warnings.
@@ -96,7 +96,7 @@ GCRY_THREAD_OPTION_PTHREAD_IMPL;
  * Private data types
  */
 #define SECURITY_LEVEL_NONE 0
-#if HAVE_LIBGCRYPT
+#if HAVE_GCRYPT_H
 #define SECURITY_LEVEL_SIGN 1
 #define SECURITY_LEVEL_ENCRYPT 2
 #endif
@@ -104,7 +104,7 @@ struct sockent_client {
   int fd;
   struct sockaddr_storage *addr;
   socklen_t addrlen;
-#if HAVE_LIBGCRYPT
+#if HAVE_GCRYPT_H
   int security_level;
   char *username;
   char *password;
@@ -118,7 +118,7 @@ struct sockent_client {
 struct sockent_server {
   int *fd;
   size_t fd_num;
-#if HAVE_LIBGCRYPT
+#if HAVE_GCRYPT_H
   int security_level;
   char *auth_file;
   fbhash_t *userdb;
@@ -468,7 +468,7 @@ static int network_dispatch_notification(notification_t *n) /* {{{ */
   return (status);
 } /* }}} int network_dispatch_notification */
 
-#if HAVE_LIBGCRYPT
+#if HAVE_GCRYPT_H
 static int network_init_gcrypt(void) /* {{{ */
 {
   gcry_error_t err;
@@ -570,7 +570,7 @@ static gcry_cipher_hd_t network_get_aes256_cypher(sockent_t *se, /* {{{ */
 
   return (*cyper_ptr);
 } /* }}} int network_get_aes256_cypher */
-#endif /* HAVE_LIBGCRYPT */
+#endif /* HAVE_GCRYPT_H */
 
 static int write_part_values(char **ret_buffer, size_t *ret_buffer_len,
                              const data_set_t *ds, const value_list_t *vl) {
@@ -978,7 +978,7 @@ static int parse_packet(sockent_t *se, void *buffer, size_t buffer_size,
     buffer_offset += (s);                                                      \
   } while (0)
 
-#if HAVE_LIBGCRYPT
+#if HAVE_GCRYPT_H
 static int parse_part_sign_sha256(sockent_t *se, /* {{{ */
                                   void **ret_buffer, size_t *ret_buffer_len,
                                   int flags) {
@@ -1103,9 +1103,9 @@ static int parse_part_sign_sha256(sockent_t *se, /* {{{ */
 
   return (0);
 } /* }}} int parse_part_sign_sha256 */
-/* #endif HAVE_LIBGCRYPT */
+/* #endif HAVE_GCRYPT_H */
 
-#else  /* if !HAVE_LIBGCRYPT */
+#else  /* if !HAVE_GCRYPT_H */
 static int parse_part_sign_sha256(sockent_t *se, /* {{{ */
                                   void **ret_buffer, size_t *ret_buffer_size,
                                   int flags) {
@@ -1147,9 +1147,9 @@ static int parse_part_sign_sha256(sockent_t *se, /* {{{ */
 
   return (0);
 } /* }}} int parse_part_sign_sha256 */
-#endif /* !HAVE_LIBGCRYPT */
+#endif /* !HAVE_GCRYPT_H */
 
-#if HAVE_LIBGCRYPT
+#if HAVE_GCRYPT_H
 static int parse_part_encr_aes256(sockent_t *se, /* {{{ */
                                   void **ret_buffer, size_t *ret_buffer_len,
                                   int flags) {
@@ -1260,9 +1260,9 @@ static int parse_part_encr_aes256(sockent_t *se, /* {{{ */
 
   return (0);
 } /* }}} int parse_part_encr_aes256 */
-/* #endif HAVE_LIBGCRYPT */
+/* #endif HAVE_GCRYPT_H */
 
-#else  /* if !HAVE_LIBGCRYPT */
+#else  /* if !HAVE_GCRYPT_H */
 static int parse_part_encr_aes256(sockent_t *se, /* {{{ */
                                   void **ret_buffer, size_t *ret_buffer_size,
                                   int flags) {
@@ -1304,7 +1304,7 @@ static int parse_part_encr_aes256(sockent_t *se, /* {{{ */
 
   return (0);
 } /* }}} int parse_part_encr_aes256 */
-#endif /* !HAVE_LIBGCRYPT */
+#endif /* !HAVE_GCRYPT_H */
 
 #undef BUFFER_READ
 
@@ -1316,11 +1316,11 @@ static int parse_packet(sockent_t *se, /* {{{ */
   value_list_t vl = VALUE_LIST_INIT;
   notification_t n = {0};
 
-#if HAVE_LIBGCRYPT
+#if HAVE_GCRYPT_H
   int packet_was_signed = (flags & PP_SIGNED);
   int packet_was_encrypted = (flags & PP_ENCRYPTED);
   int printed_ignore_warning = 0;
-#endif /* HAVE_LIBGCRYPT */
+#endif /* HAVE_GCRYPT_H */
 
   memset(&vl, '\0', sizeof(vl));
   status = 0;
@@ -1353,7 +1353,7 @@ static int parse_packet(sockent_t *se, /* {{{ */
         break;
       }
     }
-#if HAVE_LIBGCRYPT
+#if HAVE_GCRYPT_H
     else if ((se->data.server.security_level == SECURITY_LEVEL_ENCRYPT) &&
              (packet_was_encrypted == 0)) {
       if (printed_ignore_warning == 0) {
@@ -1365,7 +1365,7 @@ static int parse_packet(sockent_t *se, /* {{{ */
       buffer_size -= (size_t)pkg_length;
       continue;
     }
-#endif /* HAVE_LIBGCRYPT */
+#endif /* HAVE_GCRYPT_H */
     else if (pkg_type == TYPE_SIGN_SHA256) {
       status = parse_part_sign_sha256(se, &buffer, &buffer_size, flags);
       if (status != 0) {
@@ -1376,7 +1376,7 @@ static int parse_packet(sockent_t *se, /* {{{ */
         break;
       }
     }
-#if HAVE_LIBGCRYPT
+#if HAVE_GCRYPT_H
     else if ((se->data.server.security_level == SECURITY_LEVEL_SIGN) &&
              (packet_was_encrypted == 0) && (packet_was_signed == 0)) {
       if (printed_ignore_warning == 0) {
@@ -1388,7 +1388,7 @@ static int parse_packet(sockent_t *se, /* {{{ */
       buffer_size -= (size_t)pkg_length;
       continue;
     }
-#endif /* HAVE_LIBGCRYPT */
+#endif /* HAVE_GCRYPT_H */
     else if (pkg_type == TYPE_VALUES) {
       status =
           parse_part_values(&buffer, &buffer_size, &vl.values, &vl.values_len);
@@ -1499,7 +1499,7 @@ static void free_sockent_client(struct sockent_client *sec) /* {{{ */
     sec->fd = -1;
   }
   sfree(sec->addr);
-#if HAVE_LIBGCRYPT
+#if HAVE_GCRYPT_H
   sfree(sec->username);
   sfree(sec->password);
   if (sec->cypher != NULL)
@@ -1517,7 +1517,7 @@ static void free_sockent_server(struct sockent_server *ses) /* {{{ */
   }
 
   sfree(ses->fd);
-#if HAVE_LIBGCRYPT
+#if HAVE_GCRYPT_H
   sfree(ses->auth_file);
   fbh_destroy(ses->userdb);
   if (ses->cypher != NULL)
@@ -1846,7 +1846,7 @@ static sockent_t *sockent_create(int type) /* {{{ */
   if (type == SOCKENT_TYPE_SERVER) {
     se->data.server.fd = NULL;
     se->data.server.fd_num = 0;
-#if HAVE_LIBGCRYPT
+#if HAVE_GCRYPT_H
     se->data.server.security_level = SECURITY_LEVEL_NONE;
     se->data.server.auth_file = NULL;
     se->data.server.userdb = NULL;
@@ -1857,7 +1857,7 @@ static sockent_t *sockent_create(int type) /* {{{ */
     se->data.client.addr = NULL;
     se->data.client.resolve_interval = 0;
     se->data.client.next_resolve_reconnect = 0;
-#if HAVE_LIBGCRYPT
+#if HAVE_GCRYPT_H
     se->data.client.security_level = SECURITY_LEVEL_NONE;
     se->data.client.username = NULL;
     se->data.client.password = NULL;
@@ -1870,7 +1870,7 @@ static sockent_t *sockent_create(int type) /* {{{ */
 
 static int sockent_init_crypto(sockent_t *se) /* {{{ */
 {
-#if HAVE_LIBGCRYPT /* {{{ */
+#if HAVE_GCRYPT_H /* {{{ */
   if (se->type == SOCKENT_TYPE_CLIENT) {
     if (se->data.client.security_level > SECURITY_LEVEL_NONE) {
       if (network_init_gcrypt() < 0) {
@@ -1913,7 +1913,7 @@ static int sockent_init_crypto(sockent_t *se) /* {{{ */
       }
     }
   }
-#endif /* }}} HAVE_LIBGCRYPT */
+#endif /* }}} HAVE_GCRYPT_H */
 
   return (0);
 } /* }}} int sockent_init_crypto */
@@ -2375,7 +2375,7 @@ static void network_send_buffer_plain(sockent_t *se, /* {{{ */
   } /* while (42) */
 } /* }}} void network_send_buffer_plain */
 
-#if HAVE_LIBGCRYPT
+#if HAVE_GCRYPT_H
 #define BUFFER_ADD(p, s)                                                       \
   do {                                                                         \
     memcpy(buffer + buffer_offset, (p), (s));                                  \
@@ -2525,20 +2525,20 @@ static void network_send_buffer_encrypted(sockent_t *se, /* {{{ */
   network_send_buffer_plain(se, buffer, buffer_size);
 } /* }}} void network_send_buffer_encrypted */
 #undef BUFFER_ADD
-#endif /* HAVE_LIBGCRYPT */
+#endif /* HAVE_GCRYPT_H */
 
 static void network_send_buffer(char *buffer, size_t buffer_len) /* {{{ */
 {
   DEBUG("network plugin: network_send_buffer: buffer_len = %zu", buffer_len);
 
   for (sockent_t *se = sending_sockets; se != NULL; se = se->next) {
-#if HAVE_LIBGCRYPT
+#if HAVE_GCRYPT_H
     if (se->data.client.security_level == SECURITY_LEVEL_ENCRYPT)
       network_send_buffer_encrypted(se, buffer, buffer_len);
     else if (se->data.client.security_level == SECURITY_LEVEL_SIGN)
       network_send_buffer_signed(se, buffer, buffer_len);
     else /* if (se->data.client.security_level == SECURITY_LEVEL_NONE) */
-#endif   /* HAVE_LIBGCRYPT */
+#endif   /* HAVE_GCRYPT_H */
       network_send_buffer_plain(se, buffer, buffer_len);
   } /* for (sending_sockets) */
 } /* }}} void network_send_buffer */
@@ -2731,7 +2731,7 @@ static int network_config_set_buffer_size(const oconfig_item_t *ci) /* {{{ */
   return (0);
 } /* }}} int network_config_set_buffer_size */
 
-#if HAVE_LIBGCRYPT
+#if HAVE_GCRYPT_H
 static int network_config_set_security_level(oconfig_item_t *ci, /* {{{ */
                                              int *retval) {
   char *str;
@@ -2755,7 +2755,7 @@ static int network_config_set_security_level(oconfig_item_t *ci, /* {{{ */
 
   return (0);
 } /* }}} int network_config_set_security_level */
-#endif /* HAVE_LIBGCRYPT */
+#endif /* HAVE_GCRYPT_H */
 
 static int network_config_add_listen(const oconfig_item_t *ci) /* {{{ */
 {
@@ -2784,13 +2784,13 @@ static int network_config_add_listen(const oconfig_item_t *ci) /* {{{ */
   for (int i = 0; i < ci->children_num; i++) {
     oconfig_item_t *child = ci->children + i;
 
-#if HAVE_LIBGCRYPT
+#if HAVE_GCRYPT_H
     if (strcasecmp("AuthFile", child->key) == 0)
       cf_util_get_string(child, &se->data.server.auth_file);
     else if (strcasecmp("SecurityLevel", child->key) == 0)
       network_config_set_security_level(child, &se->data.server.security_level);
     else
-#endif /* HAVE_LIBGCRYPT */
+#endif /* HAVE_GCRYPT_H */
         if (strcasecmp("Interface", child->key) == 0)
       network_config_set_interface(child, &se->interface);
     else {
@@ -2798,7 +2798,7 @@ static int network_config_add_listen(const oconfig_item_t *ci) /* {{{ */
     }
   }
 
-#if HAVE_LIBGCRYPT
+#if HAVE_GCRYPT_H
   if ((se->data.server.security_level > SECURITY_LEVEL_NONE) &&
       (se->data.server.auth_file == NULL)) {
     ERROR("network plugin: A security level higher than `none' was "
@@ -2807,7 +2807,7 @@ static int network_config_add_listen(const oconfig_item_t *ci) /* {{{ */
     sockent_destroy(se);
     return (-1);
   }
-#endif /* HAVE_LIBGCRYPT */
+#endif /* HAVE_GCRYPT_H */
 
   status = sockent_init_crypto(se);
   if (status != 0) {
@@ -2862,7 +2862,7 @@ static int network_config_add_server(const oconfig_item_t *ci) /* {{{ */
   for (int i = 0; i < ci->children_num; i++) {
     oconfig_item_t *child = ci->children + i;
 
-#if HAVE_LIBGCRYPT
+#if HAVE_GCRYPT_H
     if (strcasecmp("Username", child->key) == 0)
       cf_util_get_string(child, &se->data.client.username);
     else if (strcasecmp("Password", child->key) == 0)
@@ -2870,7 +2870,7 @@ static int network_config_add_server(const oconfig_item_t *ci) /* {{{ */
     else if (strcasecmp("SecurityLevel", child->key) == 0)
       network_config_set_security_level(child, &se->data.client.security_level);
     else
-#endif /* HAVE_LIBGCRYPT */
+#endif /* HAVE_GCRYPT_H */
         if (strcasecmp("Interface", child->key) == 0)
       network_config_set_interface(child, &se->interface);
     else if (strcasecmp("ResolveInterval", child->key) == 0)
@@ -2880,7 +2880,7 @@ static int network_config_add_server(const oconfig_item_t *ci) /* {{{ */
     }
   }
 
-#if HAVE_LIBGCRYPT
+#if HAVE_GCRYPT_H
   if ((se->data.client.security_level > SECURITY_LEVEL_NONE) &&
       ((se->data.client.username == NULL) ||
        (se->data.client.password == NULL))) {
@@ -2890,7 +2890,7 @@ static int network_config_add_server(const oconfig_item_t *ci) /* {{{ */
     sockent_destroy(se);
     return (-1);
   }
-#endif /* HAVE_LIBGCRYPT */
+#endif /* HAVE_GCRYPT_H */
 
   status = sockent_init_crypto(se);
   if (status != 0) {
@@ -3223,5 +3223,3 @@ void module_register(void) {
   plugin_register_flush("network", network_flush,
                         /* user_data = */ NULL);
 } /* void module_register */
-
-/* vim: set fdm=marker : */
index ffc545c..72c0363 100644 (file)
@@ -267,7 +267,3 @@ void module_register(void) {
   plugin_register_init("nginx", init);
   plugin_register_read("nginx", nginx_read);
 } /* void module_register */
-
-/*
- * vim: set shiftwidth=2 softtabstop=2 tabstop=8 :
- */
index 4840441..d167fbf 100644 (file)
@@ -166,5 +166,3 @@ void module_register(void) {
   plugin_register_init("notify_desktop", c_notify_init);
   return;
 } /* module_register */
-
-/* vim: set sw=4 ts=4 tw=78 noexpandtab : */
index f42e66c..aaa165a 100644 (file)
@@ -290,5 +290,3 @@ void module_register(void) {
   plugin_register_notification("notify_email", notify_email_notification,
                                /* user_data = */ NULL);
 } /* void module_register (void) */
-
-/* vim: set sw=2 sts=2 ts=8 et : */
index 1351691..c95f7cb 100644 (file)
@@ -153,5 +153,3 @@ void module_register(void) {
   plugin_register_complex_config("notify_nagios", nagios_config);
   plugin_register_notification("notify_nagios", nagios_notify, NULL);
 } /* void module_register (void) */
-
-/* vim: set sw=2 sts=2 ts=8 et : */
index 1dc1857..21b65f5 100644 (file)
@@ -32,9 +32,6 @@
 #include "common.h"
 #include "plugin.h"
 
-#if HAVE_STDINT_H
-#include <stdint.h>
-#endif
 #if HAVE_NETDB_H
 #include <netdb.h>
 #endif
index 049daee..01d74e1 100644 (file)
@@ -152,5 +152,3 @@ void module_register(void) {
   plugin_register_init("numa", numa_init);
   plugin_register_read("numa", numa_read);
 } /* void module_register */
-
-/* vim: set sw=2 sts=2 et : */
index d40e095..c0ee7ab 100644 (file)
--- a/src/nut.c
+++ b/src/nut.c
@@ -255,5 +255,3 @@ void module_register(void) {
   plugin_register_read("nut", nut_read);
   plugin_register_shutdown("nut", nut_shutdown);
 } /* void module_register */
-
-/* vim: set sw=2 ts=8 sts=2 tw=78 : */
index d1caf46..816a70b 100644 (file)
@@ -631,5 +631,3 @@ void module_register(void) {
   plugin_register_read("olsrd", olsrd_read);
   plugin_register_shutdown("olsrd", olsrd_shutdown);
 } /* void module_register */
-
-/* vim: set sw=2 sts=2 et fdm=marker : */
index 10fa5ca..407e857 100644 (file)
@@ -534,5 +534,3 @@ void module_register(void) {
   plugin_register_config("onewire", cow_load_config, config_keys,
                          config_keys_num);
 }
-
-/* vim: set sw=2 sts=2 ts=8 et fdm=marker cindent : */
index 90694b7..1045d50 100644 (file)
@@ -715,5 +715,3 @@ void module_register(void) {
                          config_keys_num);
   plugin_register_init("openvpn", openvpn_init);
 } /* void module_register */
-
-/* vim: set sw=2 ts=2 : */
index 4eacc54..b52ea4e 100644 (file)
@@ -706,7 +706,3 @@ void module_register(void) /* {{{ */
   plugin_register_read("oracle", o_read);
   plugin_register_shutdown("oracle", o_shutdown);
 } /* }}} void module_register */
-
-/*
- * vim: shiftwidth=2 softtabstop=2 et fdm=marker
- */
index 5910913..c79cfd2 100644 (file)
@@ -38,9 +38,7 @@
 
 #undef DONT_POISON_SPRINTF_YET
 
-#if HAVE_STDBOOL_H
 #include <stdbool.h>
-#endif
 
 #include <EXTERN.h>
 #include <perl.h>
@@ -2711,5 +2709,3 @@ void module_register(void) {
   plugin_register_complex_config("perl", perl_config);
   return;
 } /* void module_register (void) */
-
-/* vim: set sw=4 ts=4 tw=78 noexpandtab : */
index 7fd23a0..97eeb0d 100644 (file)
@@ -685,5 +685,3 @@ void module_register(void) /* {{{ */
   plugin_register_read("pinba", plugin_read);
   plugin_register_shutdown("pinba", plugin_shutdown);
 } /* }}} void module_register */
-
-/* vim: set sw=2 sts=2 et fdm=marker : */
index 82de59f..6d9545f 100644 (file)
@@ -679,5 +679,3 @@ void module_register(void) {
   plugin_register_read("ping", ping_read);
   plugin_register_shutdown("ping", ping_shutdown);
 } /* void module_register */
-
-/* vim: set sw=2 sts=2 et fdm=marker : */
index 2af8988..3a388a5 100644 (file)
@@ -1265,5 +1265,3 @@ void module_register(void) {
   plugin_register_complex_config("postgresql", c_psql_config);
   plugin_register_shutdown("postgresql", c_psql_shutdown);
 } /* module_register */
-
-/* vim: set sw=4 ts=4 tw=78 noexpandtab : */
index f2149ef..8562108 100644 (file)
@@ -960,5 +960,3 @@ void module_register(void) {
   plugin_register_read("powerdns", powerdns_read);
   plugin_register_shutdown("powerdns", powerdns_shutdown);
 } /* void module_register */
-
-/* vim: set sw=2 sts=2 ts=8 fdm=marker : */
index 86f690f..4f61351 100644 (file)
@@ -1916,7 +1916,7 @@ static int ps_read(void) {
   ps_list_reset();
 
   /* Open the kvm interface, get a descriptor */
-  kd = kvm_open(NULL, NULL, NULL, 0, errbuf);
+  kd = kvm_openfiles(NULL, NULL, NULL, KVM_NO_FILES, errbuf);
   if (kd == NULL) {
     ERROR("processes plugin: Cannot open kvm interface: %s", errbuf);
     return (0);
index 64735e6..12fbf45 100644 (file)
@@ -213,5 +213,3 @@ void module_register(void) {
                          config_keys_num);
   plugin_register_read("protocols", protocols_read);
 } /* void module_register */
-
-/* vim: set sw=2 sts=2 et : */
index 7875c7e..ea888ca 100644 (file)
@@ -451,5 +451,3 @@ void module_register(void) /* {{{ */
    * X elements */
 }
 /* }}} */
-
-/* vim: set sw=2 sts=2 et fdm=marker : */
index 07493c7..5c978dc 100644 (file)
@@ -409,5 +409,3 @@ static int cr_config(oconfig_item_t *ci) {
 void module_register(void) {
   plugin_register_complex_config("routeros", cr_config);
 } /* void module_register */
-
-/* vim: set sw=2 noet fdm=marker : */
index 6eb67d4..5cf17c1 100644 (file)
@@ -529,7 +529,3 @@ void module_register(void) {
   plugin_register_init("rrdcached", rc_init);
   plugin_register_shutdown("rrdcached", rc_shutdown);
 } /* void module_register */
-
-/*
- * vim: set sw=2 sts=2 et :
- */
index 3bfec47..ff75edb 100644 (file)
@@ -1695,7 +1695,3 @@ void module_register(void) {
   plugin_register_init("snmp", csnmp_init);
   plugin_register_shutdown("snmp", csnmp_shutdown);
 } /* void module_register */
-
-/*
- * vim: shiftwidth=2 softtabstop=2 tabstop=8 fdm=marker
- */
index 47e01d8..aa4e35c 100644 (file)
@@ -914,5 +914,3 @@ void module_register(void) {
   plugin_register_read("statsd", statsd_read);
   plugin_register_shutdown("statsd", statsd_shutdown);
 }
-
-/* vim: set sw=2 sts=2 et fdm=marker : */
index cbe1ab1..19eed46 100644 (file)
@@ -738,5 +738,3 @@ void module_register(void) {
   plugin_register_init("swap", swap_init);
   plugin_register_read("swap", swap_read);
 } /* void module_register */
-
-/* vim: set fdm=marker : */
index 3e8fead..578e019 100644 (file)
@@ -520,5 +520,3 @@ void module_register(void) {
   plugin_register_complex_config("table", tbl_config);
   plugin_register_init("table", tbl_init);
 } /* module_register */
-
-/* vim: set sw=4 ts=4 tw=78 noexpandtab : */
index bb4eb30..466dbff 100644 (file)
@@ -337,5 +337,3 @@ void module_register(void) {
   plugin_register_init("tail", ctail_init);
   plugin_register_shutdown("tail", ctail_shutdown);
 } /* void module_register */
-
-/* vim: set sw=2 sts=2 ts=8 : */
index b1a3292..425c101 100644 (file)
@@ -551,5 +551,3 @@ void module_register(void) {
   plugin_register_init("tail_csv", tcsv_init);
   plugin_register_shutdown("tail_csv", tcsv_shutdown);
 }
-
-/* vim: set sw=4 sts=4 et : */
index dc93b98..7c82c79 100644 (file)
@@ -260,5 +260,3 @@ void module_register(void) {
   tproc.invoke = tn_invoke;
   fc_register_target("notification", tproc);
 } /* module_register */
-
-/* vim: set sw=2 sts=2 tw=78 et fdm=marker : */
index b43a025..2bdb3b8 100644 (file)
@@ -561,5 +561,3 @@ void module_register(void) {
   tproc.invoke = tr_invoke;
   fc_register_target("replace", tproc);
 } /* module_register */
-
-/* vim: set sw=2 sts=2 tw=78 et fdm=marker : */
index 347d627..4cce8dd 100644 (file)
@@ -457,5 +457,3 @@ void module_register(void) {
   tproc.invoke = ts_invoke;
   fc_register_target("scale", tproc);
 } /* module_register */
-
-/* vim: set sw=2 ts=2 tw=78 fdm=marker : */
index a40273c..e9dbc1d 100644 (file)
@@ -420,5 +420,3 @@ void module_register(void) {
   tproc.invoke = ts_invoke;
   fc_register_target("set", tproc);
 } /* module_register */
-
-/* vim: set sw=2 sts=2 tw=78 et fdm=marker : */
index 54e37e1..27bca39 100644 (file)
@@ -451,5 +451,3 @@ void module_register(void) {
   tproc.invoke = v5_invoke;
   fc_register_target("v5upgrade", tproc);
 } /* module_register */
-
-/* vim: set sw=2 sts=2 tw=78 et fdm=marker : */
index f949d34..08838fb 100644 (file)
 #include "common.h"
 #include "plugin.h"
 
-#if defined(__OpenBSD__) || defined(__NetBSD__)
+#if defined(__OpenBSD__)
+#define HAVE_KVM_GETFILES 1
+#endif
+
+#if defined(__NetBSD__)
 #undef HAVE_SYSCTLBYNAME /* force HAVE_LIBKVM_NLIST path */
 #endif
 
-#if !KERNEL_LINUX && !HAVE_SYSCTLBYNAME && !HAVE_LIBKVM_NLIST && !KERNEL_AIX
+#if !KERNEL_LINUX && !HAVE_SYSCTLBYNAME && !HAVE_KVM_GETFILES && !HAVE_LIBKVM_NLIST && !KERNEL_AIX
 #error "No applicable input method."
 #endif
 
 #include <netinet/tcpip.h>
 /* #endif HAVE_SYSCTLBYNAME */
 
-/* This is for OpenBSD and NetBSD. */
+#elif HAVE_KVM_GETFILES
+#include <sys/types.h>
+#include <sys/sysctl.h>
+#define _KERNEL /* for DTYPE_SOCKET */
+#include <sys/file.h>
+#undef _KERNEL
+
+#include <netinet/in.h>
+
+#include <kvm.h>
+/* #endif HAVE_KVM_GETFILES */
+
+/* This is for NetBSD. */
 #elif HAVE_LIBKVM_NLIST
 #include <arpa/inet.h>
 #include <net/route.h>
 #include <netdb.h>
 #include <netinet/in.h>
+#include <netinet/ip.h>
 #include <netinet/in_pcb.h>
 #include <netinet/in_systm.h>
-#include <netinet/ip.h>
 #include <netinet/ip_var.h>
 #include <netinet/tcp.h>
 #include <netinet/tcp_timer.h>
@@ -169,6 +185,19 @@ static const char *tcp_state[] = {"CLOSED",    "LISTEN",      "SYN_SENT",
 #define TCP_STATE_MAX 10
 /* #endif HAVE_SYSCTLBYNAME */
 
+#elif HAVE_KVM_GETFILES
+static const char *tcp_state[] = {"CLOSED",    "LISTEN",      "SYN_SENT",
+                                  "SYN_RECV",  "ESTABLISHED", "CLOSE_WAIT",
+                                  "FIN_WAIT1", "CLOSING",     "LAST_ACK",
+                                  "FIN_WAIT2", "TIME_WAIT"};
+
+#define TCP_STATE_LISTEN 1
+#define TCP_STATE_MIN 0
+#define TCP_STATE_MAX 10
+
+static kvm_t *kvmd;
+/* #endif HAVE_KVM_GETFILES */
+
 #elif HAVE_LIBKVM_NLIST
 static const char *tcp_state[] = {"CLOSED",    "LISTEN",      "SYN_SENT",
                                   "SYN_RECV",  "ESTABLISHED", "CLOSE_WAIT",
@@ -775,6 +804,49 @@ static int conn_read(void) {
 } /* int conn_read */
   /* #endif HAVE_SYSCTLBYNAME */
 
+#elif HAVE_KVM_GETFILES
+
+static int conn_init(void) {
+  char buf[_POSIX2_LINE_MAX];
+
+  kvmd = kvm_openfiles(NULL, NULL, NULL, KVM_NO_FILES, buf);
+  if (kvmd == NULL) {
+    ERROR("tcpconns plugin: kvm_openfiles failed: %s", buf);
+    return (-1);
+  }
+
+  return (0);
+} /* int conn_init */
+
+static int conn_read(void) {
+  struct kinfo_file *kf;
+  int i, fcnt;
+
+  conn_reset_port_entry();
+
+  kf = kvm_getfiles(kvmd, KERN_FILE_BYFILE, DTYPE_SOCKET,
+                   sizeof(*kf), &fcnt);
+  if (kf == NULL) {
+    ERROR("tcpconns plugin: kvm_getfiles failed.");
+    return (-1);
+  }
+
+  for (i = 0; i < fcnt; i++) {
+    if (kf[i].so_protocol != IPPROTO_TCP)
+      continue;
+    if (kf[i].inp_fport == 0)
+      continue;
+    conn_handle_ports(ntohs(kf[i].inp_lport), ntohs(kf[i].inp_fport),
+                      kf[i].t_state);
+  }
+
+  conn_submit_all();
+
+  return (0);
+}
+/* int conn_read */
+/* #endif HAVE_KVM_GETFILES */
+
 #elif HAVE_LIBKVM_NLIST
 static int kread(u_long addr, void *buf, int size) {
   int status;
@@ -958,7 +1030,3 @@ void module_register(void) {
 #endif
   plugin_register_read("tcpconns", conn_read);
 } /* void module_register */
-
-/*
- * vim: set shiftwidth=2 softtabstop=2 tabstop=8 fdm=marker :
- */
index 960d646..a959cdd 100644 (file)
@@ -728,5 +728,3 @@ void module_register(void) {
   plugin_register_read("teamspeak2", tss2_read);
   plugin_register_shutdown("teamspeak2", tss2_shutdown);
 } /* void module_register */
-
-/* vim: set sw=4 ts=4 : */
index cccb3db..fbfd95d 100644 (file)
--- a/src/ted.c
+++ b/src/ted.c
@@ -39,8 +39,7 @@
 #include "common.h"
 #include "plugin.h"
 
-#if HAVE_TERMIOS_H && HAVE_SYS_IOCTL_H && HAVE_MATH_H
-#include <math.h>
+#if HAVE_TERMIOS_H && HAVE_SYS_IOCTL_H
 #include <sys/ioctl.h>
 #include <termios.h>
 #else
@@ -300,5 +299,3 @@ void module_register(void) {
   plugin_register_read("ted", ted_read);
   plugin_register_shutdown("ted", ted_shutdown);
 } /* void module_register */
-
-/* vim: set sw=4 et : */
index 743db28..a4a999f 100644 (file)
@@ -834,5 +834,3 @@ static int ut_config(oconfig_item_t *ci) { /* {{{ */
 void module_register(void) {
   plugin_register_complex_config("threshold", ut_config);
 }
-
-/* vim: set sw=2 ts=8 sts=2 tw=78 et fdm=marker : */
index cb366d3..09ee25d 100644 (file)
@@ -150,5 +150,3 @@ void module_register(void) {
   plugin_register_read("tokyotyrant", tt_read);
   plugin_register_shutdown("tokyotyrant", tt_shutdown);
 }
-
-/* vim: set sw=8 ts=8 tw=78 : */
index f61360e..b08c89f 100644 (file)
@@ -429,5 +429,3 @@ void module_register(void) {
   plugin_register_init("unixsock", us_init);
   plugin_register_shutdown("unixsock", us_shutdown);
 } /* void module_register (void) */
-
-/* vim: set sw=4 ts=4 sts=4 tw=78 : */
index a8de21a..9e8950b 100644 (file)
@@ -177,5 +177,3 @@ void cmd_destroy_flush(cmd_flush_t *flush) {
   sfree(flush->identifiers);
   flush->identifiers_num = 0;
 } /* void cmd_destroy_flush */
-
-/* vim: set sw=4 ts=4 tw=78 noexpandtab : */
index d9b4e1b..129aa85 100644 (file)
@@ -40,5 +40,3 @@ cmd_status_t cmd_handle_flush(FILE *fh, char *buffer);
 void cmd_destroy_flush(cmd_flush_t *flush);
 
 #endif /* UTILS_CMD_FLUSH_H */
-
-/* vim: set sw=4 ts=4 tw=78 noexpandtab : */
index 926375d..063548b 100644 (file)
@@ -181,5 +181,3 @@ int handle_getthreshold(FILE *fh, char *buffer) {
 
   return (0);
 } /* int handle_getthreshold */
-
-/* vim: set sw=2 sts=2 ts=8 et : */
index dd4e5cf..78700ee 100644 (file)
@@ -32,5 +32,3 @@
 int handle_getthreshold(FILE *fh, char *buffer);
 
 #endif /* UTILS_CMD_GETTHRESHOLD_H */
-
-/* vim: set sw=2 sts=2 ts=8 : */
index c23650b..e5f17b6 100644 (file)
@@ -164,5 +164,3 @@ void cmd_destroy_getval(cmd_getval_t *getval) {
 
   sfree(getval->raw_identifier);
 } /* void cmd_destroy_getval */
-
-/* vim: set sw=2 sts=2 ts=8 : */
index 8d488b3..5c03fa4 100644 (file)
@@ -41,5 +41,3 @@ cmd_status_t cmd_handle_getval(FILE *fh, char *buffer);
 void cmd_destroy_getval(cmd_getval_t *getval);
 
 #endif /* UTILS_CMD_GETVAL_H */
-
-/* vim: set sw=2 sts=2 ts=8 : */
index f863889..4e603a2 100644 (file)
@@ -108,5 +108,3 @@ cmd_status_t cmd_handle_listval(FILE *fh, char *buffer) {
 void cmd_destroy_listval(cmd_listval_t *listval __attribute__((unused))) {
   /* nothing to do */
 } /* void cmd_destroy_listval */
-
-/* vim: set sw=2 sts=2 ts=8 : */
index 8a4e8c8..6abdeee 100644 (file)
@@ -41,5 +41,3 @@ cmd_status_t cmd_handle_listval(FILE *fh, char *buffer);
 void cmd_destroy_listval(cmd_listval_t *listval);
 
 #endif /* UTILS_CMD_LISTVAL_H */
-
-/* vim: set sw=2 sts=2 ts=8 : */
index 0edfbb8..8f687fd 100644 (file)
@@ -180,5 +180,3 @@ int handle_putnotif(FILE *fh, char *buffer) {
 
   return (0);
 } /* int handle_putnotif */
-
-/* vim: set shiftwidth=2 softtabstop=2 tabstop=8 : */
index af0b93e..7ad0f1a 100644 (file)
@@ -31,6 +31,4 @@
 
 int handle_putnotif(FILE *fh, char *buffer);
 
-/* vim: set shiftwidth=2 softtabstop=2 tabstop=8 : */
-
 #endif /* UTILS_CMD_PUTNOTIF_H */
index 3ea7c9d..31a9a6f 100644 (file)
@@ -309,5 +309,3 @@ void cmd_error_fh(void *ud, cmd_status_t status, const char *format,
 
   fflush(fh);
 } /* void cmd_error_fh */
-
-/* vim: set sw=4 ts=4 tw=78 noexpandtab : */
index 9a58227..c803029 100644 (file)
@@ -1059,5 +1059,3 @@ void udb_query_delete_preparation_area(
 
   free(q_area);
 } /* }}} void udb_query_delete_preparation_area */
-
-/* vim: set sw=2 sts=2 et fdm=marker : */
index 8f06918..4d6129a 100644 (file)
@@ -83,4 +83,3 @@ udb_query_allocate_preparation_area(udb_query_t *q);
 void udb_query_delete_preparation_area(udb_query_preparation_area_t *q_area);
 
 #endif /* UTILS_DB_QUERY_H */
-/* vim: set sw=2 sts=2 et : */
index a4a5784..2bda965 100644 (file)
@@ -1169,6 +1169,3 @@ main(int argc, char *argv[])
     return 0;
 } /* static int main(int argc, char *argv[]) */
 #endif
-/*
- * vim:shiftwidth=4:tabstop=8:softtabstop=4
- */
index ecc5674..f94e2e5 100644 (file)
@@ -255,5 +255,3 @@ char *fbh_get(fbhash_t *h, const char *key) /* {{{ */
 
   return (value_copy);
 } /* }}} char *fbh_get */
-
-/* vim: set sw=2 sts=2 et fdm=marker : */
index 79e9c00..fcd6e92 100644 (file)
@@ -48,5 +48,3 @@ void fbh_destroy(fbhash_t *h);
 char *fbh_get(fbhash_t *h, const char *key);
 
 #endif /* UTILS_FBHASH_H */
-
-/* vim: set sw=2 sts=2 et fdm=marker : */
index 4f509f4..0436340 100644 (file)
@@ -237,5 +237,3 @@ int format_graphite(char *buffer, size_t buffer_size, data_set_t const *ds,
   sfree(rates);
   return (status);
 } /* int format_graphite */
-
-/* vim: set sw=2 sts=2 et fdm=marker : */
index 415a283..a82142f 100644 (file)
@@ -49,12 +49,12 @@ static data_set_t ds_double = {
 
 DEF_TEST(metric_name) {
   struct {
-    char *plugin_instance;
-    char *type_instance;
-    char *prefix;
-    char *suffix;
+    const char *plugin_instance;
+    const char *type_instance;
+    const char *prefix;
+    const char *suffix;
     unsigned int flags;
-    char *want_name;
+    const char *want_name;
   } cases[] = {
       {
           .want_name = "example@com.test.single",
@@ -157,8 +157,35 @@ DEF_TEST(metric_name) {
   return 0;
 }
 
+DEF_TEST(null_termination) {
+  value_list_t vl = {
+      .values = &(value_t){.gauge = 1337},
+      .values_len = 1,
+      .time = TIME_T_TO_CDTIME_T_STATIC(1480063672),
+      .interval = TIME_T_TO_CDTIME_T_STATIC(10),
+      .host = "example.com",
+      .plugin = "test",
+      .type = "single",
+  };
+  char const *want = "example_com.test.single 1337 1480063672\r\n";
+
+  char buffer[128];
+  for (size_t i = 0; i < sizeof(buffer); i++)
+    buffer[i] = (char)i;
+
+  EXPECT_EQ_INT(0, format_graphite(buffer, sizeof(buffer), &ds_single, &vl,
+                                   NULL, NULL, '_', 0));
+  EXPECT_EQ_STR(want, buffer);
+  EXPECT_EQ_INT(0, buffer[strlen(want)]);
+  for (size_t i = strlen(want) + 1; i < sizeof(buffer); i++)
+    EXPECT_EQ_INT((int)i, (int)buffer[i]);
+
+  return 0;
+}
+
 int main(void) {
   RUN_TEST(metric_name);
+  RUN_TEST(null_termination);
 
   END_TEST;
 }
index 0a95a86..1a0e151 100644 (file)
@@ -685,5 +685,3 @@ int format_json_notification(char *buffer, size_t buffer_size, /* {{{ */
   return ENOTSUP;
 } /* }}} int format_json_notification */
 #endif
-
-/* vim: set sw=2 sts=2 et fdm=marker : */
index 4c25d18..1e54b97 100644 (file)
@@ -336,5 +336,3 @@ int format_kairosdb_value_list(char *buffer, /* {{{ */
       buffer, ret_buffer_fill, ret_buffer_free, ds, vl, store_rates,
       (*ret_buffer_free) - 2));
 } /* }}} int format_kairosdb_value_list */
-
-/* vim: set sw=2 sts=2 et fdm=marker : */
index f0311e8..f30b265 100644 (file)
@@ -342,5 +342,3 @@ double latency_counter_get_rate(const latency_counter_t *lc, /* {{{ */
 
   return sum / (CDTIME_T_TO_DOUBLE(now - lc->start_time));
 } /* }}} double latency_counter_get_rate */
-
-/* vim: set sw=2 sts=2 et fdm=marker : */
index 85493e1..9d878da 100644 (file)
@@ -61,5 +61,3 @@ cdtime_t latency_counter_get_percentile(latency_counter_t *lc, double percent);
  */
 double latency_counter_get_rate(const latency_counter_t *lc, cdtime_t lower,
                                 cdtime_t upper, const cdtime_t now);
-
-/* vim: set sw=2 sts=2 et : */
index ef29d8b..427a159 100644 (file)
@@ -232,5 +232,3 @@ int main(void) {
 
   END_TEST;
 }
-
-/* vim: set sw=2 sts=2 et : */
index dcb84af..7710121 100644 (file)
@@ -317,5 +317,3 @@ int luaC_pushvaluelist(lua_State *L, const data_set_t *ds,
 
   return (0);
 } /* }}} int luaC_pushvaluelist */
-
-/* vim: set sw=2 sts=2 et fdm=marker : */
index 8ff507c..61d9070 100644 (file)
@@ -53,4 +53,3 @@ int luaC_pushvaluelist(lua_State *L, const data_set_t *ds,
                        const value_list_t *vl);
 
 #endif /* UTILS_LUA_H */
-/* vim: set sw=2 sts=2 et fdm=marker : */
index 2e487b5..e2f2980 100644 (file)
@@ -368,5 +368,3 @@ void *match_get_user_data(cu_match_t *obj) {
     return (NULL);
   return (obj->user_data);
 } /* void *match_get_user_data */
-
-/* vim: set sw=2 sts=2 ts=8 : */
index 1383530..1cff1eb 100644 (file)
@@ -177,5 +177,3 @@ int match_apply(cu_match_t *obj, const char *str);
 void *match_get_user_data(cu_match_t *obj);
 
 #endif /* UTILS_MATCH_H */
-
-/* vim: set sw=2 sts=2 ts=8 : */
index 695038d..76fc8d4 100644 (file)
@@ -109,5 +109,3 @@ int main(void) {
 
   END_TEST;
 }
-
-/* vim: set sw=2 sts=2 et : */
index ba37f03..a2a7380 100644 (file)
@@ -146,5 +146,3 @@ int parse_option(char **ret_buffer, char **ret_key, char **ret_value) {
 
   return (0);
 } /* int parse_option */
-
-/* vim: set sw=2 ts=8 tw=78 et : */
index a638e69..3dd0a79 100644 (file)
@@ -31,5 +31,3 @@ int parse_string(char **ret_buffer, char **ret_string);
 int parse_option(char **ret_buffer, char **ret_key, char **ret_value);
 
 #endif /* UTILS_PARSE_OPTION */
-
-/* vim: set sw=2 ts=8 tw=78 et : */
index 750d265..ae72575 100644 (file)
@@ -664,5 +664,3 @@ int cu_rrd_create_file(const char *filename, /* {{{ */
 
   return (status);
 } /* }}} int cu_rrd_create_file */
-
-/* vim: set sw=2 sts=2 et fdm=marker : */
index 9bc67ae..d5f9a12 100644 (file)
@@ -51,5 +51,3 @@ int cu_rrd_create_file(const char *filename, const data_set_t *ds,
                        const value_list_t *vl, const rrdcreate_config_t *cfg);
 
 #endif /* UTILS_RRDCREATE_H */
-
-/* vim: set sw=2 sts=2 et : */
index 505c693..1a99384 100644 (file)
@@ -336,5 +336,3 @@ int tail_match_read(cu_tail_match_t *obj) {
 
   return (0);
 } /* int tail_match_read */
-
-/* vim: set sw=2 sts=2 ts=8 : */
index 09e3d40..03b70e9 100644 (file)
@@ -137,5 +137,3 @@ int tail_match_add_match_simple(cu_tail_match_t *obj, const char *regex,
  *   Zero on success, nonzero on failure.
 */
 int tail_match_read(cu_tail_match_t *obj);
-
-/* vim: set sw=2 sts=2 ts=8 : */
index 89c9e7d..546d481 100644 (file)
 #include <sys/sysctl.h>
 #endif
 
-#if HAVE_LIBHAL_H
-#include <libhal.h>
-#endif
-
 #define UUID_RAW_LENGTH 16
 #define UUID_PRINTABLE_COMPACT_LENGTH (UUID_RAW_LENGTH * 2)
 #define UUID_PRINTABLE_NORMAL_LENGTH (UUID_PRINTABLE_COMPACT_LENGTH + 4)
@@ -127,52 +123,6 @@ static char *uuid_get_from_sysctl(void) {
 }
 #endif
 
-#if HAVE_LIBHAL_H
-
-#define UUID_PATH "/org/freedesktop/Hal/devices/computer"
-#define UUID_PROPERTY "smbios.system.uuid"
-
-static char *uuid_get_from_hal(void) {
-  LibHalContext *ctx;
-
-  DBusError error;
-  DBusConnection *con;
-
-  dbus_error_init(&error);
-
-  if (!(con = dbus_bus_get(DBUS_BUS_SYSTEM, &error)))
-    goto bailout_nobus;
-
-  ctx = libhal_ctx_new();
-  libhal_ctx_set_dbus_connection(ctx, con);
-
-  if (!libhal_ctx_init(ctx, &error))
-    goto bailout;
-
-  if (!libhal_device_property_exists(ctx, UUID_PATH, UUID_PROPERTY, &error))
-    goto bailout;
-
-  char *uuid =
-      libhal_device_get_property_string(ctx, UUID_PATH, UUID_PROPERTY, &error);
-  if (looks_like_a_uuid(uuid))
-    return (uuid);
-
-bailout : {
-  DBusError ctxerror;
-  dbus_error_init(&ctxerror);
-  if (!(libhal_ctx_shutdown(ctx, &ctxerror)))
-    dbus_error_free(&ctxerror);
-}
-
-  libhal_ctx_free(ctx);
-
-bailout_nobus:
-  if (dbus_error_is_set(&error))
-    dbus_error_free(&error);
-  return (NULL);
-}
-#endif
-
 static char *uuid_get_from_file(const char *path) {
   FILE *file;
   char uuid[UUID_PRINTABLE_NORMAL_LENGTH + 1] = "";
@@ -215,11 +165,6 @@ static char *uuid_get_local(void) {
     return (uuid);
 #endif
 
-#if HAVE_LIBHAL_H
-  if ((uuid = uuid_get_from_hal()) != NULL)
-    return (uuid);
-#endif
-
   if ((uuid = uuid_get_from_dmidecode()) != NULL)
     return (uuid);
 
@@ -262,17 +207,3 @@ void module_register(void) {
                          STATIC_ARRAY_SIZE(config_keys));
   plugin_register_init("uuid", uuid_init);
 }
-
-/*
- * vim: set tabstop=4:
- * vim: set shiftwidth=4:
- * vim: set expandtab:
- */
-/*
- * Local variables:
- *  indent-tabs-mode: nil
- *  c-indent-level: 4
- *  c-basic-offset: 4
- *  tab-width: 4
- * End:
- */
index 41b60d8..3538e7e 100644 (file)
@@ -1331,5 +1331,3 @@ void module_register(void) /* {{{ */
   plugin_register_complex_config("varnish", varnish_config);
   plugin_register_init("varnish", varnish_init);
 } /* }}} */
-
-/* vim: set sw=8 noet fdm=marker : */
index c3c07a0..4dce6e0 100644 (file)
@@ -32,6 +32,7 @@
 #include <libxml/parser.h>
 #include <libxml/tree.h>
 #include <libxml/xpath.h>
+#include <libxml/xpathInternals.h>
 
 /* Plugin name */
 #define PLUGIN_NAME "virt"
@@ -52,6 +53,8 @@ static const char *config_keys[] = {"Connection",
 
                                     "PluginInstanceFormat",
 
+                                    "Instances",
+
                                     NULL};
 #define NR_CONFIG_KEYS ((sizeof config_keys / sizeof config_keys[0]) - 1)
 
@@ -73,25 +76,12 @@ static ignorelist_t *il_interface_devices = NULL;
 static int ignore_device_match(ignorelist_t *, const char *domname,
                                const char *devpath);
 
-/* Actual list of domains found on last refresh. */
-static virDomainPtr *domains = NULL;
-static int nr_domains = 0;
-
-static void free_domains(void);
-static int add_domain(virDomainPtr dom);
-
 /* Actual list of block devices found on last refresh. */
 struct block_device {
   virDomainPtr dom; /* domain */
   char *path;       /* name of block device */
 };
 
-static struct block_device *block_devices = NULL;
-static int nr_block_devices = 0;
-
-static void free_block_devices(void);
-static int add_block_device(virDomainPtr dom, const char *path);
-
 /* Actual list of network interfaces found on last refresh. */
 struct interface_device {
   virDomainPtr dom; /* domain */
@@ -100,12 +90,52 @@ struct interface_device {
   char *number;     /* interface device number */
 };
 
-static struct interface_device *interface_devices = NULL;
-static int nr_interface_devices = 0;
+struct lv_read_state {
+  /* Actual list of domains found on last refresh. */
+  virDomainPtr *domains;
+  int nr_domains;
+
+  struct block_device *block_devices;
+  int nr_block_devices;
+
+  struct interface_device *interface_devices;
+  int nr_interface_devices;
+};
+
+static void free_domains(struct lv_read_state *state);
+static int add_domain(struct lv_read_state *state, virDomainPtr dom);
+
+static void free_block_devices(struct lv_read_state *state);
+static int add_block_device(struct lv_read_state *state, virDomainPtr dom,
+                            const char *path);
+
+static void free_interface_devices(struct lv_read_state *state);
+static int add_interface_device(struct lv_read_state *state, virDomainPtr dom,
+                                const char *path, const char *address,
+                                unsigned int number);
+
+#define METADATA_VM_PARTITION_URI "http://ovirt.org/ovirtmap/tag/1.0"
+#define METADATA_VM_PARTITION_ELEMENT "tag"
+#define METADATA_VM_PARTITION_PREFIX "ovirtmap"
+
+#define BUFFER_MAX_LEN 256
+#define PARTITION_TAG_MAX_LEN 32
+
+struct lv_read_instance {
+  struct lv_read_state read_state;
+  char tag[PARTITION_TAG_MAX_LEN];
+  size_t id;
+};
+
+struct lv_user_data {
+  struct lv_read_instance inst;
+  user_data_t ud;
+};
 
-static void free_interface_devices(void);
-static int add_interface_device(virDomainPtr dom, const char *path,
-                                const char *address, unsigned int number);
+#define NR_INSTANCES_DEFAULT 1
+#define NR_INSTANCES_MAX 128
+static int nr_instances = NR_INSTANCES_DEFAULT;
+static struct lv_user_data lv_read_user_data[NR_INSTANCES_MAX];
 
 /* HostnameFormat. */
 #define HF_MAX_FIELDS 3
@@ -136,7 +166,7 @@ static enum if_field interface_format = if_name;
 /* Time that we last refreshed. */
 static time_t last_refresh = (time_t)0;
 
-static int refresh_lists(void);
+static int refresh_lists(struct lv_read_instance *inst);
 
 /* ERROR(...) macro for virterrors. */
 #define VIRT_ERROR(conn, s)                                                    \
@@ -276,13 +306,6 @@ static void submit_derive2(const char *type, derive_t v0, derive_t v1,
   submit(dom, type, devname, values, STATIC_ARRAY_SIZE(values));
 } /* void submit_derive2 */
 
-static int lv_init(void) {
-  if (virInitialize() != 0)
-    return -1;
-  else
-    return 0;
-}
-
 static int lv_config(const char *key, const char *value) {
   if (virInitialize() != 0)
     return 1;
@@ -453,13 +476,35 @@ static int lv_config(const char *key, const char *value) {
     return 0;
   }
 
+  if (strcasecmp(key, "Instances") == 0) {
+    char *eptr = NULL;
+    double val = strtod(value, &eptr);
+
+    if (*eptr != '\0') {
+      ERROR(PLUGIN_NAME " plugin: Invalid value for Instances = '%s'", value);
+      return 1;
+    }
+    if (val <= 0) {
+      ERROR(PLUGIN_NAME " plugin: Instances <= 0 makes no sense.");
+      return 1;
+    }
+    if (val > NR_INSTANCES_MAX) {
+      ERROR(PLUGIN_NAME " plugin: Instances=%f > NR_INSTANCES_MAX=%i"
+                        " use a lower setting or recompile the plugin.",
+            val, NR_INSTANCES_MAX);
+      return 1;
+    }
+
+    nr_instances = (int)val;
+    DEBUG(PLUGIN_NAME " plugin: configured %i instances", nr_instances);
+    return 0;
+  }
+
   /* Unrecognised option. */
   return -1;
 }
 
-static int lv_read(void) {
-  time_t t;
-
+static int lv_connect(void) {
   if (conn == NULL) {
     /* `conn_string == NULL' is acceptable. */
     conn = virConnectOpenReadOnly(conn_string);
@@ -472,16 +517,42 @@ static int lv_read(void) {
   }
   c_release(LOG_NOTICE, &conn_complain,
             PLUGIN_NAME " plugin: Connection established.");
+  return 0;
+}
+
+static void lv_disconnect(void) {
+  if (conn != NULL)
+    virConnectClose(conn);
+  conn = NULL;
+  WARNING(PLUGIN_NAME " plugin: closed connection to libvirt");
+}
+
+static int lv_read(user_data_t *ud) {
+  time_t t;
+  struct lv_read_instance *inst = NULL;
+  struct lv_read_state *state = NULL;
+
+  if (ud->data == NULL) {
+    ERROR(PLUGIN_NAME " plugin: NULL userdata");
+    return -1;
+  }
+
+  inst = ud->data;
+  state = &inst->read_state;
+
+  if (inst->id == 0) {
+    if (lv_connect() < 0)
+      return -1;
+  }
 
   time(&t);
 
   /* Need to refresh domain or device lists? */
   if ((last_refresh == (time_t)0) ||
       ((interval > 0) && ((last_refresh + interval) <= t))) {
-    if (refresh_lists() != 0) {
-      if (conn != NULL)
-        virConnectClose(conn);
-      conn = NULL;
+    if (refresh_lists(inst) != 0) {
+      if (inst->id == 0)
+        lv_disconnect();
       return -1;
     }
     last_refresh = t;
@@ -501,13 +572,13 @@ static int lv_read(void) {
 #endif
 
   /* Get CPU usage, memory, VCPU usage for each domain. */
-  for (int i = 0; i < nr_domains; ++i) {
+  for (int i = 0; i < state->nr_domains; ++i) {
     virDomainInfo info;
     virVcpuInfoPtr vinfo = NULL;
     virDomainMemoryStatPtr minfo = NULL;
     int status;
 
-    status = virDomainGetInfo(domains[i], &info);
+    status = virDomainGetInfo(state->domains[i], &info);
     if (status != 0) {
       ERROR(PLUGIN_NAME " plugin: virDomainGetInfo failed with status %i.",
             status);
@@ -519,8 +590,8 @@ static int lv_read(void) {
       continue;
     }
 
-    cpu_submit(info.cpuTime, domains[i], "virt_cpu_total");
-    memory_submit((gauge_t)info.memory * 1024, domains[i]);
+    cpu_submit(info.cpuTime, state->domains[i], "virt_cpu_total");
+    memory_submit((gauge_t)info.memory * 1024, state->domains[i]);
 
     vinfo = malloc(info.nrVirtCpu * sizeof(vinfo[0]));
     if (vinfo == NULL) {
@@ -528,7 +599,7 @@ static int lv_read(void) {
       continue;
     }
 
-    status = virDomainGetVcpus(domains[i], vinfo, info.nrVirtCpu,
+    status = virDomainGetVcpus(state->domains[i], vinfo, info.nrVirtCpu,
                                /* cpu map = */ NULL, /* cpu map length = */ 0);
     if (status < 0) {
       ERROR(PLUGIN_NAME " plugin: virDomainGetVcpus failed with status %i.",
@@ -538,7 +609,8 @@ static int lv_read(void) {
     }
 
     for (int j = 0; j < info.nrVirtCpu; ++j)
-      vcpu_submit(vinfo[j].cpuTime, domains[i], vinfo[j].number, "virt_vcpu");
+      vcpu_submit(vinfo[j].cpuTime, state->domains[i], vinfo[j].number,
+                  "virt_vcpu");
 
     sfree(vinfo);
 
@@ -549,8 +621,8 @@ static int lv_read(void) {
       continue;
     }
 
-    status =
-        virDomainMemoryStats(domains[i], minfo, VIR_DOMAIN_MEMORY_STAT_NR, 0);
+    status = virDomainMemoryStats(state->domains[i], minfo,
+                                  VIR_DOMAIN_MEMORY_STAT_NR, 0);
 
     if (status < 0) {
       ERROR("virt plugin: virDomainMemoryStats failed with status %i.", status);
@@ -559,7 +631,7 @@ static int lv_read(void) {
     }
 
     for (int j = 0; j < status; j++) {
-      memory_stats_submit((gauge_t)minfo[j].val * 1024, domains[i],
+      memory_stats_submit((gauge_t)minfo[j].val * 1024, state->domains[i],
                           minfo[j].tag);
     }
 
@@ -567,78 +639,220 @@ static int lv_read(void) {
   }
 
   /* Get block device stats for each domain. */
-  for (int i = 0; i < nr_block_devices; ++i) {
+  for (int i = 0; i < state->nr_block_devices; ++i) {
     struct _virDomainBlockStats stats;
 
-    if (virDomainBlockStats(block_devices[i].dom, block_devices[i].path, &stats,
+    if (virDomainBlockStats(state->block_devices[i].dom,
+                            state->block_devices[i].path, &stats,
                             sizeof stats) != 0)
       continue;
 
     char *type_instance = NULL;
     if (blockdevice_format_basename && blockdevice_format == source)
-      type_instance = strdup(basename(block_devices[i].path));
+      type_instance = strdup(basename(state->block_devices[i].path));
     else
-      type_instance = strdup(block_devices[i].path);
+      type_instance = strdup(state->block_devices[i].path);
 
     if ((stats.rd_req != -1) && (stats.wr_req != -1))
       submit_derive2("disk_ops", (derive_t)stats.rd_req, (derive_t)stats.wr_req,
-                     block_devices[i].dom, type_instance);
+                     state->block_devices[i].dom, type_instance);
 
     if ((stats.rd_bytes != -1) && (stats.wr_bytes != -1))
       submit_derive2("disk_octets", (derive_t)stats.rd_bytes,
-                     (derive_t)stats.wr_bytes, block_devices[i].dom,
+                     (derive_t)stats.wr_bytes, state->block_devices[i].dom,
                      type_instance);
 
     sfree(type_instance);
   } /* for (nr_block_devices) */
 
   /* Get interface stats for each domain. */
-  for (int i = 0; i < nr_interface_devices; ++i) {
+  for (int i = 0; i < state->nr_interface_devices; ++i) {
     struct _virDomainInterfaceStats stats;
     char *display_name = NULL;
 
     switch (interface_format) {
     case if_address:
-      display_name = interface_devices[i].address;
+      display_name = state->interface_devices[i].address;
       break;
     case if_number:
-      display_name = interface_devices[i].number;
+      display_name = state->interface_devices[i].number;
       break;
     case if_name:
     default:
-      display_name = interface_devices[i].path;
+      display_name = state->interface_devices[i].path;
     }
 
-    if (virDomainInterfaceStats(interface_devices[i].dom,
-                                interface_devices[i].path, &stats,
+    if (virDomainInterfaceStats(state->interface_devices[i].dom,
+                                state->interface_devices[i].path, &stats,
                                 sizeof stats) != 0)
       continue;
 
     if ((stats.rx_bytes != -1) && (stats.tx_bytes != -1))
       submit_derive2("if_octets", (derive_t)stats.rx_bytes,
-                     (derive_t)stats.tx_bytes, interface_devices[i].dom,
+                     (derive_t)stats.tx_bytes, state->interface_devices[i].dom,
                      display_name);
 
     if ((stats.rx_packets != -1) && (stats.tx_packets != -1))
       submit_derive2("if_packets", (derive_t)stats.rx_packets,
-                     (derive_t)stats.tx_packets, interface_devices[i].dom,
-                     display_name);
+                     (derive_t)stats.tx_packets,
+                     state->interface_devices[i].dom, display_name);
 
     if ((stats.rx_errs != -1) && (stats.tx_errs != -1))
       submit_derive2("if_errors", (derive_t)stats.rx_errs,
-                     (derive_t)stats.tx_errs, interface_devices[i].dom,
+                     (derive_t)stats.tx_errs, state->interface_devices[i].dom,
                      display_name);
 
     if ((stats.rx_drop != -1) && (stats.tx_drop != -1))
       submit_derive2("if_dropped", (derive_t)stats.rx_drop,
-                     (derive_t)stats.tx_drop, interface_devices[i].dom,
+                     (derive_t)stats.tx_drop, state->interface_devices[i].dom,
                      display_name);
   } /* for (nr_interface_devices) */
 
   return 0;
 }
 
-static int refresh_lists(void) {
+static int lv_init_instance(size_t i, plugin_read_cb callback) {
+  struct lv_user_data *lv_ud = &(lv_read_user_data[i]);
+  struct lv_read_instance *inst = &(lv_ud->inst);
+
+  memset(lv_ud, 0, sizeof(*lv_ud));
+
+  ssnprintf(inst->tag, sizeof(inst->tag), "%s-%zu", PLUGIN_NAME, i);
+  inst->id = i;
+
+  user_data_t *ud = &(lv_ud->ud);
+  ud->data = inst;
+  ud->free_func = NULL;
+
+  INFO(PLUGIN_NAME " plugin: reader %s initialized", inst->tag);
+  return plugin_register_complex_read(NULL, inst->tag, callback, 0, ud);
+}
+
+static void lv_clean_read_state(struct lv_read_state *state) {
+  free_block_devices(state);
+  free_interface_devices(state);
+  free_domains(state);
+}
+
+static void lv_fini_instance(size_t i) {
+  struct lv_read_instance *inst = &(lv_read_user_data[i].inst);
+  struct lv_read_state *state = &(inst->read_state);
+
+  lv_clean_read_state(state);
+  INFO(PLUGIN_NAME " plugin: reader %s finalized", inst->tag);
+}
+
+static int lv_init(void) {
+  if (virInitialize() != 0)
+    return -1;
+
+  if (lv_connect() != 0)
+    return -1;
+
+  DEBUG(PLUGIN_NAME " plugin: starting %i instances", nr_instances);
+
+  for (int i = 0; i < nr_instances; ++i)
+    lv_init_instance(i, lv_read);
+
+  return 0;
+}
+
+/*
+ * returns 0 on success and <0 on error
+ */
+static int lv_domain_get_tag(xmlXPathContextPtr xpath_ctx, const char *dom_name,
+                             char *dom_tag) {
+  char xpath_str[BUFFER_MAX_LEN] = {'\0'};
+  xmlXPathObjectPtr xpath_obj = NULL;
+  xmlNodePtr xml_node = NULL;
+  int ret = -1;
+  int err;
+
+  err = xmlXPathRegisterNs(xpath_ctx,
+                           (const xmlChar *)METADATA_VM_PARTITION_PREFIX,
+                           (const xmlChar *)METADATA_VM_PARTITION_URI);
+  if (err) {
+    ERROR(PLUGIN_NAME " plugin: xmlXpathRegisterNs(%s, %s) failed on domain %s",
+          METADATA_VM_PARTITION_PREFIX, METADATA_VM_PARTITION_URI, dom_name);
+    goto done;
+  }
+
+  ssnprintf(xpath_str, sizeof(xpath_str), "/domain/metadata/%s:%s/text()",
+            METADATA_VM_PARTITION_PREFIX, METADATA_VM_PARTITION_ELEMENT);
+  xpath_obj = xmlXPathEvalExpression((xmlChar *)xpath_str, xpath_ctx);
+  if (xpath_obj == NULL) {
+    ERROR(PLUGIN_NAME " plugin: xmlXPathEval(%s) failed on domain %s",
+          xpath_str, dom_name);
+    goto done;
+  }
+
+  if (xpath_obj->type != XPATH_NODESET) {
+    ERROR(PLUGIN_NAME " plugin: xmlXPathEval(%s) unexpected return type %d "
+                      "(wanted %d) on domain %s",
+          xpath_str, xpath_obj->type, XPATH_NODESET, dom_name);
+    goto done;
+  }
+
+  /*
+   * from now on there is no real error, it's ok if a domain
+   * doesn't have the metadata partition tag.
+   */
+  ret = 0;
+  if (xpath_obj->nodesetval == NULL || xpath_obj->nodesetval->nodeNr != 1) {
+    DEBUG(PLUGIN_NAME " plugin: xmlXPathEval(%s) return nodeset size=%i "
+                      "expected=1 on domain %s",
+          xpath_str,
+          (xpath_obj->nodesetval == NULL) ? 0 : xpath_obj->nodesetval->nodeNr,
+          dom_name);
+  } else {
+    xml_node = xpath_obj->nodesetval->nodeTab[0];
+    sstrncpy(dom_tag, (const char *)xml_node->content, PARTITION_TAG_MAX_LEN);
+  }
+
+done:
+  /* deregister to clean up */
+  err = xmlXPathRegisterNs(xpath_ctx,
+                           (const xmlChar *)METADATA_VM_PARTITION_PREFIX, NULL);
+  if (err) {
+    /* we can't really recover here */
+    ERROR(PLUGIN_NAME
+          " plugin: deregistration of namespace %s failed for domain %s",
+          METADATA_VM_PARTITION_PREFIX, dom_name);
+  }
+  if (xpath_obj)
+    xmlXPathFreeObject(xpath_obj);
+
+  return ret;
+}
+
+static int is_known_tag(const char *dom_tag) {
+  for (int i = 0; i < nr_instances; ++i)
+    if (!strcmp(dom_tag, lv_read_user_data[i].inst.tag))
+      return 1;
+  return 0;
+}
+
+static int lv_instance_include_domain(struct lv_read_instance *inst,
+                                      const char *dom_name,
+                                      const char *dom_tag) {
+  if ((dom_tag[0] != '\0') && (strcmp(dom_tag, inst->tag) == 0))
+    return 1;
+
+  /* instance#0 will always be there, so it is in charge of extra duties */
+  if (inst->id == 0) {
+    if (dom_tag[0] == '\0' || !is_known_tag(dom_tag)) {
+      DEBUG(PLUGIN_NAME " plugin#%s: refreshing domain %s "
+                        "with unknown tag '%s'",
+            inst->tag, dom_name, dom_tag);
+      return 1;
+    }
+  }
+
+  return 0;
+}
+
+static int refresh_lists(struct lv_read_instance *inst) {
+  struct lv_read_state *state = &inst->read_state;
   int n;
 
   n = virConnectNumOfDomains(conn);
@@ -647,6 +861,8 @@ static int refresh_lists(void) {
     return -1;
   }
 
+  lv_clean_read_state(state);
+
   if (n > 0) {
     int *domids;
 
@@ -664,10 +880,6 @@ static int refresh_lists(void) {
       return -1;
     }
 
-    free_block_devices();
-    free_interface_devices();
-    free_domains();
-
     /* Fetch each domain and add it to the list, unless ignore. */
     for (int i = 0; i < n; ++i) {
       virDomainPtr dom = NULL;
@@ -676,6 +888,7 @@ static int refresh_lists(void) {
       xmlDocPtr xml_doc = NULL;
       xmlXPathContextPtr xpath_ctx = NULL;
       xmlXPathObjectPtr xpath_obj = NULL;
+      char tag[PARTITION_TAG_MAX_LEN] = {'\0'};
 
       dom = virDomainLookupByID(conn, domids[i]);
       if (dom == NULL) {
@@ -693,11 +906,6 @@ static int refresh_lists(void) {
       if (il_domains && ignorelist_match(il_domains, name) != 0)
         goto cont;
 
-      if (add_domain(dom) < 0) {
-        ERROR(PLUGIN_NAME " plugin: malloc failed.");
-        goto cont;
-      }
-
       /* Get a list of devices for this domain. */
       xml = virDomainGetXMLDesc(dom, 0);
       if (!xml) {
@@ -714,6 +922,19 @@ static int refresh_lists(void) {
 
       xpath_ctx = xmlXPathNewContext(xml_doc);
 
+      if (lv_domain_get_tag(xpath_ctx, name, tag) < 0) {
+        ERROR(PLUGIN_NAME " plugin: lv_domain_get_tag failed.");
+        goto cont;
+      }
+
+      if (!lv_instance_include_domain(inst, name, tag))
+        goto cont;
+
+      if (add_domain(state, dom) < 0) {
+        ERROR(PLUGIN_NAME " plugin: malloc failed.");
+        goto cont;
+      }
+
       /* Block devices. */
       char *bd_xmlpath = "/domain/devices/disk/target[@dev]";
       if (blockdevice_format == source)
@@ -739,7 +960,7 @@ static int refresh_lists(void) {
             ignore_device_match(il_block_devices, name, path) != 0)
           goto cont2;
 
-        add_block_device(dom, path);
+        add_block_device(state, dom, path);
       cont2:
         if (path)
           xmlFree(path);
@@ -785,7 +1006,7 @@ static int refresh_lists(void) {
              ignore_device_match(il_interface_devices, name, address) != 0))
           goto cont3;
 
-        add_interface_device(dom, path, address, j + 1);
+        add_interface_device(state, dom, path, address, j + 1);
       cont3:
         if (path)
           xmlFree(path);
@@ -806,57 +1027,64 @@ static int refresh_lists(void) {
     sfree(domids);
   }
 
+  DEBUG(PLUGIN_NAME " plugin#%s: refreshing"
+                    " domains=%i block_devices=%i iface_devices=%i",
+        inst->tag, state->nr_domains, state->nr_block_devices,
+        state->nr_interface_devices);
+
   return 0;
 }
 
-static void free_domains(void) {
-  if (domains) {
-    for (int i = 0; i < nr_domains; ++i)
-      virDomainFree(domains[i]);
-    sfree(domains);
+static void free_domains(struct lv_read_state *state) {
+  if (state->domains) {
+    for (int i = 0; i < state->nr_domains; ++i)
+      virDomainFree(state->domains[i]);
+    sfree(state->domains);
   }
-  domains = NULL;
-  nr_domains = 0;
+  state->domains = NULL;
+  state->nr_domains = 0;
 }
 
-static int add_domain(virDomainPtr dom) {
+static int add_domain(struct lv_read_state *state, virDomainPtr dom) {
   virDomainPtr *new_ptr;
-  int new_size = sizeof(domains[0]) * (nr_domains + 1);
+  int new_size = sizeof(state->domains[0]) * (state->nr_domains + 1);
 
-  if (domains)
-    new_ptr = realloc(domains, new_size);
+  if (state->domains)
+    new_ptr = realloc(state->domains, new_size);
   else
     new_ptr = malloc(new_size);
 
   if (new_ptr == NULL)
     return -1;
 
-  domains = new_ptr;
-  domains[nr_domains] = dom;
-  return nr_domains++;
+  state->domains = new_ptr;
+  state->domains[state->nr_domains] = dom;
+  return state->nr_domains++;
 }
 
-static void free_block_devices(void) {
-  if (block_devices) {
-    for (int i = 0; i < nr_block_devices; ++i)
-      sfree(block_devices[i].path);
-    sfree(block_devices);
+static void free_block_devices(struct lv_read_state *state) {
+  if (state->block_devices) {
+    for (int i = 0; i < state->nr_block_devices; ++i)
+      sfree(state->block_devices[i].path);
+    sfree(state->block_devices);
   }
-  block_devices = NULL;
-  nr_block_devices = 0;
+  state->block_devices = NULL;
+  state->nr_block_devices = 0;
 }
 
-static int add_block_device(virDomainPtr dom, const char *path) {
+static int add_block_device(struct lv_read_state *state, virDomainPtr dom,
+                            const char *path) {
   struct block_device *new_ptr;
-  int new_size = sizeof(block_devices[0]) * (nr_block_devices + 1);
+  int new_size =
+      sizeof(state->block_devices[0]) * (state->nr_block_devices + 1);
   char *path_copy;
 
   path_copy = strdup(path);
   if (!path_copy)
     return -1;
 
-  if (block_devices)
-    new_ptr = realloc(block_devices, new_size);
+  if (state->block_devices)
+    new_ptr = realloc(state->block_devices, new_size);
   else
     new_ptr = malloc(new_size);
 
@@ -864,29 +1092,31 @@ static int add_block_device(virDomainPtr dom, const char *path) {
     sfree(path_copy);
     return -1;
   }
-  block_devices = new_ptr;
-  block_devices[nr_block_devices].dom = dom;
-  block_devices[nr_block_devices].path = path_copy;
-  return nr_block_devices++;
+  state->block_devices = new_ptr;
+  state->block_devices[state->nr_block_devices].dom = dom;
+  state->block_devices[state->nr_block_devices].path = path_copy;
+  return state->nr_block_devices++;
 }
 
-static void free_interface_devices(void) {
-  if (interface_devices) {
-    for (int i = 0; i < nr_interface_devices; ++i) {
-      sfree(interface_devices[i].path);
-      sfree(interface_devices[i].address);
-      sfree(interface_devices[i].number);
+static void free_interface_devices(struct lv_read_state *state) {
+  if (state->interface_devices) {
+    for (int i = 0; i < state->nr_interface_devices; ++i) {
+      sfree(state->interface_devices[i].path);
+      sfree(state->interface_devices[i].address);
+      sfree(state->interface_devices[i].number);
     }
-    sfree(interface_devices);
+    sfree(state->interface_devices);
   }
-  interface_devices = NULL;
-  nr_interface_devices = 0;
+  state->interface_devices = NULL;
+  state->nr_interface_devices = 0;
 }
 
-static int add_interface_device(virDomainPtr dom, const char *path,
-                                const char *address, unsigned int number) {
+static int add_interface_device(struct lv_read_state *state, virDomainPtr dom,
+                                const char *path, const char *address,
+                                unsigned int number) {
   struct interface_device *new_ptr;
-  int new_size = sizeof(interface_devices[0]) * (nr_interface_devices + 1);
+  int new_size =
+      sizeof(state->interface_devices[0]) * (state->nr_interface_devices + 1);
   char *path_copy, *address_copy, number_string[15];
 
   if ((path == NULL) || (address == NULL))
@@ -904,8 +1134,8 @@ static int add_interface_device(virDomainPtr dom, const char *path,
 
   snprintf(number_string, sizeof(number_string), "interface-%u", number);
 
-  if (interface_devices)
-    new_ptr = realloc(interface_devices, new_size);
+  if (state->interface_devices)
+    new_ptr = realloc(state->interface_devices, new_size);
   else
     new_ptr = malloc(new_size);
 
@@ -914,12 +1144,13 @@ static int add_interface_device(virDomainPtr dom, const char *path,
     sfree(address_copy);
     return -1;
   }
-  interface_devices = new_ptr;
-  interface_devices[nr_interface_devices].dom = dom;
-  interface_devices[nr_interface_devices].path = path_copy;
-  interface_devices[nr_interface_devices].address = address_copy;
-  interface_devices[nr_interface_devices].number = strdup(number_string);
-  return nr_interface_devices++;
+  state->interface_devices = new_ptr;
+  state->interface_devices[state->nr_interface_devices].dom = dom;
+  state->interface_devices[state->nr_interface_devices].path = path_copy;
+  state->interface_devices[state->nr_interface_devices].address = address_copy;
+  state->interface_devices[state->nr_interface_devices].number =
+      strdup(number_string);
+  return state->nr_interface_devices++;
 }
 
 static int ignore_device_match(ignorelist_t *il, const char *domname,
@@ -943,13 +1174,11 @@ static int ignore_device_match(ignorelist_t *il, const char *domname,
 }
 
 static int lv_shutdown(void) {
-  free_block_devices();
-  free_interface_devices();
-  free_domains();
+  for (int i = 0; i < nr_instances; ++i) {
+    lv_fini_instance(i);
+  }
 
-  if (conn != NULL)
-    virConnectClose(conn);
-  conn = NULL;
+  lv_disconnect();
 
   ignorelist_free(il_domains);
   il_domains = NULL;
@@ -964,10 +1193,5 @@ static int lv_shutdown(void) {
 void module_register(void) {
   plugin_register_config(PLUGIN_NAME, lv_config, config_keys, NR_CONFIG_KEYS);
   plugin_register_init(PLUGIN_NAME, lv_init);
-  plugin_register_read(PLUGIN_NAME, lv_read);
   plugin_register_shutdown(PLUGIN_NAME, lv_shutdown);
 }
-
-/*
- * vim: shiftwidth=4 tabstop=8 softtabstop=4 expandtab fdm=marker
- */
diff --git a/src/virt_test.c b/src/virt_test.c
new file mode 100644 (file)
index 0000000..cb3cc25
--- /dev/null
@@ -0,0 +1,207 @@
+/**
+ * collectd - src/virt_test.c
+ * Copyright (C) 2016 Francesco Romani <fromani at redhat.com>
+ * Based on
+ * collectd - src/ceph_test.c
+ * Copyright (C) 2015      Florian octo Forster
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; only version 2 of the License is applicable.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
+ *
+ * Authors:
+ *   Florian octo Forster <octo at collectd.org>
+ **/
+
+#include "virt.c" /* sic */
+#include "testing.h"
+
+#include <unistd.h>
+
+static const char minimal_xml[] =
+    ""
+    "<?xml version=\"1.0\" encoding=\"utf-8\"?>"
+    "<domain type=\"kvm\" xmlns:ovirt=\"http://ovirt.org/vm/tune/1.0\">"
+    "  <metadata/>"
+    "</domain>";
+
+static const char minimal_metadata_xml[] =
+    ""
+    "<?xml version=\"1.0\" encoding=\"utf-8\"?>"
+    "<domain type=\"kvm\" xmlns:ovirt=\"http://ovirt.org/vm/tune/1.0\">"
+    "  <metadata>"
+    "    <ovirtmap:tag "
+    "xmlns:ovirtmap=\"http://ovirt.org/ovirtmap/tag/1.0\">virt-0</ovirtmap:tag>"
+    "  </metadata>"
+    "</domain>";
+
+struct xml_state {
+  xmlDocPtr xml_doc;
+  xmlXPathContextPtr xpath_ctx;
+  xmlXPathObjectPtr xpath_obj;
+  char tag[PARTITION_TAG_MAX_LEN];
+};
+
+static int init_state(struct xml_state *st, const char *xml) {
+  memset(st, 0, sizeof(*st));
+
+  st->xml_doc = xmlReadDoc((const xmlChar *)xml, NULL, NULL, XML_PARSE_NONET);
+  if (st->xml_doc == NULL) {
+    return -1;
+  }
+  st->xpath_ctx = xmlXPathNewContext(st->xml_doc);
+  if (st->xpath_ctx == NULL) {
+    return -1;
+  }
+  return 0;
+}
+
+static void fini_state(struct xml_state *st) {
+  if (st->xpath_ctx) {
+    xmlXPathFreeContext(st->xpath_ctx);
+    st->xpath_ctx = NULL;
+  }
+  if (st->xml_doc) {
+    xmlFreeDoc(st->xml_doc);
+    st->xml_doc = NULL;
+  }
+}
+
+#define TAG "virt-0"
+
+DEF_TEST(lv_domain_get_tag_no_metadata_xml) {
+  int err;
+  struct xml_state st;
+  err = init_state(&st, minimal_xml);
+  EXPECT_EQ_INT(0, err);
+
+  err = lv_domain_get_tag(st.xpath_ctx, "test", st.tag);
+
+  EXPECT_EQ_INT(0, err);
+  EXPECT_EQ_STR("", st.tag);
+
+  fini_state(&st);
+  return 0;
+}
+
+DEF_TEST(lv_domain_get_tag_valid_xml) {
+  int err;
+  struct xml_state st;
+  err = init_state(&st, minimal_metadata_xml);
+  EXPECT_EQ_INT(0, err);
+
+  err = lv_domain_get_tag(st.xpath_ctx, "test", st.tag);
+
+  EXPECT_EQ_INT(0, err);
+  EXPECT_EQ_STR(TAG, st.tag);
+
+  return 0;
+}
+
+DEF_TEST(lv_default_instance_include_domain_without_tag) {
+  struct lv_read_instance *inst = NULL;
+  int ret;
+
+  ret = lv_init_instance(0, lv_read);
+  inst = &(lv_read_user_data[0].inst);
+  EXPECT_EQ_STR("virt-0", inst->tag);
+
+  ret = lv_instance_include_domain(inst, "testing", "");
+  EXPECT_EQ_INT(1, ret);
+
+  lv_fini_instance(0);
+  return 0;
+}
+
+DEF_TEST(lv_regular_instance_skip_domain_without_tag) {
+  struct lv_read_instance *inst = NULL;
+  int ret;
+
+  ret = lv_init_instance(1, lv_read);
+  inst = &(lv_read_user_data[1].inst);
+  EXPECT_EQ_STR("virt-1", inst->tag);
+
+  ret = lv_instance_include_domain(inst, "testing", "");
+  EXPECT_EQ_INT(0, ret);
+
+  lv_fini_instance(0);
+  return 0;
+}
+
+DEF_TEST(lv_include_domain_matching_tags) {
+  struct lv_read_instance *inst = NULL;
+  int ret;
+
+  ret = lv_init_instance(0, lv_read);
+  inst = &(lv_read_user_data[0].inst);
+  EXPECT_EQ_STR("virt-0", inst->tag);
+
+  ret = lv_instance_include_domain(inst, "testing", "virt-0");
+  EXPECT_EQ_INT(1, ret);
+
+  ret = lv_init_instance(1, lv_read);
+  inst = &(lv_read_user_data[1].inst);
+  EXPECT_EQ_STR("virt-1", inst->tag);
+
+  ret = lv_instance_include_domain(inst, "testing", "virt-1");
+  EXPECT_EQ_INT(1, ret);
+
+  lv_fini_instance(0);
+  lv_fini_instance(1);
+  return 0;
+}
+
+DEF_TEST(lv_default_instance_include_domain_with_unknown_tag) {
+  struct lv_read_instance *inst = NULL;
+  int ret;
+
+  ret = lv_init_instance(0, lv_read);
+  inst = &(lv_read_user_data[0].inst);
+  EXPECT_EQ_STR("virt-0", inst->tag);
+
+  ret = lv_instance_include_domain(inst, "testing", "unknownFormat-tag");
+  EXPECT_EQ_INT(1, ret);
+
+  lv_fini_instance(0);
+  return 0;
+}
+
+DEF_TEST(lv_regular_instance_skip_domain_with_unknown_tag) {
+  struct lv_read_instance *inst = NULL;
+  int ret;
+
+  ret = lv_init_instance(1, lv_read);
+  inst = &(lv_read_user_data[1].inst);
+  EXPECT_EQ_STR("virt-1", inst->tag);
+
+  ret = lv_instance_include_domain(inst, "testing", "unknownFormat-tag");
+  EXPECT_EQ_INT(0, ret);
+
+  lv_fini_instance(0);
+  return 0;
+}
+#undef TAG
+
+int main(void) {
+  RUN_TEST(lv_domain_get_tag_no_metadata_xml);
+  RUN_TEST(lv_domain_get_tag_valid_xml);
+
+  RUN_TEST(lv_default_instance_include_domain_without_tag);
+  RUN_TEST(lv_regular_instance_skip_domain_without_tag);
+  RUN_TEST(lv_include_domain_matching_tags);
+  RUN_TEST(lv_default_instance_include_domain_with_unknown_tag);
+  RUN_TEST(lv_regular_instance_skip_domain_with_unknown_tag);
+
+  END_TEST;
+}
+
+/* vim: set sw=2 sts=2 et : */
index cd9e7d2..0d7769b 100644 (file)
@@ -260,5 +260,3 @@ void module_register(void) {
   plugin_register_config("vmem", vmem_config, config_keys, config_keys_num);
   plugin_register_read("vmem", vmem_read);
 } /* void module_register */
-
-/* vim: set sw=2 sts=2 ts=8 : */
index c5a7fb3..96af6fc 100644 (file)
@@ -321,5 +321,3 @@ void module_register(void) {
   plugin_register_init("vserver", vserver_init);
   plugin_register_read("vserver", vserver_read);
 } /* void module_register(void) */
-
-/* vim: set ts=4 sw=4 noexpandtab : */
index b85ab47..3fac9cc 100644 (file)
@@ -583,5 +583,3 @@ static int wg_config(oconfig_item_t *ci) {
 void module_register(void) {
   plugin_register_complex_config("write_graphite", wg_config);
 }
-
-/* vim: set sw=4 ts=4 sts=4 tw=78 et : */
index c1b3f0b..c33ab54 100644 (file)
@@ -812,5 +812,3 @@ void module_register(void) /* {{{ */
   plugin_register_complex_config("write_http", wh_config);
   plugin_register_init("write_http", wh_init);
 } /* }}} void module_register */
-
-/* vim: set fdm=marker sw=8 ts=8 tw=78 et : */
index 2d34b21..5ecb182 100644 (file)
@@ -136,5 +136,3 @@ void module_register(void) {
   /* If config is supplied, the global wl_format will be set. */
   plugin_register_write("write_log", wl_write, NULL);
 }
-
-/* vim: set sw=4 ts=4 sts=4 tw=78 et : */
index e175e1f..10f7832 100644 (file)
 #include "plugin.h"
 #include "utils_cache.h"
 
-#if HAVE_STDINT_H
 #define MONGO_HAVE_STDINT 1
-#else
-#define MONGO_USE_LONG_LONG_INT 1
-#endif
 #include <mongo.h>
 
 #if (MONGO_MAJOR == 0) && (MONGO_MINOR < 8)
@@ -348,5 +344,3 @@ static int wm_config(oconfig_item_t *ci) /* {{{ */
 void module_register(void) {
   plugin_register_complex_config("write_mongodb", wm_config);
 }
-
-/* vim: set sw=2 sts=2 tw=78 et fdm=marker : */
index 6b77712..61c43fe 100644 (file)
@@ -870,5 +870,3 @@ void module_register() {
                           /* user data = */ NULL);
   plugin_register_shutdown("write_prometheus", prom_shutdown);
 }
-
-/* vim: set sw=2 sts=2 et fdm=marker : */
index 0a5c5df..9cff34a 100644 (file)
@@ -252,5 +252,3 @@ static int wr_config(oconfig_item_t *ci) /* {{{ */
 void module_register(void) {
   plugin_register_complex_config("write_redis", wr_config);
 }
-
-/* vim: set sw=2 sts=2 tw=78 et fdm=marker : */
index 3835a3d..a51b4b5 100644 (file)
@@ -895,5 +895,3 @@ static int wrr_config(oconfig_item_t *ci) /* {{{ */
 void module_register(void) {
   plugin_register_complex_config("write_riemann", wrr_config);
 }
-
-/* vim: set sw=8 sts=8 ts=8 noet : */
index 452c291..992d856 100644 (file)
@@ -225,5 +225,3 @@ int write_riemann_threshold_check(const data_set_t *ds, const value_list_t *vl,
 
   return (0);
 } /* }}} int ut_check_threshold */
-
-/* vim: set sw=2 ts=8 sts=2 tw=78 et fdm=marker : */
index 72ed6bc..c0c0634 100644 (file)
@@ -1248,5 +1248,3 @@ static int sensu_config(oconfig_item_t *ci) /* {{{ */
 void module_register(void) {
   plugin_register_complex_config("write_sensu", sensu_config);
 }
-
-/* vim: set sw=8 sts=8 ts=8 noet : */
index 0c87c47..429c159 100644 (file)
@@ -582,5 +582,3 @@ static int wt_config(oconfig_item_t *ci) {
 void module_register(void) {
   plugin_register_complex_config("write_tsdb", wt_config);
 }
-
-/* vim: set sw=4 ts=4 sts=4 tw=78 et : */
index 87e3564..b06434d 100644 (file)
@@ -66,7 +66,3 @@ static int cxmms_read(void) {
 void module_register(void) {
   plugin_register_read("xmms", cxmms_read);
 } /* void module_register */
-
-/*
- * vim: shiftwidth=2:softtabstop=2:textwidth=78
- */