Merge branch 'collectd-5.5'
authorFlorian Forster <octo@collectd.org>
Thu, 18 Jun 2015 11:05:23 +0000 (13:05 +0200)
committerFlorian Forster <octo@collectd.org>
Thu, 18 Jun 2015 11:05:23 +0000 (13:05 +0200)
1  2 
src/curl_json.c
src/modbus.c
src/network.c
src/onewire.c
src/snmp.c
src/tail.c
src/tail_csv.c

diff --combined src/curl_json.c
@@@ -552,7 -552,6 +552,6 @@@ static int cj_config_add_key (cj_t *db
        db->tree = cj_avl_create();
  
      tree = db->tree;
-     name = key->path;
      ptr = key->path;
      if (*ptr == '/')
        ++ptr;
@@@ -763,6 -762,9 +762,6 @@@ static int cj_config_add_url (oconfig_i
    {
      user_data_t ud;
      char *cb_name;
 -    struct timespec interval = { 0, 0 };
 -
 -    CDTIME_T_TO_TIMESPEC (db->interval, &interval);
  
      if (db->instance == NULL)
        db->instance = strdup("default");
                 db->instance, db->url ? db->url : db->sock);
  
      plugin_register_complex_read (/* group = */ NULL, cb_name, cj_read,
 -                                  /* interval = */ (db->interval > 0) ? &interval : NULL,
 +                                  /* interval = */ db->interval,
                                    &ud);
      sfree (cb_name);
    }
diff --combined src/modbus.c
@@@ -463,7 -463,6 +463,6 @@@ static int mb_read_data (mb_host_t *hos
    else
      values_num = 1;
  
-   status = 0;
    if (host->connection == NULL)
    {
      status = EBADF;
@@@ -733,7 -732,6 +732,6 @@@ static int mb_config_add_data (oconfig_
    for (i = 0; i < ci->children_num; i++)
    {
      oconfig_item_t *child = ci->children + i;
-     status = 0;
  
      if (strcasecmp ("Type", child->key) == 0)
        status = cf_util_get_string_buffer (child,
@@@ -894,7 -892,6 +892,6 @@@ static int mb_config_add_slave (mb_host
    for (i = 0; i < ci->children_num; i++)
    {
      oconfig_item_t *child = ci->children + i;
-     status = 0;
  
      if (strcasecmp ("Instance", child->key) == 0)
        status = cf_util_get_string_buffer (child,
@@@ -1017,15 -1014,18 +1014,15 @@@ static int mb_config_add_host (oconfig_
    {
      user_data_t ud;
      char name[1024];
 -    struct timespec interval = { 0, 0 };
  
      ud.data = host;
      ud.free_func = host_free;
  
      ssnprintf (name, sizeof (name), "modbus-%s", host->host);
  
 -    CDTIME_T_TO_TIMESPEC (host->interval, &interval);
 -
      plugin_register_complex_read (/* group = */ NULL, name,
          /* callback = */ mb_read,
 -        /* interval = */ (host->interval > 0) ? &interval : NULL,
 +        /* interval = */ host->interval,
          &ud);
    }
    else
diff --combined src/network.c
@@@ -283,8 -283,8 +283,8 @@@ typedef struct receive_list_entry_s rec
  static int network_config_ttl = 0;
  /* Ethernet - (IPv6 + UDP) = 1500 - (40 + 8) = 1452 */
  static size_t network_config_packet_size = 1452;
 -static int network_config_forward = 0;
 -static int network_config_stats = 0;
 +static _Bool network_config_forward = 0;
 +static _Bool network_config_stats = 0;
  
  static sockent_t *sending_sockets = NULL;
  
@@@ -310,7 -310,6 +310,7 @@@ static pthread_t dispatch_thread_id
  static char            *send_buffer;
  static char            *send_buffer_ptr;
  static int              send_buffer_fill;
 +static cdtime_t         send_buffer_last_update;
  static value_list_t     send_buffer_vl = VALUE_LIST_STATIC;
  static pthread_mutex_t  send_buffer_lock = PTHREAD_MUTEX_INITIALIZER;
  
@@@ -354,7 -353,7 +354,7 @@@ static _Bool check_send_okay (const val
    _Bool received = 0;
    int status;
  
 -  if (network_config_forward != 0)
 +  if (network_config_forward)
      return (1);
  
    if (vl->meta == NULL)
@@@ -2567,10 -2566,6 +2567,6 @@@ static int network_receive (void) /* {{
                receive_list_tail = private_list_tail;
                receive_list_length += private_list_length;
  
-               private_list_head = NULL;
-               private_list_tail = NULL;
-               private_list_length = 0;
                pthread_cond_signal (&receive_list_cond);
                pthread_mutex_unlock (&receive_list_lock);
        }
@@@ -2588,7 -2583,6 +2584,7 @@@ static void network_init_buffer (void
        memset (send_buffer, 0, network_config_packet_size);
        send_buffer_ptr = send_buffer;
        send_buffer_fill = 0;
 +      send_buffer_last_update = 0;
  
        memset (&send_buffer_vl, 0, sizeof (send_buffer_vl));
  } /* int network_init_buffer */
@@@ -2928,7 -2922,6 +2924,7 @@@ static int network_write (const data_se
                /* status == bytes added to the buffer */
                send_buffer_fill += status;
                send_buffer_ptr  += status;
 +              send_buffer_last_update = cdtime();
  
                stats_values_sent++;
        }
        return ((status < 0) ? -1 : 0);
  } /* int network_write */
  
 -static int network_config_set_boolean (const oconfig_item_t *ci, /* {{{ */
 -    int *retval)
 -{
 -  if ((ci->values_num != 1)
 -      || ((ci->values[0].type != OCONFIG_TYPE_BOOLEAN)
 -        && (ci->values[0].type != OCONFIG_TYPE_STRING)))
 -  {
 -    ERROR ("network plugin: The `%s' config option needs "
 -        "exactly one boolean argument.", ci->key);
 -    return (-1);
 -  }
 -
 -  if (ci->values[0].type == OCONFIG_TYPE_BOOLEAN)
 -  {
 -    if (ci->values[0].value.boolean)
 -      *retval = 1;
 -    else
 -      *retval = 0;
 -  }
 -  else
 -  {
 -    char *str = ci->values[0].value.string;
 -
 -    if (IS_TRUE (str))
 -      *retval = 1;
 -    else if (IS_FALSE (str))
 -      *retval = 0;
 -    else
 -    {
 -      ERROR ("network plugin: Cannot parse string value `%s' of the `%s' "
 -          "option as boolean value.",
 -          str, ci->key);
 -      return (-1);
 -    }
 -  }
 -
 -  return (0);
 -} /* }}} int network_config_set_boolean */
 -
  static int network_config_set_ttl (const oconfig_item_t *ci) /* {{{ */
  {
 -  int tmp;
 -  if ((ci->values_num != 1)
 -      || (ci->values[0].type != OCONFIG_TYPE_NUMBER))
 -  {
 -    WARNING ("network plugin: The `TimeToLive' config option needs exactly "
 -        "one numeric argument.");
 -    return (-1);
 -  }
 +  int tmp = 0;
  
 -  tmp = (int) ci->values[0].value.number;
 -  if ((tmp > 0) && (tmp <= 255))
 +  if (cf_util_get_int (ci, &tmp) != 0)
 +    return (-1);
 +  else if ((tmp > 0) && (tmp <= 255))
      network_config_ttl = tmp;
    else {
      WARNING ("network plugin: The `TimeToLive' must be between 1 and 255.");
  static int network_config_set_interface (const oconfig_item_t *ci, /* {{{ */
      int *interface)
  {
 -  if ((ci->values_num != 1)
 -      || (ci->values[0].type != OCONFIG_TYPE_STRING))
 -  {
 -    WARNING ("network plugin: The `Interface' config option needs exactly "
 -        "one string argument.");
 -    return (-1);
 -  }
 +  char if_name[256];
  
 -  if (interface == NULL)
 +  if (cf_util_get_string_buffer (ci, if_name, sizeof (if_name)) != 0)
      return (-1);
  
 -  *interface = if_nametoindex (ci->values[0].value.string);
 -
 +  *interface = if_nametoindex (if_name);
    return (0);
  } /* }}} int network_config_set_interface */
  
  static int network_config_set_buffer_size (const oconfig_item_t *ci) /* {{{ */
  {
 -  int tmp;
 -  if ((ci->values_num != 1)
 -      || (ci->values[0].type != OCONFIG_TYPE_NUMBER))
 -  {
 -    WARNING ("network plugin: The `MaxPacketSize' config option needs exactly "
 -        "one numeric argument.");
 -    return (-1);
 -  }
 +  int tmp = 0;
  
 -  tmp = (int) ci->values[0].value.number;
 -  if ((tmp >= 1024) && (tmp <= 65535))
 +  if (cf_util_get_int (ci, &tmp) != 0)
 +    return (-1);
 +  else if ((tmp >= 1024) && (tmp <= 65535))
      network_config_packet_size = tmp;
 -
 -  return (0);
 -} /* }}} int network_config_set_buffer_size */
 -
 -#if HAVE_LIBGCRYPT
 -static int network_config_set_string (const oconfig_item_t *ci, /* {{{ */
 -    char **ret_string)
 -{
 -  char *tmp;
 -  if ((ci->values_num != 1)
 -      || (ci->values[0].type != OCONFIG_TYPE_STRING))
 -  {
 -    WARNING ("network plugin: The `%s' config option needs exactly "
 -        "one string argument.", ci->key);
 +  else {
 +    WARNING ("network plugin: The `MaxPacketSize' must be between 1024 and 65535.");
      return (-1);
    }
  
 -  tmp = strdup (ci->values[0].value.string);
 -  if (tmp == NULL)
 -    return (-1);
 -
 -  sfree (*ret_string);
 -  *ret_string = tmp;
 -
    return (0);
 -} /* }}} int network_config_set_string */
 -#endif /* HAVE_LIBGCRYPT */
 +} /* }}} int network_config_set_buffer_size */
  
  #if HAVE_LIBGCRYPT
  static int network_config_set_security_level (oconfig_item_t *ci, /* {{{ */
@@@ -3071,14 -3142,15 +3067,14 @@@ static int network_config_add_listen (c
  
  #if HAVE_LIBGCRYPT
      if (strcasecmp ("AuthFile", child->key) == 0)
 -      network_config_set_string (child, &se->data.server.auth_file);
 +      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 */
      if (strcasecmp ("Interface", child->key) == 0)
 -      network_config_set_interface (child,
 -          &se->interface);
 +      network_config_set_interface (child, &se->interface);
      else
      {
        WARNING ("network plugin: Option `%s' is not allowed here.",
@@@ -3157,18 -3229,19 +3153,18 @@@ static int network_config_add_server (c
  
  #if HAVE_LIBGCRYPT
      if (strcasecmp ("Username", child->key) == 0)
 -      network_config_set_string (child, &se->data.client.username);
 +      cf_util_get_string (child, &se->data.client.username);
      else if (strcasecmp ("Password", child->key) == 0)
 -      network_config_set_string (child, &se->data.client.password);
 +      cf_util_get_string (child, &se->data.client.password);
      else if (strcasecmp ("SecurityLevel", child->key) == 0)
        network_config_set_security_level (child,
            &se->data.client.security_level);
      else
  #endif /* HAVE_LIBGCRYPT */
      if (strcasecmp ("Interface", child->key) == 0)
 -      network_config_set_interface (child,
 -          &se->interface);
 -              else if (strcasecmp ("ResolveInterval", child->key) == 0)
 -                      cf_util_get_cdtime(child, &se->data.client.resolve_interval);
 +      network_config_set_interface (child, &se->interface);
 +    else if (strcasecmp ("ResolveInterval", child->key) == 0)
 +      cf_util_get_cdtime(child, &se->data.client.resolve_interval);
      else
      {
        WARNING ("network plugin: Option `%s' is not allowed here.",
@@@ -3237,9 -3310,9 +3233,9 @@@ static int network_config (oconfig_item
      else if (strcasecmp ("MaxPacketSize", child->key) == 0)
        network_config_set_buffer_size (child);
      else if (strcasecmp ("Forward", child->key) == 0)
 -      network_config_set_boolean (child, &network_config_forward);
 +      cf_util_get_boolean (child, &network_config_forward);
      else if (strcasecmp ("ReportStats", child->key) == 0)
 -      network_config_set_boolean (child, &network_config_stats);
 +      cf_util_get_boolean (child, &network_config_stats);
      else
      {
        WARNING ("network plugin: Option `%s' is not allowed here.",
@@@ -3460,7 -3533,7 +3456,7 @@@ static int network_init (void
        network_init_gcrypt ();
  #endif
  
 -      if (network_config_stats != 0)
 +      if (network_config_stats)
                plugin_register_read ("network", network_stats_read);
  
        plugin_register_shutdown ("network", network_shutdown);
   * just send the buffer if `flush'  is called - if the requested value was in
   * there, good. If not, well, then there is nothing to flush.. -octo
   */
 -static int network_flush (__attribute__((unused)) cdtime_t timeout,
 +static int network_flush (cdtime_t timeout,
                __attribute__((unused)) const char *identifier,
                __attribute__((unused)) user_data_t *user_data)
  {
        pthread_mutex_lock (&send_buffer_lock);
  
        if (send_buffer_fill > 0)
 -        flush_buffer ();
 -
 +      {
 +              if (timeout > 0)
 +              {
 +                      cdtime_t now = cdtime ();
 +                      if ((send_buffer_last_update + timeout) > now)
 +                      {
 +                              pthread_mutex_unlock (&send_buffer_lock);
 +                              return (0);
 +                      }
 +              }
 +              flush_buffer ();
 +      }
        pthread_mutex_unlock (&send_buffer_lock);
  
        return (0);
diff --combined src/onewire.c
@@@ -384,7 -384,6 +384,6 @@@ static int cow_read_values (const char 
      if (endptr == NULL)
      {
        ERROR ("onewire plugin: Buffer is not a number: %s", buffer);
-       status = -1;
        continue;
      }
  
@@@ -528,7 -527,6 +527,6 @@@ static int cow_simple_read (void
        if (endptr == NULL)
        {
            ERROR ("onewire plugin: Buffer is not a number: %s", buffer);
-           status = -1;
            continue;
        }
  
@@@ -592,6 -590,7 +590,6 @@@ static int cow_shutdown (void
  static int cow_init (void)
  {
    int status;
 -  struct timespec cb_interval;
  
    if (device_g == NULL)
    {
      return (1);
    }
  
 -  CDTIME_T_TO_TIMESPEC (ow_interval, &cb_interval);
 -
    plugin_register_complex_read (/* group = */ NULL, "onewire", cow_read,
 -      (ow_interval != 0) ? &cb_interval : NULL,
 -      /* user data = */ NULL);
 +      ow_interval, /* user data = */ NULL);
    plugin_register_shutdown ("onewire", cow_shutdown);
  
    return (0);
diff --combined src/snmp.c
@@@ -402,7 -402,6 +402,6 @@@ static int csnmp_config_add_data (oconf
    for (i = 0; i < ci->children_num; i++)
    {
      oconfig_item_t *option = ci->children + i;
-     status = 0;
  
      if (strcasecmp ("Type", option->key) == 0)
        status = cf_util_get_string(option, &dd->type);
@@@ -646,6 -645,7 +645,6 @@@ static int csnmp_config_add_host (oconf
    /* Registration stuff. */
    char cb_name[DATA_MAX_NAME_LEN];
    user_data_t cb_data;
 -  struct timespec cb_interval;
  
    hd = (host_definition_t *) malloc (sizeof (host_definition_t));
    if (hd == NULL)
    cb_data.data = hd;
    cb_data.free_func = csnmp_host_definition_destroy;
  
 -  CDTIME_T_TO_TIMESPEC (hd->interval, &cb_interval);
 -
    status = plugin_register_complex_read (/* group = */ NULL, cb_name,
 -      csnmp_read_host, /* interval = */ &cb_interval,
 -      /* user_data = */ &cb_data);
 +      csnmp_read_host, hd->interval, /* user_data = */ &cb_data);
    if (status != 0)
    {
      ERROR ("snmp plugin: Registering complex read function failed.");
@@@ -1519,7 -1522,7 +1518,7 @@@ static int csnmp_read_table (host_defin
      for (vb = res->variables, i = 0; (vb != NULL); vb = vb->next_variable, i++)
      {
        /* Calculate value index from todo list */
-       while (!oid_list_todo[i] && (i < oid_list_len))
+       while ((i < oid_list_len) && !oid_list_todo[i])
          i++;
  
        /* An instance is configured and the res variable we process is the
diff --combined src/tail.c
@@@ -224,7 -224,6 +224,6 @@@ static int ctail_config_add_file (oconf
    cdtime_t interval = 0;
    char *plugin_instance = NULL;
    int num_matches = 0;
-   int status;
    int i;
  
    if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING))
      return (-1);
    }
  
-   status = 0;
    for (i = 0; i < ci->children_num; i++)
    {
      oconfig_item_t *option = ci->children + i;
+     int status;
  
      if (strcasecmp ("Instance", option->key) == 0)
        status = cf_util_get_string (option, &plugin_instance);
@@@ -331,6 -330,7 +330,6 @@@ static int ctail_read (user_data_t *ud
  
  static int ctail_init (void)
  {
 -  struct timespec cb_interval;
    char str[255];
    user_data_t ud;
    size_t i;
    {
      ud.data = (void *)tail_match_list[i];
      ssnprintf(str, sizeof(str), "tail-%zu", i);
 -    CDTIME_T_TO_TIMESPEC (tail_match_list_intervals[i], &cb_interval);
 -    plugin_register_complex_read (NULL, str, ctail_read, &cb_interval, &ud);
 +    plugin_register_complex_read (NULL, str, ctail_read, tail_match_list_intervals[i], &ud);
    }
  
    return (0);
diff --combined src/tail_csv.c
@@@ -312,7 -312,6 +312,6 @@@ static int tcsv_config_add_metric(oconf
  
      for (i = 0; i < ci->children_num; ++i){
          oconfig_item_t *option = ci->children + i;
-         status = 0;
  
          if (strcasecmp("Type", option->key) == 0)
              status = cf_util_get_string(option, &md->type);
@@@ -429,6 -428,7 +428,6 @@@ static int tcsv_config_add_file(oconfig
      /* Registration variables */
      char cb_name[DATA_MAX_NAME_LEN];
      user_data_t cb_data;
 -    struct timespec cb_interval;
  
      id = malloc(sizeof(*id));
      if (id == NULL)
      memset(&cb_data, 0, sizeof(cb_data));
      cb_data.data = id;
      cb_data.free_func = tcsv_instance_definition_destroy;
 -    CDTIME_T_TO_TIMESPEC(id->interval, &cb_interval);
 -    status = plugin_register_complex_read(NULL, cb_name, tcsv_read, &cb_interval, &cb_data);
 +    status = plugin_register_complex_read(NULL, cb_name, tcsv_read, id->interval, &cb_data);
  
      if (status != 0){
          ERROR("tail_csv plugin: Registering complex read function failed.");