Merge branch 'collectd-5.5'
authorRuben Kerkhof <ruben@rubenkerkhof.com>
Thu, 3 Mar 2016 20:36:20 +0000 (21:36 +0100)
committerRuben Kerkhof <ruben@rubenkerkhof.com>
Thu, 3 Mar 2016 20:36:20 +0000 (21:36 +0100)
1  2 
src/bind.c
src/daemon/plugin.c
src/daemon/utils_cache.c
src/ntpd.c
src/perl.c
src/python.c

diff --combined src/bind.c
@@@ -836,8 -836,6 +836,6 @@@ static int bind_xml_stats_search_zones 
  
    for (i = 0; i < zone_nodes->nodesetval->nodeNr; i++)
    {
-     xmlNode *node;
      node = zone_nodes->nodesetval->nodeTab[i];
      assert (node != NULL);
  
@@@ -1760,7 -1758,7 +1758,7 @@@ static int bind_init (void) /* {{{ *
    curl_easy_setopt (curl, CURLOPT_MAXREDIRS, 50L);
  #ifdef HAVE_CURLOPT_TIMEOUT_MS
    curl_easy_setopt (curl, CURLOPT_TIMEOUT_MS, (timeout >= 0) ?
 -      (long) timeout : CDTIME_T_TO_MS(plugin_get_interval()));
 +      (long) timeout : (long) CDTIME_T_TO_MS(plugin_get_interval()));
  #endif
  
  
diff --combined src/daemon/plugin.c
@@@ -80,12 -80,6 +80,12 @@@ struct write_queue_
        write_queue_t *next;
  };
  
 +struct flush_callback_s {
 +      char *name;
 +      cdtime_t timeout;
 +};
 +typedef struct flush_callback_s flush_callback_t;
 +
  /*
   * Private variables
   */
@@@ -288,7 -282,7 +288,7 @@@ static int register_callback (llist_t *
                {
                        ERROR ("plugin: register_callback: "
                                        "llentry_create failed.");
 -                      free (key);
 +                      sfree (key);
                        destroy_callback (cf);
                        return (-1);
                }
@@@ -358,9 -352,9 +358,9 @@@ static void log_list_callbacks (llist_
                *str = '\0';
                strjoin(str, len, keys, n, "', '");
                INFO("%s ['%s']", comment, str);
 -              free(str);
 +              sfree (str);
        }
 -      free(keys);
 +      sfree (keys);
  } /* }}} void log_list_callbacks */
  
  static int create_register_callback (llist_t **list, /* {{{ */
@@@ -483,9 -477,7 +483,9 @@@ static void *plugin_read_thread (void _
        {
                read_func_t *rf;
                plugin_ctx_t old_ctx;
 +              cdtime_t start;
                cdtime_t now;
 +              cdtime_t elapsed;
                int status;
                int rf_type;
                int rc;
  
                DEBUG ("plugin_read_thread: Handling `%s'.", rf->rf_name);
  
 +              start = cdtime ();
 +
                old_ctx = plugin_set_ctx (rf->rf_ctx);
  
                if (rf_type == RF_SIMPLE)
                /* update the ``next read due'' field */
                now = cdtime ();
  
 +              /* calculate the time spent in the read function */
 +              elapsed = (now - start);
 +
 +              if (elapsed > rf->rf_effective_interval)
 +                      WARNING ("plugin_read_thread: read-function of the `%s' plugin took %.3f "
 +                              "seconds, which is above its read interval (%.3f seconds). You might "
 +                              "want to adjust the `Interval' or `ReadThreads' settings.",
 +                              rf->rf_name, CDTIME_T_TO_DOUBLE(elapsed),
 +                              CDTIME_T_TO_DOUBLE(rf->rf_effective_interval));
 +
 +              DEBUG ("plugin_read_thread: read-function of the `%s' plugin took "
 +                              "%.6f seconds.",
 +                              rf->rf_name, CDTIME_T_TO_DOUBLE(elapsed));
 +
                DEBUG ("plugin_read_thread: Effective interval of the "
 -                              "%s plugin is %.3f seconds.",
 +                              "`%s' plugin is %.3f seconds.",
                                rf->rf_name,
                                CDTIME_T_TO_DOUBLE (rf->rf_effective_interval));
  
                        rf->rf_next_read = now;
                }
  
 -              DEBUG ("plugin_read_thread: Next read of the %s plugin at %.3f.",
 +              DEBUG ("plugin_read_thread: Next read of the `%s' plugin at %.3f.",
                                rf->rf_name,
                                CDTIME_T_TO_DOUBLE (rf->rf_next_read));
  
@@@ -907,7 -883,7 +907,7 @@@ static void start_write_threads (size_
  static void stop_write_threads (void) /* {{{ */
  {
        write_queue_t *q;
 -      int i;
 +      size_t i;
  
        if (write_threads == NULL)
                return;
  
        if (i > 0)
        {
 -              WARNING ("plugin: %i value list%s left after shutting down "
 +              WARNING ("plugin: %zu value list%s left after shutting down "
                                "the write threads.",
                                i, (i == 1) ? " was" : "s were");
        }
   */
  void plugin_set_dir (const char *dir)
  {
 -      if (plugindir != NULL)
 -              free (plugindir);
 +      sfree (plugindir);
  
        if (dir == NULL)
 -              plugindir = NULL;
 -      else if ((plugindir = strdup (dir)) == NULL)
        {
 -              char errbuf[1024];
 -              ERROR ("strdup failed: %s",
 -                              sstrerror (errno, errbuf, sizeof (errbuf)));
 +              plugindir = NULL;
 +              return;
        }
 +
 +      plugindir = strdup (dir);
 +      if (plugindir == NULL)
 +              ERROR ("plugin_set_dir: strdup(\"%s\") failed", dir);
  }
  
  static _Bool plugin_is_loaded (char const *name)
@@@ -1107,7 -1083,6 +1107,7 @@@ int plugin_load (char const *plugin_nam
                        /* success */
                        plugin_mark_loaded (plugin_name);
                        ret = 0;
 +                      INFO ("plugin_load: plugin \"%s\" successfully loaded.", plugin_name);
                        break;
                }
                else
@@@ -1272,7 -1247,7 +1272,7 @@@ int plugin_register_read (const char *n
  
  int plugin_register_complex_read (const char *group, const char *name,
                plugin_read_cb callback,
 -              const struct timespec *interval,
 +              cdtime_t interval,
                user_data_t *user_data)
  {
        read_func_t *rf;
                rf->rf_group[0] = '\0';
        rf->rf_name = strdup (name);
        rf->rf_type = RF_COMPLEX;
 -      if (interval != NULL)
 -              rf->rf_interval = TIMESPEC_TO_CDTIME_T (interval);
 -      else
 -              rf->rf_interval = plugin_get_interval ();
 +      rf->rf_interval = (interval != 0) ? interval : plugin_get_interval ();
  
        /* Set user data */
        if (user_data == NULL)
@@@ -1324,105 -1302,11 +1324,105 @@@ int plugin_register_write (const char *
                                (void *) callback, ud));
  } /* int plugin_register_write */
  
 +static int plugin_flush_timeout_callback (user_data_t *ud)
 +{
 +      flush_callback_t *cb = ud->data;
 +
 +      return plugin_flush (cb->name, cb->timeout, /* identifier = */ NULL);
 +} /* static int plugin_flush_callback */
 +
 +static void plugin_flush_timeout_callback_free (void *data)
 +{
 +      flush_callback_t *cb = data;
 +
 +      if (cb == NULL) return;
 +
 +      sfree (cb->name);
 +      sfree (cb);
 +} /* static void plugin_flush_callback_free */
 +
 +static char *plugin_flush_callback_name (const char *name)
 +{
 +      char *flush_prefix = "flush/";
 +      size_t prefix_size;
 +      char *flush_name;
 +      size_t name_size;
 +
 +      prefix_size = strlen(flush_prefix);
 +      name_size = strlen(name);
 +
 +      flush_name = malloc (sizeof(char) * (name_size + prefix_size + 1));
 +      if (flush_name == NULL)
 +      {
 +              ERROR ("plugin_flush_callback_name: malloc failed.");
 +              return (NULL);
 +      }
 +
 +      sstrncpy (flush_name, flush_prefix, prefix_size + 1);
 +      sstrncpy (flush_name + prefix_size, name, name_size + 1);
 +
 +      return flush_name;
 +} /* static char *plugin_flush_callback_name */
 +
  int plugin_register_flush (const char *name,
                plugin_flush_cb callback, user_data_t *ud)
  {
 -      return (create_register_callback (&list_flush, name,
 -                              (void *) callback, ud));
 +      int status;
 +      plugin_ctx_t ctx = plugin_get_ctx ();
 +
 +      status = create_register_callback (&list_flush, name,
 +              (void *) callback, ud);
 +      if (status != 0)
 +              return status;
 +
 +      if (ctx.flush_interval != 0)
 +      {
 +              char *flush_name;
 +              user_data_t ud;
 +              flush_callback_t *cb;
 +
 +              flush_name = plugin_flush_callback_name (name);
 +              if (flush_name == NULL)
 +                      return (-1);
 +
 +              cb = malloc(sizeof(flush_callback_t));
 +              if (cb == NULL)
 +              {
 +                      ERROR ("plugin_register_flush: malloc failed.");
 +                      sfree (flush_name);
 +                      return (-1);
 +              }
 +
 +              cb->name = strdup (name);
 +              if (cb->name == NULL)
 +              {
 +                      ERROR ("plugin_register_flush: strdup failed.");
 +                      sfree (cb);
 +                      sfree (flush_name);
 +                      return (-1);
 +              }
 +              cb->timeout = ctx.flush_timeout;
 +
 +              ud.data = cb;
 +              ud.free_func = plugin_flush_timeout_callback_free;
 +
 +              status = plugin_register_complex_read (
 +                      /* group     = */ "flush",
 +                      /* name      = */ flush_name,
 +                      /* callback  = */ plugin_flush_timeout_callback,
 +                      /* interval  = */ ctx.flush_interval,
 +                      /* user data = */ &ud);
 +
 +              sfree (flush_name);
 +              if (status != 0)
 +              {
 +                      sfree (cb->name);
 +                      sfree (cb);
 +                      return status;
 +              }
 +      }
 +
 +      return 0;
  } /* int plugin_register_flush */
  
  int plugin_register_missing (const char *name,
@@@ -1463,7 -1347,7 +1463,7 @@@ static void plugin_free_data_sets (void
  int plugin_register_data_set (const data_set_t *ds)
  {
        data_set_t *ds_copy;
 -      int i;
 +      size_t i;
  
        if ((data_sets != NULL)
                        && (c_avl_get (data_sets, ds->type, NULL) == 0))
                        * ds->ds_num);
        if (ds_copy->ds == NULL)
        {
 -              free (ds_copy);
 +              sfree (ds_copy);
                return (-1);
        }
  
@@@ -1641,21 -1525,7 +1641,21 @@@ int plugin_unregister_write (const cha
  
  int plugin_unregister_flush (const char *name)
  {
 -      return (plugin_unregister (list_flush, name));
 +      plugin_ctx_t ctx = plugin_get_ctx ();
 +
 +      if (ctx.flush_interval != 0)
 +      {
 +              char *flush_name;
 +
 +              flush_name = plugin_flush_callback_name (name);
 +              if (flush_name != NULL)
 +              {
 +                      plugin_unregister_read(flush_name);
 +                      sfree (flush_name);
 +              }
 +      }
 +
 +      return plugin_unregister (list_flush, name);
  }
  
  int plugin_unregister_missing (const char *name)
@@@ -1697,7 -1567,6 +1697,6 @@@ int plugin_unregister_notification (con
  void plugin_init_all (void)
  {
        char const *chain_name;
-       long write_threads_num;
        llentry_t *le;
        int status;
  
@@@ -2161,8 -2030,8 +2160,8 @@@ static int plugin_dispatch_values_inter
        if (ds->ds_num != vl->values_len)
        {
                ERROR ("plugin_dispatch_values: ds->type = %s: "
 -                              "(ds->ds_num = %i) != "
 -                              "(vl->values_len = %i)",
 +                              "(ds->ds_num = %zu) != "
 +                              "(vl->values_len = %zu)",
                                ds->type, ds->ds_num, vl->values_len);
                return (-1);
        }
                         * don't get confused.. */
                        if (saved_values != NULL)
                        {
 -                              free (vl->values);
 +                              sfree (vl->values);
                                vl->values     = saved_values;
                                vl->values_len = saved_values_len;
                        }
         * confused.. */
        if (saved_values != NULL)
        {
 -              free (vl->values);
 +              sfree (vl->values);
                vl->values     = saved_values;
                vl->values_len = saved_values_len;
        }
@@@ -2730,11 -2599,7 +2729,11 @@@ int plugin_notification_meta_free (noti
  
      if (this->type == NM_TYPE_STRING)
      {
 -      free ((char *)this->nm_value.nm_string);
 +      /* Assign to a temporary variable to work around nm_string's const
 +       * modifier. */
 +      void *tmp = (void *) this->nm_value.nm_string;
 +
 +      sfree (tmp);
        this->nm_value.nm_string = NULL;
      }
      sfree (this);
@@@ -2841,7 -2706,7 +2840,7 @@@ static void *plugin_thread_start (void 
  
        plugin_set_ctx (plugin_thread->ctx);
  
 -      free (plugin_thread);
 +      sfree (plugin_thread);
  
        return start_routine (plugin_arg);
  } /* void *plugin_thread_start */
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,7 -79,7 +79,7 @@@ 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;
  
@@@ -128,7 -128,7 +128,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);
    }
  
@@@ -375,7 -375,7 +375,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. */
@@@ -549,7 -567,7 +549,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);
@@@ -736,7 -754,6 +736,6 @@@ int uc_get_history_by_name (const char 
    if (ce->history_length < num_steps)
    {
      gauge_t *tmp;
-     size_t i;
  
      tmp = realloc (ce->history, sizeof (*ce->history)
        * num_steps * ce->values_num);
diff --combined src/ntpd.c
@@@ -38,6 -38,9 +38,6 @@@
  #if HAVE_NETDB_H
  # include <netdb.h>
  #endif
 -#if HAVE_SYS_SOCKET_H
 -# include <sys/socket.h>
 -#endif
  #if HAVE_NETINET_IN_H
  # include <netinet/in.h>
  #endif
@@@ -163,16 -166,16 +163,16 @@@ struct resp_pk
  /* l_fp to double */
  #define M_LFPTOD(r_i, r_uf, d) \
        do { \
-               register int32_t  i; \
-               register uint32_t f; \
+               register int32_t  ri; \
+               register uint32_t rf; \
                \
-               i = (r_i); \
-               f = (r_uf); \
-               if (i < 0) { \
-                       M_NEG(i, f); \
-                       (d) = -((double) i + ((double) f) / 4294967296.0); \
+               ri = (r_i); \
+               rf = (r_uf); \
+               if (ri < 0) { \
+                       M_NEG(ri, rf); \
+                       (d) = -((double) ri + ((double) rf) / 4294967296.0); \
                } else { \
-                       (d) = (double) i + ((double) f) / 4294967296.0; \
+                       (d) = (double) ri + ((double) rf) / 4294967296.0; \
                } \
        } while (0)
  
@@@ -262,7 -265,7 +262,7 @@@ static char *refclock_names[] 
        "JJY",        "TT_IRIG",      "GPS_ZYFER",  "GPS_RIPENCC", /* 40-43 */
        "NEOCLK4X"                                                 /* 44    */
  };
 -static int refclock_names_num = STATIC_ARRAY_SIZE (refclock_names);
 +static size_t refclock_names_num = STATIC_ARRAY_SIZE (refclock_names);
  /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
   * End of the copied stuff..                                         *
   * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
@@@ -865,7 -868,7 +865,7 @@@ static int ntpd_get_name_refclock (cha
        uint32_t refclock_id = ntpd_get_refclock_id (peer_info);
        uint32_t unit_id = ntohl (peer_info->srcadr) & 0x00FF;
  
 -      if (refclock_id >= refclock_names_num)
 +      if (((size_t) refclock_id) >= refclock_names_num)
                return (ntpd_get_name_from_address (buffer, buffer_size,
                                        peer_info,
                                        /* do_reverse_lookup = */ 0));
diff --combined src/perl.c
@@@ -301,32 -301,33 +301,32 @@@ static int hv2data_source (pTHX_ HV *ha
        return 0;
  } /* static int hv2data_source (HV *, data_source_t *) */
  
 -static int av2value (pTHX_ char *name, AV *array, value_t *value, int len)
 +/* av2value converts at most "len" elements from "array" to "value". Returns the
 + * number of elements converted or zero on error. */
 +static size_t av2value (pTHX_ char *name, AV *array, value_t *value, size_t array_len)
  {
        const data_set_t *ds;
 +      size_t i;
  
 -      int i = 0;
 -
 -      if ((NULL == name) || (NULL == array) || (NULL == value))
 -              return -1;
 -
 -      if (av_len (array) < len - 1)
 -              len = av_len (array) + 1;
 -
 -      if (0 >= len)
 -              return -1;
 +      if ((NULL == name) || (NULL == array) || (NULL == value) || (array_len == 0))
 +              return 0;
  
        ds = plugin_get_ds (name);
        if (NULL == ds) {
                log_err ("av2value: Unknown dataset \"%s\"", name);
 -              return -1;
 +              return 0;
        }
  
 -      if (ds->ds_num < len) {
 -              log_warn ("av2value: Value length exceeds data set length.");
 -              len = ds->ds_num;
 +      if (array_len < ds->ds_num) {
 +              log_warn ("av2value: array does not contain enough elements for type \"%s\": got %zu, want %zu",
 +                              name, array_len, ds->ds_num);
 +              return 0;
 +      } else if (array_len > ds->ds_num) {
 +              log_warn ("av2value: array contains excess elements for type \"%s\": got %zu, want %zu",
 +                              name, array_len, ds->ds_num);
        }
  
 -      for (i = 0; i < len; ++i) {
 +      for (i = 0; i < ds->ds_num; ++i) {
                SV **tmp = av_fetch (array, i, 0);
  
                if (NULL != tmp) {
                                value[i].absolute = SvIV (*tmp);
                }
                else {
 -                      return -1;
 +                      return 0;
                }
        }
 -      return len;
 -} /* static int av2value (char *, AV *, value_t *, int) */
 +
 +      return ds->ds_num;
 +} /* static size_t av2value (char *, AV *, value_t *, size_t) */
  
  /*
   * value list:
@@@ -380,14 -380,16 +380,14 @@@ static int hv2value_list (pTHX_ HV *has
  
        {
                AV  *array = (AV *)SvRV (*tmp);
 -              int len    = av_len (array) + 1;
 -
 -              if (len <= 0)
 +              /* av_len returns the highest index, not the actual length. */
 +              size_t array_len = (size_t) (av_len (array) + 1);
 +              if (array_len == 0)
                        return -1;
  
 -              vl->values     = (value_t *)smalloc (len * sizeof (value_t));
 -              vl->values_len = av2value (aTHX_ vl->type, (AV *)SvRV (*tmp),
 -                              vl->values, len);
 -
 -              if (-1 == vl->values_len) {
 +              vl->values     = calloc (array_len, sizeof (*vl->values));
 +              vl->values_len = av2value (aTHX_ vl->type, (AV *)SvRV (*tmp), vl->values, array_len);
 +              if (vl->values_len == 0) {
                        sfree (vl->values);
                        return -1;
                }
@@@ -602,7 -604,7 +602,7 @@@ static int hv2notification (pTHX_ HV *h
  
  static int data_set2av (pTHX_ data_set_t *ds, AV *array)
  {
 -      int i = 0;
 +      size_t i;
  
        if ((NULL == ds) || (NULL == array))
                return -1;
  static int value_list2hv (pTHX_ value_list_t *vl, data_set_t *ds, HV *hash)
  {
        AV *values = NULL;
 -
 -      int i   = 0;
 -      int len = 0;
 +      size_t i;
  
        if ((NULL == vl) || (NULL == ds) || (NULL == hash))
                return -1;
  
 -      len = vl->values_len;
 -
 -      if (ds->ds_num < len) {
 -              log_warn ("value2av: Value length exceeds data set length.");
 -              len = ds->ds_num;
 -      }
 -
        values = newAV ();
 -      av_extend (values, len - 1);
 +      /* av_extend takes the last *index* to which the array should be extended. */
 +      av_extend (values, vl->values_len - 1);
  
 -      for (i = 0; i < len; ++i) {
 +      assert (ds->ds_num == vl->values_len);
 +      for (i = 0; i < vl->values_len; ++i) {
                SV *val = NULL;
  
                if (DS_TYPE_COUNTER == ds->ds[i].type)
@@@ -2076,7 -2085,7 +2076,7 @@@ static int perl_shutdown (void
                return 0;
  
        if (NULL == aTHX) {
-               c_ithread_t *t = NULL;
+               t = NULL;
  
                pthread_mutex_lock (&perl_threads->mutex);
                t = c_ithread_create (perl_threads->head->interp);
diff --combined src/python.c
@@@ -355,7 -355,7 +355,7 @@@ static int cpy_read_callback(user_data_
  }
  
  static int cpy_write_callback(const data_set_t *ds, const value_list_t *value_list, user_data_t *data) {
 -      int i;
 +      size_t i;
        cpy_callback_t *c = data->data;
        PyObject *ret, *list, *temp, *dict = NULL;
        Values *v;
                }
                for (i = 0; i < value_list->values_len; ++i) {
                        if (ds->ds[i].type == DS_TYPE_COUNTER) {
 -                              if ((long) value_list->values[i].counter == value_list->values[i].counter)
 -                                      PyList_SetItem(list, i, PyInt_FromLong(value_list->values[i].counter));
 -                              else
 -                                      PyList_SetItem(list, i, PyLong_FromUnsignedLongLong(value_list->values[i].counter));
 +                              PyList_SetItem(list, i, PyLong_FromUnsignedLongLong(value_list->values[i].counter));
                        } else if (ds->ds[i].type == DS_TYPE_GAUGE) {
                                PyList_SetItem(list, i, PyFloat_FromDouble(value_list->values[i].gauge));
                        } else if (ds->ds[i].type == DS_TYPE_DERIVE) {
 -                              if ((long) value_list->values[i].derive == value_list->values[i].derive)
 -                                      PyList_SetItem(list, i, PyInt_FromLong(value_list->values[i].derive));
 -                              else
 -                                      PyList_SetItem(list, i, PyLong_FromLongLong(value_list->values[i].derive));
 +                              PyList_SetItem(list, i, PyLong_FromLongLong(value_list->values[i].derive));
                        } else if (ds->ds[i].type == DS_TYPE_ABSOLUTE) {
 -                              if ((long) value_list->values[i].absolute == value_list->values[i].absolute)
 -                                      PyList_SetItem(list, i, PyInt_FromLong(value_list->values[i].absolute));
 -                              else
 -                                      PyList_SetItem(list, i, PyLong_FromUnsignedLongLong(value_list->values[i].absolute));
 +                              PyList_SetItem(list, i, PyLong_FromUnsignedLongLong(value_list->values[i].absolute));
                        } else {
                                Py_BEGIN_ALLOW_THREADS
                                ERROR("cpy_write_callback: Unknown value type %d.", ds->ds[i].type);
                }
                dict = PyDict_New();  /* New reference. */
                if (value_list->meta) {
-                       int i, num;
+                       int num;
                        char **table;
                        meta_data_t *meta = value_list->meta;
  
@@@ -575,7 -584,7 +575,7 @@@ static PyObject *float_or_none(float nu
  }
  
  static PyObject *cpy_get_dataset(PyObject *self, PyObject *args) {
 -      int i;
 +      size_t i;
        char *name;
        const data_set_t *ds;
        PyObject *list, *tuple;
@@@ -669,6 -678,7 +669,6 @@@ static PyObject *cpy_register_read(PyOb
        double interval = 0;
        char *name = NULL;
        PyObject *callback = NULL, *data = NULL;
 -      struct timespec ts;
        static char *kwlist[] = {"callback", "interval", "data", "name", NULL};
        
        if (PyArg_ParseTupleAndKeywords(args, kwds, "O|dOet", kwlist, &callback, &interval, &data, NULL, &name) == 0) return NULL;
        user_data.free_func = cpy_destroy_user_data;
        user_data.data = c;
  
 -      ts.tv_sec = interval;
 -      ts.tv_nsec = (interval - ts.tv_sec) * 1000000000;
        plugin_register_complex_read(/* group = */ "python", buf,
 -                      cpy_read_callback, &ts, &user_data);
 -
 +                      cpy_read_callback, DOUBLE_TO_CDTIME_T (interval), &user_data);
        return cpy_string_to_unicode_or_bytes(buf);
  }