Merge branch 'collectd-5.5'
authorRuben Kerkhof <ruben@rubenkerkhof.com>
Fri, 20 May 2016 10:51:25 +0000 (12:51 +0200)
committerRuben Kerkhof <ruben@rubenkerkhof.com>
Fri, 20 May 2016 10:51:25 +0000 (12:51 +0200)
1  2 
src/daemon/utils_cache.c
src/exec.c

diff --combined src/daemon/utils_cache.c
@@@ -37,7 -37,7 +37,7 @@@
  typedef struct cache_entry_s
  {
        char name[6 * DATA_MAX_NAME_LEN];
 -      int        values_num;
 +      size_t     values_num;
        gauge_t   *values_gauge;
        value_t   *values_raw;
        /* Time contained in the package
@@@ -79,16 -79,17 +79,16 @@@ static int cache_compare (const cache_e
    return (strcmp (a->name, b->name));
  } /* int cache_compare */
  
 -static cache_entry_t *cache_alloc (int values_num)
 +static cache_entry_t *cache_alloc (size_t values_num)
  {
    cache_entry_t *ce;
  
 -  ce = (cache_entry_t *) malloc (sizeof (cache_entry_t));
 +  ce = calloc (1, sizeof (*ce));
    if (ce == NULL)
    {
 -    ERROR ("utils_cache: cache_alloc: malloc failed.");
 +    ERROR ("utils_cache: cache_alloc: calloc failed.");
      return (NULL);
    }
 -  memset (ce, '\0', sizeof (cache_entry_t));
    ce->values_num = values_num;
  
    ce->values_gauge = calloc (values_num, sizeof (*ce->values_gauge));
@@@ -127,7 -128,7 +127,7 @@@ static void cache_free (cache_entry_t *
  
  static void uc_check_range (const data_set_t *ds, cache_entry_t *ce)
  {
 -  int i;
 +  size_t i;
  
    for (i = 0; i < ds->ds_num; i++)
    {
  static int uc_insert (const data_set_t *ds, const value_list_t *vl,
      const char *key)
  {
 -  int i;
    char *key_copy;
    cache_entry_t *ce;
 +  size_t i;
  
    /* `cache_lock' has been locked by `uc_update' */
  
    if (ce == NULL)
    {
      sfree (key_copy);
 -    ERROR ("uc_insert: cache_alloc (%i) failed.", ds->ds_num);
 +    ERROR ("uc_insert: cache_alloc (%zu) failed.", ds->ds_num);
      return (-1);
    }
  
@@@ -246,7 -247,7 +246,7 @@@ int uc_check_timeout (void
  
    int status;
    int i;
 -  
 +
    pthread_mutex_lock (&cache_lock);
  
    now = cdtime ();
        continue;
  
      /* If entry has not been updated, add to `keys' array */
 -    tmp = (char **) realloc ((void *) keys,
 +    tmp = realloc ((void *) keys,
        (keys_len + 1) * sizeof (char *));
      if (tmp == NULL)
      {
@@@ -374,7 -375,7 +374,7 @@@ int uc_update (const data_set_t *ds, co
    char name[6 * DATA_MAX_NAME_LEN];
    cache_entry_t *ce = NULL;
    int status;
 -  int i;
 +  size_t i;
  
    if (FORMAT_VL (name, sizeof (name), vl) != 0)
    {
      {
        case DS_TYPE_COUNTER:
        {
 -        counter_t diff;
 -
 -        /* check if the counter has wrapped around */
 -        if (vl->values[i].counter < ce->values_raw[i].counter)
 -        {
 -          if (ce->values_raw[i].counter <= 4294967295U)
 -            diff = (4294967295U - ce->values_raw[i].counter)
 -              + vl->values[i].counter;
 -          else
 -            diff = (18446744073709551615ULL - ce->values_raw[i].counter)
 -              + vl->values[i].counter;
 -        }
 -        else /* counter has NOT wrapped around */
 -        {
 -          diff = vl->values[i].counter - ce->values_raw[i].counter;
 -        }
 -
 +        counter_t diff = counter_diff (ce->values_raw[i].counter, vl->values[i].counter);
          ce->values_gauge[i] = ((double) diff)
            / (CDTIME_T_TO_DOUBLE (vl->time - ce->last_time));
          ce->values_raw[i].counter = vl->values[i].counter;
  
        case DS_TYPE_DERIVE:
        {
 -        derive_t diff;
 -
 -        diff = vl->values[i].derive - ce->values_raw[i].derive;
 +        derive_t diff = vl->values[i].derive - ce->values_raw[i].derive;
  
          ce->values_gauge[i] = ((double) diff)
            / (CDTIME_T_TO_DOUBLE (vl->time - ce->last_time));
        return (-1);
      } /* switch (ds->ds[i].type) */
  
 -    DEBUG ("uc_update: %s: ds[%i] = %lf", name, i, ce->values_gauge[i]);
 +    DEBUG ("uc_update: %s: ds[%zu] = %lf", name, i, ce->values_gauge[i]);
    } /* for (i) */
  
    /* Update the history if it exists. */
@@@ -498,7 -517,7 +498,7 @@@ int uc_get_rate_by_name (const char *na
      else
      {
        ret_num = ce->values_num;
 -      ret = (gauge_t *) malloc (ret_num * sizeof (gauge_t));
 +      ret = malloc (ret_num * sizeof (*ret));
        if (ret == NULL)
        {
          ERROR ("utils_cache: uc_get_rate_by_name: malloc failed.");
@@@ -548,7 -567,7 +548,7 @@@ gauge_t *uc_get_rate (const data_set_t 
     * values are returned. */
    if (ret_num != (size_t) ds->ds_num)
    {
 -    ERROR ("utils_cache: uc_get_rate: ds[%s] has %i values, "
 +    ERROR ("utils_cache: uc_get_rate: ds[%s] has %zu values, "
        "but uc_get_rate_by_name returned %zu.",
        ds->type, ds->ds_num, ret_num);
      sfree (ret);
@@@ -690,7 -709,7 +690,7 @@@ int uc_set_state (const data_set_t *ds
  
    if (FORMAT_VL (name, sizeof (name), vl) != 0)
    {
-     ERROR ("uc_get_state: FORMAT_VL failed.");
+     ERROR ("uc_set_state: FORMAT_VL failed.");
      return (STATE_ERROR);
    }
  
@@@ -798,7 -817,7 +798,7 @@@ int uc_get_hits (const data_set_t *ds, 
  
    if (FORMAT_VL (name, sizeof (name), vl) != 0)
    {
-     ERROR ("uc_get_state: FORMAT_VL failed.");
+     ERROR ("uc_get_hits: FORMAT_VL failed.");
      return (STATE_ERROR);
    }
  
@@@ -823,7 -842,7 +823,7 @@@ int uc_set_hits (const data_set_t *ds, 
  
    if (FORMAT_VL (name, sizeof (name), vl) != 0)
    {
-     ERROR ("uc_get_state: FORMAT_VL failed.");
+     ERROR ("uc_set_hits: FORMAT_VL failed.");
      return (STATE_ERROR);
    }
  
@@@ -849,7 -868,7 +849,7 @@@ int uc_inc_hits (const data_set_t *ds, 
  
    if (FORMAT_VL (name, sizeof (name), vl) != 0)
    {
-     ERROR ("uc_get_state: FORMAT_VL failed.");
+     ERROR ("uc_inc_hits: FORMAT_VL failed.");
      return (STATE_ERROR);
    }
  
diff --combined src/exec.c
@@@ -126,12 -126,13 +126,12 @@@ static int exec_config_exec (oconfig_it
      return (-1);
    }
  
 -  pl = (program_list_t *) malloc (sizeof (program_list_t));
 +  pl = calloc (1, sizeof (*pl));
    if (pl == NULL)
    {
 -    ERROR ("exec plugin: malloc failed.");
 +    ERROR ("exec plugin: calloc failed.");
      return (-1);
    }
 -  memset (pl, '\0', sizeof (program_list_t));
  
    if (strcasecmp ("NotificationExec", ci->key) == 0)
      pl->flags |= PL_NOTIF_ACTION;
      return (-1);
    }
  
 -  pl->argv = (char **) malloc (ci->values_num * sizeof (char *));
 +  pl->argv = calloc (ci->values_num, sizeof (*pl->argv));
    if (pl->argv == NULL)
    {
 -    ERROR ("exec plugin: malloc failed.");
 +    ERROR ("exec plugin: calloc failed.");
      sfree (pl->exec);
      sfree (pl->user);
      sfree (pl);
      return (-1);
    }
 -  memset (pl->argv, '\0', ci->values_num * sizeof (char *));
  
    {
      char *tmp = strrchr (ci->values[1].value.string, '/');
    pl->argv[0] = strdup (buffer);
    if (pl->argv[0] == NULL)
    {
 -    ERROR ("exec plugin: malloc failed.");
 +    ERROR ("exec plugin: strdup failed.");
      sfree (pl->argv);
      sfree (pl->exec);
      sfree (pl->user);
@@@ -742,8 -744,7 +742,7 @@@ static void *exec_notification_one (voi
      char errbuf[1024];
      ERROR ("exec plugin: fdopen (%i) failed: %s", fd,
          sstrerror (errno, errbuf, sizeof (errbuf)));
-     kill (pl->pid, SIGTERM);
-     pl->pid = 0;
+     kill (pid, SIGTERM);
      close (fd);
      sfree (arg);
      pthread_exit ((void *) 1);
@@@ -867,7 -868,8 +866,7 @@@ static int exec_notification (const not
      if (pl->pid != 0)
        continue;
  
 -    pln = (program_list_and_notification_t *) malloc (sizeof
 -        (program_list_and_notification_t));
 +    pln = malloc (sizeof (*pln));
      if (pln == NULL)
      {
        ERROR ("exec plugin: malloc failed.");