Merge branch 'collectd-5.7' into collectd-5.8
authorFlorian Forster <octo@collectd.org>
Sun, 10 Feb 2019 20:44:20 +0000 (21:44 +0100)
committerFlorian Forster <octo@collectd.org>
Sun, 10 Feb 2019 20:44:20 +0000 (21:44 +0100)
1  2 
src/daemon/common.c
src/daemon/common_test.c
src/log_logstash.c
src/write_prometheus.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>
  #include <sys/capability.h>
  #endif
  
 +#if HAVE_KSTAT_H
 +#include <kstat.h>
 +#endif
 +
  #ifdef HAVE_LIBKSTAT
  extern kstat_ctl_t *kc;
  #endif
@@@ -85,9 -85,21 +85,9 @@@ char *sstrncpy(char *dest, const char *
    strncpy(dest, src, n);
    dest[n - 1] = '\0';
  
 -  return (dest);
 +  return dest;
  } /* char *sstrncpy */
  
 -int ssnprintf(char *dest, size_t n, const char *format, ...) {
 -  int ret = 0;
 -  va_list ap;
 -
 -  va_start(ap, format);
 -  ret = vsnprintf(dest, n, format, ap);
 -  dest[n - 1] = '\0';
 -  va_end(ap);
 -
 -  return (ret);
 -} /* int ssnprintf */
 -
  char *ssnprintf_alloc(char const *format, ...) /* {{{ */
  {
    char static_buffer[1024] = "";
    status = vsnprintf(static_buffer, sizeof(static_buffer), format, ap);
    va_end(ap);
    if (status < 0)
 -    return (NULL);
 +    return NULL;
  
    /* "status" does not include the null byte. */
    alloc_buffer_size = (size_t)(status + 1);
    if (alloc_buffer_size <= sizeof(static_buffer))
 -    return (strdup(static_buffer));
 +    return strdup(static_buffer);
  
    /* Allocate a buffer large enough to hold the string. */
    alloc_buffer = calloc(1, alloc_buffer_size);
    if (alloc_buffer == NULL)
 -    return (NULL);
 +    return NULL;
  
    /* Print again into this new buffer. */
    va_start(ap, format);
    va_end(ap);
    if (status < 0) {
      sfree(alloc_buffer);
 -    return (NULL);
 +    return NULL;
    }
  
 -  return (alloc_buffer);
 +  return alloc_buffer;
  } /* }}} char *ssnprintf_alloc */
  
  char *sstrdup(const char *s) {
    size_t sz;
  
    if (s == NULL)
 -    return (NULL);
 +    return NULL;
  
    /* Do not use `strdup' here, because it's not specified in POSIX. It's
     * ``only'' an XSI extension. */
      ERROR("sstrdup: Out of memory.");
      exit(3);
    }
 -  memcpy(r, s, sizeof(char) * sz);
 +  memcpy(r, s, sz);
  
 -  return (r);
 +  return r;
  } /* char *sstrdup */
  
  /* Even though Posix requires "strerror_r" to return an "int",
@@@ -183,13 -195,13 +183,13 @@@ char *sstrerror(int errnum, char *buf, 
  
  #else
    if (strerror_r(errnum, buf, buflen) != 0) {
 -    ssnprintf(buf, buflen, "Error #%i; "
 -                           "Additionally, strerror_r failed.",
 -              errnum);
 +    snprintf(buf, buflen, "Error #%i; "
 +                          "Additionally, strerror_r failed.",
 +             errnum);
    }
  #endif /* STRERROR_R_CHAR_P */
  
 -  return (buf);
 +  return buf;
  } /* char *sstrerror */
  
  void *smalloc(size_t size) {
      exit(3);
    }
  
 -  return (r);
 +  return r;
  } /* void *smalloc */
  
  #if 0
@@@ -216,7 -228,7 +216,7 @@@ void sfree (void **ptr
  }
  #endif
  
 -ssize_t sread(int fd, void *buf, size_t count) {
 +int sread(int fd, void *buf, size_t count) {
    char *ptr;
    size_t nleft;
    ssize_t status;
        continue;
  
      if (status < 0)
 -      return (status);
 +      return status;
  
      if (status == 0) {
 -      DEBUG("Received EOF from fd %i. "
 -            "Closing fd and returning error.",
 -            fd);
 -      close(fd);
 -      return (-1);
 +      DEBUG("Received EOF from fd %i. ", fd);
 +      return -1;
      }
  
      assert((0 > status) || (nleft >= (size_t)status));
      ptr = ptr + ((size_t)status);
    }
  
 -  return (0);
 +  return 0;
  }
  
 -ssize_t swrite(int fd, const void *buf, size_t count) {
 +int swrite(int fd, const void *buf, size_t count) {
    const char *ptr;
    size_t nleft;
    ssize_t status;
      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 errno ? errno : -1;
 +      errno = ECONNRESET;
 +      return -1;
      }
    }
  
      ptr = ptr + ((size_t)status);
    }
  
 -  return (0);
 +  return 0;
  }
  
  int strsplit(char *string, char **fields, size_t size) {
        break;
    }
  
 -  return ((int)i);
 +  return (int)i;
  }
  
  int strjoin(char *buffer, size_t buffer_size, char **fields, size_t fields_num,
  
    if (((fields_num != 0) && (fields == NULL)) ||
        ((buffer_size != 0) && (buffer == NULL)))
 -    return (-EINVAL);
 +    return -EINVAL;
  
    if (buffer != NULL)
      buffer[0] = 0;
        buffer_req += sep_len;
      buffer_req += field_len;
  
+     if (buffer_size == 0)
+       continue;
      if ((i != 0) && (sep_len > 0)) {
        if (sep_len >= avail) {
          /* prevent subsequent iterations from writing to the
@@@ -373,14 -390,14 +376,14 @@@ int escape_string(char *buffer, size_t 
    /* Check if we need to escape at all first */
    temp = strpbrk(buffer, " \t\"\\");
    if (temp == NULL)
 -    return (0);
 +    return 0;
  
    if (buffer_size < 3)
 -    return (EINVAL);
 +    return EINVAL;
  
    temp = calloc(1, buffer_size);
    if (temp == NULL)
 -    return (ENOMEM);
 +    return ENOMEM;
  
    temp[0] = '"';
    j = 1;
  
    sstrncpy(buffer, temp, buffer_size);
    sfree(temp);
 -  return (0);
 +  return 0;
  } /* int escape_string */
  
  int strunescape(char *buf, size_t buf_len) {
        ERROR("string unescape: backslash found at end of string.");
        /* Ensure null-byte at the end of the buffer. */
        buf[i] = 0;
 -      return (-1);
 +      return -1;
      }
  
      switch (buf[i + 1]) {
      memmove(buf + i + 1, buf + i + 2, buf_len - i - 2);
      buf[buf_len - 1] = 0;
    }
 -  return (0);
 +  return 0;
  } /* int strunescape */
  
  size_t strstripnewline(char *buffer) {
      buffer[buffer_len] = 0;
    }
  
 -  return (buffer_len);
 +  return buffer_len;
  } /* size_t strstripnewline */
  
  int escape_slashes(char *buffer, size_t buffer_size) {
    if (buffer_len <= 1) {
      if (strcmp("/", buffer) == 0) {
        if (buffer_size < 5)
 -        return (-1);
 +        return -1;
        sstrncpy(buffer, "root", buffer_size);
      }
 -    return (0);
 +    return 0;
    }
  
    /* Move one to the left */
        buffer[i] = '_';
    }
  
 -  return (0);
 +  return 0;
  } /* int escape_slashes */
  
  void replace_special(char *buffer, size_t buffer_size) {
@@@ -510,7 -527,7 +513,7 @@@ int timeval_cmp(struct timeval tv0, str
        delta->tv_sec = 0;
        delta->tv_usec = 0;
      }
 -    return (0);
 +    return 0;
    }
  
    if ((tv0.tv_sec < tv1.tv_sec) ||
    assert((delta == NULL) ||
           ((0 <= delta->tv_usec) && (delta->tv_usec < 1000000)));
  
 -  return (status);
 +  return status;
  } /* int timeval_cmp */
  
  int check_create_dir(const char *file_orig) {
     * Sanity checks first
     */
    if (file_orig == NULL)
 -    return (-1);
 +    return -1;
  
    if ((len = strlen(file_orig)) < 1)
 -    return (-1);
 +    return -1;
    else if (len >= sizeof(file_copy))
 -    return (-1);
 +    return -1;
  
    /*
     * If `file_orig' ends in a slash the last component is a directory,
        ERROR("Cowardly refusing to create a directory that "
              "begins with a `.' (dot): `%s'",
              file_orig);
 -      return (-2);
 +      return -2;
      }
  
      /*
      if (strjoin(dir + path_is_absolute, (size_t)(dir_len - path_is_absolute),
                  fields, (size_t)(i + 1), "/") < 0) {
        ERROR("strjoin failed: `%s', component #%i", file_orig, i);
 -      return (-1);
 +      return -1;
      }
  
      while (42) {
            char errbuf[1024];
            ERROR("check_create_dir: mkdir (%s): %s", dir,
                  sstrerror(errno, errbuf, sizeof(errbuf)));
 -          return (-1);
 +          return -1;
          } else {
            char errbuf[1024];
            ERROR("check_create_dir: stat (%s): %s", dir,
                  sstrerror(errno, errbuf, sizeof(errbuf)));
 -          return (-1);
 +          return -1;
          }
        } else if (!S_ISDIR(statbuf.st_mode)) {
          ERROR("check_create_dir: `%s' exists but is not "
                "a directory!",
                dir);
 -        return (-1);
 +        return -1;
        }
        break;
      }
    }
  
 -  return (0);
 +  return 0;
  } /* check_create_dir */
  
  #ifdef HAVE_LIBKSTAT
@@@ -663,20 -680,20 +666,20 @@@ int get_kstat(kstat_t **ksp_ptr, char *
    *ksp_ptr = NULL;
  
    if (kc == NULL)
 -    return (-1);
 +    return -1;
  
 -  ssnprintf(ident, sizeof(ident), "%s,%i,%s", module, instance, name);
 +  snprintf(ident, sizeof(ident), "%s,%i,%s", module, instance, name);
  
    *ksp_ptr = kstat_lookup(kc, module, instance, name);
    if (*ksp_ptr == NULL) {
      ERROR("get_kstat: Cound not find kstat %s", ident);
 -    return (-1);
 +    return -1;
    }
  
    if ((*ksp_ptr)->ks_type != KSTAT_TYPE_NAMED) {
      ERROR("get_kstat: kstat %s has wrong type", ident);
      *ksp_ptr = NULL;
 -    return (-1);
 +    return -1;
    }
  
  #ifdef assert
  
    if (kstat_read(kc, *ksp_ptr, NULL) == -1) {
      ERROR("get_kstat: kstat %s could not be read", ident);
 -    return (-1);
 +    return -1;
    }
  
    if ((*ksp_ptr)->ks_type != KSTAT_TYPE_NAMED) {
      ERROR("get_kstat: kstat %s has wrong type", ident);
 -    return (-1);
 +    return -1;
    }
  
 -  return (0);
 +  return 0;
  }
  
  long long get_kstat_value(kstat_t *ksp, char *name) {
  
    if (ksp == NULL) {
      ERROR("get_kstat_value (\"%s\"): ksp is NULL.", name);
 -    return (-1LL);
 +    return -1LL;
    } else if (ksp->ks_type != KSTAT_TYPE_NAMED) {
      ERROR("get_kstat_value (\"%s\"): ksp->ks_type (%#x) "
            "is not KSTAT_TYPE_NAMED (%#x).",
            name, (unsigned int)ksp->ks_type, (unsigned int)KSTAT_TYPE_NAMED);
 -    return (-1LL);
 +    return -1LL;
    }
  
    if ((kn = (kstat_named_t *)kstat_data_lookup(ksp, name)) == NULL)
 -    return (-1LL);
 +    return -1LL;
  
    if (kn->data_type == KSTAT_DATA_INT32)
      retval = (long long)kn->value.i32;
    else
      WARNING("get_kstat_value: Not a numeric value: %s", name);
  
 -  return (retval);
 +  return retval;
  }
  #endif /* HAVE_LIBKSTAT */
  
  #ifndef HAVE_HTONLL
  unsigned long long ntohll(unsigned long long n) {
  #if BYTE_ORDER == BIG_ENDIAN
 -  return (n);
 +  return n;
  #else
    return (((unsigned long long)ntohl(n)) << 32) + ntohl(n >> 32);
  #endif
  
  unsigned long long htonll(unsigned long long n) {
  #if BYTE_ORDER == BIG_ENDIAN
 -  return (n);
 +  return n;
  #else
    return (((unsigned long long)htonl(n)) << 32) + htonl(n >> 32);
  #endif
@@@ -783,13 -800,13 +786,13 @@@ double ntohd(double d) 
    if ((ret.byte[0] == 0x00) && (ret.byte[1] == 0x00) && (ret.byte[2] == 0x00) &&
        (ret.byte[3] == 0x00) && (ret.byte[4] == 0x00) && (ret.byte[5] == 0x00) &&
        (ret.byte[6] == 0xf8) && (ret.byte[7] == 0x7f)) {
 -    return (NAN);
 +    return NAN;
    } else {
      uint64_t tmp;
  
      tmp = ret.integer;
      ret.integer = FP_CONVERT(tmp);
 -    return (ret.floating);
 +    return ret.floating;
    }
  } /* double ntohd */
  
@@@ -805,14 -822,14 +808,14 @@@ double htond(double d) 
      ret.byte[4] = ret.byte[5] = 0x00;
      ret.byte[6] = 0xf8;
      ret.byte[7] = 0x7f;
 -    return (ret.floating);
 +    return ret.floating;
    } else {
      uint64_t tmp;
  
      ret.floating = d;
      tmp = FP_CONVERT(ret.integer);
      ret.integer = tmp;
 -    return (ret.floating);
 +    return ret.floating;
    }
  } /* double htond */
  #endif /* FP_LAYOUT_NEED_ENDIANFLIP || FP_LAYOUT_NEED_INTSWAP */
@@@ -830,7 -847,7 +833,7 @@@ int format_name(char *ret, int ret_len
    do {                                                                         \
      size_t l = strlen(str);                                                    \
      if (l >= buffer_size)                                                      \
 -      return (ENOBUFS);                                                        \
 +      return ENOBUFS;                                                          \
      memcpy(buffer, (str), l);                                                  \
      buffer += l;                                                               \
      buffer_size -= l;                                                          \
    buffer[0] = 0;
  
  #undef APPEND
 -  return (0);
 +  return 0;
  } /* int format_name */
  
  int format_values(char *ret, size_t ret_len, /* {{{ */
  
  #define BUFFER_ADD(...)                                                        \
    do {                                                                         \
 -    status = ssnprintf(ret + offset, ret_len - offset, __VA_ARGS__);           \
 +    status = snprintf(ret + offset, ret_len - offset, __VA_ARGS__);            \
      if (status < 1) {                                                          \
        sfree(rates);                                                            \
 -      return (-1);                                                             \
 +      return -1;                                                               \
      } else if (((size_t)status) >= (ret_len - offset)) {                       \
        sfree(rates);                                                            \
 -      return (-1);                                                             \
 +      return -1;                                                               \
      } else                                                                     \
        offset += ((size_t)status);                                              \
    } while (0)
          rates = uc_get_rate(ds, vl);
        if (rates == NULL) {
          WARNING("format_values: uc_get_rate failed.");
 -        return (-1);
 +        return -1;
        }
        BUFFER_ADD(":" GAUGE_FORMAT, rates[i]);
      } else if (ds->ds[i].type == DS_TYPE_COUNTER)
      else {
        ERROR("format_values: Unknown data source type: %i", ds->ds[i].type);
        sfree(rates);
 -      return (-1);
 +      return -1;
      }
    } /* for ds->ds_num */
  
  #undef BUFFER_ADD
  
    sfree(rates);
 -  return (0);
 +  return 0;
  } /* }}} int format_values */
  
  int parse_identifier(char *str, char **ret_host, char **ret_plugin,
  
    hostname = str;
    if (hostname == NULL)
 -    return (-1);
 +    return -1;
  
    plugin = strchr(hostname, '/');
    if (plugin == NULL)
 -    return (-1);
 +    return -1;
    *plugin = '\0';
    plugin++;
  
    type = strchr(plugin, '/');
    if (type == NULL) {
      if (default_host == NULL)
 -      return (-1);
 +      return -1;
      /* else: no host specified; use default */
      type = plugin;
      plugin = hostname;
    *ret_plugin_instance = plugin_instance;
    *ret_type = type;
    *ret_type_instance = type_instance;
 -  return (0);
 +  return 0;
  } /* int parse_identifier */
  
  int parse_identifier_vl(const char *str, value_list_t *vl) /* {{{ */
    int status;
  
    if ((str == NULL) || (vl == NULL))
 -    return (EINVAL);
 +    return EINVAL;
  
    sstrncpy(str_copy, str, sizeof(str_copy));
  
                              &type_instance,
                              /* default_host = */ NULL);
    if (status != 0)
 -    return (status);
 +    return status;
  
    sstrncpy(vl->host, host, sizeof(vl->host));
    sstrncpy(vl->plugin, plugin, sizeof(vl->plugin));
    sstrncpy(vl->type_instance, (type_instance != NULL) ? type_instance : "",
             sizeof(vl->type_instance));
  
 -  return (0);
 +  return 0;
  } /* }}} int parse_identifier_vl */
  
  int parse_value(const char *value_orig, value_t *ret_value, int ds_type) {
    size_t value_len;
  
    if (value_orig == NULL)
 -    return (EINVAL);
 +    return EINVAL;
  
    value = strdup(value_orig);
    if (value == NULL)
 -    return (ENOMEM);
 +    return ENOMEM;
    value_len = strlen(value);
  
    while ((value_len > 0) && isspace((int)value[value_len - 1])) {
@@@ -1090,7 -1107,7 +1093,7 @@@ int parse_values(char *buffer, value_li
              || (endptr == ptr)  /* Invalid string */
              || (endptr == NULL) /* This should not happen */
              || (*endptr != 0))  /* Trailing chars */
 -          return (-1);
 +          return -1;
  
          vl->time = DOUBLE_TO_CDTIME_T(tmp);
        }
    } /* while (strtok_r) */
  
    if ((ptr != NULL) || (i == 0))
 -    return (-1);
 -  return (0);
 +    return -1;
 +  return 0;
  } /* int parse_values */
  
  int parse_value_file(char const *path, value_t *ret_value, int ds_type) {
  
    fh = fopen(path, "r");
    if (fh == NULL)
 -    return (-1);
 +    return -1;
  
    if (fgets(buffer, sizeof(buffer), fh) == NULL) {
      fclose(fh);
 -    return (-1);
 +    return -1;
    }
  
    fclose(fh);
@@@ -1175,7 -1192,7 +1178,7 @@@ int getpwnam_r(const char *name, struc
  
    pthread_mutex_unlock(&getpwnam_r_lock);
  
 -  return (status);
 +  return status;
  } /* int getpwnam_r */
  #endif /* !HAVE_GETPWNAM_R */
  
@@@ -1200,7 -1217,7 +1203,7 @@@ int notification_init(notification_t *n
    if (type_instance != NULL)
      sstrncpy(n->type_instance, type_instance, sizeof(n->type_instance));
  
 -  return (0);
 +  return 0;
  } /* int notification_init */
  
  int walk_directory(const char *dir, dirwalk_callback_f callback,
    closedir(dh);
  
    if ((success == 0) && (failure > 0))
 -    return (-1);
 -  return (0);
 +    return -1;
 +  return 0;
  }
  
  ssize_t read_file_contents(const char *filename, char *buf, size_t bufsize) {
  
    fh = fopen(filename, "r");
    if (fh == NULL)
 -    return (-1);
 +    return -1;
  
    ret = (ssize_t)fread(buf, 1, bufsize, fh);
    if ((ret == 0) && (ferror(fh) != 0)) {
    }
  
    fclose(fh);
 -  return (ret);
 +  return ret;
  }
  
  counter_t counter_diff(counter_t old_value, counter_t new_value) {
      diff = new_value - old_value;
    }
  
 -  return (diff);
 +  return diff;
  } /* counter_t counter_diff */
  
  int rate_to_value(value_t *ret_value, gauge_t rate, /* {{{ */
      state->last_time = t;
  
      *ret_value = state->last_value;
 -    return (0);
 +    return 0;
    }
  
    /* Counter and absolute can't handle negative rates. Reset "last time"
    if ((rate < 0.0) &&
        ((ds_type == DS_TYPE_COUNTER) || (ds_type == DS_TYPE_ABSOLUTE))) {
      memset(state, 0, sizeof(*state));
 -    return (EINVAL);
 +    return EINVAL;
    }
  
    /* Another invalid state: The time is not increasing. */
    if (t <= state->last_time) {
      memset(state, 0, sizeof(*state));
 -    return (EINVAL);
 +    return EINVAL;
    }
  
    delta_t = t - state->last_time;
      }
  
      state->last_time = t;
 -    return (EAGAIN);
 +    return EAGAIN;
    } /* }}} */
  
    if (ds_type == DS_TYPE_DERIVE) {
  
    state->last_time = t;
    *ret_value = state->last_value;
 -  return (0);
 +  return 0;
  } /* }}} value_t rate_to_value */
  
  int value_to_rate(gauge_t *ret_rate, /* {{{ */
    /* Another invalid state: The time is not increasing. */
    if (t <= state->last_time) {
      memset(state, 0, sizeof(*state));
 -    return (EINVAL);
 +    return EINVAL;
    }
  
    interval = CDTIME_T_TO_DOUBLE(t - state->last_time);
    if (state->last_time == 0) {
      state->last_value = value;
      state->last_time = t;
 -    return (EAGAIN);
 +    return EAGAIN;
    }
  
    switch (ds_type) {
  
    state->last_value = value;
    state->last_time = t;
 -  return (0);
 +  return 0;
  } /* }}} value_t rate_to_value */
  
  int service_name_to_port_number(const char *service_name) {
    int service_number;
  
    if (service_name == NULL)
 -    return (-1);
 +    return -1;
  
    struct addrinfo ai_hints = {.ai_family = AF_UNSPEC};
  
    if (status != 0) {
      ERROR("service_name_to_port_number: getaddrinfo failed: %s",
            gai_strerror(status));
 -    return (-1);
 +    return -1;
    }
  
    service_number = -1;
    freeaddrinfo(ai_list);
  
    if ((service_number > 0) && (service_number <= 65535))
 -    return (service_number);
 -  return (-1);
 +    return service_number;
 +  return -1;
  } /* int service_name_to_port_number */
  
  void set_sock_opts(int sockfd) /* {{{ */
@@@ -1489,16 -1506,16 +1492,16 @@@ int strtoderive(const char *string, der
    char *endptr;
  
    if ((string == NULL) || (ret_value == NULL))
 -    return (EINVAL);
 +    return EINVAL;
  
    errno = 0;
    endptr = NULL;
    tmp = (derive_t)strtoll(string, &endptr, /* base = */ 0);
    if ((endptr == string) || (errno != 0))
 -    return (-1);
 +    return -1;
  
    *ret_value = tmp;
 -  return (0);
 +  return 0;
  } /* }}} int strtoderive */
  
  int strtogauge(const char *string, gauge_t *ret_value) /* {{{ */
    char *endptr = NULL;
  
    if ((string == NULL) || (ret_value == NULL))
 -    return (EINVAL);
 +    return EINVAL;
  
    errno = 0;
    endptr = NULL;
    tmp = (gauge_t)strtod(string, &endptr);
    if (errno != 0)
 -    return (errno);
 +    return errno;
    else if ((endptr == NULL) || (*endptr != 0))
 -    return (EINVAL);
 +    return EINVAL;
  
    *ret_value = tmp;
 -  return (0);
 +  return 0;
  } /* }}} int strtogauge */
  
  int strarray_add(char ***ret_array, size_t *ret_array_len,
    size_t array_len = *ret_array_len;
  
    if (str == NULL)
 -    return (EINVAL);
 +    return EINVAL;
  
    array = realloc(*ret_array, (array_len + 1) * sizeof(*array));
    if (array == NULL)
 -    return (ENOMEM);
 +    return ENOMEM;
    *ret_array = array;
  
    array[array_len] = strdup(str);
    if (array[array_len] == NULL)
 -    return (ENOMEM);
 +    return ENOMEM;
  
    array_len++;
    *ret_array_len = array_len;
 -  return (0);
 +  return 0;
  } /* }}} int strarray_add */
  
  void strarray_free(char **array, size_t array_len) /* {{{ */
@@@ -1559,27 -1576,27 +1562,27 @@@ int check_capability(int arg) /* {{{ *
    cap_flag_value_t cap_flag_value;
  
    if (!CAP_IS_SUPPORTED(cap_value))
 -    return (-1);
 +    return -1;
  
    if (!(cap = cap_get_proc())) {
      ERROR("check_capability: cap_get_proc failed.");
 -    return (-1);
 +    return -1;
    }
  
    if (cap_get_flag(cap, cap_value, CAP_EFFECTIVE, &cap_flag_value) < 0) {
      ERROR("check_capability: cap_get_flag failed.");
      cap_free(cap);
 -    return (-1);
 +    return -1;
    }
    cap_free(cap);
  
 -  return (cap_flag_value != CAP_SET);
 +  return cap_flag_value != CAP_SET;
  } /* }}} int check_capability */
  #else
  int check_capability(__attribute__((unused)) int arg) /* {{{ */
  {
    WARNING("check_capability: unsupported capability implementation. "
            "Some plugin(s) may require elevated privileges to work properly.");
 -  return (0);
 +  return 0;
  } /* }}} int check_capability */
  #endif /* HAVE_CAPABILITY */
diff --combined src/daemon/common_test.c
  #include "common.h"
  #include "testing.h"
  
 +#if HAVE_KSTAT_H
 +#include <kstat.h>
 +#endif
 +
  #if HAVE_LIBKSTAT
  kstat_ctl_t *kc;
  #endif /* HAVE_LIBKSTAT */
@@@ -59,7 -55,28 +59,7 @@@ DEF_TEST(sstrncpy) 
    EXPECT_EQ_STR("collect", ptr);
    OK(buffer[3] == buffer[12]);
  
 -  return (0);
 -}
 -
 -DEF_TEST(ssnprintf) {
 -  char buffer[16] = "";
 -  char *ptr = &buffer[4];
 -  int status;
 -
 -  buffer[0] = buffer[1] = buffer[2] = buffer[3] = 0xff;
 -  buffer[12] = buffer[13] = buffer[14] = buffer[15] = 0xff;
 -
 -  status = ssnprintf(ptr, 8, "%i", 1337);
 -  OK(status == 4);
 -  EXPECT_EQ_STR("1337", ptr);
 -
 -  status = ssnprintf(ptr, 8, "%s", "collectd");
 -  OK(status == 8);
 -  OK(ptr[7] == 0);
 -  EXPECT_EQ_STR("collect", ptr);
 -  OK(buffer[3] == buffer[12]);
 -
 -  return (0);
 +  return 0;
  }
  
  DEF_TEST(sstrdup) {
@@@ -74,7 -91,7 +74,7 @@@
    ptr = sstrdup(NULL);
    OK(ptr == NULL);
  
 -  return (0);
 +  return 0;
  }
  
  DEF_TEST(strsplit) {
    status = strsplit(buffer, fields, 8);
    OK(status == 0);
  
 -  return (0);
 +  return 0;
  }
  
  DEF_TEST(strjoin) {
                       cases[i].fields_num, cases[i].separator);
      EXPECT_EQ_INT(cases[i].want_return, status);
      EXPECT_EQ_STR(cases[i].want_buffer, buffer);
-   }
  
-   /* use (NULL, 0) to determine required buffer size. */
-   EXPECT_EQ_INT(3, strjoin(NULL, 0, (char *[]){"a", "b"}, 2, "-"));
+     /* use (NULL, 0) to determine required buffer size. */
+     EXPECT_EQ_INT(cases[i].want_return,
+                   strjoin(NULL, 0, cases[i].fields, cases[i].fields_num,
+                           cases[i].separator));
+   }
  
 -  return (0);
 +  return 0;
  }
  
  DEF_TEST(escape_slashes) {
@@@ -247,7 -266,7 +249,7 @@@ DEF_TEST(strunescape) 
    status = strunescape(buffer, sizeof(buffer));
    OK(status != 0);
    EXPECT_EQ_STR("\tbackslash end", buffer);
 -  return (0);
 +  return 0;
  
    /* Backslash at buffer end */
    strncpy(buffer, "\\t3\\56", sizeof(buffer));
    OK(buffer[5] == '6');
    OK(buffer[6] == '7');
  
 -  return (0);
 +  return 0;
  }
  
  DEF_TEST(parse_values) {
      EXPECT_EQ_DOUBLE(cases[i].value, vl.values[0].gauge);
    }
  
 -  return (0);
 +  return 0;
  }
  
  DEF_TEST(value_to_rate) {
  
  int main(void) {
    RUN_TEST(sstrncpy);
 -  RUN_TEST(ssnprintf);
    RUN_TEST(sstrdup);
    RUN_TEST(strsplit);
    RUN_TEST(strjoin);
  
    END_TEST;
  }
 -
 -/* vim: set sw=2 sts=2 et : */
diff --combined src/log_logstash.c
@@@ -183,22 -183,14 +183,14 @@@ err
  
  static void log_logstash_log(int severity, const char *msg,
                               user_data_t __attribute__((unused)) * user_data) {
-   yajl_gen g;
- #if !defined(HAVE_YAJL_V2)
-   yajl_gen_config conf = {};
-   conf.beautify = 0;
- #endif
    if (severity > log_level)
      return;
  
  #if HAVE_YAJL_V2
-   g = yajl_gen_alloc(NULL);
+   yajl_gen g = yajl_gen_alloc(NULL);
  #else
-   g = yajl_gen_alloc(&conf, NULL);
+   yajl_gen g = yajl_gen_alloc(&(yajl_gen_config){0}, NULL);
  #endif
    if (g == NULL) {
      fprintf(stderr, "Could not allocate JSON generator.\n");
      return;
@@@ -236,7 -228,7 +228,7 @@@ static int log_logstash_notification(co
  
    if (g == NULL) {
      fprintf(stderr, "Could not allocate JSON generator.\n");
 -    return (0);
 +    return 0;
    }
  
    if (yajl_gen_map_open(g) != yajl_gen_status_ok)
    }
  
    log_logstash_print(g, LOG_INFO, (n->time != 0) ? n->time : cdtime());
 -  return (0);
 +  return 0;
  
  err:
    yajl_gen_free(g);
    fprintf(stderr, "Could not correctly generate JSON notification\n");
 -  return (0);
 +  return 0;
  } /* int log_logstash_notification */
  
  void module_register(void) {
    plugin_register_notification("log_logstash", log_logstash_notification,
                                 /* user_data = */ NULL);
  } /* void module_register (void) */
 -
 -/* vim: set sw=4 ts=4 tw=78 noexpandtab : */
diff --combined src/write_prometheus.c
@@@ -163,8 -163,8 +163,8 @@@ static char *format_labels(char *buffer
     * know that they are sane. */
    for (size_t i = 0; i < m->n_label; i++) {
      char value[LABEL_VALUE_SIZE];
 -    ssnprintf(labels[i], LABEL_BUFFER_SIZE, "%s=\"%s\"", m->label[i]->name,
 -              escape_label_value(value, sizeof(value), m->label[i]->value));
 +    snprintf(labels[i], LABEL_BUFFER_SIZE, "%s=\"%s\"", m->label[i]->name,
 +             escape_label_value(value, sizeof(value), m->label[i]->value));
    }
  
    strjoin(buffer, buffer_size, labels, m->n_label, ",");
@@@ -182,13 -182,13 +182,13 @@@ static void format_text(ProtobufCBuffe
    while (c_avl_iterator_next(iter, (void *)&unused_name, (void *)&fam) == 0) {
      char line[1024]; /* 4x DATA_MAX_NAME_LEN? */
  
 -    ssnprintf(line, sizeof(line), "# HELP %s %s\n", fam->name, fam->help);
 +    snprintf(line, sizeof(line), "# HELP %s %s\n", fam->name, fam->help);
      buffer->append(buffer, strlen(line), (uint8_t *)line);
  
 -    ssnprintf(line, sizeof(line), "# TYPE %s %s\n", fam->name,
 -              (fam->type == IO__PROMETHEUS__CLIENT__METRIC_TYPE__GAUGE)
 -                  ? "gauge"
 -                  : "counter");
 +    snprintf(line, sizeof(line), "# TYPE %s %s\n", fam->name,
 +             (fam->type == IO__PROMETHEUS__CLIENT__METRIC_TYPE__GAUGE)
 +                 ? "gauge"
 +                 : "counter");
      buffer->append(buffer, strlen(line), (uint8_t *)line);
  
      for (size_t i = 0; i < fam->n_metric; i++) {
  
        char timestamp_ms[24] = "";
        if (m->has_timestamp_ms)
 -        ssnprintf(timestamp_ms, sizeof(timestamp_ms), " %" PRIi64,
 -                  m->timestamp_ms);
 +        snprintf(timestamp_ms, sizeof(timestamp_ms), " %" PRIi64,
 +                 m->timestamp_ms);
  
        if (fam->type == IO__PROMETHEUS__CLIENT__METRIC_TYPE__GAUGE)
 -        ssnprintf(line, sizeof(line), "%s{%s} " GAUGE_FORMAT "%s\n", fam->name,
 -                  format_labels(labels, sizeof(labels), m), m->gauge->value,
 -                  timestamp_ms);
 +        snprintf(line, sizeof(line), "%s{%s} " GAUGE_FORMAT "%s\n", fam->name,
 +                 format_labels(labels, sizeof(labels), m), m->gauge->value,
 +                 timestamp_ms);
        else /* if (fam->type == IO__PROMETHEUS__CLIENT__METRIC_TYPE__COUNTER) */
 -        ssnprintf(line, sizeof(line), "%s{%s} %.0f%s\n", fam->name,
 -                  format_labels(labels, sizeof(labels), m), m->counter->value,
 -                  timestamp_ms);
 +        snprintf(line, sizeof(line), "%s{%s} %.0f%s\n", fam->name,
 +                 format_labels(labels, sizeof(labels), m), m->counter->value,
 +                 timestamp_ms);
  
        buffer->append(buffer, strlen(line), (uint8_t *)line);
      }
    c_avl_iterator_destroy(iter);
  
    char server[1024];
 -  ssnprintf(server, sizeof(server), "\n# collectd/write_prometheus %s at %s\n",
 -            PACKAGE_VERSION, hostname_g);
 +  snprintf(server, sizeof(server), "\n# collectd/write_prometheus %s at %s\n",
 +           PACKAGE_VERSION, hostname_g);
    buffer->append(buffer, strlen(server), (uint8_t *)server);
  
    pthread_mutex_unlock(&metrics_lock);
@@@ -635,7 -635,7 +635,7 @@@ metric_family_create(char *name, data_s
    msg->name = name;
  
    char help[1024];
 -  ssnprintf(
 +  snprintf(
        help, sizeof(help),
        "write_prometheus plugin: '%s' Type: '%s', Dstype: '%s', Dsname: '%s'",
        vl->plugin, vl->type, DS_TYPE_TO_STRING(ds->ds[ds_index].type),
@@@ -760,7 -760,12 +760,12 @@@ static int prom_open_socket(int addrfam
  
    int fd = -1;
    for (struct addrinfo *ai = res; ai != NULL; ai = ai->ai_next) {
-     fd = socket(ai->ai_family, ai->ai_socktype | SOCK_CLOEXEC, 0);
+     int flags = ai->ai_socktype;
+ #ifdef SOCK_CLOEXEC
+     flags |= SOCK_CLOEXEC;
+ #endif
+     fd = socket(ai->ai_family, flags, 0);
      if (fd == -1)
        continue;
  
@@@ -804,13 -809,8 +809,13 @@@ static struct MHD_Daemon *prom_start_da
      return NULL;
    }
  
 +  unsigned int flags = MHD_USE_THREAD_PER_CONNECTION | MHD_USE_DEBUG;
 +#if MHD_VERSION >= 0x00095300
 +  flags |= MHD_USE_INTERNAL_POLLING_THREAD;
 +#endif
 +
    struct MHD_Daemon *d = MHD_start_daemon(
 -      MHD_USE_THREAD_PER_CONNECTION | MHD_USE_DEBUG, httpd_port,
 +      flags, httpd_port,
        /* MHD_AcceptPolicyCallback = */ NULL,
        /* MHD_AcceptPolicyCallback arg = */ NULL, http_handler, NULL,
        MHD_OPTION_LISTEN_SOCKET, fd, MHD_OPTION_EXTERNAL_LOGGER, prom_logger,
@@@ -980,3 -980,5 +985,3 @@@ void module_register() 
                            /* user data = */ NULL);
    plugin_register_shutdown("write_prometheus", prom_shutdown);
  }
 -
 -/* vim: set sw=2 sts=2 et fdm=marker : */