Merge branch 'collectd-5.7'
authorFlorian Forster <octo@collectd.org>
Thu, 22 Dec 2016 09:57:57 +0000 (10:57 +0100)
committerFlorian Forster <octo@collectd.org>
Thu, 22 Dec 2016 09:57:57 +0000 (10:57 +0100)
1  2 
src/daemon/common.c
src/daemon/configfile.c
src/netapp.c

diff --combined src/daemon/common.c
  #include "plugin.h"
  #include "utils_cache.h"
  
 -#ifdef HAVE_MATH_H
 -#include <math.h>
 -#endif
 -
  /* for getaddrinfo */
  #include <netdb.h>
  #include <sys/types.h>
@@@ -267,8 -271,10 +267,10 @@@ ssize_t swrite(int fd, const void *buf
    ptr = (const char *)buf;
    nleft = count;
  
-   if (fd < 0)
-     return (-1);
+   if (fd < 0) {
+     errno = EINVAL;
+     return errno;
+   }
  
    /* checking for closed peer connection */
    pfd.fd = fd;
    if (poll(&pfd, 1, 0) > 0) {
      char buffer[32];
      if (recv(fd, buffer, sizeof(buffer), MSG_PEEK | MSG_DONTWAIT) == 0) {
-       // if recv returns zero (even though poll() said there is data to be
-       // read),
-       // that means the connection has been closed
-       return -1;
+       /* if recv returns zero (even though poll() said there is data to be
+        * read), that means the connection has been closed */
+       return errno ? errno : -1;
      }
    }
  
        continue;
  
      if (status < 0)
-       return (status);
+       return errno ? errno : status;
  
      nleft = nleft - ((size_t)status);
      ptr = ptr + ((size_t)status);
diff --combined src/daemon/configfile.c
@@@ -245,7 -245,7 +245,7 @@@ static int dispatch_value_plugindir(oco
  
  static int dispatch_loadplugin(oconfig_item_t *ci) {
    const char *name;
 -  unsigned int flags = 0;
 +  _Bool global = 0;
    plugin_ctx_t ctx = {0};
    plugin_ctx_t old_ctx;
    int ret_val;
      oconfig_item_t *child = ci->children + i;
  
      if (strcasecmp("Globals", child->key) == 0)
 -      cf_util_get_flag(child, &flags, PLUGIN_FLAGS_GLOBAL);
 +      cf_util_get_boolean(child, &global);
      else if (strcasecmp("Interval", child->key) == 0)
        cf_util_get_cdtime(child, &ctx.interval);
      else if (strcasecmp("FlushInterval", child->key) == 0)
    }
  
    old_ctx = plugin_set_ctx(ctx);
 -  ret_val = plugin_load(name, (uint32_t)flags);
 +  ret_val = plugin_load(name, global);
    /* reset to the "global" context */
    plugin_set_ctx(old_ctx);
  
@@@ -1119,14 -1119,36 +1119,36 @@@ int cf_util_get_boolean(const oconfig_i
    if ((ci == NULL) || (ret_bool == NULL))
      return (EINVAL);
  
-   if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_BOOLEAN)) {
+   if ((ci->values_num != 1) || ((ci->values[0].type != OCONFIG_TYPE_BOOLEAN) &&
+                                 (ci->values[0].type != OCONFIG_TYPE_STRING))) {
      ERROR("cf_util_get_boolean: The %s option requires "
            "exactly one boolean argument.",
            ci->key);
      return (-1);
    }
  
-   *ret_bool = ci->values[0].value.boolean ? 1 : 0;
+   switch (ci->values[0].type) {
+   case OCONFIG_TYPE_BOOLEAN:
+     *ret_bool = ci->values[0].value.boolean ? 1 : 0;
+     break;
+   case OCONFIG_TYPE_STRING:
+     WARNING("cf_util_get_boolean: Using string value `%s' for boolean option "
+             "`%s' is deprecated and will be removed in future releases. "
+             "Use unquoted true or false instead.",
+             ci->values[0].value.string, ci->key);
+     if (IS_TRUE(ci->values[0].value.string))
+       *ret_bool = 1;
+     else if (IS_FALSE(ci->values[0].value.string))
+       *ret_bool = 0;
+     else {
+       ERROR("cf_util_get_boolean: Cannot parse string value `%s' of the `%s' "
+             "option as a boolean value.",
+             ci->values[0].value.string, ci->key);
+       return (-1);
+     }
+     break;
+   }
  
    return (0);
  } /* }}} int cf_util_get_boolean */
diff --combined src/netapp.c
@@@ -674,7 -674,7 +674,7 @@@ static int submit_double(const char *ho
                           const char *type, const char *type_inst, double d,
                           cdtime_t timestamp, cdtime_t interval) {
    return (submit_values(host, plugin_inst, type, type_inst,
-                         &(value_t){.gauge = counter}, 1, timestamp, interval));
+                         &(value_t){.gauge = d}, 1, timestamp, interval));
  } /* }}} int submit_uint64 */
  
  /* Calculate hit ratio from old and new counters and submit the resulting
@@@ -1910,15 -1910,13 +1910,13 @@@ static int cna_query_quota(host_config_
  static int cna_handle_snapvault_data(const char *hostname, /* {{{ */
                                       cfg_snapvault_t *cfg_snapvault,
                                       na_elem_t *data, cdtime_t interval) {
-   na_elem_iter_t status_iter;
-   status = na_elem_child(data, "status-list");
-   if (!status) {
+   na_elem_t *status_list = na_elem_child(data, "status-list");
+   if (status_list == NULL) {
      ERROR("netapp plugin: SnapVault status record missing status-list");
      return (0);
    }
  
-   status_iter = na_child_iterator(status);
+   na_elem_iter_t status_iter = na_child_iterator(status_list);
    for (na_elem_t *status = na_iterator_next(&status_iter); status != NULL;
         status = na_iterator_next(&status_iter)) {
      const char *dest_sys, *dest_path, *src_sys, *src_path;
@@@ -3111,3 -3109,5 +3109,3 @@@ void module_register(void) 
    plugin_register_init("netapp", cna_init);
    plugin_register_shutdown("netapp", cna_shutdown);
  }
 -
 -/* vim: set sw=2 ts=2 noet fdm=marker : */