Merge branch 'collectd-5.7'
authorFlorian Forster <octo@collectd.org>
Thu, 21 Sep 2017 15:26:23 +0000 (17:26 +0200)
committerFlorian Forster <octo@collectd.org>
Thu, 21 Sep 2017 15:26:23 +0000 (17:26 +0200)
1  2 
contrib/redhat/collectd.spec
src/network.c
src/ntpd.c
src/perl.c

@@@ -88,7 -88,6 +88,7 @@@
  %define with_lvm 0%{!?_without_lvm:1}
  %define with_madwifi 0%{!?_without_madwifi:1}
  %define with_mbmon 0%{!?_without_mbmon:1}
 +%define with_mcelog 0%{!?_without_mcelog:1}
  %define with_md 0%{!?_without_md:1}
  %define with_memcachec 0%{!?_without_memcachec:1}
  %define with_memcached 0%{!?_without_memcached:1}
  %define with_olsrd 0%{!?_without_olsrd:1}
  %define with_openldap 0%{!?_without_openldap:1}
  %define with_openvpn 0%{!?_without_openvpn:1}
 +%define with_ovs_events 0%{!?_without_ovs_events:1}
 +%define with_ovs_stats 0%{!?_without_ovs_stats:1}
  %define with_perl 0%{!?_without_perl:1}
  %define with_pinba 0%{!?_without_pinba:1}
  %define with_ping 0%{!?_without_ping:1}
  %define with_serial 0%{!?_without_serial:1}
  %define with_smart 0%{!?_without_smart:1}
  %define with_snmp 0%{!?_without_snmp:1}
 +%define with_snmp_agent 0%{!?_without_snmp_agent:1}
  %define with_statsd 0%{!?_without_statsd:1}
  %define with_swap 0%{!?_without_swap:1}
  %define with_syslog 0%{!?_without_syslog:1}
  %define with_aquaero 0%{!?_without_aquaero:0}
  # plugin barometer disabled, requires a libi2c
  %define with_barometer 0%{!?_without_barometer:0}
 -# plugin grpc disabled, requires protobuf-compiler >= 3.0
 -%define with_grpc 0%{!?_without_grpc:0}
 +# plugin dpdkevents disabled, requires libdpdk
 +%define with_dpdkevents 0%{!?_without_dpdkevents:0}
  # plugin dpdkstat disabled, requires libdpdk
  %define with_dpdkstat 0%{!?_without_dpdkstat:0}
 +# plugin grpc disabled, requires protobuf-compiler >= 3.0
 +%define with_grpc 0%{!?_without_grpc:0}
  # plugin lpar disabled, requires AIX
  %define with_lpar 0%{!?_without_lpar:0}
 +# plugin intel_pmu disabled, requires libjevents
 +%define with_intel_pmu 0%{!?_without_intel_pmu:0}
  # plugin intel_rdt disabled, requires intel-cmt-cat
  %define with_intel_rdt 0%{!?_without_intel_rdt:0}
  # plugin mic disabled, requires Mic
  %define with_cpusleep 0
  %define with_gps 0
  %define with_mqtt 0
 +%define with_ovs_events 0
 +%define with_ovs_stats 0
  %define with_redis 0
  %define with_rrdcached 0
  %define with_write_redis 0
  Summary:      Statistics collection and monitoring daemon
  Name:         collectd
  Version:      5.7.1
 -Release:      3%{?dist}
 +Release:      7%{?dist}
  URL:          https://collectd.org
  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
@@@ -472,16 -462,6 +472,16 @@@ The HDDTemp plugin collects the tempera
  provided via SMART and queried by the external hddtemp daemon.
  %endif
  
 +%if %{with_intel_pmu}
 +%package intel_pmu
 +Summary:      Intel PMU plugin for collectd
 +Group:                System Environment/Daemons
 +Requires:     %{name}%{?_isa} = %{version}-%{release}
 +%description intel_pmu
 +The intel_pmu plugin reads performance counters provided by the Linux
 +kernel perf interface.
 +%endif
 +
  %if %{with_intel_rdt}
  %package intel_rdt
  Summary:      Intel RDT plugin for collectd
@@@ -521,8 -501,8 +521,8 @@@ the byte- and packet-counters of select
  Summary:      Java plugin for collectd
  Group:                System Environment/Daemons
  Requires:     %{name}%{?_isa} = %{version}-%{release}
- BuildRequires:        java-devel, jpackage-utils
- Requires:     java, jpackage-utils
+ BuildRequires:        java-devel >= 1.6, jpackage-utils >= 1.6
+ Requires:     java >= 1.6, jpackage-utils >= 1.6
  %description java
  This plugin for collectd allows plugins to be written in Java and executed
  in an embedded JVM.
@@@ -560,16 -540,6 +560,16 @@@ This plugin collects size of “Logica
  of Linux' “Logical Volume Manager” (LVM).
  %endif
  
 +%if %{with_mcelog}
 +%package mcelog
 +Summary:      Mcelog plugin for collectd
 +Group:                System Environment/Daemons
 +Requires:     %{name}%{?_isa} = %{version}-%{release}
 +%description mcelog
 +This plugin monitors machine check exceptions reported by mcelog and generates
 +appropriate notifications when machine check exceptions are detected.
 +%endif
 +
  %if %{with_memcachec}
  %package memcachec
  Summary:      Memcachec plugin for collectd
@@@ -685,29 -655,6 +685,29 @@@ BuildRequires: openldap-deve
  This plugin reads monitoring information from OpenLDAP's cn=Monitor subtree.
  %endif
  
 +%if %{with_ovs_events}
 +%package ovs_events
 +Summary:       Open vSwitch events plugin for collectd
 +Group:         System Environment/Daemons
 +Requires:      %{name}%{?_isa} = %{version}-%{release}
 +BuildRequires: yajl-devel
 +%description ovs_events
 +This plugin monitors the link status of Open vSwitch (OVS) connected
 +interfaces, dispatches the values to collectd and sends notifications
 +whenever a link state change occurs in the OVS database.
 +%endif
 +
 +%if %{with_ovs_stats}
 +%package ovs_stats
 +Summary:       Open vSwitch statistics plugin for collectd
 +Group:         System Environment/Daemons
 +Requires:      %{name}%{?_isa} = %{version}-%{release}
 +BuildRequires: yajl-devel
 +%description ovs_stats
 +This plugin collects statictics of OVS connected bridges and
 +interfaces.
 +%endif
 +
  %if %{with_perl}
  %package perl
  Summary:      Perl plugin for collectd
@@@ -846,16 -793,6 +846,16 @@@ BuildRequires:   net-snmp-deve
  This plugin for collectd allows querying of network equipment using SNMP.
  %endif
  
 +%if %{with_snmp_agent}
 +%package snmp_agent
 +Summary:      SNMP AgentX plugin for collectd
 +Group:                System Environment/Daemons
 +Requires:     %{name}%{?_isa} = %{version}-%{release}
 +BuildRequires:        net-snmp-devel
 +%description snmp_agent
 +This plugin for collectd to support AgentX integration.
 +%endif
 +
  %if %{with_varnish}
  %package varnish
  Summary:      Varnish plugin for collectd
@@@ -1164,12 -1101,6 +1164,12 @@@ Collectd utilitie
  %define _with_drbd --disable-drbd
  %endif
  
 +%if %{with_dpdkevents}
 +%define _with_dpdkevents --enable-dpdkevents
 +%else
 +%define _with_dpdkevents --disable-dpdkevents
 +%endif
 +
  %if %{with_dpdkstat}
  %define _with_dpdkstat --enable-dpdkstat
  %else
  %define _with_hugepages --disable-hugepages
  %endif
  
 +%if %{with_intel_pmu}
 +%define _with_intel_pmu --enable-intel_pmu
 +%else
 +%define _with_intel_pmu --disable-intel_pmu
 +%endif
 +
  %if %{with_intel_rdt}
  %define _with_intel_rdt --enable-intel_rdt
  %else
  %define _with_mbmon --disable-mbmon
  %endif
  
 +%if %{with_mcelog}
 +%define _with_mcelog --enable-mcelog
 +%else
 +%define _with_mbmon --disable-mcelog
 +%endif
 +
  %if %{with_md}
  %define _with_md --enable-md
  %else
  %define _with_oracle --disable-oracle
  %endif
  
 +%if %{with_ovs_events}
 +%define _with_ovs_events --enable-ovs_events
 +%else
 +%define _with_ovs_events --disable-ovs_events
 +%endif
 +
 +%if %{with_ovs_stats}
 +%define _with_ovs_stats --enable-ovs_stats
 +%else
 +%define _with_ovs_stats --disable-ovs_stats
 +%endif
 +
  %if %{with_perl}
  %define _with_perl --enable-perl --with-perl-bindings="INSTALLDIRS=vendor"
  %else
  %define _with_snmp --disable-snmp
  %endif
  
 +%if %{with_snmp_agent}
 +%define _with_snmp_agent --enable-snmp_agent
 +%else
 +%define _with_snmp_agent --disable-snmp_agent
 +%endif
 +
  %if %{with_statsd}
  %define _with_statsd --enable-statsd
  %else
  %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 \
        %{?_with_disk} \
        %{?_with_dns} \
        %{?_with_drbd} \
 +      %{?_with_dpdkevents} \
        %{?_with_dpdkstat} \
        %{?_with_email} \
        %{?_with_entropy} \
        %{?_with_grpc} \
        %{?_with_hddtemp} \
        %{?_with_hugepages} \
 +      %{?_with_intel_pmu} \
        %{?_with_intel_rdt} \
        %{?_with_interface} \
        %{?_with_ipc} \
        %{?_with_lvm} \
        %{?_with_madwifi} \
        %{?_with_mbmon} \
 +      %{?_with_mcelog} \
        %{?_with_md} \
        %{?_with_memcachec} \
        %{?_with_memcached} \
        %{?_with_openldap} \
        %{?_with_openvpn} \
        %{?_with_oracle} \
 +      %{?_with_ovs_events} \
 +      %{?_with_ovs_stats} \
        %{?_with_perl} \
        %{?_with_pf} \
        %{?_with_pinba} \
        %{?_with_sigrok} \
        %{?_with_smart} \
        %{?_with_snmp} \
 +      %{?_with_snmp_agent} \
        %{?_with_statsd} \
        %{?_with_swap} \
        %{?_with_syslog} \
  %if %{with_drbd}
  %{_libdir}/%{name}/drbd.so
  %endif
 -%if %{with_dpdkstat}
 -%{_libdir}/%{name}/dpdkstat.so
 -%endif
  %if %{with_ethstat}
  %{_libdir}/%{name}/ethstat.so
  %endif
  %if %{with_mbmon}
  %{_libdir}/%{name}/mbmon.so
  %endif
 +%if %{with_mcelog}
 +%{_libdir}/%{name}/mcelog.so
 +%endif
  %if %{with_md}
  %{_libdir}/%{name}/md.so
  %endif
  %{_libdir}/%{name}/dbi.so
  %endif
  
 +%if %{with_dpdkevents}
 +%files dpdkevents
 +%{_libdir}/%{name}/dpdkevents.so
 +%endif
 +
 +%if %{with_dpdkstat}
 +%files dpdkstat
 +%{_libdir}/%{name}/dpdkstat.so
 +%endif
 +
  %if %{with_email}
  %files email
  %{_libdir}/%{name}/email.so
  %{_libdir}/%{name}/hddtemp.so
  %endif
  
 +%if %{with_intel_pmu}
 +%files intel_pmu
 +%{_libdir}/%{name}/intel_pmu.so
 +%endif
 +
  %if %{with_intel_rdt}
  %files intel_rdt
  %{_libdir}/%{name}/intel_rdt.so
  %{_libdir}/%{name}/openldap.so
  %endif
  
 +%if %{with_ovs_events}
 +%files ovs_events
 +%{_libdir}/%{name}/ovs_events.so
 +%endif
 +
 +%if %{with_ovs_stats}
 +%files ovs_stats
 +%{_libdir}/%{name}/ovs_stats.so
 +%endif
 +
  %if %{with_perl}
  %files perl
  %{perl_vendorlib}/Collectd.pm
  %{_libdir}/%{name}/snmp.so
  %endif
  
 +%if %{with_snmp_agent}
 +%files snmp_agent
 +%{_libdir}/%{name}/snmp_agent.so
 +%endif
 +
  %if %{with_varnish}
  %files varnish
  %{_libdir}/%{name}/varnish.so
  %doc contrib/
  
  %changelog
 -* Sun Mar 05 2017 Ruben Kerkhof <ruben@rubenkerkhof.com> - 5.7.1-2
 +* Fri Aug 18 2017 Ruben Kerkhof <ruben@rubenkerkhof.com> - 5.7.1-7
 +- Add new intel_pmu plugin
 +
 +* Sun Mar 05 2017 Ruben Kerkhof <ruben@rubenkerkhof.com> - 5.7.1-6
 +- Move recently added plugins to subpackages
 +
 +* Sun Mar 05 2017 Ruben Kerkhof <ruben@rubenkerkhof.com> - 5.7.1-5
 +- Add new ovs_stats plugin
 +
 +* Sun Mar 05 2017 Ruben Kerkhof <ruben@rubenkerkhof.com> - 5.7.1-4
  - Don't enable XFS support on RHEL6, it is missing for i386
  
 +* Sun Mar 05 2017 Ruben Kerkhof <ruben@rubenkerkhof.com> - 5.7.1-3
 +- Add dpdkevents plugin, disabled by default
 +
  * Wed Feb 22 2017 Ruben Kerkhof <ruben@rubenkerkhof.com> - 5.7.1-2
  - Enable XFS support in df plugin
  - Fix bogus date in changelog
  * Sun Jan 01 2017 Marc Fournier <marc.fournier@camptocamp.com> - 5.7.1-1
  - New upstream version
  
 +* Sat Dec 31 2016 Ruben Kerkhof <ruben@rubenkerkhof.com> - 5.7.0-4
 +- Add new ovs_events plugin
 +
 +* Sat Dec 31 2016 Ruben Kerkhof <ruben@rubenkerkhof.com> - 5.7.0-3
 +- Add new mcelog plugin
 +
  * Tue Nov 29 2016 Ruben Kerkhof <ruben@rubenkerkhof.com> - 5.7.0-2
  - Disable redis plugin on RHEL 6, hiredis has been retired from EPEL6
  
diff --combined src/network.c
@@@ -51,7 -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 +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 +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;
  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;
@@@ -324,9 -324,9 +324,9 @@@ static _Bool check_receive_okay(const v
    /* This is a value we already sent. Don't allow it to be received again in
     * order to avoid looping. */
    if ((status == 0) && (time_sent >= ((uint64_t)vl->time)))
 -    return (0);
 +    return 0;
  
 -  return (1);
 +  return 1;
  } /* }}} _Bool check_receive_okay */
  
  static _Bool check_send_okay(const value_list_t *vl) /* {{{ */
    int status;
  
    if (network_config_forward)
 -    return (1);
 +    return 1;
  
    if (vl->meta == NULL)
 -    return (1);
 +    return 1;
  
    status = meta_data_get_boolean(vl->meta, "network:received", &received);
    if (status == -ENOENT)
 -    return (1);
 +    return 1;
    else if (status != 0) {
      ERROR("network plugin: check_send_okay: meta_data_get_boolean failed "
            "with status %i.",
            status);
 -    return (1);
 +    return 1;
    }
  
    /* By default, only *send* value lists that were not *received* by the
     * network plugin. */
 -  return (!received);
 +  return !received;
  } /* }}} _Bool check_send_okay */
  
  static _Bool check_notify_received(const notification_t *n) /* {{{ */
    for (notification_meta_t *ptr = n->meta; ptr != NULL; ptr = ptr->next)
      if ((strcmp("network:received", ptr->name) == 0) &&
          (ptr->type == NM_TYPE_BOOLEAN))
 -      return ((_Bool)ptr->nm_value.nm_boolean);
 +      return (_Bool)ptr->nm_value.nm_boolean;
  
 -  return (0);
 +  return 0;
  } /* }}} _Bool check_notify_received */
  
  static _Bool check_send_notify_okay(const notification_t *n) /* {{{ */
    _Bool received = 0;
  
    if (n->meta == NULL)
 -    return (1);
 +    return 1;
  
    received = check_notify_received(n);
  
  
    /* By default, only *send* value lists that were not *received* by the
     * network plugin. */
 -  return (!received);
 +  return !received;
  } /* }}} _Bool check_send_notify_okay */
  
  static int network_dispatch_values(value_list_t *vl, /* {{{ */
  
    if ((vl->time == 0) || (strlen(vl->host) == 0) || (strlen(vl->plugin) == 0) ||
        (strlen(vl->type) == 0))
 -    return (-EINVAL);
 +    return -EINVAL;
  
    if (!check_receive_okay(vl)) {
  #if COLLECT_DEBUG
            name);
  #endif
      stats_values_not_dispatched++;
 -    return (0);
 +    return 0;
    }
  
    assert(vl->meta == NULL);
    vl->meta = meta_data_create();
    if (vl->meta == NULL) {
      ERROR("network plugin: meta_data_create failed.");
 -    return (-ENOMEM);
 +    return -ENOMEM;
    }
  
    status = meta_data_add_boolean(vl->meta, "network:received", 1);
      ERROR("network plugin: meta_data_add_boolean failed.");
      meta_data_destroy(vl->meta);
      vl->meta = NULL;
 -    return (status);
 +    return status;
    }
  
    if (username != NULL) {
        ERROR("network plugin: meta_data_add_string failed.");
        meta_data_destroy(vl->meta);
        vl->meta = NULL;
 -      return (status);
 +      return status;
      }
    }
  
    meta_data_destroy(vl->meta);
    vl->meta = NULL;
  
 -  return (0);
 +  return 0;
  } /* }}} int network_dispatch_values */
  
  static int network_dispatch_notification(notification_t *n) /* {{{ */
      ERROR("network plugin: plugin_notification_meta_add_boolean failed.");
      plugin_notification_meta_free(n->meta);
      n->meta = NULL;
 -    return (status);
 +    return status;
    }
  
    status = plugin_dispatch_notification(n);
    plugin_notification_meta_free(n->meta);
    n->meta = NULL;
  
 -  return (status);
 +  return status;
  } /* }}} int network_dispatch_notification */
  
 -#if HAVE_LIBGCRYPT
 +#if HAVE_GCRYPT_H
  static int network_init_gcrypt(void) /* {{{ */
  {
    gcry_error_t err;
     * Because you can't know in a library whether another library has
     * already initialized the library */
    if (gcry_control(GCRYCTL_ANY_INITIALIZATION_P))
 -    return (0);
 +    return 0;
  
  /* http://www.gnupg.org/documentation/manuals/gcrypt/Multi_002dThreading.html
   * To ensure thread-safety, it's important to set GCRYCTL_SET_THREAD_CBS
    if (err) {
      ERROR("network plugin: gcry_control (GCRYCTL_SET_THREAD_CBS) failed: %s",
            gcry_strerror(err));
 -    return (-1);
 +    return -1;
    }
  #endif
  
    if (err) {
      ERROR("network plugin: gcry_control (GCRYCTL_INIT_SECMEM) failed: %s",
            gcry_strerror(err));
 -    return (-1);
 +    return -1;
    }
  
    gcry_control(GCRYCTL_INITIALIZATION_FINISHED);
 -  return (0);
 +  return 0;
  } /* }}} int network_init_gcrypt */
  
  static gcry_cipher_hd_t network_get_aes256_cypher(sockent_t *se, /* {{{ */
      cyper_ptr = &se->data.server.cypher;
  
      if (username == NULL)
 -      return (NULL);
 +      return NULL;
  
      secret = fbh_get(se->data.server.userdb, username);
      if (secret == NULL)
 -      return (NULL);
 +      return NULL;
  
      gcry_md_hash_buffer(GCRY_MD_SHA256, password_hash, secret, strlen(secret));
  
        ERROR("network plugin: gcry_cipher_open returned: %s",
              gcry_strerror(err));
        *cyper_ptr = NULL;
 -      return (NULL);
 +      return NULL;
      }
    } else {
      gcry_cipher_reset(*cyper_ptr);
            gcry_strerror(err));
      gcry_cipher_close(*cyper_ptr);
      *cyper_ptr = NULL;
 -    return (NULL);
 +    return NULL;
    }
  
    err = gcry_cipher_setiv(*cyper_ptr, iv, iv_size);
            gcry_strerror(err));
      gcry_cipher_close(*cyper_ptr);
      *cyper_ptr = NULL;
 -    return (NULL);
 +    return NULL;
    }
  
 -  return (*cyper_ptr);
 +  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) {
                 (num_values * sizeof(uint8_t)) + (num_values * sizeof(value_t));
  
    if (*ret_buffer_len < packet_len)
 -    return (-1);
 +    return -1;
  
    pkg_values_types = malloc(num_values * sizeof(*pkg_values_types));
    if (pkg_values_types == NULL) {
      ERROR("network plugin: write_part_values: malloc failed.");
 -    return (-1);
 +    return -1;
    }
  
    pkg_values = malloc(num_values * sizeof(*pkg_values));
    if (pkg_values == NULL) {
      free(pkg_values_types);
      ERROR("network plugin: write_part_values: malloc failed.");
 -    return (-1);
 +    return -1;
    }
  
    pkg_ph.type = htons(TYPE_VALUES);
        ERROR("network plugin: write_part_values: "
              "Unknown data source type: %i",
              ds->ds[i].type);
 -      return (-1);
 +      return -1;
      } /* switch (ds->ds[i].type) */
    }   /* for (num_values) */
  
    free(pkg_values_types);
    free(pkg_values);
  
 -  return (0);
 +  return 0;
  } /* int write_part_values */
  
  static int write_part_number(char **ret_buffer, size_t *ret_buffer_len,
    packet_len = sizeof(pkg_head) + sizeof(pkg_value);
  
    if (*ret_buffer_len < packet_len)
 -    return (-1);
 +    return -1;
  
    pkg_head.type = htons(type);
    pkg_head.length = htons(packet_len);
    *ret_buffer = packet_ptr + packet_len;
    *ret_buffer_len -= packet_len;
  
 -  return (0);
 +  return 0;
  } /* int write_part_number */
  
  static int write_part_string(char **ret_buffer, size_t *ret_buffer_len,
  
    buffer_len = 2 * sizeof(uint16_t) + str_len + 1;
    if (*ret_buffer_len < buffer_len)
 -    return (-1);
 +    return -1;
  
    pkg_type = htons(type);
    pkg_length = htons(buffer_len);
    *ret_buffer = buffer + buffer_len;
    *ret_buffer_len -= buffer_len;
  
 -  return (0);
 +  return 0;
  } /* int write_part_string */
  
  static int parse_part_values(void **ret_buffer, size_t *ret_buffer_len,
      NOTICE("network plugin: packet is too short: "
             "buffer_len = %zu",
             buffer_len);
 -    return (-1);
 +    return -1;
    }
  
    memcpy((void *)&tmp16, buffer, sizeof(tmp16));
              "Chunk of size %zu expected, "
              "but buffer has only %zu bytes left.",
              exp_size, buffer_len);
 -    return (-1);
 +    return -1;
    }
    assert(pkg_numval <= ((buffer_len - 6) / 9));
  
      WARNING("network plugin: parse_part_values: "
              "Length and number of values "
              "in the packet don't match.");
 -    return (-1);
 +    return -1;
    }
  
    pkg_types = calloc(pkg_numval, sizeof(*pkg_types));
      sfree(pkg_types);
      sfree(pkg_values);
      ERROR("network plugin: parse_part_values: calloc failed.");
 -    return (-1);
 +    return -1;
    }
  
    memcpy(pkg_types, buffer, pkg_numval * sizeof(*pkg_types));
               pkg_types[i]);
        sfree(pkg_types);
        sfree(pkg_values);
 -      return (-1);
 +      return -1;
      } /* switch (pkg_types[i]) */
    }
  
  
    sfree(pkg_types);
  
 -  return (0);
 +  return 0;
  } /* int parse_part_values */
  
  static int parse_part_number(void **ret_buffer, size_t *ret_buffer_len,
              "Chunk of size %zu expected, "
              "but buffer has only %zu bytes left.",
              exp_size, buffer_len);
 -    return (-1);
 +    return -1;
    }
  
    memcpy((void *)&tmp16, buffer, sizeof(tmp16));
    *ret_buffer = buffer;
    *ret_buffer_len = buffer_len - pkg_length;
  
 -  return (0);
 +  return 0;
  } /* int parse_part_number */
  
  static int parse_part_string(void **ret_buffer, size_t *ret_buffer_len,
    size_t payload_size;
  
    if (output_len == 0)
 -    return (EINVAL);
 +    return EINVAL;
  
    if (buffer_len < header_size) {
      WARNING("network plugin: parse_part_string: "
              "Chunk of at least size %zu expected, "
              "but buffer has only %zu bytes left.",
              header_size, buffer_len);
 -    return (-1);
 +    return -1;
    }
  
    memcpy((void *)&tmp16, buffer, sizeof(tmp16));
              "Chunk of size %" PRIu16 " received, "
              "but buffer has only %zu bytes left.",
              pkg_length, buffer_len);
 -    return (-1);
 +    return -1;
    }
  
    /* Check that pkg_length is in the valid range */
              "Header claims this packet is only %hu "
              "bytes long.",
              pkg_length);
 -    return (-1);
 +    return -1;
    }
  
    /* Check that the package data fits into the output buffer.
              "which is too small to hold the received "
              "%zu byte string.",
              output_len, payload_size);
 -    return (-1);
 +    return -1;
    }
  
    /* All sanity checks successfull, let's copy the data over */
      WARNING("network plugin: parse_part_string: "
              "Received string does not end "
              "with a NULL-byte.");
 -    return (-1);
 +    return -1;
    }
  
    *ret_buffer = buffer;
    *ret_buffer_len = buffer_len - pkg_length;
  
 -  return (0);
 +  return 0;
  } /* int parse_part_string */
  
  /* Forward declaration: parse_part_sign_sha256 and parse_part_encr_aes256 call
@@@ -978,7 -978,7 +978,7 @@@ static int parse_packet(sockent_t *se, 
      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) {
  
    /* Check if the buffer has enough data for this structure. */
    if (buffer_len <= PART_SIGNATURE_SHA256_SIZE)
 -    return (-ENOMEM);
 +    return -ENOMEM;
  
    /* Read type and length header */
    BUFFER_READ(&pss.head.type, sizeof(pss.head.type));
    if ((pss_head_length <= PART_SIGNATURE_SHA256_SIZE) ||
        (pss_head_length > buffer_len)) {
      ERROR("network plugin: HMAC-SHA-256 with invalid length received.");
 -    return (-1);
 +    return -1;
    }
  
    if (se->data.server.userdb == NULL) {
      *ret_buffer = buffer + pss_head_length;
      *ret_buffer_len -= pss_head_length;
  
 -    return (0);
 +    return 0;
    }
  
    /* Copy the hash. */
    username_len = pss_head_length - PART_SIGNATURE_SHA256_SIZE;
    pss.username = malloc(username_len + 1);
    if (pss.username == NULL)
 -    return (-ENOMEM);
 +    return -ENOMEM;
  
    /* Read the username */
    BUFFER_READ(pss.username, username_len);
    if (secret == NULL) {
      ERROR("network plugin: Unknown user: %s", pss.username);
      sfree(pss.username);
 -    return (-ENOENT);
 +    return -ENOENT;
    }
  
    /* Create a hash device and check the HMAC */
            gcry_strerror(err));
      sfree(secret);
      sfree(pss.username);
 -    return (-1);
 +    return -1;
    }
  
    err = gcry_md_setkey(hd, secret, strlen(secret));
      gcry_md_close(hd);
      sfree(secret);
      sfree(pss.username);
 -    return (-1);
 +    return -1;
    }
  
    gcry_md_write(hd, buffer + PART_SIGNATURE_SHA256_SIZE,
      gcry_md_close(hd);
      sfree(secret);
      sfree(pss.username);
 -    return (-1);
 +    return -1;
    }
    memcpy(hash, hash_ptr, sizeof(hash));
  
    *ret_buffer = buffer + buffer_len;
    *ret_buffer_len = 0;
  
 -  return (0);
 +  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) {
    buffer_offset = 0;
  
    if (buffer_size <= PART_SIGNATURE_SHA256_SIZE)
 -    return (-ENOMEM);
 +    return -ENOMEM;
  
    BUFFER_READ(&pss.head.type, sizeof(pss.head.type));
    BUFFER_READ(&pss.head.length, sizeof(pss.head.length));
    part_len = ntohs(pss.head.length);
  
    if ((part_len <= PART_SIGNATURE_SHA256_SIZE) || (part_len > buffer_size))
 -    return (-EINVAL);
 +    return -EINVAL;
  
    if (warning_has_been_printed == 0) {
      WARNING("network plugin: Received signed packet, but the network "
    *ret_buffer = buffer + buffer_size;
    *ret_buffer_size = 0;
  
 -  return (0);
 +  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) {
    if (buffer_len <= PART_ENCRYPTION_AES256_SIZE) {
      NOTICE("network plugin: parse_part_encr_aes256: "
             "Discarding short packet.");
 -    return (-1);
 +    return -1;
    }
  
    buffer_offset = 0;
    if ((part_size <= PART_ENCRYPTION_AES256_SIZE) || (part_size > buffer_len)) {
      NOTICE("network plugin: parse_part_encr_aes256: "
             "Discarding part with invalid size.");
 -    return (-1);
 +    return -1;
    }
  
    /* Read the username */
        (username_len > (part_size - (PART_ENCRYPTION_AES256_SIZE + 1)))) {
      NOTICE("network plugin: parse_part_encr_aes256: "
             "Discarding part with invalid username length.");
 -    return (-1);
 +    return -1;
    }
  
    assert(username_len > 0);
    pea.username = malloc(username_len + 1);
    if (pea.username == NULL)
 -    return (-ENOMEM);
 +    return -ENOMEM;
    BUFFER_READ(pea.username, username_len);
    pea.username[username_len] = 0;
  
    if (cypher == NULL) {
      ERROR("network plugin: Failed to get cypher. Username: %s", pea.username);
      sfree(pea.username);
 -    return (-1);
 +    return -1;
    }
  
    payload_len = part_size - (PART_ENCRYPTION_AES256_SIZE + username_len);
                              part_size - buffer_offset,
                              /* in = */ NULL, /* in len = */ 0);
    if (err != 0) {
-     sfree(pea.username);
      ERROR("network plugin: gcry_cipher_decrypt returned: %s. Username: %s",
            gcry_strerror(err), pea.username);
 -    return (-1);
+     sfree(pea.username);
 +    return -1;
    }
  
    /* Read the hash */
    if (memcmp(hash, pea.hash, sizeof(hash)) != 0) {
      ERROR("network plugin: Checksum mismatch. Username: %s", pea.username);
      sfree(pea.username);
 -    return (-1);
 +    return -1;
    }
  
    parse_packet(se, buffer + buffer_offset, payload_len, flags | PP_ENCRYPTED,
                 pea.username);
  
-   /* XXX: Free pea.username?!? */
    /* Update return values */
    *ret_buffer = buffer + part_size;
    *ret_buffer_len = buffer_len - part_size;
  
    sfree(pea.username);
  
 -  return (0);
 +  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) {
    if ((ph_length <= PART_ENCRYPTION_AES256_SIZE) || (ph_length > buffer_size)) {
      ERROR("network plugin: AES-256 encrypted part "
            "with invalid length received.");
 -    return (-1);
 +    return -1;
    }
  
    if (warning_has_been_printed == 0) {
    *ret_buffer = (void *)(((char *)*ret_buffer) + ph_length);
    *ret_buffer_size -= ph_length;
  
 -  return (0);
 +  return 0;
  } /* }}} int parse_part_encr_aes256 */
 -#endif /* !HAVE_LIBGCRYPT */
 +#endif /* !HAVE_GCRYPT_H */
  
  #undef BUFFER_READ
  
@@@ -1320,11 -1318,11 +1318,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;
          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) {
        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) {
          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) {
        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);
      WARNING("network plugin: parse_packet: Received truncated "
              "packet, try increasing `MaxPacketSize'");
  
 -  return (status);
 +  return status;
  } /* }}} int parse_packet */
  
  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)
@@@ -1521,7 -1519,7 +1519,7 @@@ static void free_sockent_server(struct 
    }
  
    sfree(ses->fd);
 -#if HAVE_LIBGCRYPT
 +#if HAVE_GCRYPT_H
    sfree(ses->auth_file);
    fbh_destroy(ses->userdb);
    if (ses->cypher != NULL)
@@@ -1567,7 -1565,7 +1565,7 @@@ static int network_set_ttl(const socken
    assert(se->type == SOCKENT_TYPE_CLIENT);
  
    if ((network_config_ttl < 1) || (network_config_ttl > 255))
 -    return (-1);
 +    return -1;
  
    if (ai->ai_family == AF_INET) {
      struct sockaddr_in *addr = (struct sockaddr_in *)ai->ai_addr;
        char errbuf[1024];
        ERROR("network plugin: setsockopt (ipv4-ttl): %s",
              sstrerror(errno, errbuf, sizeof(errbuf)));
 -      return (-1);
 +      return -1;
      }
    } else if (ai->ai_family == AF_INET6) {
      /* Useful example:
        char errbuf[1024];
        ERROR("network plugin: setsockopt(ipv6-ttl): %s",
              sstrerror(errno, errbuf, sizeof(errbuf)));
 -      return (-1);
 +      return -1;
      }
    }
  
 -  return (0);
 +  return 0;
  } /* int network_set_ttl */
  
  static int network_set_interface(const sockent_t *se,
          char errbuf[1024];
          ERROR("network plugin: setsockopt (ipv4-multicast-if): %s",
                sstrerror(errno, errbuf, sizeof(errbuf)));
 -        return (-1);
 +        return -1;
        }
  
 -      return (0);
 +      return 0;
      }
    } else if (ai->ai_family == AF_INET6) {
      struct sockaddr_in6 *addr = (struct sockaddr_in6 *)ai->ai_addr;
          char errbuf[1024];
          ERROR("network plugin: setsockopt (ipv6-multicast-if): %s",
                sstrerror(errno, errbuf, sizeof(errbuf)));
 -        return (-1);
 +        return -1;
        }
  
 -      return (0);
 +      return 0;
      }
    }
  
      char interface_name[IFNAMSIZ];
  
      if (if_indextoname(se->interface, interface_name) == NULL)
 -      return (-1);
 +      return -1;
  
      DEBUG("network plugin: Binding socket to interface %s", interface_name);
  
        char errbuf[1024];
        ERROR("network plugin: setsockopt (bind-if): %s",
              sstrerror(errno, errbuf, sizeof(errbuf)));
 -      return (-1);
 +      return -1;
      }
  /* #endif HAVE_IF_INDEXTONAME && SO_BINDTODEVICE */
  
  #endif
    }
  
 -  return (0);
 +  return 0;
  } /* }}} network_set_interface */
  
  static int network_bind_socket(int fd, const struct addrinfo *ai,
      char errbuf[1024];
      ERROR("network plugin: setsockopt (reuseaddr): %s",
            sstrerror(errno, errbuf, sizeof(errbuf)));
 -    return (-1);
 +    return -1;
    }
  
    DEBUG("fd = %i; calling `bind'", fd);
    if (bind(fd, ai->ai_addr, ai->ai_addrlen) == -1) {
      char errbuf[1024];
      ERROR("bind: %s", sstrerror(errno, errbuf, sizeof(errbuf)));
 -    return (-1);
 +    return -1;
    }
  
    if (ai->ai_family == AF_INET) {
          char errbuf[1024];
          ERROR("network plugin: setsockopt (multicast-loop): %s",
                sstrerror(errno, errbuf, sizeof(errbuf)));
 -        return (-1);
 +        return -1;
        }
  
        if (setsockopt(fd, IPPROTO_IP, IP_ADD_MEMBERSHIP, &mreq, sizeof(mreq)) ==
          char errbuf[1024];
          ERROR("network plugin: setsockopt (add-membership): %s",
                sstrerror(errno, errbuf, sizeof(errbuf)));
 -        return (-1);
 +        return -1;
        }
  
 -      return (0);
 +      return 0;
      }
    } else if (ai->ai_family == AF_INET6) {
      /* Useful example:
          char errbuf[1024];
          ERROR("network plugin: setsockopt (ipv6-multicast-loop): %s",
                sstrerror(errno, errbuf, sizeof(errbuf)));
 -        return (-1);
 +        return -1;
        }
  
        if (setsockopt(fd, IPPROTO_IPV6, IPV6_ADD_MEMBERSHIP, &mreq,
          char errbuf[1024];
          ERROR("network plugin: setsockopt (ipv6-add-membership): %s",
                sstrerror(errno, errbuf, sizeof(errbuf)));
 -        return (-1);
 +        return -1;
        }
  
 -      return (0);
 +      return 0;
      }
    }
  
      char interface_name[IFNAMSIZ];
  
      if (if_indextoname(interface_idx, interface_name) == NULL)
 -      return (-1);
 +      return -1;
  
      DEBUG("fd = %i; Binding socket to interface %s", fd, interface_name);
  
        char errbuf[1024];
        ERROR("network plugin: setsockopt (bind-if): %s",
              sstrerror(errno, errbuf, sizeof(errbuf)));
 -      return (-1);
 +      return -1;
      }
    }
  #endif /* HAVE_IF_INDEXTONAME && SO_BINDTODEVICE */
  
 -  return (0);
 +  return 0;
  } /* int network_bind_socket */
  
  /* Initialize a sockent structure. `type' must be either `SOCKENT_TYPE_CLIENT'
@@@ -1835,11 -1833,11 +1833,11 @@@ static sockent_t *sockent_create(int ty
    sockent_t *se;
  
    if ((type != SOCKENT_TYPE_CLIENT) && (type != SOCKENT_TYPE_SERVER))
 -    return (NULL);
 +    return NULL;
  
    se = calloc(1, sizeof(*se));
    if (se == NULL)
 -    return (NULL);
 +    return NULL;
  
    se->type = type;
    se->node = NULL;
    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;
      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;
  #endif
    }
  
 -  return (se);
 +  return se;
  } /* }}} sockent_t *sockent_create */
  
  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) {
          ERROR("network plugin: Cannot configure client socket with "
                "security: Failed to initialize crypto library.");
 -        return (-1);
 +        return -1;
        }
  
        if ((se->data.client.username == NULL) ||
          ERROR("network plugin: Client socket with "
                "security requested, but no "
                "credentials are configured.");
 -        return (-1);
 +        return -1;
        }
        gcry_md_hash_buffer(GCRY_MD_SHA256, se->data.client.password_hash,
                            se->data.client.password,
          (se->data.server.auth_file == NULL)) {
        ERROR("network plugin: Server socket with security requested, "
              "but no \"AuthFile\" is configured.");
 -      return (-1);
 +      return -1;
      }
      if (se->data.server.auth_file != NULL) {
        if (network_init_gcrypt() < 0) {
          ERROR("network plugin: Cannot configure server socket with security: "
                "Failed to initialize crypto library.");
 -        return (-1);
 +        return -1;
        }
  
        se->data.server.userdb = fbh_create(se->data.server.auth_file);
        if (se->data.server.userdb == NULL) {
          ERROR("network plugin: Reading password file \"%s\" failed.",
                se->data.server.auth_file);
 -        return (-1);
 +        return -1;
        }
      }
    }
 -#endif /* }}} HAVE_LIBGCRYPT */
 +#endif /* }}} HAVE_GCRYPT_H */
  
 -  return (0);
 +  return 0;
  } /* }}} int sockent_init_crypto */
  
  static int sockent_client_disconnect(sockent_t *se) /* {{{ */
    struct sockent_client *client;
  
    if ((se == NULL) || (se->type != SOCKENT_TYPE_CLIENT))
 -    return (EINVAL);
 +    return EINVAL;
  
    client = &se->data.client;
    if (client->fd >= 0) /* connected */
    sfree(client->addr);
    client->addrlen = 0;
  
 -  return (0);
 +  return 0;
  } /* }}} int sockent_client_disconnect */
  
  static int sockent_client_connect(sockent_t *se) /* {{{ */
    cdtime_t now;
  
    if ((se == NULL) || (se->type != SOCKENT_TYPE_CLIENT))
 -    return (EINVAL);
 +    return EINVAL;
  
    client = &se->data.client;
  
    }
  
    if (client->fd >= 0 && !reconnect) /* already connected and not stale*/
 -    return (0);
 +    return 0;
  
    struct addrinfo ai_hints = {.ai_family = AF_UNSPEC,
                                .ai_flags = AI_ADDRCONFIG,
          LOG_ERR, &complaint, "network plugin: getaddrinfo (%s, %s) failed: %s",
          (se->node == NULL) ? "(null)" : se->node,
          (se->service == NULL) ? "(null)" : se->service, gai_strerror(status));
 -    return (-1);
 +    return -1;
    } else {
      c_release(LOG_NOTICE, &complaint,
                "network plugin: Successfully resolved \"%s\".", se->node);
  
    freeaddrinfo(ai_list);
    if (client->fd < 0)
 -    return (-1);
 +    return -1;
  
    if (client->resolve_interval > 0)
      client->next_resolve_reconnect = now + client->resolve_interval;
 -  return (0);
 +  return 0;
  } /* }}} int sockent_client_connect */
  
  /* Open the file descriptors for a initialized sockent structure. */
@@@ -2041,7 -2039,7 +2039,7 @@@ static int sockent_server_listen(socken
    const char *service;
  
    if (se == NULL)
 -    return (-1);
 +    return -1;
  
    assert(se->data.server.fd == NULL);
    assert(se->data.server.fd_num == 0);
      ERROR("network plugin: getaddrinfo (%s, %s) failed: %s",
            (se->node == NULL) ? "(null)" : se->node,
            (se->service == NULL) ? "(null)" : se->service, gai_strerror(status));
 -    return (-1);
 +    return -1;
    }
  
    for (struct addrinfo *ai_ptr = ai_list; ai_ptr != NULL;
    freeaddrinfo(ai_list);
  
    if (se->data.server.fd_num == 0)
 -    return (-1);
 -  return (0);
 +    return -1;
 +  return 0;
  } /* }}} int sockent_server_listen */
  
  /* Add a sockent to the global list of sockets */
@@@ -2113,7 -2111,7 +2111,7 @@@ static int sockent_add(sockent_t *se) /
    sockent_t *last_ptr;
  
    if (se == NULL)
 -    return (-1);
 +    return -1;
  
    if (se->type == SOCKENT_TYPE_SERVER) {
      struct pollfd *tmp;
                    sizeof(*tmp) * (listen_sockets_num + se->data.server.fd_num));
      if (tmp == NULL) {
        ERROR("network plugin: realloc failed.");
 -      return (-1);
 +      return -1;
      }
      listen_sockets_pollfd = tmp;
      tmp = listen_sockets_pollfd + listen_sockets_num;
  
      if (listen_sockets == NULL) {
        listen_sockets = se;
 -      return (0);
 +      return 0;
      }
      last_ptr = listen_sockets;
    } else /* if (se->type == SOCKENT_TYPE_CLIENT) */
    {
      if (sending_sockets == NULL) {
        sending_sockets = se;
 -      return (0);
 +      return 0;
      }
      last_ptr = sending_sockets;
    }
      last_ptr = last_ptr->next;
    last_ptr->next = se;
  
 -  return (0);
 +  return 0;
  } /* }}} int sockent_add */
  
  static void *dispatch_thread(void __attribute__((unused)) * arg) /* {{{ */
      sfree(ent);
    } /* while (42) */
  
 -  return (NULL);
 +  return NULL;
  } /* }}} void *dispatch_thread */
  
  static int network_receive(void) /* {{{ */
      pthread_mutex_unlock(&receive_list_lock);
    }
  
 -  return (status);
 +  return status;
  } /* }}} int network_receive */
  
  static void *receive_thread(void __attribute__((unused)) * arg) {
 -  return (network_receive() ? (void *)1 : (void *)0);
 +  return network_receive() ? (void *)1 : (void *)0;
  } /* void *receive_thread */
  
  static void network_init_buffer(void) {
@@@ -2379,7 -2377,7 +2377,7 @@@ static void network_send_buffer_plain(s
    } /* 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));                                  \
@@@ -2529,20 -2527,20 +2527,20 @@@ static void network_send_buffer_encrypt
    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 */
@@@ -2555,28 -2553,28 +2553,28 @@@ static int add_to_buffer(char *buffer, 
    if (strcmp(vl_def->host, vl->host) != 0) {
      if (write_part_string(&buffer, &buffer_size, TYPE_HOST, vl->host,
                            strlen(vl->host)) != 0)
 -      return (-1);
 +      return -1;
      sstrncpy(vl_def->host, vl->host, sizeof(vl_def->host));
    }
  
    if (vl_def->time != vl->time) {
      if (write_part_number(&buffer, &buffer_size, TYPE_TIME_HR,
                            (uint64_t)vl->time))
 -      return (-1);
 +      return -1;
      vl_def->time = vl->time;
    }
  
    if (vl_def->interval != vl->interval) {
      if (write_part_number(&buffer, &buffer_size, TYPE_INTERVAL_HR,
                            (uint64_t)vl->interval))
 -      return (-1);
 +      return -1;
      vl_def->interval = vl->interval;
    }
  
    if (strcmp(vl_def->plugin, vl->plugin) != 0) {
      if (write_part_string(&buffer, &buffer_size, TYPE_PLUGIN, vl->plugin,
                            strlen(vl->plugin)) != 0)
 -      return (-1);
 +      return -1;
      sstrncpy(vl_def->plugin, vl->plugin, sizeof(vl_def->plugin));
    }
  
      if (write_part_string(&buffer, &buffer_size, TYPE_PLUGIN_INSTANCE,
                            vl->plugin_instance,
                            strlen(vl->plugin_instance)) != 0)
 -      return (-1);
 +      return -1;
      sstrncpy(vl_def->plugin_instance, vl->plugin_instance,
               sizeof(vl_def->plugin_instance));
    }
    if (strcmp(vl_def->type, vl->type) != 0) {
      if (write_part_string(&buffer, &buffer_size, TYPE_TYPE, vl->type,
                            strlen(vl->type)) != 0)
 -      return (-1);
 +      return -1;
      sstrncpy(vl_def->type, ds->type, sizeof(vl_def->type));
    }
  
    if (strcmp(vl_def->type_instance, vl->type_instance) != 0) {
      if (write_part_string(&buffer, &buffer_size, TYPE_TYPE_INSTANCE,
                            vl->type_instance, strlen(vl->type_instance)) != 0)
 -      return (-1);
 +      return -1;
      sstrncpy(vl_def->type_instance, vl->type_instance,
               sizeof(vl_def->type_instance));
    }
  
    if (write_part_values(&buffer, &buffer_size, ds, vl) != 0)
 -    return (-1);
 +    return -1;
  
 -  return (buffer - buffer_orig);
 +  return buffer - buffer_orig;
  } /* }}} int add_to_buffer */
  
  static void flush_buffer(void) {
@@@ -2645,17 -2643,17 +2643,17 @@@ static int network_write(const data_set
      pthread_mutex_lock(&stats_lock);
      stats_values_not_sent++;
      pthread_mutex_unlock(&stats_lock);
 -    return (0);
 +    return 0;
    }
  
    uc_meta_data_add_unsigned_int(vl, "network:time_sent", (uint64_t)vl->time);
  
    pthread_mutex_lock(&send_buffer_lock);
  
-   status = add_to_buffer(send_buffer_ptr,
-                          network_config_packet_size -
-                              (send_buffer_fill + BUFF_SIG_SIZE),
-                          &send_buffer_vl, ds, vl);
+   status =
+       add_to_buffer(send_buffer_ptr, network_config_packet_size -
+                                          (send_buffer_fill + BUFF_SIG_SIZE),
+                     &send_buffer_vl, ds, vl);
    if (status >= 0) {
      /* status == bytes added to the buffer */
      send_buffer_fill += status;
    } else {
      flush_buffer();
  
-     status = add_to_buffer(send_buffer_ptr,
-                            network_config_packet_size -
-                                (send_buffer_fill + BUFF_SIG_SIZE),
-                            &send_buffer_vl, ds, vl);
+     status =
+         add_to_buffer(send_buffer_ptr, network_config_packet_size -
+                                            (send_buffer_fill + BUFF_SIG_SIZE),
+                       &send_buffer_vl, ds, vl);
  
      if (status >= 0) {
        send_buffer_fill += status;
  
    pthread_mutex_unlock(&send_buffer_lock);
  
 -  return ((status < 0) ? -1 : 0);
 +  return (status < 0) ? -1 : 0;
  } /* int network_write */
  
  static int network_config_set_ttl(const oconfig_item_t *ci) /* {{{ */
    int tmp = 0;
  
    if (cf_util_get_int(ci, &tmp) != 0)
 -    return (-1);
 +    return -1;
    else if ((tmp > 0) && (tmp <= 255))
      network_config_ttl = tmp;
    else {
      WARNING("network plugin: The `TimeToLive' must be between 1 and 255.");
 -    return (-1);
 +    return -1;
    }
  
 -  return (0);
 +  return 0;
  } /* }}} int network_config_set_ttl */
  
  static int network_config_set_interface(const oconfig_item_t *ci, /* {{{ */
    char if_name[256];
  
    if (cf_util_get_string_buffer(ci, if_name, sizeof(if_name)) != 0)
 -    return (-1);
 +    return -1;
  
    *interface = if_nametoindex(if_name);
 -  return (0);
 +  return 0;
  } /* }}} int network_config_set_interface */
  
  static int network_config_set_buffer_size(const oconfig_item_t *ci) /* {{{ */
    int tmp = 0;
  
    if (cf_util_get_int(ci, &tmp) != 0)
 -    return (-1);
 +    return -1;
    else if ((tmp >= 1024) && (tmp <= 65535))
      network_config_packet_size = tmp;
    else {
      WARNING(
          "network plugin: The `MaxPacketSize' must be between 1024 and 65535.");
 -    return (-1);
 +    return -1;
    }
  
 -  return (0);
 +  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;
    if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) {
      WARNING("network plugin: The `SecurityLevel' config option needs exactly "
              "one string argument.");
 -    return (-1);
 +    return -1;
    }
  
    str = ci->values[0].value.string;
      *retval = SECURITY_LEVEL_NONE;
    else {
      WARNING("network plugin: Unknown security level: %s.", str);
 -    return (-1);
 +    return -1;
    }
  
 -  return (0);
 +  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) /* {{{ */
  {
      ERROR("network plugin: The `%s' config option needs "
            "one or two string arguments.",
            ci->key);
 -    return (-1);
 +    return -1;
    }
  
    se = sockent_create(SOCKENT_TYPE_SERVER);
    if (se == NULL) {
      ERROR("network plugin: sockent_create failed.");
 -    return (-1);
 +    return -1;
    }
  
    se->node = strdup(ci->values[0].value.string);
    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 {
      }
    }
  
 -#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 "
            "requested, but no AuthFile option was given. Cowardly refusing to "
            "open this socket!");
      sockent_destroy(se);
 -    return (-1);
 +    return -1;
    }
 -#endif /* HAVE_LIBGCRYPT */
 +#endif /* HAVE_GCRYPT_H */
  
    status = sockent_init_crypto(se);
    if (status != 0) {
      ERROR("network plugin: network_config_add_listen: sockent_init_crypto() "
            "failed.");
      sockent_destroy(se);
 -    return (-1);
 +    return -1;
    }
  
    status = sockent_server_listen(se);
      ERROR("network plugin: network_config_add_listen: sockent_server_listen "
            "failed.");
      sockent_destroy(se);
 -    return (-1);
 +    return -1;
    }
  
    status = sockent_add(se);
    if (status != 0) {
      ERROR("network plugin: network_config_add_listen: sockent_add failed.");
      sockent_destroy(se);
 -    return (-1);
 +    return -1;
    }
  
 -  return (0);
 +  return 0;
  } /* }}} int network_config_add_listen */
  
  static int network_config_add_server(const oconfig_item_t *ci) /* {{{ */
      ERROR("network plugin: The `%s' config option needs "
            "one or two string arguments.",
            ci->key);
 -    return (-1);
 +    return -1;
    }
  
    se = sockent_create(SOCKENT_TYPE_CLIENT);
    if (se == NULL) {
      ERROR("network plugin: sockent_create failed.");
 -    return (-1);
 +    return -1;
    }
  
    se->node = strdup(ci->values[0].value.string);
    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)
      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)
      }
    }
  
 -#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))) {
            "requested, but no Username or Password option was given. "
            "Cowardly refusing to open this socket!");
      sockent_destroy(se);
 -    return (-1);
 +    return -1;
    }
 -#endif /* HAVE_LIBGCRYPT */
 +#endif /* HAVE_GCRYPT_H */
  
    status = sockent_init_crypto(se);
    if (status != 0) {
      ERROR("network plugin: network_config_add_server: sockent_init_crypto() "
            "failed.");
      sockent_destroy(se);
 -    return (-1);
 +    return -1;
    }
  
    /* No call to sockent_client_connect() here -- it is called from
    if (status != 0) {
      ERROR("network plugin: network_config_add_server: sockent_add failed.");
      sockent_destroy(se);
 -    return (-1);
 +    return -1;
    }
  
 -  return (0);
 +  return 0;
  } /* }}} int network_config_add_server */
  
  static int network_config(oconfig_item_t *ci) /* {{{ */
      }
    }
  
 -  return (0);
 +  return 0;
  } /* }}} int network_config */
  
  static int network_notification(const notification_t *n,
    int status;
  
    if (!check_send_notify_okay(n))
 -    return (0);
 +    return 0;
  
    memset(buffer, 0, sizeof(buffer));
  
    status = write_part_number(&buffer_ptr, &buffer_free, TYPE_TIME_HR,
                               (uint64_t)n->time);
    if (status != 0)
 -    return (-1);
 +    return -1;
  
    status = write_part_number(&buffer_ptr, &buffer_free, TYPE_SEVERITY,
                               (uint64_t)n->severity);
    if (status != 0)
 -    return (-1);
 +    return -1;
  
    if (strlen(n->host) > 0) {
      status = write_part_string(&buffer_ptr, &buffer_free, TYPE_HOST, n->host,
                                 strlen(n->host));
      if (status != 0)
 -      return (-1);
 +      return -1;
    }
  
    if (strlen(n->plugin) > 0) {
      status = write_part_string(&buffer_ptr, &buffer_free, TYPE_PLUGIN,
                                 n->plugin, strlen(n->plugin));
      if (status != 0)
 -      return (-1);
 +      return -1;
    }
  
    if (strlen(n->plugin_instance) > 0) {
      status = write_part_string(&buffer_ptr, &buffer_free, TYPE_PLUGIN_INSTANCE,
                                 n->plugin_instance, strlen(n->plugin_instance));
      if (status != 0)
 -      return (-1);
 +      return -1;
    }
  
    if (strlen(n->type) > 0) {
      status = write_part_string(&buffer_ptr, &buffer_free, TYPE_TYPE, n->type,
                                 strlen(n->type));
      if (status != 0)
 -      return (-1);
 +      return -1;
    }
  
    if (strlen(n->type_instance) > 0) {
      status = write_part_string(&buffer_ptr, &buffer_free, TYPE_TYPE_INSTANCE,
                                 n->type_instance, strlen(n->type_instance));
      if (status != 0)
 -      return (-1);
 +      return -1;
    }
  
    status = write_part_string(&buffer_ptr, &buffer_free, TYPE_MESSAGE,
                               n->message, strlen(n->message));
    if (status != 0)
 -    return (-1);
 +    return -1;
  
    network_send_buffer(buffer, sizeof(buffer) - buffer_free);
  
 -  return (0);
 +  return 0;
  } /* int network_notification */
  
  static int network_shutdown(void) {
    plugin_unregister_write("network");
    plugin_unregister_shutdown("network");
  
 -  return (0);
 +  return 0;
  } /* int network_shutdown */
  
  static int network_stats_read(void) /* {{{ */
    vl.type_instance[0] = 0;
    plugin_dispatch_values(&vl);
  
 -  return (0);
 +  return 0;
  } /* }}} int network_stats_read */
  
  static int network_init(void) {
    /* Check if we were already initialized. If so, just return - there's
     * nothing more to do (for now, that is). */
    if (have_init)
 -    return (0);
 +    return 0;
    have_init = 1;
  
    if (network_config_stats)
    send_buffer = malloc(network_config_packet_size);
    if (send_buffer == NULL) {
      ERROR("network plugin: malloc failed.");
 -    return (-1);
 +    return -1;
    }
    network_init_buffer();
  
    /* If no threads need to be started, return here. */
    if ((listen_sockets_num == 0) ||
        ((dispatch_thread_running != 0) && (receive_thread_running != 0)))
 -    return (0);
 +    return 0;
  
    if (dispatch_thread_running == 0) {
      int status;
      }
    }
  
 -  return (0);
 +  return 0;
  } /* int network_init */
  
  /*
@@@ -3211,14 -3209,14 +3209,14 @@@ static int network_flush(cdtime_t timeo
        cdtime_t now = cdtime();
        if ((send_buffer_last_update + timeout) > now) {
          pthread_mutex_unlock(&send_buffer_lock);
 -        return (0);
 +        return 0;
        }
      }
      flush_buffer();
    }
    pthread_mutex_unlock(&send_buffer_lock);
  
 -  return (0);
 +  return 0;
  } /* int network_flush */
  
  void module_register(void) {
    plugin_register_flush("network", network_flush,
                          /* user_data = */ NULL);
  } /* void module_register */
 -
 -/* vim: set fdm=marker : */
diff --combined src/ntpd.c
@@@ -32,6 -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
@@@ -263,11 -266,11 +263,11 @@@ static int ntpd_config(const char *key
      if (ntpd_host != NULL)
        free(ntpd_host);
      if ((ntpd_host = strdup(value)) == NULL)
 -      return (1);
 +      return 1;
    } else if (strcasecmp(key, "Port") == 0) {
      int port = (int)(atof(value));
      if ((port > 0) && (port <= 65535))
 -      ssnprintf(ntpd_port, sizeof(ntpd_port), "%i", port);
 +      snprintf(ntpd_port, sizeof(ntpd_port), "%i", port);
      else
        sstrncpy(ntpd_port, value, sizeof(ntpd_port));
    } else if (strcasecmp(key, "ReverseLookups") == 0) {
      else
        include_unit_id = 0;
    } else {
 -    return (-1);
 +    return -1;
    }
  
 -  return (0);
 +  return 0;
  }
  
  static void ntpd_submit(const char *type, const char *type_inst,
@@@ -319,7 -322,7 +319,7 @@@ static int ntpd_connect(void) 
    int status;
  
    if (sock_descr >= 0)
 -    return (sock_descr);
 +    return sock_descr;
  
    DEBUG("Opening a new socket");
  
      ERROR("ntpd plugin: getaddrinfo (%s, %s): %s", host, port,
            (status == EAI_SYSTEM) ? sstrerror(errno, errbuf, sizeof(errbuf))
                                   : gai_strerror(status));
 -    return (-1);
 +    return -1;
    }
  
    for (struct addrinfo *ai_ptr = ai_list; ai_ptr != NULL;
      ERROR("ntpd plugin: Unable to connect to server.");
    }
  
 -  return (sock_descr);
 +  return sock_descr;
  }
  
  /* For a description of the arguments see `ntpd_do_query' below. */
@@@ -396,7 -399,7 +396,7 @@@ static int ntpd_receive_response(int *r
    ssize_t pkt_padding; /* Padding in this packet */
  
    if ((sd = ntpd_connect()) < 0)
 -    return (-1);
 +    return -1;
  
    items = NULL;
    items_num = 0;
      char errbuf[1024];
      ERROR("ntpd plugin: gettimeofday failed: %s",
            sstrerror(errno, errbuf, sizeof(errbuf)));
 -    return (-1);
 +    return -1;
    }
    time_end.tv_sec++; /* wait for a most one second */
  
        char errbuf[1024];
        ERROR("ntpd plugin: gettimeofday failed: %s",
              sstrerror(errno, errbuf, sizeof(errbuf)));
 -      return (-1);
 +      return -1;
      }
  
      if (timeval_cmp(time_end, time_now, &time_left) <= 0)
        char errbuf[1024];
        ERROR("ntpd plugin: poll failed: %s",
              sstrerror(errno, errbuf, sizeof(errbuf)));
 -      return (-1);
 +      return -1;
      }
  
      if (status == 0) /* timeout */
        DEBUG("Closing socket #%i", sd);
        close(sd);
        sock_descr = sd = -1;
 -      return (-1);
 +      return -1;
      }
  
      DEBUG("recv'd %i bytes", status);
      if (INFO_ERR(res.err_nitems) != 0) {
        ERROR("ntpd plugin: Received error code %i",
              (int)INFO_ERR(res.err_nitems));
 -      return ((int)INFO_ERR(res.err_nitems));
 +      return (int)INFO_ERR(res.err_nitems);
      }
  
      /* extract number of items in this packet and the size of these items */
        done = 1;
    } /* while (done == 0) */
  
 -  return (0);
 +  return 0;
  } /* int ntpd_receive_response */
  
  /* For a description of the arguments see `ntpd_do_query' below. */
@@@ -647,7 -650,7 +647,7 @@@ static int ntpd_send_request(int req_co
    assert(req_size >= 0);
  
    if ((sd = ntpd_connect()) < 0)
 -    return (-1);
 +    return -1;
  
    req.rm_vn_mode = RM_VN_MODE(0, 0, 0);
    req.auth_seq = AUTH_SEQ(0, 0);
      DEBUG("`swrite' failed. Closing socket #%i", sd);
      close(sd);
      sock_descr = sd = -1;
 -    return (status);
 +    return status;
    }
  
 -  return (0);
 +  return 0;
  }
  
  /*
@@@ -701,10 -704,10 +701,10 @@@ static int ntpd_do_query(int req_code, 
  
    status = ntpd_send_request(req_code, req_items, req_size, req_data);
    if (status != 0)
 -    return (status);
 +    return status;
  
    status = ntpd_receive_response(res_items, res_size, res_data, res_item_size);
 -  return (status);
 +  return status;
  }
  
  static double ntpd_read_fp(int32_t val_int) {
    val_int = ntohl(val_int);
    val_double = ((double)val_int) / FP_FRAC;
  
 -  return (val_double);
 +  return val_double;
  }
  
  static uint32_t
@@@ -721,7 -724,7 +721,7 @@@ ntpd_get_refclock_id(struct info_peer_s
    uint32_t addr = ntohl(peer_info->srcadr);
    uint32_t refclock_id = (addr >> 8) & 0x00FF;
  
 -  return (refclock_id);
 +  return refclock_id;
  }
  
  static int ntpd_get_name_from_address(char *buffer, size_t buffer_size,
      ERROR("ntpd plugin: getnameinfo failed: %s",
            (status == EAI_SYSTEM) ? sstrerror(errno, errbuf, sizeof(errbuf))
                                   : gai_strerror(status));
 -    return (-1);
 +    return -1;
    }
  
 -  return (0);
 +  return 0;
  } /* ntpd_get_name_from_address */
  
  static int ntpd_get_name_refclock(char *buffer, size_t buffer_size,
    uint32_t unit_id = ntohl(peer_info->srcadr) & 0x00FF;
  
    if (((size_t)refclock_id) >= refclock_names_num)
 -    return (ntpd_get_name_from_address(buffer, buffer_size, peer_info,
 -                                       /* do_reverse_lookup = */ 0));
 +    return ntpd_get_name_from_address(buffer, buffer_size, peer_info, 0);
  
    if (include_unit_id)
 -    ssnprintf(buffer, buffer_size, "%s-%" PRIu32, refclock_names[refclock_id],
 -              unit_id);
 +    snprintf(buffer, buffer_size, "%s-%" PRIu32, refclock_names[refclock_id],
 +             unit_id);
    else
      sstrncpy(buffer, refclock_names[refclock_id], buffer_size);
  
 -  return (0);
 +  return 0;
  } /* int ntpd_get_name_refclock */
  
  static int ntpd_get_name(char *buffer, size_t buffer_size,
    uint32_t addr = ntohl(peer_info->srcadr);
  
    if (!peer_info->v6_flag && ((addr & REFCLOCK_MASK) == REFCLOCK_ADDR))
 -    return (ntpd_get_name_refclock(buffer, buffer_size, peer_info));
 +    return ntpd_get_name_refclock(buffer, buffer_size, peer_info);
    else
 -    return (ntpd_get_name_from_address(buffer, buffer_size, peer_info,
 -                                       do_reverse_lookups));
 +    return ntpd_get_name_from_address(buffer, buffer_size, peer_info,
 +                                      do_reverse_lookups);
  } /* int ntpd_addr_to_name */
  
  static int ntpd_read(void) {
    if (status != 0) {
      ERROR("ntpd plugin: ntpd_do_query (REQ_GET_KERNEL) failed with status %i",
            status);
 -    return (status);
 +    return status;
    } else if ((ik == NULL) || (ik_num == 0) || (ik_size == 0)) {
      ERROR("ntpd plugin: ntpd_do_query returned unexpected data. "
            "(ik = %p; ik_num = %i; ik_size = %i)",
            (void *)ik, ik_num, ik_size);
 -    return (-1);
 +    return -1;
    }
  
    if (ntohs(ik->status) & STA_NANO) {
    }
  
    /* kerninfo -> estimated error */
-   offset_loop = scale_loop * ((gauge_t)ntohl(ik->offset));
+   offset_loop = (gauge_t)((int32_t)ntohl(ik->offset) * scale_loop);
    freq_loop = ntpd_read_fp(ik->freq);
-   offset_error = scale_error * ((gauge_t)ntohl(ik->esterror));
+   offset_error = (gauge_t)((int32_t)ntohl(ik->esterror) * scale_error);
  
    DEBUG("info_kernel:\n"
          "  pll offset    = %.8g\n"
      ERROR(
          "ntpd plugin: ntpd_do_query (REQ_PEER_LIST_SUM) failed with status %i",
          status);
 -    return (status);
 +    return status;
    } else if ((ps == NULL) || (ps_num == 0) || (ps_size == 0)) {
      ERROR("ntpd plugin: ntpd_do_query returned unexpected data. "
            "(ps = %p; ps_num = %i; ps_size = %i)",
            (void *)ps, ps_num, ps_size);
 -    return (-1);
 +    return -1;
    }
  
    for (int i = 0; i < ps_num; i++) {
    free(ps);
    ps = NULL;
  
 -  return (0);
 +  return 0;
  } /* int ntpd_read */
  
  void module_register(void) {
diff --combined src/perl.c
@@@ -38,7 -38,9 +38,7 @@@
  
  #undef DONT_POISON_SPRINTF_YET
  
 -#if HAVE_STDBOOL_H
  #include <stdbool.h>
 -#endif
  
  #include <EXTERN.h>
  #include <perl.h>
@@@ -424,6 -426,8 +424,6 @@@ static int hv2value_list(pTHX_ HV *hash
  
    if (NULL != (tmp = hv_fetch(hash, "host", 4, 0)))
      sstrncpy(vl->host, SvPV_nolen(*tmp), sizeof(vl->host));
 -  else
 -    sstrncpy(vl->host, hostname_g, sizeof(vl->host));
  
    if (NULL != (tmp = hv_fetch(hash, "plugin", 6, 0)))
      sstrncpy(vl->plugin, SvPV_nolen(*tmp), sizeof(vl->plugin));
@@@ -492,8 -496,7 +492,8 @@@ static int av2data_set(pTHX_ AV *array
   *   meta     => [ { name => <name>, value => <value> }, ... ]
   * }
   */
 -static int av2notification_meta(pTHX_ AV *array, notification_meta_t **ret_meta) {
 +static int av2notification_meta(pTHX_ AV *array,
 +                                notification_meta_t **ret_meta) {
    notification_meta_t *tail = NULL;
  
    int len = av_len(array);
@@@ -880,12 -883,12 +880,12 @@@ static int oconfig_item2hv(pTHX_ oconfi
  static char *get_module_name(char *buf, size_t buf_len, const char *module) {
    int status = 0;
    if (base_name[0] == '\0')
 -    status = ssnprintf(buf, buf_len, "%s", module);
 +    status = snprintf(buf, buf_len, "%s", module);
    else
 -    status = ssnprintf(buf, buf_len, "%s::%s", base_name, module);
 +    status = snprintf(buf, buf_len, "%s::%s", base_name, module);
    if ((status < 0) || ((unsigned int)status >= buf_len))
 -    return (NULL);
 -  return (buf);
 +    return NULL;
 +  return buf;
  } /* char *get_module_name */
  
  /*
@@@ -1624,19 -1627,18 +1624,19 @@@ static void _plugin_register_generic_us
        ret = plugin_register_flush("perl", perl_flush, /* user_data = */ NULL);
      }
  
 -    if (0 == ret)
 +    if (0 == ret) {
        ret = plugin_register_flush(pluginname, perl_flush, &userdata);
 +    } else {
 +      free(userdata.data);
 +    }
    } else {
      ret = -1;
    }
  
    if (0 == ret)
      XSRETURN_YES;
 -  else {
 -    free(userdata.data);
 +  else
      XSRETURN_EMPTY;
 -  }
  } /* static void _plugin_register_generic_userdata ( ... ) */
  
  /*
@@@ -2497,7 -2499,7 +2497,7 @@@ static int perl_config_loadplugin(pTHX
  
    if (NULL == get_module_name(module_name, sizeof(module_name), value)) {
      log_err("Invalid module name %s", value);
 -    return (1);
 +    return 1;
    }
  
    if (0 != init_pi(perl_argc, perl_argv))
@@@ -2616,6 -2618,12 +2616,12 @@@ static int perl_config_plugin(pTHX_ oco
    char *plugin;
    HV *config;
  
+   if (NULL == perl_threads) {
+     log_err("A `Plugin' block was encountered but no plugin was loaded yet. "
+             "Put the appropriate `LoadPlugin' option in front of it.");
+     return -1;
+   }
    dSP;
  
    if ((1 != ci->values_num) || (OCONFIG_TYPE_STRING != ci->values[0].type)) {
@@@ -2717,3 -2725,5 +2723,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 : */