Code

Merge branch 'collectd-4.4'
authorFlorian Forster <octo@leeloo.lan.home.verplant.org>
Tue, 15 Jul 2008 15:12:21 +0000 (17:12 +0200)
committerFlorian Forster <octo@leeloo.lan.home.verplant.org>
Tue, 15 Jul 2008 15:12:21 +0000 (17:12 +0200)
Conflicts:

src/snmp.c

1  2 
src/collectd.h
src/configfile.c
src/ntpd.c
src/perl.c
src/snmp.c
src/vserver.c

diff --combined src/collectd.h
index 5912fe6f809b0557dac19b3460e9f038ac5230e0,eece4203894b1a51786446b6787fba77f152d944..a262bf1d1fc99621e07b9aea7619351bc736d809
@@@ -56,9 -56,6 +56,9 @@@
  #if HAVE_STDINT_H
  # include <stdint.h>
  #endif
 +#if HAVE_STDBOOL_H
 +# include <stdbool.h>
 +#endif
  #if HAVE_UNISTD_H
  # include <unistd.h>
  #endif
  # include <kstat.h>
  #endif
  
- #if HAVE_PTH_H
- # include <pth.h>
- #endif
  #if HAVE_SENSORS_SENSORS_H
  # include <sensors/sensors.h>
  #endif
  #endif
  
  #if __GNUC__
- # pragma GCC poison strcpy strcat sprintf strtok
+ # pragma GCC poison strcpy strcat strtok
+ #endif
+ /* 
+  * Special hack for the perl plugin: Because the later included perl.h defines
+  * a macro which is never used, but contains `sprintf', we cannot poison that
+  * identifies just yet. The parl plugin will do that itself once perl.h is
+  * included.
+  */
+ #ifndef DONT_POISON_SPRINTF_YET
+ # if __GNUC__
+ #  pragma GCC poison sprintf
+ # endif
  #endif
  
  extern char hostname_g[];
diff --combined src/configfile.c
index 2afef4f024e402a2cc94bd7f02744e599fac440a,1df911195df20c358e89e6f4012f9e6ac5e82a0b..d483032af71b398d10a44c808c65285e55e805e8
@@@ -182,7 -182,8 +182,7 @@@ static int dispatch_global_option (cons
        else if (ci->values[0].type == OCONFIG_TYPE_NUMBER)
        {
                char tmp[128];
 -              snprintf (tmp, sizeof (tmp), "%lf", ci->values[0].value.number);
 -              tmp[127] = '\0';
 +              ssnprintf (tmp, sizeof (tmp), "%lf", ci->values[0].value.number);
                return (global_option_set (ci->key, tmp));
        }
        else if (ci->values[0].type == OCONFIG_TYPE_BOOLEAN)
@@@ -257,13 -258,13 +257,13 @@@ static int dispatch_value_plugin (cons
                int status = -1;
  
                if (ci->values[i].type == OCONFIG_TYPE_STRING)
 -                      status = snprintf (buffer_ptr, buffer_free, " %s",
 +                      status = ssnprintf (buffer_ptr, buffer_free, " %s",
                                        ci->values[i].value.string);
                else if (ci->values[i].type == OCONFIG_TYPE_NUMBER)
 -                      status = snprintf (buffer_ptr, buffer_free, " %lf",
 +                      status = ssnprintf (buffer_ptr, buffer_free, " %lf",
                                        ci->values[i].value.number);
                else if (ci->values[i].type == OCONFIG_TYPE_BOOLEAN)
 -                      status = snprintf (buffer_ptr, buffer_free, " %s",
 +                      status = ssnprintf (buffer_ptr, buffer_free, " %s",
                                        ci->values[i].value.boolean
                                        ? "true" : "false");
  
@@@ -327,7 -328,7 +327,7 @@@ static int dispatch_block_plugin (oconf
                if (ci->children[i].children == NULL)
                        dispatch_value_plugin (name, ci->children + i);
                else
-                       {DEBUG ("No nested config blocks allow for this plugin.");}
+                       {DEBUG ("No nested config blocks allowed for this plugin.");}
        }
  
        return (0);
@@@ -547,7 -548,7 +547,7 @@@ static oconfig_item_t *cf_read_dir (con
                if ((de->d_name[0] == '.') || (de->d_name[0] == '\0'))
                        continue;
  
 -              status = snprintf (name, sizeof (name), "%s/%s",
 +              status = ssnprintf (name, sizeof (name), "%s/%s",
                                dir, de->d_name);
                if (status >= sizeof (name))
                {
diff --combined src/ntpd.c
index 1a0a07dd5a66a9a01d2cf3172e4b12db371431df,a7ef0fa3fd13fd0efbbce605688efa72eb93b7d8..44964bb5a8dbd936d23ef2e828e4d05b2561c543
@@@ -68,7 -68,7 +68,7 @@@ static char  ntpd_port[16]
  #define MAXFILENAME 128
  #define MAXSEQ  127
  #define MODE_PRIVATE 7
- #define NTP_OLDVERSION ((u_char) 1) /* oldest credible version */
+ #define NTP_OLDVERSION ((uint8_t) 1) /* oldest credible version */
  #define IMPL_XNTPD 3
  #define FP_FRAC 65536.0
  
@@@ -117,27 -117,27 +117,27 @@@ struct resp_pk
  
  #define       ISRESPONSE(rm_vn_mode)  (((rm_vn_mode)&RESP_BIT)!=0)
  #define       ISMORE(rm_vn_mode)      (((rm_vn_mode)&MORE_BIT)!=0)
- #define INFO_VERSION(rm_vn_mode) ((u_char)(((rm_vn_mode)>>3)&0x7))
+ #define INFO_VERSION(rm_vn_mode) ((uint8_t)(((rm_vn_mode)>>3)&0x7))
  #define       INFO_MODE(rm_vn_mode)   ((rm_vn_mode)&0x7)
  
  #define       RM_VN_MODE(resp, more, version)         \
-                               ((u_char)(((resp)?RESP_BIT:0)\
+                               ((uint8_t)(((resp)?RESP_BIT:0)\
                                |((more)?MORE_BIT:0)\
                                |((version?version:(NTP_OLDVERSION+1))<<3)\
                                |(MODE_PRIVATE)))
  
  #define       INFO_IS_AUTH(auth_seq)  (((auth_seq) & 0x80) != 0)
  #define       INFO_SEQ(auth_seq)      ((auth_seq)&0x7f)
- #define       AUTH_SEQ(auth, seq)     ((u_char)((((auth)!=0)?0x80:0)|((seq)&0x7f)))
+ #define       AUTH_SEQ(auth, seq)     ((uint8_t)((((auth)!=0)?0x80:0)|((seq)&0x7f)))
  
- #define       INFO_ERR(err_nitems)    ((u_short)((ntohs(err_nitems)>>12)&0xf))
- #define       INFO_NITEMS(err_nitems) ((u_short)(ntohs(err_nitems)&0xfff))
- #define       ERR_NITEMS(err, nitems) (htons((u_short)((((u_short)(err)<<12)&0xf000)\
-                               |((u_short)(nitems)&0xfff))))
+ #define       INFO_ERR(err_nitems)    ((uint16_t)((ntohs(err_nitems)>>12)&0xf))
+ #define       INFO_NITEMS(err_nitems) ((uint16_t)(ntohs(err_nitems)&0xfff))
+ #define       ERR_NITEMS(err, nitems) (htons((uint16_t)((((uint16_t)(err)<<12)&0xf000)\
+                               |((uint16_t)(nitems)&0xfff))))
  
  #define       INFO_MBZ(mbz_itemsize)  ((ntohs(mbz_itemsize)>>12)&0xf)
- #define       INFO_ITEMSIZE(mbz_itemsize)     ((u_short)(ntohs(mbz_itemsize)&0xfff))
- #define       MBZ_ITEMSIZE(itemsize)  (htons((u_short)(itemsize)))
+ #define       INFO_ITEMSIZE(mbz_itemsize)     ((uint16_t)(ntohs(mbz_itemsize)&0xfff))
+ #define       MBZ_ITEMSIZE(itemsize)  (htons((uint16_t)(itemsize)))
  
  /* negate a long float type */
  #define M_NEG(v_i, v_f) \
@@@ -269,10 -269,11 +269,10 @@@ static int ntpd_config (const char *key
        {
                int port = (int) (atof (value));
                if ((port > 0) && (port <= 65535))
 -                      snprintf (ntpd_port, sizeof (ntpd_port),
 +                      ssnprintf (ntpd_port, sizeof (ntpd_port),
                                        "%i", port);
                else
 -                      strncpy (ntpd_port, value, sizeof (ntpd_port));
 -              ntpd_port[sizeof (ntpd_port) - 1] = '\0';
 +                      sstrncpy (ntpd_port, value, sizeof (ntpd_port));
        }
        else if (strcasecmp (key, "ReverseLookups") == 0)
        {
@@@ -304,10 -305,9 +304,10 @@@ static void ntpd_submit (char *type, ch
        sstrncpy (vl.host, hostname_g, sizeof (vl.host));
        sstrncpy (vl.plugin, "ntpd", sizeof (vl.plugin));
        sstrncpy (vl.plugin_instance, "", sizeof (vl.plugin_instance));
 -      strncpy (vl.type_instance, type_inst, sizeof (vl.type_instance));
 +      sstrncpy (vl.type, type, sizeof (vl.type));
 +      sstrncpy (vl.type_instance, type_inst, sizeof (vl.type_instance));
  
 -      plugin_dispatch_values (type, &vl);
 +      plugin_dispatch_values (&vl);
  }
  
  /* returns `tv0 - tv1' in milliseconds or 0 if `tv1 > tv0' */
@@@ -874,7 -874,7 +874,7 @@@ static int ntpd_read (void
  
                        if (refclock_id < refclock_names_num)
                        {
 -                              strncpy (peername, refclock_names[refclock_id],
 +                              sstrncpy (peername, refclock_names[refclock_id],
                                                sizeof (peername));
                        }
                        else
                                addr_obj.s_addr = ptr->srcadr;
                                addr_str = inet_ntoa (addr_obj);
  
 -                              strncpy (peername, addr_str, sizeof (peername));
 +                              sstrncpy (peername, addr_str, sizeof (peername));
                        }
                }
                else /* Normal network host. */
diff --combined src/perl.c
index 541826fb6eb04a2746904f2bcd441f0ec42a6e75,cb61be52b3fe260f67dd99cff418ba672a05022c..268e1d1428968b5d0eb4f9269ec7e2a004615bcc
  /* do not automatically get the thread specific perl interpreter */
  #define PERL_NO_GET_CONTEXT
  
+ #define DONT_POISON_SPRINTF_YET 1
  #include "collectd.h"
+ #undef DONT_POISON_SPRINTF_YET
  
  #include "configfile.h"
  
  #include <EXTERN.h>
  #include <perl.h>
  
+ #if __GNUC__
+ # pragma GCC poison sprintf
+ #endif
  #include <XSUB.h>
  
  /* Some versions of Perl define their own version of DEBUG... :-/ */
@@@ -210,7 -216,8 +216,7 @@@ static int hv2data_source (pTHX_ HV *ha
                return -1;
  
        if (NULL != (tmp = hv_fetch (hash, "name", 4, 0))) {
 -              strncpy (ds->name, SvPV_nolen (*tmp), DATA_MAX_NAME_LEN);
 -              ds->name[DATA_MAX_NAME_LEN - 1] = '\0';
 +              sstrncpy (ds->name, SvPV_nolen (*tmp), sizeof (ds->name));
        }
        else {
                log_err ("hv2data_source: No DS name given.");
@@@ -372,10 -379,6 +378,10 @@@ static int value_list2hv (pTHX_ value_l
                                newSVpv (vl->plugin_instance, 0), 0))
                        return -1;
  
 +      if ('\0' != vl->type[0])
 +              if (NULL == hv_store (hash, "type", 4, newSVpv (vl->type, 0), 0))
 +                      return -1;
 +
        if ('\0' != vl->type_instance[0])
                if (NULL == hv_store (hash, "type_instance", 13,
                                newSVpv (vl->type_instance, 0), 0))
@@@ -427,11 -430,12 +433,11 @@@ static int notification2hv (pTHX_ notif
  static char *get_module_name (char *buf, size_t buf_len, const char *module) {
        int status = 0;
        if (base_name[0] == '\0')
 -              status = snprintf (buf, buf_len, "%s", module);
 +              status = ssnprintf (buf, buf_len, "%s", module);
        else
 -              status = snprintf (buf, buf_len, "%s::%s", base_name, module);
 +              status = ssnprintf (buf, buf_len, "%s::%s", base_name, module);
        if ((status < 0) || ((unsigned int)status >= buf_len))
                return (NULL);
 -      buf[buf_len - 1] = '\0';
        return (buf);
  } /* char *get_module_name */
  
@@@ -477,7 -481,8 +483,7 @@@ static int pplugin_register_data_set (p
                                ds[i].name, ds[i].type, ds[i].min, ds[i].max);
        }
  
 -      strncpy (set->type, name, DATA_MAX_NAME_LEN);
 -      set->type[DATA_MAX_NAME_LEN - 1] = '\0';
 +      sstrncpy (set->type, name, sizeof (set->type));
  
        set->ds_num = len + 1;
        set->ds = ds;
@@@ -512,7 -517,7 +518,7 @@@ static int pplugin_unregister_data_set 
   *   type_instance   => $tinstance,
   * }
   */
 -static int pplugin_dispatch_values (pTHX_ char *name, HV *values)
 +static int pplugin_dispatch_values (pTHX_ HV *values)
  {
        value_list_t list = VALUE_LIST_INIT;
        value_t      *val = NULL;
  
        int ret = 0;
  
 -      if ((NULL == name) || (NULL == values))
 +      if (NULL == values)
 +              return -1;
 +
 +      if (NULL == (tmp = hv_fetch (values, "type", 4, 0))) {
 +              log_err ("pplugin_dispatch_values: No type given.");
                return -1;
 +      }
 +
 +      sstrncpy (list.type, SvPV_nolen (*tmp), sizeof (list.type));
  
        if ((NULL == (tmp = hv_fetch (values, "values", 6, 0)))
                        || (! (SvROK (*tmp) && (SVt_PVAV == SvTYPE (SvRV (*tmp)))))) {
  
                val = (value_t *)smalloc (len * sizeof (value_t));
  
 -              list.values_len = av2value (aTHX_ name, (AV *)SvRV (*tmp), val, len);
 +              list.values_len = av2value (aTHX_ list.type, (AV *)SvRV (*tmp),
 +                              val, len);
                list.values = val;
  
                if (-1 == list.values_len) {
        }
  
        if (NULL != (tmp = hv_fetch (values, "host", 4, 0))) {
 -              strncpy (list.host, SvPV_nolen (*tmp), DATA_MAX_NAME_LEN);
 -              list.host[DATA_MAX_NAME_LEN - 1] = '\0';
 +              sstrncpy (list.host, SvPV_nolen (*tmp), sizeof (list.host));
        }
        else {
                sstrncpy (list.host, hostname_g, sizeof (list.host));
        }
  
 -      if (NULL != (tmp = hv_fetch (values, "plugin", 6, 0))) {
 -              strncpy (list.plugin, SvPV_nolen (*tmp), DATA_MAX_NAME_LEN);
 -              list.plugin[DATA_MAX_NAME_LEN - 1] = '\0';
 -      }
 +      if (NULL != (tmp = hv_fetch (values, "plugin", 6, 0)))
 +              sstrncpy (list.plugin, SvPV_nolen (*tmp), sizeof (list.plugin));
  
 -      if (NULL != (tmp = hv_fetch (values, "plugin_instance", 15, 0))) {
 -              strncpy (list.plugin_instance, SvPV_nolen (*tmp), DATA_MAX_NAME_LEN);
 -              list.plugin_instance[DATA_MAX_NAME_LEN - 1] = '\0';
 -      }
 +      if (NULL != (tmp = hv_fetch (values, "plugin_instance", 15, 0)))
 +              sstrncpy (list.plugin_instance, SvPV_nolen (*tmp),
 +                              sizeof (list.plugin_instance));
  
 -      if (NULL != (tmp = hv_fetch (values, "type_instance", 13, 0))) {
 -              strncpy (list.type_instance, SvPV_nolen (*tmp), DATA_MAX_NAME_LEN);
 -              list.type_instance[DATA_MAX_NAME_LEN - 1] = '\0';
 -      }
 +      if (NULL != (tmp = hv_fetch (values, "type_instance", 13, 0)))
 +              sstrncpy (list.type_instance, SvPV_nolen (*tmp),
 +                              sizeof (list.type_instance));
  
 -      ret = plugin_dispatch_values (name, &list);
 +      ret = plugin_dispatch_values (&list);
  
        sfree (val);
        return ret;
@@@ -624,25 -626,31 +630,25 @@@ static int pplugin_dispatch_notificatio
                n.time = time (NULL);
  
        if (NULL != (tmp = hv_fetch (notif, "message", 7, 0)))
 -              strncpy (n.message, SvPV_nolen (*tmp), sizeof (n.message));
 -      n.message[sizeof (n.message) - 1] = '\0';
 +              sstrncpy (n.message, SvPV_nolen (*tmp), sizeof (n.message));
  
        if (NULL != (tmp = hv_fetch (notif, "host", 4, 0)))
 -              strncpy (n.host, SvPV_nolen (*tmp), sizeof (n.host));
 +              sstrncpy (n.host, SvPV_nolen (*tmp), sizeof (n.host));
        else
 -              strncpy (n.host, hostname_g, sizeof (n.host));
 -      n.host[sizeof (n.host) - 1] = '\0';
 +              sstrncpy (n.host, hostname_g, sizeof (n.host));
  
        if (NULL != (tmp = hv_fetch (notif, "plugin", 6, 0)))
 -              strncpy (n.plugin, SvPV_nolen (*tmp), sizeof (n.plugin));
 -      n.plugin[sizeof (n.plugin) - 1] = '\0';
 +              sstrncpy (n.plugin, SvPV_nolen (*tmp), sizeof (n.plugin));
  
        if (NULL != (tmp = hv_fetch (notif, "plugin_instance", 15, 0)))
 -              strncpy (n.plugin_instance, SvPV_nolen (*tmp),
 +              sstrncpy (n.plugin_instance, SvPV_nolen (*tmp),
                                sizeof (n.plugin_instance));
 -      n.plugin_instance[sizeof (n.plugin_instance) - 1] = '\0';
  
        if (NULL != (tmp = hv_fetch (notif, "type", 4, 0)))
 -              strncpy (n.type, SvPV_nolen (*tmp), sizeof (n.type));
 -      n.type[sizeof (n.type) - 1] = '\0';
 +              sstrncpy (n.type, SvPV_nolen (*tmp), sizeof (n.type));
  
        if (NULL != (tmp = hv_fetch (notif, "type_instance", 13, 0)))
 -              strncpy (n.type_instance, SvPV_nolen (*tmp), sizeof (n.type_instance));
 -      n.type_instance[sizeof (n.type_instance) - 1] = '\0';
 +              sstrncpy (n.type_instance, SvPV_nolen (*tmp), sizeof (n.type_instance));
        return plugin_dispatch_notification (&n);
  } /* static int pplugin_dispatch_notification (HV *) */
  
@@@ -691,7 -699,6 +697,7 @@@ static int pplugin_call_all (pTHX_ int 
                 *   time   => $time,
                 *   host   => $hostname,
                 *   plugin => $plugin,
 +               *   type   => $type,
                 *   plugin_instance => $instance,
                 *   type_instance   => $type_instance
                 * };
@@@ -867,43 -874,33 +873,43 @@@ static XS (Collectd_plugin_unregister_d
   */
  static XS (Collectd_plugin_dispatch_values)
  {
 -      SV *values = NULL;
 +      SV *values     = NULL;
 +      int values_idx = 0;
  
        int ret = 0;
  
        dXSARGS;
  
 -      if (2 != items) {
 -              log_err ("Usage: Collectd::plugin_dispatch_values(name, values)");
 +      if (2 == items) {
 +              log_warn ("Collectd::plugin_dispatch_values with two arguments "
 +                              "is deprecated - pass the type through values->{type}.");
 +              values_idx = 1;
 +      }
 +      else if (1 != items) {
 +              log_err ("Usage: Collectd::plugin_dispatch_values(values)");
                XSRETURN_EMPTY;
        }
  
 -      log_debug ("Collectd::plugin_dispatch_values: "
 -                      "name = \"%s\", values=\"%s\"",
 -                      SvPV_nolen (ST (0)), SvPV_nolen (ST (1)));
 +      log_debug ("Collectd::plugin_dispatch_values: values=\"%s\"",
 +                      SvPV_nolen (ST (values_idx)));
  
 -      values = ST (1);
 +      values = ST (values_idx);
  
        if (! (SvROK (values) && (SVt_PVHV == SvTYPE (SvRV (values))))) {
                log_err ("Collectd::plugin_dispatch_values: Invalid values.");
                XSRETURN_EMPTY;
        }
  
 -      if ((NULL == ST (0)) || (NULL == values))
 +      if (((2 == items) && (NULL == ST (0))) || (NULL == values))
                XSRETURN_EMPTY;
  
 -      ret = pplugin_dispatch_values (aTHX_ SvPV_nolen (ST (0)),
 -                      (HV *)SvRV (values));
 +      if ((2 == items) && (NULL == hv_store ((HV *)SvRV (values), "type", 4,
 +                      newSVsv (ST (0)), 0))) {
 +              log_err ("Collectd::plugin_dispatch_values: Could not store type.");
 +              XSRETURN_EMPTY;
 +      }
 +
 +      ret = pplugin_dispatch_values (aTHX_ (HV *)SvRV (values));
  
        if (0 == ret)
                XSRETURN_YES;
@@@ -1264,8 -1261,7 +1270,8 @@@ static int perl_notify (const notificat
        return pplugin_call_all (aTHX_ PLUGIN_NOTIF, notif);
  } /* static int perl_notify (const notification_t *) */
  
 -static int perl_flush (const int timeout)
 +/* TODO: Implement flushing of single identifiers. */
 +static int perl_flush (int timeout, const char *identifier)
  {
        dTHX;
  
@@@ -1362,7 -1358,8 +1368,7 @@@ static int g_pv_get (pTHX_ SV *var, MAG
  static int g_pv_set (pTHX_ SV *var, MAGIC *mg)
  {
        char *pv = mg->mg_ptr;
 -      strncpy (pv, SvPV_nolen (var), DATA_MAX_NAME_LEN);
 -      pv[DATA_MAX_NAME_LEN - 1] = '\0';
 +      sstrncpy (pv, SvPV_nolen (var), DATA_MAX_NAME_LEN);
        return 0;
  } /* static int g_pv_set (pTHX_ SV *, MAGIC *) */
  
@@@ -1563,7 -1560,8 +1569,7 @@@ static int perl_config_basename (pTHX_ 
        value = ci->values[0].value.string;
  
        log_debug ("perl_config: Setting plugin basename to \"%s\"", value);
 -      strncpy (base_name, value, sizeof (base_name));
 -      base_name[sizeof (base_name) - 1] = '\0';
 +      sstrncpy (base_name, value, sizeof (base_name));
        return 0;
  } /* static int perl_config_basename (oconfig_item_it *) */
  
diff --combined src/snmp.c
index 05612576837dcbb1f8be3801af197adebd86694f,460624b4e4a2f8bd9be1b7ca22a6dfa2ec15b192..07465ddd26d1a951addd40b0ea28f9a7cad6b409
@@@ -198,8 -198,7 +198,8 @@@ static int csnmp_config_add_data_instan
    else
    {
      /* Instance is a simple string */
 -    strncpy (dd->instance.string, ci->values[0].value.string, DATA_MAX_NAME_LEN - 1);
 +    sstrncpy (dd->instance.string, ci->values[0].value.string,
 +      sizeof (dd->instance.string));
    }
  
    return (0);
@@@ -708,51 -707,22 +708,51 @@@ static value_t csnmp_value_list_to_valu
        || (vl->type == ASN_GAUGE))
    {
      temp = (uint32_t) *vl->val.integer;
-     DEBUG ("snmp plugin: Parsed int32 value is %llu.", temp);
+     DEBUG ("snmp plugin: Parsed int32 value is %"PRIu64".", temp);
    }
    else if (vl->type == ASN_COUNTER64)
    {
      temp = (uint32_t) vl->val.counter64->high;
      temp = temp << 32;
      temp += (uint32_t) vl->val.counter64->low;
-     DEBUG ("snmp plugin: Parsed int64 value is %llu.", temp);
+     DEBUG ("snmp plugin: Parsed int64 value is %"PRIu64".", temp);
    }
 +  else if (vl->type == ASN_OCTET_STR)
 +  {
 +    /* We'll handle this later.. */
 +  }
    else
    {
      WARNING ("snmp plugin: I don't know the ASN type `%i'", (int) vl->type);
      defined = 0;
    }
  
 -  if (type == DS_TYPE_COUNTER)
 +  if (vl->type == ASN_OCTET_STR)
 +  {
 +    char *string;
 +    char *endptr;
 +
 +    string = (char *) vl->val.string;
 +    endptr = NULL;
 +
 +    if (string != NULL)
 +    {
 +      if (type == DS_TYPE_COUNTER)
 +      ret.counter = (counter_t) strtoll (string, &endptr, /* base = */ 0);
 +      else if (type == DS_TYPE_GAUGE)
 +      ret.gauge = (gauge_t) strtod (string, &endptr);
 +    }
 +
 +    /* Check if an error occurred */
 +    if ((string == NULL) || (endptr == string))
 +    {
 +      if (type == DS_TYPE_COUNTER)
 +      ret.counter = 0;
 +      else if (type == DS_TYPE_GAUGE)
 +      ret.gauge = NAN;
 +    }
 +  }
 +  else if (type == DS_TYPE_COUNTER)
    {
      ret.counter = temp;
    }
@@@ -863,10 -833,11 +863,10 @@@ static int csnmp_instance_list_add (csn
      if (instance_len > vb->val_len)
        instance_len = vb->val_len;
  
 -    strncpy (il->instance, (char *) ((vb->type == ASN_OCTET_STR)
 +    sstrncpy (il->instance, (char *) ((vb->type == ASN_OCTET_STR)
          ? vb->val.string
          : vb->val.bitstring),
        instance_len);
 -    il->instance[instance_len] = '\0';
  
      for (ptr = il->instance; *ptr != '\0'; ptr++)
      {
    else
    {
      value_t val = csnmp_value_list_to_value (vb, DS_TYPE_COUNTER, 1.0, 0.0);
 -    snprintf (il->instance, sizeof (il->instance),
 +    ssnprintf (il->instance, sizeof (il->instance),
        "%llu", val.counter);
    }
 -  il->instance[sizeof (il->instance) - 1] = '\0';
  
    /* TODO: Debugging output */
  
@@@ -935,7 -907,8 +935,7 @@@ static int csnmp_dispatch_table (host_d
      return (-1);
    }
  
 -  strncpy (vl.host, host->name, sizeof (vl.host));
 -  vl.host[sizeof (vl.host) - 1] = '\0';
 +  sstrncpy (vl.host, host->name, sizeof (vl.host));
    sstrncpy (vl.plugin, "snmp", sizeof (vl.plugin));
  
    vl.interval = host->interval;
        || (instance_list_ptr->subid == value_table_ptr[0]->subid));
  #endif
  
 +    sstrncpy (vl.type, data->type, sizeof (vl.type));
 +
      {
        char temp[DATA_MAX_NAME_LEN];
  
        if (instance_list_ptr == NULL)
 -      snprintf (temp, sizeof (temp), "%u",
 -          (uint32_t) subid);
 +      ssnprintf (temp, sizeof (temp), "%u", (uint32_t) subid);
        else
 -      strncpy (temp, instance_list_ptr->instance,
 -          sizeof (temp));
 -      temp[sizeof (temp) - 1] = '\0';
 +      sstrncpy (temp, instance_list_ptr->instance, sizeof (temp));
  
        if (data->instance_prefix == NULL)
 -      strncpy (vl.type_instance, temp, sizeof (vl.type_instance));
 +      sstrncpy (vl.type_instance, temp, sizeof (vl.type_instance));
        else
 -      snprintf (vl.type_instance, sizeof (vl.type_instance), "%s%s",
 +      ssnprintf (vl.type_instance, sizeof (vl.type_instance), "%s%s",
            data->instance_prefix, temp);
 -      vl.type_instance[sizeof (vl.type_instance) - 1] = '\0';
      }
  
      for (i = 0; i < data->values_len; i++)
        vl.values[i] = value_table_ptr[i]->value;
  
      /* If we get here `vl.type_instance' and all `vl.values' have been set */
 -    plugin_dispatch_values (data->type, &vl);
 +    plugin_dispatch_values (&vl);
  
      subid++;
    } /* while (have_more != 0) */
@@@ -1324,10 -1299,11 +1324,10 @@@ static int csnmp_read_value (host_defin
        vl.values[i].gauge = NAN;
    }
  
 -  strncpy (vl.host, host->name, sizeof (vl.host));
 -  vl.host[sizeof (vl.host) - 1] = '\0';
 +  sstrncpy (vl.host, host->name, sizeof (vl.host));
    sstrncpy (vl.plugin, "snmp", sizeof (vl.plugin));
 -  strncpy (vl.type_instance, data->instance.string, sizeof (vl.type_instance));
 -  vl.type_instance[sizeof (vl.type_instance) - 1] = '\0';
 +  sstrncpy (vl.type, data->type, sizeof (vl.type));
 +  sstrncpy (vl.type_instance, data->instance.string, sizeof (vl.type_instance));
  
    vl.interval = host->interval;
  
      snmp_free_pdu (res);
    res = NULL;
  
 -  DEBUG ("snmp plugin: -> plugin_dispatch_values (%s, &vl);", data->type);
 -  plugin_dispatch_values (data->type, &vl);
 +  DEBUG ("snmp plugin: -> plugin_dispatch_values (&vl);");
 +  plugin_dispatch_values (&vl);
    sfree (vl.values);
  
    return (0);
@@@ -1424,8 -1400,8 +1424,8 @@@ static int csnmp_read_host (host_defini
    if ((time_end - time_start) > host->interval)
    {
      WARNING ("snmp plugin: Host `%s' should be queried every %i seconds, "
-       "but reading all values takes %lu seconds.",
-       host->name, host->interval, (unsigned long)(time_end - time_start));
+       "but reading all values takes %u seconds.",
+       host->name, host->interval, (unsigned int) (time_end - time_start));
    }
  
    return (0);
diff --combined src/vserver.c
index 413674b0338b3f8844c8b2ac39ce80cf67961062,7188b13e366b3b4b0f40bd4b8dbe5e8418b1bcd7..dac4392693159ad63dc1a095536b5a4cbefe9d09
@@@ -59,11 -59,10 +59,11 @@@ static void traffic_submit (const char 
        vl.time = time (NULL);
        sstrncpy (vl.host, hostname_g, sizeof (vl.host));
        sstrncpy (vl.plugin, "vserver", sizeof (vl.plugin));
 -      strncpy (vl.plugin_instance, plugin_instance, sizeof (vl.plugin_instance));
 -      strncpy (vl.type_instance, type_instance, sizeof (vl.type_instance));
 +      sstrncpy (vl.plugin_instance, plugin_instance, sizeof (vl.plugin_instance));
 +      sstrncpy (vl.type, "if_octets", sizeof (vl.type));
 +      sstrncpy (vl.type_instance, type_instance, sizeof (vl.type_instance));
  
 -      plugin_dispatch_values ("if_octets", &vl);
 +      plugin_dispatch_values (&vl);
  } /* void traffic_submit */
  
  static void load_submit (const char *plugin_instance,
        vl.time = time (NULL);
        sstrncpy (vl.host, hostname_g, sizeof (vl.host));
        sstrncpy (vl.plugin, "vserver", sizeof (vl.plugin));
 -      strncpy (vl.plugin_instance, plugin_instance, sizeof (vl.plugin_instance));
 +      sstrncpy (vl.plugin_instance, plugin_instance, sizeof (vl.plugin_instance));
 +      sstrncpy (vl.type, "load", sizeof (vl.type));
  
 -      plugin_dispatch_values ("load", &vl);
 +      plugin_dispatch_values (&vl);
  }
  
  static void submit_gauge (const char *plugin_instance, const char *type,
        vl.time = time (NULL);
        sstrncpy (vl.host, hostname_g, sizeof (vl.host));
        sstrncpy (vl.plugin, "vserver", sizeof (vl.plugin));
 -      strncpy (vl.plugin_instance, plugin_instance, sizeof (vl.plugin_instance));
 -      strncpy (vl.type_instance, type_instance, sizeof (vl.type_instance));
 +      sstrncpy (vl.plugin_instance, plugin_instance, sizeof (vl.plugin_instance));
 +      sstrncpy (vl.type, type, sizeof (vl.type));
 +      sstrncpy (vl.type_instance, type_instance, sizeof (vl.type_instance));
  
 -      plugin_dispatch_values (type, &vl);
 +      plugin_dispatch_values (&vl);
  } /* void submit_gauge */
  
  static inline long long __get_sock_bytes(const char *s)
  
  static int vserver_read (void)
  {
+ #if NAME_MAX < 1024
+ # define DIRENT_BUFFER_SIZE (sizeof (struct dirent) + 1024 + 1)
+ #else
+ # define DIRENT_BUFFER_SIZE (sizeof (struct dirent) + NAME_MAX + 1)
+ #endif
        DIR                     *proc;
        struct dirent   *dent; /* 42 */
+       char dirent_buffer[DIRENT_BUFFER_SIZE];
  
        errno = 0;
-       if (NULL == (proc = opendir (PROCDIR)))
+       proc = opendir (PROCDIR);
+       if (proc == NULL)
        {
                char errbuf[1024];
                ERROR ("vserver plugin: fopen (%s): %s", PROCDIR, 
                return (-1);
        }
  
-       while (NULL != (dent = readdir (proc)))
+       while (42)
        {
-               int  len;
+               size_t len;
                char file[BUFSIZE];
  
                FILE *fh;
                char buffer[BUFSIZE];
  
+               struct stat statbuf;
                char *cols[4];
  
+               int status;
+               status = readdir_r (proc, (struct dirent *) dirent_buffer, &dent);
+               if (status != 0)
+               {
+                       char errbuf[4096];
+                       ERROR ("vserver plugin: readdir_r failed: %s",
+                                       sstrerror (errno, errbuf, sizeof (errbuf)));
+                       closedir (proc);
+                       return (-1);
+               }
+               else if (dent == NULL)
+               {
+                       /* end of directory */
+                       break;
+               }
                if (dent->d_name[0] == '.')
                        continue;
  
-               /* This is not a directory */
-               if (dent->d_type != DT_DIR)
+               len = snprintf (file, sizeof (file), PROCDIR "/%s", dent->d_name);
+               if ((len < 0) || (len >= BUFSIZE))
+                       continue;
+               
+               status = stat (file, &statbuf);
+               if (status != 0)
+               {
+                       char errbuf[4096];
+                       WARNING ("vserver plugin: stat (%s) failed: %s",
+                                       file, sstrerror (errno, errbuf, sizeof (errbuf)));
+                       continue;
+               }
+               
+               if (!S_ISDIR (statbuf.st_mode))
                        continue;
  
                /* socket message accounting */
 -              len = snprintf (file, BUFSIZE, PROCDIR "/%s/cacct", dent->d_name);
 -              if ((len < 0) || (len >= BUFSIZE))
 +              len = ssnprintf (file, sizeof (file),
 +                              PROCDIR "/%s/cacct", dent->d_name);
 +              if ((len < 0) || (len >= sizeof (file)))
                        continue;
  
                if (NULL == (fh = fopen (file, "r")))
                }
  
                /* thread information and load */
 -              len = snprintf (file, BUFSIZE, PROCDIR "/%s/cvirt", dent->d_name);
 -              if ((len < 0) || (len >= BUFSIZE))
 +              len = ssnprintf (file, sizeof (file),
 +                              PROCDIR "/%s/cvirt", dent->d_name);
 +              if ((len < 0) || (len >= sizeof (file)))
                        continue;
  
                if (NULL == (fh = fopen (file, "r")))
                }
  
                /* processes and memory usage */
 -              len = snprintf (file, BUFSIZE, PROCDIR "/%s/limit", dent->d_name);
 -              if ((len < 0) || (len >= BUFSIZE))
 +              len = ssnprintf (file, sizeof (file),
 +                              PROCDIR "/%s/limit", dent->d_name);
 +              if ((len < 0) || (len >= sizeof (file)))
                        continue;
  
                if (NULL == (fh = fopen (file, "r")))