Code

Merge branch 'collectd-4.2' into collectd-4.3
authorFlorian Forster <octo@noris.net>
Tue, 1 Apr 2008 13:05:45 +0000 (15:05 +0200)
committerFlorian Forster <octo@noris.net>
Tue, 1 Apr 2008 13:05:45 +0000 (15:05 +0200)
Conflicts:

configure.in
src/plugin.c

1  2 
configure.in
src/common.c
src/hddtemp.c
src/plugin.c
src/unixsock.c

diff --combined configure.in
index 952f5c5d12bfd1966c7ce81e17fcd77a0125f63e,db344978d38a27dff2adecdc2f06f4c281176a16..766b6d6b554118ccd9311a9c80a05b1528c824c3
@@@ -17,7 -17,6 +17,7 @@@ AC_PROG_CP
  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")
  
  dnl configure libtool
@@@ -56,7 -55,7 +56,7 @@@ AC_HEADER_STD
  AC_HEADER_SYS_WAIT
  AC_HEADER_DIRENT
  
- AC_CHECK_HEADERS(stdint.h stdio.h errno.h math.h stdarg.h syslog.h fcntl.h signal.h assert.h sys/types.h sys/socket.h sys/select.h poll.h netdb.h arpa/inet.h sys/resource.h sys/param.h kstat.h regex.h sys/ioctl.h)
+ AC_CHECK_HEADERS(stdint.h stdio.h errno.h math.h stdarg.h syslog.h fcntl.h signal.h assert.h sys/types.h sys/socket.h sys/select.h poll.h netdb.h arpa/inet.h sys/resource.h sys/param.h kstat.h regex.h sys/ioctl.h endian.h)
  
  # For ping library
  AC_CHECK_HEADERS(netinet/in_systm.h, [], [],
@@@ -311,7 -310,7 +311,7 @@@ AC_CHECK_HEADERS(linux/un.h, [], []
  #endif
  ])
  
 -AC_CHECK_HEADERS(pwd.h grp.h sys/un.h ctype.h limits.h sys/quota.h xfs/xqm.h fs_info.h fshelp.h paths.h mntent.h mnttab.h sys/fstyp.h sys/fs_types.h sys/mntent.h sys/mnttab.h sys/statfs.h sys/statvfs.h sys/vfs.h sys/vfstab.h kvm.h)
 +AC_CHECK_HEADERS(pwd.h grp.h sys/un.h ctype.h limits.h sys/quota.h xfs/xqm.h fs_info.h fshelp.h paths.h mntent.h mnttab.h sys/fstyp.h sys/fs_types.h sys/mntent.h sys/mnttab.h sys/statfs.h sys/statvfs.h sys/vfs.h sys/vfstab.h kvm.h wordexp.h)
  
  # For the dns plugin
  AC_CHECK_HEADERS(arpa/nameser.h)
@@@ -819,20 -818,6 +819,20 @@@ AC_CHECK_LIB(resolv, res_search
  [with_libresolv="no"])
  AM_CONDITIONAL(BUILD_WITH_LIBRESOLV, test "x$with_libresolv" = "xyes")
  
 +dnl Check for HAL (hardware abstraction library)
 +with_libhal="yes"
 +AC_CHECK_LIB(hal,libhal_device_property_exists,
 +           [AC_DEFINE(HAVE_LIBHAL, 1, [Define to 1 if you have 'hal' library])],
 +           [with_libhal="no"])
 +if test "x$with_libhal" = "xyes"; then
 +      PKG_PROG_PKG_CONFIG
 +      if test "x$PKG_CONFIG" != "x"; then
 +              BUILD_WITH_LIBHAL_CFLAGS="`pkg-config --cflags hal`"
 +              BUILD_WITH_LIBHAL_LIBS="`pkg-config --libs hal`"
 +              AC_SUBST(BUILD_WITH_LIBHAL_CFLAGS)
 +              AC_SUBST(BUILD_WITH_LIBHAL_LIBS)
 +      fi
 +fi
  
  m4_divert_once([HELP_WITH], [
  collectd additional packages:])
@@@ -847,8 -832,6 +847,8 @@@ AC_ARG_WITH(rrdtool, [AS_HELP_STRING([-
                librrd_cflags="-I$withval/include"
                librrd_ldflags="-L$withval/lib"
                with_rrdtool="yes"
 +      else
 +              with_rrdtool="$withval"
        fi
  ], [with_rrdtool="yes"])
  if test "x$with_rrdtool" = "xyes"
@@@ -995,12 -978,12 +995,12 @@@ the
        then
                with_libcurl="no ($with_curl_config failed)"
        else
-               SAVE_CFLAGS=$CFLAGS
-               CFLAGS="$CFLAGS $with_curl_cflags"
+               SAVE_CPPFLAGS="$CPPFLAGS"
+               CPPFLAGS="$CPPFLAGS $with_curl_cflags"
  
                AC_CHECK_HEADERS(curl/curl.h, [], [with_libcurl="no (curl/curl.h not found)"], [])
  
-               CFLAGS="$SAVE_CFLAGS"
+               CPPFLAGS="$SAVE_CPPFLAGS"
        fi
  fi
  if test "x$with_libcurl" = "xyes"
@@@ -1034,7 -1017,7 +1034,7 @@@ AC_CHECK_LIB(IOKit, IOServiceGetMatchin
  [
        with_libiokit="yes"
        collectd_libiokit=1
 -], 
 +],
  [
        with_libiokit="no"
        collectd_libiokit=0
@@@ -1049,8 -1032,6 +1049,8 @@@ AC_ARG_WITH(libstatgrab, [AS_HELP_STRIN
                LDFLAGS="$LDFLAGS -L$withval/lib"
                CPPFLAGS="$CPPFLAGS -I$withval/include"
                with_libstatgrab="yes"
 +      else
 +              with_libstatgrab="$withval"
        fi
  ],
  [
        then
                with_libmysql="no"
        else
-               SAVE_CFLAGS=$CFLAGS
-               CFLAGS="$CFLAGS $with_mysql_cflags"
+               SAVE_CPPFLAGS="$CPPFLAGS"
+               CPPFLAGS="$CPPFLAGS $with_mysql_cflags"
  
                AC_CHECK_HEADERS(mysql/mysql.h, [], [with_libmysql="no (mysql/mysql.h not found)"], [])
  
-               CFLAGS="$SAVE_CFLAGS"
+               CPPFLAGS="$SAVE_CPPFLAGS"
        fi
  fi
  if test "x$with_libmysql" = "xyes"
@@@ -1289,12 -1270,10 +1289,12 @@@ AC_ARG_WITH(liboping, [AS_HELP_STRING([
        then
                with_liboping="no"
                with_own_liboping="no"
 -      fi
 +      else if test "x$withval" = "xyes"
 +      then
 +              with_liboping="yes"
 +      fi; fi
  ],
  [
 -      #753
        with_liboping="yes"
  ])
  
@@@ -1326,8 -1305,6 +1326,8 @@@ AC_ARG_WITH(libpcap, [AS_HELP_STRING([-
                LDFLAGS="$LDFLAGS -L$withval/lib"
                CPPFLAGS="$CPPFLAGS -I$withval/include"
                with_libpcap="yes"
 +      else
 +              with_libpcap="$withval"
        fi
  ],
  [
@@@ -1366,8 -1343,6 +1366,8 @@@ AC_ARG_WITH(libperl, [AS_HELP_STRING([-
                CPPFLAGS="$CPPFLAGS -I$withval/include"
                perl_interpreter="$withval/bin/perl"
                with_libperl="yes"
 +      else
 +              with_libperl="$withval"
        fi
  ],
  [
  fi
  AM_CONDITIONAL(BUILD_WITH_LIBPERL, test "x$with_libperl" = "xyes")
  
 +if test "x$with_libperl" = "xyes"
 +then
 +      SAVE_CFLAGS=$CFLAGS
 +      SAVE_LDFLAGS=$LDFLAGS
 +      CFLAGS="$CFLAGS $PERL_CFLAGS"
 +      LDFLAGS="$LDFLAGS $PERL_LDFLAGS"
 +
 +      AC_CACHE_CHECK([if perl supports ithreads],
 +              [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) */
 +                      ]],
 +                      [[ ]]),
 +                      [have_perl_ithreads="yes"],
 +                      [have_perl_ithreads="no"]
 +              )
 +      )
 +
 +      if test "x$have_perl_ithreads" = "xyes"
 +      then
 +              AC_DEFINE(HAVE_PERL_ITHREADS, 1, [Define if Perl supports ithreads.])
 +      fi
 +
 +      CFLAGS=$SAVE_CFLAGS
 +      LDFLAGS=$SAVE_LDFLAGS
 +fi
 +
  AC_ARG_WITH(libiptc, [AS_HELP_STRING([--with-libiptc@<:@=PREFIX@:>@], [Path to libiptc.])],
  [
        if test "x$withval" != "xno" && test "x$withval" != "xyes"
                LDFLAGS="$LDFLAGS -L$withval/lib"
                CPPFLAGS="$CPPFLAGS -I$withval/include"
                with_libiptc="yes"
 +      else
 +              with_libiptc="$withval"
        fi
  ],
  [
 -      if test "x$ac_system" = "xLinux"
 +      if test "x$ac_system" = "xLinux"
        then
                with_libiptc="yes"
        else
@@@ -1500,14 -1438,14 +1500,14 @@@ with_snmp_cflags="
  with_snmp_libs=""
  AC_ARG_WITH(libnetsnmp, [AS_HELP_STRING([--with-libnetsnmp@<:@=PREFIX@:>@], [Path to the Net-SNMPD library.])],
  [
 -      if test "x$withval" = "xno"
 +      if test "x$withval" = "xno"
        then
                with_libnetsnmp="no"
        else if test "x$withval" = "xyes"
        then
                with_libnetsnmp="yes"
        else
 -              if test -x "$withval"
 +              if test -x "$withval"
                then
                        with_snmp_config="$withval"
                        with_libnetsnmp="yes"
        then
                with_libnetsnmp="no ($with_snmp_config failed)"
        else
-               SAVE_CFLAGS=$CFLAGS
-               CFLAGS="$CFLAGS $with_snmp_cflags"
+               SAVE_CPPFLAGS="$CPPFLAGS"
+               CPPFLAGS="$CPPFLAGS $with_snmp_cflags"
                
                AC_CHECK_HEADERS(net-snmp/net-snmp-config.h, [], [with_libnetsnmp="no (net-snmp/net-snmp-config.h not found)"])
  
-               CFLAGS="$SAVE_CFLAGS"
+               CPPFLAGS="$SAVE_CPPFLAGS"
        fi
  fi
  if test "x$with_libnetsnmp" = "xyes"
  fi
  if test "x$with_libupsclient" = "xyes"
  then
-       SAVE_CFLAGS="$CFLAGS"
-       CFLAGS="$CFLAGS $with_upsclient_cflags"
+       SAVE_CPPFLAGS="$CPPFLAGS"
+       CPPFLAGS="$CPPFLAGS $with_upsclient_cflags"
  
        AC_CHECK_HEADERS(upsclient.h, [], [with_libupsclient="no (upsclient.h not found)"])
  
-       CFLAGS="$SAVE_CFLAGS"
+       CPPFLAGS="$SAVE_CPPFLAGS"
  fi
  if test "x$with_libupsclient" = "xyes"
  then
  fi
  if test "x$with_libupsclient" = "xyes"
  then
 -      AC_CHECK_TYPES([UPSCONN_t, UPSCONN], [], [], 
+       SAVE_CPPFLAGS="$CPPFLAGS"
+       CPPFLAGS="$CPPFLAGS $with_upsclient_cflags"
 +      AC_CHECK_TYPES([UPSCONN_t, UPSCONN], [], [],
  [#include <stdlib.h>
  #include <stdio.h>
  #include <upsclient.h>])
+       CPPFLAGS="$SAVE_CPPFLAGS"
  fi
  AM_CONDITIONAL(BUILD_WITH_LIBUPSCLIENT, test "x$with_libupsclient" = "xyes")
  
  fi
  AM_CONDITIONAL(BUILD_WITH_LIBNETLINK, test "x$with_libnetlink" = "xyes")
  
 +dnl Check for libvirt and libxml2 libraries.
 +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_PROG_PKG_CONFIG
 +if test "x$PKG_CONFIG" != "x"
 +then
 +      pkg-config --exists 'libxml-2.0' 2>/dev/null
 +      if test "$?" = "0"
 +      then
 +              with_libxml2="yes"
 +      else
 +              with_libxml2="no (pkg-config doesn't know library)"
 +      fi
 +
 +      pkg-config --exists libvirt 2>/dev/null
 +      if test "$?" = "0"
 +      then
 +              with_libvirt="yes"
 +      else
 +              with_libvirt="no (pkg-config doesn't know library)"
 +      fi
 +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)"])
 +
 +      CPPFLAGS="$SAVE_CPPFLAGS"
 +fi
 +if test "x$with_libxml2" = "xyes"
 +then
 +      SAVE_CFLAGS="$CFLAGS"
 +      SAVE_LD_FLAGS="$LDFLAGS"
 +
 +      CFLAGS="$CFLAGS $with_libxml2_cflags"
 +      LDFLAGS="$LDFLAGS $with_libxml2_ldflags"
 +
 +      AC_CHECK_LIB(xml2, xmlXPathEval,
 +                   [with_libxml2="yes"],
 +                   [with_libxml2="no (symbol xmlXPathEval not found)"])
 +
 +      CFLAGS="$SAVE_CFLAGS"
 +      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)
 +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
 +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)"])
 +
 +      CPPFLAGS="$SAVE_CPPFLAGS"
 +fi
 +if test "x$with_libvirt" = "xyes"
 +then
 +      SAVE_CFLAGS="$CFLAGS"
 +      SAVE_LD_FLAGS="$LDFLAGS"
 +
 +      CFLAGS="$CFLAGS $with_libvirt_cflags"
 +      LDFLAGS="$LDFLAGS $with_libvirt_ldflags"
 +
 +      AC_CHECK_LIB(virt, virDomainBlockStats,
 +                   [with_libvirt="yes"],
 +                   [with_libvirt="no (symbol virDomainBlockStats not found)"])
 +
 +      CFLAGS="$SAVE_CFLAGS"
 +      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)
 +fi
 +
 +dnl End of check for libvirt and libxml2 libraries.
 +
  # Check for enabled/disabled features
  #
  
@@@ -2038,12 -1862,10 +2043,12 @@@ plugin_entropy="no
  plugin_interface="no"
  plugin_ipvs="no"
  plugin_irq="no"
 +plugin_libvirt="no"
  plugin_load="no"
  plugin_memory="no"
  plugin_multimeter="no"
  plugin_nfs="no"
 +plugin_perl="no"
  plugin_processes="no"
  plugin_serial="no"
  plugin_swap="no"
        plugin_interface="yes"
  fi
  
 +if test "x$with_libxml2" = "xyes" && test "x$with_libvirt" = "xyes"
 +then
 +      plugin_libvirt="yes"
 +fi
 +
  if test "x$have_getloadavg" = "xyes"
  then
        plugin_load="yes"
  fi
  
 +if test "x$have_libperl$have_perl_ithreads" = "xyesyes"
 +then
 +      plugin_perl="yes"
 +fi
 +
  # Mac OS X memory interface
  if test "x$have_host_statistics" = "xyes"
  then
@@@ -2199,7 -2011,6 +2204,7 @@@ AC_PLUGIN([interface],   [$plugin_inter
  AC_PLUGIN([iptables],    [$with_libiptc],      [IPTables rule counters])
  AC_PLUGIN([ipvs],        [$plugin_ipvs],       [IPVS connection statistics])
  AC_PLUGIN([irq],         [$plugin_irq],        [IRQ statistics])
 +AC_PLUGIN([libvirt],     [$plugin_libvirt],    [Virtual machine statistics])
  AC_PLUGIN([load],        [$plugin_load],       [System load])
  AC_PLUGIN([logfile],     [yes],                [File logging plugin])
  AC_PLUGIN([mbmon],       [yes],                [Query mbmond])
@@@ -2213,7 -2024,7 +2218,7 @@@ AC_PLUGIN([nfs],         [$plugin_nfs]
  AC_PLUGIN([nginx],       [$with_libcurl],      [nginx statistics])
  AC_PLUGIN([ntpd],        [yes],                [NTPd statistics])
  AC_PLUGIN([nut],         [$with_libupsclient], [Network UPS tools statistics])
 -AC_PLUGIN([perl],        [$with_libperl],      [Embed a Perl interpreter])
 +AC_PLUGIN([perl],        [$plugin_perl],       [Embed a Perl interpreter])
  AC_PLUGIN([ping],        [$with_liboping],     [Network latency statistics])
  AC_PLUGIN([processes],   [$plugin_processes],  [Process statistics])
  AC_PLUGIN([rrdtool],     [$with_rrdtool],      [RRDTool output plugin])
@@@ -2226,7 -2037,6 +2231,7 @@@ AC_PLUGIN([tape],        [$plugin_tape]
  AC_PLUGIN([tcpconns],    [$plugin_tcpconns],   [TCP connection statistics])
  AC_PLUGIN([unixsock],    [yes],                [Unixsock communication plugin])
  AC_PLUGIN([users],       [$plugin_users],      [User statistics])
 +AC_PLUGIN([uuid],        [yes],                [UUID as hostname plugin])
  AC_PLUGIN([vserver],     [$plugin_vserver],    [Linux VServer statistics])
  AC_PLUGIN([wireless],    [$plugin_wireless],   [Wireless statistics])
  AC_PLUGIN([xmms],        [$with_libxmms],      [XMMS statistics])
@@@ -2264,11 -2074,6 +2269,11 @@@ AC_SUBST(PERL_BINDINGS_OPTIONS
  
  AC_OUTPUT(Makefile src/Makefile src/collectd.conf src/liboconfig/Makefile src/liboping/Makefile bindings/Makefile)
  
 +if test "x$with_rrdtool" = "xyes" -a "x$librrd_threadsafe" != "xyes"
 +then
 +      with_rrdtool="yes (warning: librrd is not thread-safe)"
 +fi
 +
  if test "x$with_liboping" = "xyes" -a "x$with_own_liboping" = "xyes"
  then
        with_liboping="yes (shipped version)"
@@@ -2307,8 -2112,6 +2312,8 @@@ Configuration
      libsensors  . . . . $with_lm_sensors
      libstatgrab . . . . $with_libstatgrab
      libupsclient  . . . $with_libupsclient
 +    libvirt . . . . . . $with_libvirt
 +    libxml2 . . . . . . $with_libxml2
      libxmms . . . . . . $with_libxmms
  
    Features:
      iptables  . . . . . $enable_iptables
      ipvs  . . . . . . . $enable_ipvs
      irq . . . . . . . . $enable_irq
 +    libvirt . . . . . . $enable_libvirt
      load  . . . . . . . $enable_load
      logfile . . . . . . $enable_logfile
      mbmon . . . . . . . $enable_mbmon
      tcpconns  . . . . . $enable_tcpconns
      unixsock  . . . . . $enable_unixsock
      users . . . . . . . $enable_users
 +    uuid  . . . . . . . $enable_uuid
      vserver . . . . . . $enable_vserver
      wireless  . . . . . $enable_wireless
      xmms  . . . . . . . $enable_xmms
diff --combined src/common.c
index a2c4794d6d4642dfd2da75eef7747e87849904ca,9314d814ad4d1e02bd5e5a57e361c59d0d801eca..5c3db5ddacb53677d83e4d519f8b0c7331852449
@@@ -1,6 -1,6 +1,6 @@@
  /**
   * collectd - src/common.c
 - * Copyright (C) 2005-2007  Florian octo Forster
 + * Copyright (C) 2005-2008  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
@@@ -24,6 -24,7 +24,7 @@@
  # include "config.h"
  #endif
  
+ #include "collectd.h"
  #include "common.h"
  #include "plugin.h"
  
@@@ -52,13 -53,11 +53,13 @@@ static pthread_mutex_t getpwnam_r_lock 
  static pthread_mutex_t strerror_r_lock = PTHREAD_MUTEX_INITIALIZER;
  #endif
  
 -void sstrncpy (char *d, const char *s, int len)
 +char *sstrncpy (char *dest, const char *src, size_t n)
  {
 -      strncpy (d, s, len);
 -      d[len - 1] = '\0';
 -}
 +      strncpy (dest, src, n);
 +      dest[n - 1] = '\0';
 +
 +      return (dest);
 +} /* char *sstrncpy */
  
  char *sstrdup (const char *s)
  {
@@@ -178,7 -177,7 +179,7 @@@ ssize_t sread (int fd, void *buf, size_
                        return (-1);
                }
  
 -              assert (nleft >= status);
 +              assert ((0 > status) || (nleft >= (size_t)status));
  
                nleft = nleft - status;
                ptr   = ptr   + status;
@@@ -239,8 -238,8 +240,8 @@@ int strjoin (char *dst, size_t dst_len
                char **fields, size_t fields_num,
                const char *sep)
  {
 -      int field_len;
 -      int sep_len;
 +      size_t field_len;
 +      size_t sep_len;
        int i;
  
        memset (dst, '\0', dst_len);
        if (sep != NULL)
                sep_len = strlen (sep);
  
 -      for (i = 0; i < fields_num; i++)
 +      for (i = 0; i < (int)fields_num; i++)
        {
                if ((i > 0) && (sep_len > 0))
                {
@@@ -556,7 -555,7 +557,7 @@@ long long get_kstat_value (kstat_t *ksp
  
  unsigned long long ntohll (unsigned long long n)
  {
- #if __BYTE_ORDER == __BIG_ENDIAN
+ #if BYTE_ORDER == BIG_ENDIAN
        return (n);
  #else
        return (((unsigned long long) ntohl (n)) << 32) + ntohl (n >> 32);
  
  unsigned long long htonll (unsigned long long n)
  {
- #if __BYTE_ORDER == __BIG_ENDIAN
+ #if BYTE_ORDER == BIG_ENDIAN
        return (n);
  #else
        return (((unsigned long long) htonl (n)) << 32) + htonl (n >> 32);
@@@ -825,38 -824,4 +826,38 @@@ int getpwnam_r (const char *name, struc
  
        return (status);
  } /* int getpwnam_r */
 -#endif
 +#endif /* !HAVE_GETPWNAM_R */
 +
 +int notification_init (notification_t *n, int severity, const char *message,
 +              const char *host,
 +              const char *plugin, const char *plugin_instance,
 +              const char *type, const char *type_instance)
 +{
 +      memset (n, '\0', sizeof (notification_t));
 +
 +      n->severity = severity;
 +
 +      if (message != NULL)
 +              strncpy (n->message, message, sizeof (n->message));
 +      if (host != NULL)
 +              strncpy (n->host, host, sizeof (n->host));
 +      if (plugin != NULL)
 +              strncpy (n->plugin, plugin, sizeof (n->plugin));
 +      if (plugin_instance != NULL)
 +              strncpy (n->plugin_instance, plugin_instance,
 +                              sizeof (n->plugin_instance));
 +      if (type != NULL)
 +              strncpy (n->type, type, sizeof (n->type));
 +      if (type_instance != NULL)
 +              strncpy (n->type_instance, type_instance,
 +                              sizeof (n->type_instance));
 +
 +      n->message[sizeof (n->message) - 1] = '\0';
 +      n->host[sizeof (n->host) - 1] = '\0';
 +      n->plugin[sizeof (n->plugin) - 1] = '\0';
 +      n->plugin_instance[sizeof (n->plugin_instance) - 1] = '\0';
 +      n->type[sizeof (n->type) - 1] = '\0';
 +      n->type_instance[sizeof (n->type_instance) - 1] = '\0';
 +
 +      return (0);
 +} /* int notification_init */
diff --combined src/hddtemp.c
index 651de298877a3c9848f05e17d79ea7a67e34ebaa,09f6bbe673a1b84328b3b4e95fbc18141abeea72..36ada53c4b2b673375e9a7982f3b62dd7dff383b
@@@ -48,9 -48,9 +48,9 @@@ static const char *config_keys[] 
  {
        "Host",
        "Port",
 -      NULL
 +      "TranslateDevicename"
  };
 -static int config_keys_num = 2;
 +static int config_keys_num = STATIC_ARRAY_SIZE (config_keys);
  
  typedef struct hddname
  {
@@@ -63,7 -63,6 +63,7 @@@
  static hddname_t *first_hddname = NULL;
  static char *hddtemp_host = NULL;
  static char hddtemp_port[16];
 +static int translate_devicename = 1;
  
  /*
   * NAME
@@@ -121,7 -120,7 +121,7 @@@ static int hddtemp_query_daemon (char *
        if ((ai_return = getaddrinfo (host, port, &ai_hints, &ai_list)) != 0)
        {
                char errbuf[1024];
-               ERROR ("hddtemp: getaddrinfo (%s, %s): %s",
+               ERROR ("hddtemp plugin: getaddrinfo (%s, %s): %s",
                                host, port,
                                (ai_return == EAI_SYSTEM)
                                ? sstrerror (errno, errbuf, sizeof (errbuf))
        for (ai_ptr = ai_list; ai_ptr != NULL; ai_ptr = ai_ptr->ai_next)
        {
                /* create our socket descriptor */
-               if ((fd = socket (ai_ptr->ai_family, ai_ptr->ai_socktype, ai_ptr->ai_protocol)) < 0)
+               fd = socket (ai_ptr->ai_family, ai_ptr->ai_socktype,
+                               ai_ptr->ai_protocol);
+               if (fd < 0)
                {
                        char errbuf[1024];
-                       ERROR ("hddtemp: socket: %s",
+                       ERROR ("hddtemp plugin: socket: %s",
                                        sstrerror (errno, errbuf, sizeof (errbuf)));
                        continue;
                }
  
                /* connect to the hddtemp daemon */
-               if (connect (fd, (struct sockaddr *) ai_ptr->ai_addr, ai_ptr->ai_addrlen))
+               if (connect (fd, (struct sockaddr *) ai_ptr->ai_addr,
+                                       ai_ptr->ai_addrlen))
                {
                        char errbuf[1024];
-                       INFO ("hddtemp: connect (%s, %s): %s", host, port,
+                       INFO ("hddtemp plugin: connect (%s, %s) failed: %s",
+                                       host, port,
                                        sstrerror (errno, errbuf, sizeof (errbuf)));
                        close (fd);
                        fd = -1;
  
        if (fd < 0)
        {
-               ERROR ("hddtemp: Could not connect to daemon.");
+               ERROR ("hddtemp plugin: Could not connect to daemon.");
                return (-1);
        }
  
                        if ((errno == EAGAIN) || (errno == EINTR))
                                continue;
  
-                       ERROR ("hddtemp: Error reading from socket: %s",
+                       ERROR ("hddtemp plugin: Error reading from socket: %s",
                                        sstrerror (errno, errbuf, sizeof (errbuf)));
                        close (fd);
                        return (-1);
        if (buffer_fill >= buffer_size)
        {
                buffer[buffer_size - 1] = '\0';
-               WARNING ("hddtemp: Message from hddtemp has been truncated.");
+               WARNING ("hddtemp plugin: Message from hddtemp has been "
+                               "truncated.");
        }
        else if (buffer_fill == 0)
        {
-               WARNING ("hddtemp: Peer has unexpectedly shut down the socket. "
-                               "Buffer: `%s'", buffer);
+               WARNING ("hddtemp plugin: Peer has unexpectedly shut down "
+                               "the socket. Buffer: `%s'", buffer);
                close (fd);
                return (-1);
        }
@@@ -224,15 -228,6 +229,15 @@@ static int hddtemp_config (const char *
                        strncpy (hddtemp_port, value, sizeof (hddtemp_port));
                hddtemp_port[sizeof (hddtemp_port) - 1] = '\0';
        }
 +      else if (strcasecmp (key, "TranslateDevicename") == 0)
 +      {
 +              if ((strcasecmp ("true", value) == 0)
 +                              || (strcasecmp ("yes", value) == 0)
 +                              || (strcasecmp ("on", value) == 0))
 +                      translate_devicename = 1;
 +              else
 +                      translate_devicename = 0;
 +      }
        else
        {
                return (-1);
@@@ -273,7 -268,7 +278,7 @@@ static int hddtemp_init (void
  
        if ((fh = fopen ("/proc/partitions", "r")) != NULL)
        {
-               DEBUG ("Looking at /proc/partitions...");
+               DEBUG ("hddtemp plugin: Looking at /proc/partitions...");
  
                while (fgets (buf, sizeof (buf), fh) != NULL)
                {
  
                                /* Skip all other majors. */
                                default:
-                                       DEBUG ("Skipping unknown major %i", major);
+                                       DEBUG ("hddtemp plugin: Skipping unknown major %i", major);
                                        continue;
                        } /* switch (major) */
  
                        if ((name = strdup (fields[3])) == NULL)
                        {
-                               ERROR ("hddtemp: strdup(%s) == NULL", fields[3]);
+                               ERROR ("hddtemp plugin: strdup(%s) == NULL", fields[3]);
                                continue;
                        }
  
                        if ((entry = (hddname_t *) malloc (sizeof (hddname_t))) == NULL)
                        {
-                               ERROR ("hddtemp: malloc (%u) == NULL",
+                               ERROR ("hddtemp plugin: malloc (%u) == NULL",
                                                (unsigned int) sizeof (hddname_t));
                                free (name);
                                continue;
                        }
  
-                       DEBUG ("Found disk: %s (%u:%u).", name, major, minor);
+                       DEBUG ("hddtemp plugin: Found disk: %s (%u:%u).", name, major, minor);
  
                        entry->major = major;
                        entry->minor = minor;
        else
        {
                char errbuf[1024];
-               DEBUG ("Could not open /proc/partitions: %s",
+               DEBUG ("hddtemp plugin: Could not open /proc/partitions: %s",
                                sstrerror (errno, errbuf, sizeof (errbuf)));
        }
  #endif /* COLLECT_DEBUG */
  } /* int hddtemp_init */
  
  /*
 - * hddtemp_get_name
 + * hddtemp_get_major_minor
   *
   * Description:
   *   Try to "cook" a bit the drive name as returned
   *   by the hddtemp daemon. The intend is to transform disk
   *   names into <major>-<minor> when possible.
   */
 -static char *hddtemp_get_name (char *drive)
 +static char *hddtemp_get_major_minor (char *drive)
  {
        hddname_t *list;
        char *ret;
  
        if (list == NULL)
        {
-               DEBUG ("Don't know %s, keeping name as-is.", drive);
+               DEBUG ("hddtemp plugin: Don't know %s, keeping name as-is.", drive);
                return (strdup (drive));
        }
  
@@@ -482,7 -477,7 +487,7 @@@ static int hddtemp_read (void
  
        for (i = 0; i < num_disks; i++)
        {
 -              char *name, *submit_name;
 +              char *name, *major_minor;
                double temperature;
                char *mode;
  
                if (mode[0] == 'F')
                        temperature = (temperature - 32.0) * 5.0 / 9.0;
  
 -              if ((submit_name = hddtemp_get_name (name)) != NULL)
 +              if (translate_devicename
 +                              && (major_minor = hddtemp_get_major_minor (name)) != NULL)
                {
 -                      hddtemp_submit (submit_name, temperature);
 -                      free (submit_name);
 +                      hddtemp_submit (major_minor, temperature);
 +                      free (major_minor);
                }
                else
                {
diff --combined src/plugin.c
index 0570f0ee0dc37269ce66fb724fe7f6abd64ac7dc,7d2bb57f09e01c0b6746d0e1608e307839b4aae5..8b2803dfa49b345b95d4da9f586740e6105af69a
  #include "common.h"
  #include "plugin.h"
  #include "configfile.h"
 +#include "utils_avltree.h"
  #include "utils_llist.h"
 +#include "utils_cache.h"
 +#include "utils_threshold.h"
  
  /*
   * Private structures
@@@ -54,10 -51,8 +54,10 @@@ static llist_t *list_init
  static llist_t *list_read;
  static llist_t *list_write;
  static llist_t *list_shutdown;
 -static llist_t *list_data_set;
  static llist_t *list_log;
 +static llist_t *list_notification;
 +
 +static c_avl_tree_t *data_sets;
  
  static char *plugindir = NULL;
  
@@@ -81,7 -76,6 +81,7 @@@ static const char *plugin_get_dir (void
  static int register_callback (llist_t **list, const char *name, void *callback)
  {
        llentry_t *le;
 +      char *key;
  
        if ((*list == NULL)
                        && ((*list = llist_create ()) == NULL))
        le = llist_search (*list, name);
        if (le == NULL)
        {
 -              le = llentry_create (name, callback);
 +              key = strdup (name);
 +              if (key == NULL)
 +                      return (-1);
 +
 +              le = llentry_create (key, callback);
                if (le == NULL)
 +              {
 +                      free (key);
                        return (-1);
 +              }
  
                llist_append (*list, le);
        }
@@@ -121,7 -108,6 +121,7 @@@ static int plugin_unregister (llist_t *
                return (-1);
  
        llist_remove (list, e);
 +      free (e->key);
        llentry_destroy (e);
  
        return (0);
@@@ -234,7 -220,6 +234,7 @@@ static void *plugin_read_thread (void *
        pthread_mutex_unlock (&read_lock);
  
        pthread_exit (NULL);
 +      return ((void *) 0);
  } /* void *plugin_read_thread */
  
  static void start_threads (int num)
@@@ -312,7 -297,7 +312,7 @@@ int plugin_load (const char *type
  {
        DIR  *dh;
        const char *dir;
-       char  filename[BUFSIZE];
+       char  filename[BUFSIZE] = "";
        char  typename[BUFSIZE];
        int   typename_len;
        int   ret;
  
        closedir (dh);
  
+       if (filename[0] == '\0')
+               fprintf (stderr, "Could not find plugin %s.\n", type);
        return (ret);
  }
  
@@@ -445,18 -433,12 +448,18 @@@ int plugin_register_data_set (const dat
        data_set_t *ds_copy;
        int i;
  
 -      if ((list_data_set != NULL)
 -                      && (llist_search (list_data_set, ds->type) != NULL))
 +      if ((data_sets != NULL)
 +                      && (c_avl_get (data_sets, ds->type, NULL) == 0))
        {
                NOTICE ("Replacing DS `%s' with another version.", ds->type);
                plugin_unregister_data_set (ds->type);
        }
 +      else if (data_sets == NULL)
 +      {
 +              data_sets = c_avl_create ((int (*) (const void *, const void *)) strcmp);
 +              if (data_sets == NULL)
 +                      return (-1);
 +      }
  
        ds_copy = (data_set_t *) malloc (sizeof (data_set_t));
        if (ds_copy == NULL)
        for (i = 0; i < ds->ds_num; i++)
                memcpy (ds_copy->ds + i, ds->ds + i, sizeof (data_source_t));
  
 -      return (register_callback (&list_data_set, ds->type, (void *) ds_copy));
 +      return (c_avl_insert (data_sets, (void *) ds_copy->type, (void *) ds_copy));
  } /* int plugin_register_data_set */
  
  int plugin_register_log (char *name,
        return (register_callback (&list_log, name, (void *) callback));
  } /* int plugin_register_log */
  
 +int plugin_register_notification (const char *name,
 +              int (*callback) (const notification_t *notif))
 +{
 +      return (register_callback (&list_notification, name, (void *) callback));
 +} /* int plugin_register_log */
 +
  int plugin_unregister_config (const char *name)
  {
        cf_unregister (name);
@@@ -517,7 -493,6 +520,7 @@@ int plugin_unregister_read (const char 
  
        llist_remove (list_read, e);
        free (e->value);
 +      free (e->key);
        llentry_destroy (e);
  
        return (0);
@@@ -535,14 -510,21 +538,14 @@@ int plugin_unregister_shutdown (const c
  
  int plugin_unregister_data_set (const char *name)
  {
 -      llentry_t  *e;
        data_set_t *ds;
  
 -      if (list_data_set == NULL)
 +      if (data_sets == NULL)
                return (-1);
  
 -      e = llist_search (list_data_set, name);
 -
 -      if (e == NULL)
 +      if (c_avl_remove (data_sets, name, NULL, (void *) &ds) != 0)
                return (-1);
  
 -      llist_remove (list_data_set, e);
 -      ds = (data_set_t *) e->value;
 -      llentry_destroy (e);
 -
        sfree (ds->ds);
        sfree (ds);
  
@@@ -554,11 -536,6 +557,11 @@@ int plugin_unregister_log (const char *
        return (plugin_unregister (list_log, name));
  }
  
 +int plugin_unregister_notification (const char *name)
 +{
 +      return (plugin_unregister (list_notification, name));
 +}
 +
  void plugin_init_all (void)
  {
        int (*callback) (void);
                start_threads ((num > 0) ? num : 5);
        }
  
 +      /* Init the value cache */
 +      uc_init ();
 +
        if (list_init == NULL)
                return;
  
        }
  } /* void plugin_init_all */
  
 -void plugin_read_all (const int *loop)
 +void plugin_read_all (void)
  {
        llentry_t   *le;
        read_func_t *rf;
  
 +      uc_check_timeout ();
 +
        if (list_read == NULL)
                return;
  
@@@ -671,16 -643,32 +674,29 @@@ int plugin_dispatch_values (const char 
        data_set_t *ds;
        llentry_t *le;
  
-       if ((list_write == NULL) || (data_sets == NULL))
+       if (list_write == NULL)
+       {
+               ERROR ("plugin_dispatch_values: No write callback has been "
+                               "registered. Please load at least one plugin "
+                               "that provides a write function.");
+               return (-1);
+       }
 -      if (list_data_set == NULL)
++      if (data_sets == NULL)
+       {
+               ERROR ("plugin_dispatch_values: No data sets registered. "
+                               "Could the types database be read? Check "
+                               "your `TypesDB' setting!");
                return (-1);
+       }
  
 -      le = llist_search (list_data_set, name);
 -      if (le == NULL)
 +      if (c_avl_get (data_sets, name, (void *) &ds) != 0)
        {
-               DEBUG ("No such dataset registered: %s", name);
+               INFO ("plugin_dispatch_values: Dataset not found: %s", name);
                return (-1);
        }
  
-       DEBUG ("plugin: plugin_dispatch_values: time = %u; interval = %i; "
 -      ds = (data_set_t *) le->value;
 -
+       DEBUG ("plugin_dispatch_values: time = %u; interval = %i; "
                        "host = %s; "
                        "plugin = %s; plugin_instance = %s; "
                        "type = %s; type_instance = %s;",
  #else
        if (ds->ds_num != vl->values_len)
        {
-               ERROR ("plugin: ds->type = %s: (ds->ds_num = %i) != "
+               ERROR ("plugin_dispatch_values: ds->type = %s: "
+                               "(ds->ds_num = %i) != "
                                "(vl->values_len = %i)",
                                ds->type, ds->ds_num, vl->values_len);
                return (-1);
        escape_slashes (vl->plugin_instance, sizeof (vl->plugin_instance));
        escape_slashes (vl->type_instance, sizeof (vl->type_instance));
  
 +      /* Update the value cache */
 +      uc_update (ds, vl);
 +      ut_check_threshold (ds, vl);
 +
        le = llist_head (list_write);
        while (le != NULL)
        {
        return (0);
  } /* int plugin_dispatch_values */
  
 +int plugin_dispatch_notification (const notification_t *notif)
 +{
 +      int (*callback) (const notification_t *);
 +      llentry_t *le;
 +      /* Possible TODO: Add flap detection here */
 +
 +      DEBUG ("plugin_dispatch_notification: severity = %i; message = %s; "
 +                      "time = %u; host = %s;",
 +                      notif->severity, notif->message,
 +                      (unsigned int) notif->time, notif->host);
 +
 +      /* Nobody cares for notifications */
 +      if (list_notification == NULL)
 +              return (-1);
 +
 +      le = llist_head (list_notification);
 +      while (le != NULL)
 +      {
 +              callback = (int (*) (const notification_t *)) le->value;
 +              (*callback) (notif);
 +
 +              le = le->next;
 +      }
 +
 +      return (0);
 +} /* int plugin_dispatch_notification */
 +
  void plugin_log (int level, const char *format, ...)
  {
        char msg[512];
        }
  } /* void plugin_log */
  
 -void plugin_complain (int level, complain_t *c, const char *format, ...)
 -{
 -      char message[512];
 -      va_list ap;
 -
 -      if (c->delay > 0)
 -      {
 -              c->delay--;
 -              return;
 -      }
 -
 -      if (c->interval < interval_g)
 -              c->interval = interval_g;
 -      else
 -              c->interval *= 2;
 -
 -      if (c->interval > 86400)
 -              c->interval = 86400;
 -
 -      c->delay = c->interval / interval_g;
 -
 -      va_start (ap, format);
 -      vsnprintf (message, 512, format, ap);
 -      message[511] = '\0';
 -      va_end (ap);
 -
 -      plugin_log (level, message);
 -}
 -
 -void plugin_relief (int level, complain_t *c, const char *format, ...)
 -{
 -      char message[512];
 -      va_list ap;
 -
 -      if (c->interval == 0)
 -              return;
 -
 -      c->interval = 0;
 -
 -      va_start (ap, format);
 -      vsnprintf (message, 512, format, ap);
 -      message[511] = '\0';
 -      va_end (ap);
 -
 -      plugin_log (level, message);
 -}
 -
  const data_set_t *plugin_get_ds (const char *name)
  {
        data_set_t *ds;
 -      llentry_t *le;
  
 -      le = llist_search (list_data_set, name);
 -      if (le == NULL)
 +      if (c_avl_get (data_sets, name, (void *) &ds) != 0)
        {
                DEBUG ("No such dataset registered: %s", name);
                return (NULL);
        }
  
 -      ds = (data_set_t *) le->value;
 -
        return (ds);
  } /* data_set_t *plugin_get_ds */
diff --combined src/unixsock.c
index 9fa0259685c39c90799b9963fde732dd57783605,f8c9fbfd579e7013a9d1d700d5a595872b83492c..45ed9c699b783fa9e9e10a4dfd482a594e59d1a4
@@@ -1,6 -1,6 +1,6 @@@
  /**
   * collectd - src/unixsock.c
 - * Copyright (C) 2007  Florian octo Forster
 + * Copyright (C) 2007,2008  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
@@@ -23,9 -23,7 +23,9 @@@
  #include "common.h"
  #include "plugin.h"
  #include "configfile.h"
 +
  #include "utils_cmd_putval.h"
 +#include "utils_cmd_putnotif.h"
  
  /* Folks without pthread will need to disable this plugin. */
  #include <pthread.h>
@@@ -83,7 -81,7 +83,7 @@@ static pthread_t listen_thread = (pthre
  /* Linked list and auxilliary variables for saving values */
  static value_cache_t   *cache_head = NULL;
  static pthread_mutex_t  cache_lock = PTHREAD_MUTEX_INITIALIZER;
 -static unsigned int     cache_oldest = UINT_MAX;
 +static time_t           cache_oldest = -1;
  
  /*
   * Functions
@@@ -190,7 -188,7 +190,7 @@@ static int cache_insert (const data_set
        cache_head = vc;
  
        vc->time = vl->time;
 -      if (vc->time < cache_oldest)
 +      if ((vc->time < cache_oldest) || (-1 == cache_oldest))
                cache_oldest = vc->time;
  
        pthread_mutex_unlock (&cache_lock);
@@@ -277,7 -275,7 +277,7 @@@ static int cache_update (const data_set
        vc->ds = ds;
        vc->time = vl->time;
  
 -      if (vc->time < cache_oldest)
 +      if ((vc->time < cache_oldest) || (-1 == cache_oldest))
                cache_oldest = vc->time;
  
        pthread_mutex_unlock (&cache_lock);
@@@ -613,10 -611,6 +613,10 @@@ static void *us_handle_client (void *ar
                {
                        us_handle_listval (fhout, fields, fields_num);
                }
 +              else if (strcasecmp (fields[0], "putnotif") == 0)
 +              {
 +                      handle_putnotif (fhout, fields, fields_num);
 +              }
                else
                {
                        fprintf (fhout, "-1 Unknown command: %s\n", fields[0]);
        fclose (fhout);
  
        pthread_exit ((void *) 0);
 +      return ((void *) 0);
  } /* void *us_handle_client */
  
  static void *us_server_thread (void *arg)
@@@ -759,7 -752,6 +759,6 @@@ static int us_shutdown (void
        }
  
        plugin_unregister_init ("unixsock");
-       plugin_unregister_write ("unixsock");
        plugin_unregister_shutdown ("unixsock");
  
        return (0);