From: Florian Forster Date: Wed, 30 Apr 2008 09:04:23 +0000 (+0200) Subject: Merge branch 'collectd-4.4' X-Git-Tag: collectd-4.5.0~159 X-Git-Url: https://git.octo.it/?a=commitdiff_plain;h=cacaa2126020832df99fa6423147bd3de6d4faae;hp=d22aee658210cbfa44caa39f302aa9331d4eab82;p=collectd.git Merge branch 'collectd-4.4' Conflicts: src/collectd-perl.pod src/email.c --- diff --git a/src/apache.c b/src/apache.c index 3cda5650..7667f247 100644 --- a/src/apache.c +++ b/src/apache.c @@ -146,7 +146,7 @@ static int init (void) { int status; - status = snprintf (credentials, sizeof (credentials), "%s:%s", + status = ssnprintf (credentials, sizeof (credentials), "%s:%s", user, (pass == NULL) ? "" : pass); if (status >= sizeof (credentials)) { @@ -155,7 +155,6 @@ static int init (void) "truncated."); return (-1); } - credentials[sizeof (credentials) - 1] = '\0'; curl_easy_setopt (curl, CURLOPT_USERPWD, credentials); } @@ -202,15 +201,13 @@ static void submit_counter (const char *type, const char *type_instance, strcpy (vl.host, hostname_g); strcpy (vl.plugin, "apache"); strcpy (vl.plugin_instance, ""); + sstrncpy (vl.type, type, sizeof (vl.type)); if (type_instance != NULL) - { - strncpy (vl.type_instance, type_instance, + sstrncpy (vl.type_instance, type_instance, sizeof (vl.type_instance)); - vl.type_instance[sizeof (vl.type_instance) - 1] = '\0'; - } - plugin_dispatch_values (type, &vl); + plugin_dispatch_values (&vl); } /* void submit_counter */ static void submit_gauge (const char *type, const char *type_instance, @@ -227,15 +224,13 @@ static void submit_gauge (const char *type, const char *type_instance, strcpy (vl.host, hostname_g); strcpy (vl.plugin, "apache"); strcpy (vl.plugin_instance, ""); + sstrncpy (vl.type, type, sizeof (vl.type)); if (type_instance != NULL) - { - strncpy (vl.type_instance, type_instance, + sstrncpy (vl.type_instance, type_instance, sizeof (vl.type_instance)); - vl.type_instance[sizeof (vl.type_instance) - 1] = '\0'; - } - plugin_dispatch_values (type, &vl); + plugin_dispatch_values (&vl); } /* void submit_counter */ static void submit_scoreboard (char *buf) diff --git a/src/apcups.c b/src/apcups.c index 5a03764f..fb481092 100644 --- a/src/apcups.c +++ b/src/apcups.c @@ -124,8 +124,7 @@ static int net_open (char *host, int port) assert ((port > 0x00000000) && (port <= 0x0000FFFF)); /* Convert the port to a string */ - snprintf (port_str, 8, "%i", port); - port_str[7] = '\0'; + ssnprintf (port_str, sizeof (port_str), "%i", port); /* Resolve name */ memset ((void *) &ai_hints, '\0', sizeof (ai_hints)); @@ -376,9 +375,10 @@ static void apc_submit_generic (char *type, char *type_inst, double value) strcpy (vl.host, hostname_g); strcpy (vl.plugin, "apcups"); strcpy (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); } static void apc_submit (struct apc_detail_s *apcups_detail) diff --git a/src/apple_sensors.c b/src/apple_sensors.c index 2726ad2e..ee0bf8c0 100644 --- a/src/apple_sensors.c +++ b/src/apple_sensors.c @@ -91,9 +91,10 @@ static void as_submit (const char *type, const char *type_instance, strcpy (vl.host, hostname_g); strcpy (vl.plugin, "apple_sensors"); strcpy (vl.plugin_instance, ""); - strcpy (vl.type_instance, type_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); } static int as_read (void) @@ -146,10 +147,10 @@ static int as_read (void) if (CFGetTypeID (property) != CFStringGetTypeID ()) continue; if (!CFStringGetCString (property, - type, 128, + type, sizeof (type), kCFStringEncodingASCII)) continue; - type[127] = '\0'; + type[sizeof (type) - 1] = '\0'; /* Copy the sensor location. This will be used as `instance'. */ property = NULL; @@ -160,10 +161,10 @@ static int as_read (void) if (CFGetTypeID (property) != CFStringGetTypeID ()) continue; if (!CFStringGetCString (property, - inst, 128, + inst, sizeof (inst), kCFStringEncodingASCII)) continue; - inst[127] = '\0'; + inst[sizeof (inst) - 1] = '\0'; for (i = 0; i < 128; i++) { if (inst[i] == '\0') diff --git a/src/ascent.c b/src/ascent.c index 94691d6b..6b4f21fc 100644 --- a/src/ascent.c +++ b/src/ascent.c @@ -130,10 +130,12 @@ static int ascent_submit_gauge (const char *plugin_instance, /* {{{ */ sstrncpy (vl.plugin_instance, plugin_instance, sizeof (vl.plugin_instance)); + sstrncpy (vl.type, type, sizeof (vl.type)); + if (type_instance != NULL) sstrncpy (vl.type_instance, type_instance, sizeof (vl.type_instance)); - plugin_dispatch_values (type, &vl); + plugin_dispatch_values (&vl); return (0); } /* }}} int ascent_submit_gauge */ @@ -534,7 +536,7 @@ static int ascent_init (void) /* {{{ */ { int status; - status = snprintf (credentials, sizeof (credentials), "%s:%s", + status = ssnprintf (credentials, sizeof (credentials), "%s:%s", user, (pass == NULL) ? "" : pass); if (status >= sizeof (credentials)) { @@ -542,7 +544,6 @@ static int ascent_init (void) /* {{{ */ "credentials have been truncated."); return (-1); } - credentials[sizeof (credentials) - 1] = '\0'; curl_easy_setopt (curl, CURLOPT_USERPWD, credentials); } diff --git a/src/battery.c b/src/battery.c index 345f606e..f8e67a41 100644 --- a/src/battery.c +++ b/src/battery.c @@ -75,7 +75,7 @@ static int battery_init (void) for (battery_pmu_num = 0; ; battery_pmu_num++) { - len = snprintf (filename, sizeof (filename), battery_pmu_file, battery_pmu_num); + len = ssnprintf (filename, sizeof (filename), battery_pmu_file, battery_pmu_num); if ((len < 0) || ((unsigned int)len >= sizeof (filename))) break; @@ -100,9 +100,10 @@ static void battery_submit (const char *plugin_instance, const char *type, doubl vl.time = time (NULL); strcpy (vl.host, hostname_g); strcpy (vl.plugin, "battery"); - strcpy (vl.plugin_instance, plugin_instance); + sstrncpy (vl.plugin_instance, plugin_instance, sizeof (vl.plugin_instance)); + sstrncpy (vl.type, type, sizeof (vl.type)); - plugin_dispatch_values (type, &vl); + plugin_dispatch_values (&vl); } /* void battery_submit */ #if HAVE_IOKIT_PS_IOPOWERSOURCES_H || HAVE_IOKIT_IOKITLIB_H @@ -359,11 +360,11 @@ static int battery_read (void) double charge = INVALID_VALUE; double *valptr = NULL; - len = snprintf (filename, sizeof (filename), battery_pmu_file, i); + len = ssnprintf (filename, sizeof (filename), battery_pmu_file, i); if ((len < 0) || ((unsigned int)len >= sizeof (filename))) continue; - len = snprintf (batnum_str, sizeof (batnum_str), "%i", i); + len = ssnprintf (batnum_str, sizeof (batnum_str), "%i", i); if ((len < 0) || ((unsigned int)len >= sizeof (batnum_str))) continue; @@ -435,7 +436,7 @@ static int battery_read (void) if (ent->d_name[0] == '.') continue; - len = snprintf (filename, sizeof (filename), + len = ssnprintf (filename, sizeof (filename), "/proc/acpi/battery/%s/state", ent->d_name); if ((len < 0) || ((unsigned int)len >= sizeof (filename))) diff --git a/src/collectd-perl.pod b/src/collectd-perl.pod index 8cdf08bb..b7ae9cac 100644 --- a/src/collectd-perl.pod +++ b/src/collectd-perl.pod @@ -166,6 +166,7 @@ layout looks like this: time => time (), host => $hostname_g, plugin => 'myplugin', + type => 'myplugin', plugin_instance => '', type_instance => '' } @@ -285,13 +286,19 @@ data type. Removes a callback or data-set from collectd's internal list of functionsE/ datasets. -=item B (I, I) +=item B (I) -Submits a I of type I to the daemon. If the data-set I +Submits a I to the daemon. If the data-set identified by +I->{I} is found (and the number of values matches the number of data-sources) then the type, data-set and value-list is passed to all write-callbacks that are registered with the daemon. +B: Prior to version 4.4 of collectd, the data-set type used to be passed +as the first argument to B. This syntax is still supported +for backwards compatibility but has been deprecated and will be removed in +some future version of collectd. + =item B ([B => I,] [B => I<...>]) Flush one or more plugins. I is passed on to the registered diff --git a/src/collectd.c b/src/collectd.c index f556fc5f..38d1b868 100644 --- a/src/collectd.c +++ b/src/collectd.c @@ -90,8 +90,7 @@ static int init_hostname (void) str = global_option_get ("Hostname"); if (str != NULL) { - strncpy (hostname_g, str, sizeof (hostname_g)); - hostname_g[sizeof (hostname_g) - 1] = '\0'; + sstrncpy (hostname_g, str, sizeof (hostname_g)); return (0); } @@ -127,8 +126,7 @@ static int init_hostname (void) if (ai_ptr->ai_canonname == NULL) continue; - strncpy (hostname_g, ai_ptr->ai_canonname, sizeof (hostname_g)); - hostname_g[sizeof (hostname_g) - 1] = '\0'; + sstrncpy (hostname_g, ai_ptr->ai_canonname, sizeof (hostname_g)); break; } diff --git a/src/common.c b/src/common.c index 5c3db5dd..3f6eecc3 100644 --- a/src/common.c +++ b/src/common.c @@ -61,6 +61,19 @@ char *sstrncpy (char *dest, const char *src, size_t n) 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 *sstrdup (const char *s) { char *r; @@ -91,7 +104,7 @@ char *sstrerror (int errnum, char *buf, size_t buflen) pthread_mutex_lock (&strerror_r_lock); temp = strerror (errnum); - strncpy (buf, temp, buflen); + sstrncpy (buf, temp, buflen); pthread_mutex_unlock (&strerror_r_lock); } @@ -104,9 +117,9 @@ char *sstrerror (int errnum, char *buf, size_t buflen) if (buf[0] == '\0') { if ((temp != NULL) && (temp != buf) && (temp[0] != '\0')) - strncpy (buf, temp, buflen); + sstrncpy (buf, temp, buflen); else - strncpy (buf, "strerror_r did not return " + sstrncpy (buf, "strerror_r did not return " "an error message", buflen); } } @@ -115,13 +128,12 @@ char *sstrerror (int errnum, char *buf, size_t buflen) #else if (strerror_r (errnum, buf, buflen) != 0) { - snprintf (buf, buflen, "Error #%i; " + ssnprintf (buf, buflen, "Error #%i; " "Additionally, strerror_r failed.", errnum); } #endif /* STRERROR_R_CHAR_P */ - buf[buflen - 1] = '\0'; return (buf); } /* char *sstrerror */ @@ -376,7 +388,7 @@ int check_create_dir (const char *file_orig) if ((len = strlen (file_orig)) < 1) return (-1); - else if (len >= 512) + else if (len >= sizeof (file_copy)) return (-1); /* @@ -391,8 +403,7 @@ int check_create_dir (const char *file_orig) /* * Create a copy for `strtok_r' to destroy */ - strncpy (file_copy, file_orig, 512); - file_copy[511] = '\0'; + sstrncpy (file_copy, file_orig, sizeof (file_copy)); /* * Break into components. This will eat up several slashes in a row and @@ -477,8 +488,7 @@ int get_kstat (kstat_t **ksp_ptr, char *module, int instance, char *name) if (kc == NULL) return (-1); - snprintf (ident, 128, "%s,%i,%s", module, instance, name); - ident[127] = '\0'; + ssnprintf (ident, sizeof (ident), "%s,%i,%s", module, instance, name); if (*ksp_ptr == NULL) { @@ -663,21 +673,21 @@ int format_name (char *ret, int ret_len, if ((plugin_instance == NULL) || (strlen (plugin_instance) == 0)) { if ((type_instance == NULL) || (strlen (type_instance) == 0)) - status = snprintf (ret, ret_len, "%s/%s/%s", + status = ssnprintf (ret, ret_len, "%s/%s/%s", hostname, plugin, type); else - status = snprintf (ret, ret_len, "%s/%s/%s-%s", + status = ssnprintf (ret, ret_len, "%s/%s/%s-%s", hostname, plugin, type, type_instance); } else { if ((type_instance == NULL) || (strlen (type_instance) == 0)) - status = snprintf (ret, ret_len, "%s/%s-%s/%s", + status = ssnprintf (ret, ret_len, "%s/%s-%s/%s", hostname, plugin, plugin_instance, type); else - status = snprintf (ret, ret_len, "%s/%s-%s/%s-%s", + status = ssnprintf (ret, ret_len, "%s/%s-%s/%s-%s", hostname, plugin, plugin_instance, type, type_instance); } @@ -838,26 +848,19 @@ int notification_init (notification_t *n, int severity, const char *message, n->severity = severity; if (message != NULL) - strncpy (n->message, message, sizeof (n->message)); + sstrncpy (n->message, message, sizeof (n->message)); if (host != NULL) - strncpy (n->host, host, sizeof (n->host)); + sstrncpy (n->host, host, sizeof (n->host)); if (plugin != NULL) - strncpy (n->plugin, plugin, sizeof (n->plugin)); + sstrncpy (n->plugin, plugin, sizeof (n->plugin)); if (plugin_instance != NULL) - strncpy (n->plugin_instance, plugin_instance, + sstrncpy (n->plugin_instance, plugin_instance, sizeof (n->plugin_instance)); if (type != NULL) - strncpy (n->type, type, sizeof (n->type)); + sstrncpy (n->type, type, sizeof (n->type)); if (type_instance != NULL) - strncpy (n->type_instance, type_instance, + sstrncpy (n->type_instance, type_instance, sizeof (n->type_instance)); - n->message[sizeof (n->message) - 1] = '\0'; - n->host[sizeof (n->host) - 1] = '\0'; - n->plugin[sizeof (n->plugin) - 1] = '\0'; - n->plugin_instance[sizeof (n->plugin_instance) - 1] = '\0'; - n->type[sizeof (n->type) - 1] = '\0'; - n->type_instance[sizeof (n->type_instance) - 1] = '\0'; - return (0); } /* int notification_init */ diff --git a/src/common.h b/src/common.h index e99aea69..d142679f 100644 --- a/src/common.h +++ b/src/common.h @@ -39,6 +39,7 @@ #define STATIC_ARRAY_SIZE(a) (sizeof (a) / sizeof (*(a))) char *sstrncpy (char *dest, const char *src, size_t n); +int ssnprintf (char *dest, size_t n, const char *format, ...); char *sstrdup(const char *s); void *smalloc(size_t size); char *sstrerror (int errnum, char *buf, size_t buflen); diff --git a/src/configfile.c b/src/configfile.c index 4a9789ae..2afef4f0 100644 --- a/src/configfile.c +++ b/src/configfile.c @@ -182,8 +182,7 @@ static int dispatch_global_option (const oconfig_item_t *ci) 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) @@ -258,13 +257,13 @@ static int dispatch_value_plugin (const char *plugin, oconfig_item_t *ci) 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"); @@ -548,7 +547,7 @@ static oconfig_item_t *cf_read_dir (const char *dir, int depth) 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 --git a/src/cpu.c b/src/cpu.c index c79c4b66..4d24125c 100644 --- a/src/cpu.c +++ b/src/cpu.c @@ -169,12 +169,12 @@ static void submit (int cpu_num, const char *type_instance, counter_t value) vl.time = time (NULL); strcpy (vl.host, hostname_g); strcpy (vl.plugin, "cpu"); - snprintf (vl.plugin_instance, sizeof (vl.type_instance), + ssnprintf (vl.plugin_instance, sizeof (vl.type_instance), "%i", cpu_num); - vl.plugin_instance[DATA_MAX_NAME_LEN - 1] = '\0'; - strcpy (vl.type_instance, type_instance); + strcpy (vl.type, "cpu"); + sstrncpy (vl.type_instance, type_instance, sizeof (vl.type_instance)); - plugin_dispatch_values ("cpu", &vl); + plugin_dispatch_values (&vl); } static int cpu_read (void) diff --git a/src/cpufreq.c b/src/cpufreq.c index 42248a98..f4424e65 100644 --- a/src/cpufreq.c +++ b/src/cpufreq.c @@ -37,7 +37,7 @@ static int cpufreq_init (void) while (1) { - status = snprintf (filename, sizeof (filename), + status = ssnprintf (filename, sizeof (filename), "/sys/devices/system/cpu/cpu%d/cpufreq/" "scaling_cur_freq", num_cpu); if ((status < 1) || ((unsigned int)status >= sizeof (filename))) @@ -70,10 +70,11 @@ static void cpufreq_submit (int cpu_num, double value) vl.time = time (NULL); strcpy (vl.host, hostname_g); strcpy (vl.plugin, "cpufreq"); - snprintf (vl.type_instance, sizeof (vl.type_instance), + strcpy (vl.type, "cpufreq"); + ssnprintf (vl.type_instance, sizeof (vl.type_instance), "%i", cpu_num); - plugin_dispatch_values ("cpufreq", &vl); + plugin_dispatch_values (&vl); } static int cpufreq_read (void) @@ -87,7 +88,7 @@ static int cpufreq_read (void) for (i = 0; i < num_cpu; i++) { - status = snprintf (filename, sizeof (filename), + status = ssnprintf (filename, sizeof (filename), "/sys/devices/system/cpu/cpu%d/cpufreq/" "scaling_cur_freq", i); if ((status < 1) || ((unsigned int)status >= sizeof (filename))) diff --git a/src/csv.c b/src/csv.c index ff59f91c..a94b7001 100644 --- a/src/csv.c +++ b/src/csv.c @@ -45,9 +45,11 @@ static int value_list_to_string (char *buffer, int buffer_len, int i; gauge_t *rates = NULL; + assert (0 == strcmp (ds->type, vl->type)); + memset (buffer, '\0', buffer_len); - status = snprintf (buffer, buffer_len, "%u", (unsigned int) vl->time); + status = ssnprintf (buffer, buffer_len, "%u", (unsigned int) vl->time); if ((status < 1) || (status >= buffer_len)) return (-1); offset = status; @@ -62,7 +64,7 @@ static int value_list_to_string (char *buffer, int buffer_len, { if (store_rates == 0) { - status = snprintf (buffer + offset, + status = ssnprintf (buffer + offset, buffer_len - offset, ",%llu", vl->values[i].counter); @@ -77,14 +79,14 @@ static int value_list_to_string (char *buffer, int buffer_len, "uc_get_rate failed."); return (-1); } - status = snprintf (buffer + offset, + status = ssnprintf (buffer + offset, buffer_len - offset, ",%lf", rates[i]); } } else /* if (ds->ds[i].type == DS_TYPE_GAUGE) */ { - status = snprintf (buffer + offset, buffer_len - offset, + status = ssnprintf (buffer + offset, buffer_len - offset, ",%lf", vl->values[i].gauge); } @@ -107,37 +109,39 @@ static int value_list_to_filename (char *buffer, int buffer_len, int offset = 0; int status; + assert (0 == strcmp (ds->type, vl->type)); + if (datadir != NULL) { - status = snprintf (buffer + offset, buffer_len - offset, + status = ssnprintf (buffer + offset, buffer_len - offset, "%s/", datadir); if ((status < 1) || (status >= buffer_len - offset)) return (-1); offset += status; } - status = snprintf (buffer + offset, buffer_len - offset, + status = ssnprintf (buffer + offset, buffer_len - offset, "%s/", vl->host); if ((status < 1) || (status >= buffer_len - offset)) return (-1); offset += status; if (strlen (vl->plugin_instance) > 0) - status = snprintf (buffer + offset, buffer_len - offset, + status = ssnprintf (buffer + offset, buffer_len - offset, "%s-%s/", vl->plugin, vl->plugin_instance); else - status = snprintf (buffer + offset, buffer_len - offset, + status = ssnprintf (buffer + offset, buffer_len - offset, "%s/", vl->plugin); if ((status < 1) || (status >= buffer_len - offset)) return (-1); offset += status; if (strlen (vl->type_instance) > 0) - status = snprintf (buffer + offset, buffer_len - offset, - "%s-%s", ds->type, vl->type_instance); + status = ssnprintf (buffer + offset, buffer_len - offset, + "%s-%s", vl->type, vl->type_instance); else - status = snprintf (buffer + offset, buffer_len - offset, - "%s", ds->type); + status = ssnprintf (buffer + offset, buffer_len - offset, + "%s", vl->type); if ((status < 1) || (status >= buffer_len - offset)) return (-1); offset += status; @@ -242,6 +246,11 @@ static int csv_write (const data_set_t *ds, const value_list_t *vl) struct flock fl; int status; + if (0 != strcmp (ds->type, vl->type)) { + ERROR ("csv plugin: DS type does not match value list type"); + return -1; + } + if (value_list_to_filename (filename, sizeof (filename), ds, vl) != 0) return (-1); diff --git a/src/df.c b/src/df.c index 0f357d8d..284472b1 100644 --- a/src/df.c +++ b/src/df.c @@ -128,9 +128,10 @@ static void df_submit (char *df_name, strcpy (vl.host, hostname_g); strcpy (vl.plugin, "df"); strcpy (vl.plugin_instance, ""); - strncpy (vl.type_instance, df_name, sizeof (vl.type_instance)); + strcpy (vl.type, "df"); + sstrncpy (vl.type_instance, df_name, sizeof (vl.type_instance)); - plugin_dispatch_values ("df", &vl); + plugin_dispatch_values (&vl); } /* void df_submit */ static int df_read (void) @@ -173,13 +174,13 @@ static int df_read (void) if (strcmp (mnt_ptr->dir, "/") == 0) { - strncpy (mnt_name, "root", sizeof (mnt_name)); + sstrncpy (mnt_name, "root", sizeof (mnt_name)); } else { int i, len; - strncpy (mnt_name, mnt_ptr->dir + 1, sizeof (mnt_name)); + sstrncpy (mnt_name, mnt_ptr->dir + 1, sizeof (mnt_name)); len = strlen (mnt_name); for (i = 0; i < len; i++) diff --git a/src/disk.c b/src/disk.c index 5491dcbd..23bec09c 100644 --- a/src/disk.c +++ b/src/disk.c @@ -208,10 +208,11 @@ static void disk_submit (const char *plugin_instance, vl.time = time (NULL); strcpy (vl.host, hostname_g); strcpy (vl.plugin, "disk"); - strncpy (vl.plugin_instance, plugin_instance, + sstrncpy (vl.plugin_instance, plugin_instance, sizeof (vl.plugin_instance)); + sstrncpy (vl.type, type, sizeof (vl.type)); - plugin_dispatch_values (type, &vl); + plugin_dispatch_values (&vl); } /* void disk_submit */ #if HAVE_IOKIT_IOKITLIB_H @@ -368,7 +369,8 @@ static int disk_read (void) write_tme = dict_get_value (stats_dict, kIOBlockStorageDriverStatisticsTotalWriteTimeKey); - if (snprintf (disk_name, 64, "%i-%i", disk_major, disk_minor) >= 64) + if (ssnprintf (disk_name, sizeof (disk_name), + "%i-%i", disk_major, disk_minor) >= sizeof (disk_name)) { DEBUG ("snprintf (major, minor) failed."); CFRelease (child_dict); diff --git a/src/dns.c b/src/dns.c index e9996b99..c315eab9 100644 --- a/src/dns.c +++ b/src/dns.c @@ -301,9 +301,10 @@ static void submit_counter (const char *type, const char *type_instance, vl.time = time (NULL); strcpy (vl.host, hostname_g); strcpy (vl.plugin, "dns"); - strncpy (vl.type_instance, type_instance, sizeof (vl.type_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_counter */ static void submit_octets (counter_t queries, counter_t responses) @@ -319,8 +320,9 @@ static void submit_octets (counter_t queries, counter_t responses) vl.time = time (NULL); strcpy (vl.host, hostname_g); strcpy (vl.plugin, "dns"); + strcpy (vl.type, "dns_octets"); - plugin_dispatch_values ("dns_octets", &vl); + plugin_dispatch_values (&vl); } /* void submit_counter */ static int dns_read (void) diff --git a/src/email.c b/src/email.c index 87daed11..200b60c1 100644 --- a/src/email.c +++ b/src/email.c @@ -394,8 +394,7 @@ static void *open_connection (void *arg) addr.sun_family = AF_UNIX; - strncpy (addr.sun_path, path, (size_t)(UNIX_PATH_MAX - 1)); - addr.sun_path[UNIX_PATH_MAX - 1] = '\0'; + sstrncpy (addr.sun_path, path, (size_t)(UNIX_PATH_MAX - 1)); unlink (addr.sun_path); errno = 0; @@ -659,9 +658,10 @@ static void email_submit (const char *type, const char *type_instance, gauge_t v vl.time = time (NULL); strcpy (vl.host, hostname_g); strcpy (vl.plugin, "email"); - strncpy (vl.type_instance, type_instance, sizeof (vl.type_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 email_submit */ /* Copy list l1 to list l2. l2 may partly exist already, but it is assumed diff --git a/src/entropy.c b/src/entropy.c index 5f9eb530..85d41cfc 100644 --- a/src/entropy.c +++ b/src/entropy.c @@ -42,9 +42,10 @@ static void entropy_submit (double entropy) strcpy (vl.host, hostname_g); strcpy (vl.plugin, "entropy"); strcpy (vl.plugin_instance, ""); + strcpy (vl.type, "entropy"); strcpy (vl.type_instance, ""); - plugin_dispatch_values ("entropy", &vl); + plugin_dispatch_values (&vl); } static int entropy_read (void) diff --git a/src/exec.c b/src/exec.c index 07c35c9b..ac0175cf 100644 --- a/src/exec.c +++ b/src/exec.c @@ -170,10 +170,9 @@ static int exec_config_exec (oconfig_item_t *ci) /* {{{ */ { char *tmp = strrchr (ci->values[1].value.string, '/'); if (tmp == NULL) - strncpy (buffer, ci->values[1].value.string, sizeof (buffer)); + sstrncpy (buffer, ci->values[1].value.string, sizeof (buffer)); else - strncpy (buffer, tmp + 1, sizeof (buffer)); - buffer[sizeof (buffer) - 1] = '\0'; + sstrncpy (buffer, tmp + 1, sizeof (buffer)); } pl->argv[0] = strdup (buffer); if (pl->argv[0] == NULL) @@ -196,17 +195,16 @@ static int exec_config_exec (oconfig_item_t *ci) /* {{{ */ { if (ci->values[i + 1].type == OCONFIG_TYPE_NUMBER) { - snprintf (buffer, sizeof (buffer), "%lf", + ssnprintf (buffer, sizeof (buffer), "%lf", ci->values[i + 1].value.number); } else { if (ci->values[i + 1].value.boolean) - strncpy (buffer, "true", sizeof (buffer)); + sstrncpy (buffer, "true", sizeof (buffer)); else - strncpy (buffer, "false", sizeof (buffer)); + sstrncpy (buffer, "false", sizeof (buffer)); } - buffer[sizeof (buffer) - 1] = '\0'; pl->argv[i] = strdup (buffer); } diff --git a/src/hddtemp.c b/src/hddtemp.c index 36ada53c..a9c09418 100644 --- a/src/hddtemp.c +++ b/src/hddtemp.c @@ -223,11 +223,10 @@ static int hddtemp_config (const char *key, const char *value) { int port = (int) (atof (value)); if ((port > 0) && (port <= 65535)) - snprintf (hddtemp_port, sizeof (hddtemp_port), + ssnprintf (hddtemp_port, sizeof (hddtemp_port), "%i", port); else - strncpy (hddtemp_port, value, sizeof (hddtemp_port)); - hddtemp_port[sizeof (hddtemp_port) - 1] = '\0'; + sstrncpy (hddtemp_port, value, sizeof (hddtemp_port)); } else if (strcasecmp (key, "TranslateDevicename") == 0) { @@ -430,7 +429,7 @@ static char *hddtemp_get_major_minor (char *drive) if ((ret = (char *) malloc (128 * sizeof (char))) == NULL) return (NULL); - if (snprintf (ret, 128, "%i-%i", list->major, list->minor) >= 128) + if (ssnprintf (ret, 128, "%i-%i", list->major, list->minor) >= 128) { free (ret); return (NULL); @@ -451,9 +450,10 @@ static void hddtemp_submit (char *type_instance, double value) vl.time = time (NULL); strcpy (vl.host, hostname_g); strcpy (vl.plugin, "hddtemp"); - strncpy (vl.type_instance, type_instance, sizeof (vl.type_instance)); + strcpy (vl.type, "temperature"); + sstrncpy (vl.type_instance, type_instance, sizeof (vl.type_instance)); - plugin_dispatch_values ("temperature", &vl); + plugin_dispatch_values (&vl); } static int hddtemp_read (void) diff --git a/src/interface.c b/src/interface.c index 33736b67..ff4a0aa1 100644 --- a/src/interface.c +++ b/src/interface.c @@ -199,9 +199,10 @@ static void if_submit (const char *dev, const char *type, vl.time = time (NULL); strcpy (vl.host, hostname_g); strcpy (vl.plugin, "interface"); - strncpy (vl.type_instance, dev, sizeof (vl.type_instance)); + sstrncpy (vl.type, type, sizeof (vl.type)); + sstrncpy (vl.type_instance, dev, sizeof (vl.type_instance)); - plugin_dispatch_values (type, &vl); + plugin_dispatch_values (&vl); } /* void if_submit */ static int interface_read (void) diff --git a/src/ipmi.c b/src/ipmi.c index 95e2e7c1..7a00c887 100644 --- a/src/ipmi.c +++ b/src/ipmi.c @@ -193,9 +193,10 @@ static void sensor_read_handler (ipmi_sensor_t *sensor, sstrncpy (vl.host, hostname_g, sizeof (vl.host)); sstrncpy (vl.plugin, "ipmi", sizeof (vl.plugin)); + sstrncpy (vl.type, type, sizeof (vl.type)); sstrncpy (vl.type_instance, sensor_name_ptr, sizeof (vl.type_instance)); - plugin_dispatch_values (type, &vl); + plugin_dispatch_values (&vl); } /* void sensor_read_handler */ static int sensor_list_add (ipmi_sensor_t *sensor) diff --git a/src/iptables.c b/src/iptables.c index 72b4481c..576cd63e 100644 --- a/src/iptables.c +++ b/src/iptables.c @@ -112,8 +112,7 @@ static int iptables_config (const char *key, const char *value) free (value_copy); return (1); } - strncpy (temp.table, table, table_len); - temp.table[table_len] = '\0'; + sstrncpy (temp.table, table, table_len); chain_len = strlen (chain); if ((unsigned int)chain_len >= sizeof(temp.chain)) @@ -122,8 +121,7 @@ static int iptables_config (const char *key, const char *value) free (value_copy); return (1); } - strncpy (temp.chain, chain, chain_len); - temp.chain[chain_len] = '\0'; + sstrncpy (temp.chain, chain, chain_len); if (fields_num >= 3) { @@ -152,7 +150,7 @@ static int iptables_config (const char *key, const char *value) } if (fields_num >= 4) - strncpy (temp.name, fields[3], sizeof (temp.name) - 1); + sstrncpy (temp.name, fields[3], sizeof (temp.name)); free (value_copy); value_copy = NULL; @@ -222,31 +220,32 @@ static int submit_match (const struct ipt_entry_match *match, strcpy (vl.host, hostname_g); strcpy (vl.plugin, "iptables"); - status = snprintf (vl.plugin_instance, sizeof (vl.plugin_instance), + status = ssnprintf (vl.plugin_instance, sizeof (vl.plugin_instance), "%s-%s", chain->table, chain->chain); if ((status < 1) || ((unsigned int)status >= sizeof (vl.plugin_instance))) return (0); if (chain->name[0] != '\0') { - strncpy (vl.type_instance, chain->name, sizeof (vl.type_instance)); + sstrncpy (vl.type_instance, chain->name, sizeof (vl.type_instance)); } else { if (chain->rule_type == RTYPE_NUM) - snprintf (vl.type_instance, sizeof (vl.type_instance), + ssnprintf (vl.type_instance, sizeof (vl.type_instance), "%i", chain->rule.num); else - strncpy (vl.type_instance, (char *) match->data, + sstrncpy (vl.type_instance, (char *) match->data, sizeof (vl.type_instance)); } - vl.type_instance[sizeof (vl.type_instance) - 1] = '\0'; + strcpy (vl.type, "ipt_bytes"); values[0].counter = (counter_t) entry->counters.bcnt; - plugin_dispatch_values ("ipt_bytes", &vl); + plugin_dispatch_values (&vl); + strcpy (vl.type, "ipt_packets"); values[0].counter = (counter_t) entry->counters.pcnt; - plugin_dispatch_values ("ipt_packets", &vl); + plugin_dispatch_values (&vl); return (0); } /* void submit_match */ diff --git a/src/ipvs.c b/src/ipvs.c index 68a3d7f3..a64e7b7a 100644 --- a/src/ipvs.c +++ b/src/ipvs.c @@ -191,7 +191,7 @@ static int get_pi (struct ip_vs_service_entry *se, char *pi, size_t size) /* inet_ntoa() returns a pointer to a statically allocated buffer * I hope non-glibc systems behave the same */ - len = snprintf (pi, size, "%s_%s%u", inet_ntoa (addr), + len = ssnprintf (pi, size, "%s_%s%u", inet_ntoa (addr), (se->protocol == IPPROTO_TCP) ? "TCP" : "UDP", ntohs (se->port)); @@ -215,7 +215,7 @@ static int get_ti (struct ip_vs_dest_entry *de, char *ti, size_t size) /* inet_ntoa() returns a pointer to a statically allocated buffer * I hope non-glibc systems behave the same */ - len = snprintf (ti, size, "%s_%u", inet_ntoa (addr), + len = ssnprintf (ti, size, "%s_%u", inet_ntoa (addr), ntohs (de->port)); if ((0 > len) || (size <= len)) { @@ -240,10 +240,12 @@ static void cipvs_submit_connections (char *pi, char *ti, counter_t value) strcpy (vl.host, hostname_g); strcpy (vl.plugin, "ipvs"); - strcpy (vl.plugin_instance, pi); - strcpy (vl.type_instance, (NULL != ti) ? ti : "total"); + sstrncpy (vl.plugin_instance, pi, sizeof (vl.plugin_instance)); + strcpy (vl.type, "connections"); + sstrncpy (vl.type_instance, (NULL != ti) ? ti : "total", + sizeof (vl.type_instance)); - plugin_dispatch_values ("connections", &vl); + plugin_dispatch_values (&vl); return; } /* cipvs_submit_connections */ @@ -264,10 +266,12 @@ static void cipvs_submit_if (char *pi, char *t, char *ti, strcpy (vl.host, hostname_g); strcpy (vl.plugin, "ipvs"); - strcpy (vl.plugin_instance, pi); - strcpy (vl.type_instance, (NULL != ti) ? ti : "total"); + sstrncpy (vl.plugin_instance, pi, sizeof (vl.plugin_instance)); + sstrncpy (vl.type, t, sizeof (vl.type)); + sstrncpy (vl.type_instance, (NULL != ti) ? ti : "total", + sizeof (vl.type_instance)); - plugin_dispatch_values (t, &vl); + plugin_dispatch_values (&vl); return; } /* cipvs_submit_if */ diff --git a/src/irq.c b/src/irq.c index 9eb1de42..792ac346 100644 --- a/src/irq.c +++ b/src/irq.c @@ -134,13 +134,14 @@ static void irq_submit (unsigned int irq, counter_t value) vl.time = time (NULL); strcpy (vl.host, hostname_g); strcpy (vl.plugin, "irq"); + strcpy (vl.type, "irq"); - status = snprintf (vl.type_instance, sizeof (vl.type_instance), + status = ssnprintf (vl.type_instance, sizeof (vl.type_instance), "%u", irq); if ((status < 1) || ((unsigned int)status >= sizeof (vl.type_instance))) return; - plugin_dispatch_values ("irq", &vl); + plugin_dispatch_values (&vl); } /* void irq_submit */ static int irq_read (void) diff --git a/src/libvirt.c b/src/libvirt.c index 327536a1..370e794a 100644 --- a/src/libvirt.c +++ b/src/libvirt.c @@ -634,7 +634,7 @@ ignore_device_match (ignorelist_t *il, const char *domname, const char *devpath) ERROR ("libvirt plugin: malloc failed."); return 0; } - snprintf (name, n, "%s:%s", domname, devpath); + ssnprintf (name, n, "%s:%s", domname, devpath); r = ignorelist_match (il, name); free (name); return r; @@ -652,8 +652,7 @@ init_value_list (value_list_t *vl, time_t t, virDomainPtr dom) vl->time = t; vl->interval = interval_g; - strncpy (vl->plugin, "libvirt", sizeof (vl->plugin)); - vl->plugin[sizeof (vl->plugin) - 1] = '\0'; + sstrncpy (vl->plugin, "libvirt", sizeof (vl->plugin)); vl->host[0] = '\0'; host_ptr = vl->host; @@ -706,7 +705,9 @@ cpu_submit (unsigned long long cpu_time, vl.values = values; vl.values_len = 1; - plugin_dispatch_values (type, &vl); + sstrncpy (vl.type, type, sizeof (vl.type)); + + plugin_dispatch_values (&vl); } static void @@ -723,10 +724,10 @@ vcpu_submit (counter_t cpu_time, vl.values = values; vl.values_len = 1; - snprintf (vl.type_instance, sizeof (vl.type_instance), "%d", vcpu_nr); - vl.type_instance[sizeof (vl.type_instance) - 1] = '\0'; + sstrncpy (vl.type, type, sizeof (vl.type)); + ssnprintf (vl.type_instance, sizeof (vl.type_instance), "%d", vcpu_nr); - plugin_dispatch_values (type, &vl); + plugin_dispatch_values (&vl); } static void @@ -744,10 +745,10 @@ submit_counter2 (const char *type, counter_t v0, counter_t v1, vl.values = values; vl.values_len = 2; - strncpy (vl.type_instance, devname, sizeof (vl.type_instance)); - vl.type_instance[sizeof (vl.type_instance) - 1] = '\0'; + sstrncpy (vl.type, type, sizeof (vl.type)); + sstrncpy (vl.type_instance, devname, sizeof (vl.type_instance)); - plugin_dispatch_values (type, &vl); + plugin_dispatch_values (&vl); } /* void submit_counter2 */ static int diff --git a/src/load.c b/src/load.c index 15215d3c..7d11b986 100644 --- a/src/load.c +++ b/src/load.c @@ -53,8 +53,9 @@ static void load_submit (gauge_t snum, gauge_t mnum, gauge_t lnum) vl.time = time (NULL); strcpy (vl.host, hostname_g); strcpy (vl.plugin, "load"); + strcpy (vl.type, "load"); - plugin_dispatch_values ("load", &vl); + plugin_dispatch_values (&vl); } static int load_read (void) diff --git a/src/logfile.c b/src/logfile.c index 36ac58d7..382386b7 100644 --- a/src/logfile.c +++ b/src/logfile.c @@ -158,7 +158,7 @@ static int logfile_notification (const notification_t *n) int buf_len = sizeof (buf); int status; - status = snprintf (buf_ptr, buf_len, "Notification: severity = %s", + status = ssnprintf (buf_ptr, buf_len, "Notification: severity = %s", (n->severity == NOTIF_FAILURE) ? "FAILURE" : ((n->severity == NOTIF_WARNING) ? "WARNING" : ((n->severity == NOTIF_OKAY) ? "OKAY" : "UNKNOWN"))); @@ -170,7 +170,7 @@ static int logfile_notification (const notification_t *n) #define APPEND(bufptr, buflen, key, value) \ if ((buflen > 0) && (strlen (value) > 0)) { \ - int status = snprintf (bufptr, buflen, ", %s = %s", key, value); \ + int status = ssnprintf (bufptr, buflen, ", %s = %s", key, value); \ if (status > 0) { \ bufptr += status; \ buflen -= status; \ diff --git a/src/mbmon.c b/src/mbmon.c index 50d73632..923118f6 100644 --- a/src/mbmon.c +++ b/src/mbmon.c @@ -230,9 +230,10 @@ static void mbmon_submit (const char *type, const char *type_instance, vl.time = time (NULL); strcpy (vl.host, hostname_g); strcpy (vl.plugin, "mbmon"); - strncpy (vl.type_instance, type_instance, sizeof (vl.type_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 mbmon_submit */ /* Trim trailing whitespace from a string. */ diff --git a/src/memcached.c b/src/memcached.c index a1825780..ca93102f 100644 --- a/src/memcached.c +++ b/src/memcached.c @@ -200,11 +200,10 @@ static int memcached_config (const char *key, const char *value) /* {{{ */ } else if (strcasecmp (key, "Port") == 0) { int port = (int) (atof (value)); if ((port > 0) && (port <= 65535)) { - snprintf (memcached_port, sizeof (memcached_port), "%i", port); + ssnprintf (memcached_port, sizeof (memcached_port), "%i", port); } else { - strncpy (memcached_port, value, sizeof (memcached_port)); + sstrncpy (memcached_port, value, sizeof (memcached_port)); } - memcached_port[sizeof (memcached_port) - 1] = '\0'; } else { return -1; } @@ -226,13 +225,11 @@ static void submit_counter (const char *type, const char *type_inst, vl.time = time (NULL); strcpy (vl.host, hostname_g); strcpy (vl.plugin, "memcached"); + sstrncpy (vl.type, type, sizeof (vl.type)); if (type_inst != NULL) - { - strncpy (vl.type_instance, type_inst, sizeof (vl.type_instance)); - vl.type_instance[sizeof (vl.type_instance) - 1] = '\0'; - } + sstrncpy (vl.type_instance, type_inst, sizeof (vl.type_instance)); - plugin_dispatch_values (type, &vl); + plugin_dispatch_values (&vl); } /* void memcached_submit_cmd */ /* }}} */ @@ -250,13 +247,11 @@ static void submit_counter2 (const char *type, const char *type_inst, vl.time = time (NULL); strcpy (vl.host, hostname_g); strcpy (vl.plugin, "memcached"); + sstrncpy (vl.type, type, sizeof (vl.type)); if (type_inst != NULL) - { - strncpy (vl.type_instance, type_inst, sizeof (vl.type_instance)); - vl.type_instance[sizeof (vl.type_instance) - 1] = '\0'; - } + sstrncpy (vl.type_instance, type_inst, sizeof (vl.type_instance)); - plugin_dispatch_values (type, &vl); + plugin_dispatch_values (&vl); } /* void memcached_submit_cmd */ /* }}} */ @@ -273,13 +268,11 @@ static void submit_gauge (const char *type, const char *type_inst, vl.time = time (NULL); strcpy (vl.host, hostname_g); strcpy (vl.plugin, "memcached"); + sstrncpy (vl.type, type, sizeof (vl.type)); if (type_inst != NULL) - { - strncpy (vl.type_instance, type_inst, sizeof (vl.type_instance)); - vl.type_instance[sizeof (vl.type_instance) - 1] = '\0'; - } + sstrncpy (vl.type_instance, type_inst, sizeof (vl.type_instance)); - plugin_dispatch_values (type, &vl); + plugin_dispatch_values (&vl); } /* }}} */ @@ -297,13 +290,11 @@ static void submit_gauge2 (const char *type, const char *type_inst, vl.time = time (NULL); strcpy (vl.host, hostname_g); strcpy (vl.plugin, "memcached"); + sstrncpy (vl.type, type, sizeof (vl.type)); if (type_inst != NULL) - { - strncpy (vl.type_instance, type_inst, sizeof (vl.type_instance)); - vl.type_instance[sizeof (vl.type_instance) - 1] = '\0'; - } + sstrncpy (vl.type_instance, type_inst, sizeof (vl.type_instance)); - plugin_dispatch_values (type, &vl); + plugin_dispatch_values (&vl); } /* }}} */ diff --git a/src/memory.c b/src/memory.c index fe3a16eb..b56fc5a3 100644 --- a/src/memory.c +++ b/src/memory.c @@ -111,10 +111,10 @@ static void memory_submit (const char *type_instance, gauge_t value) vl.time = time (NULL); strcpy (vl.host, hostname_g); strcpy (vl.plugin, "memory"); - strncpy (vl.type_instance, type_instance, sizeof (vl.type_instance)); - vl.type_instance[sizeof (vl.type_instance) - 1] = '\0'; + strcpy (vl.type, "memory"); + sstrncpy (vl.type_instance, type_instance, sizeof (vl.type_instance)); - plugin_dispatch_values ("memory", &vl); + plugin_dispatch_values (&vl); } static int memory_read (void) diff --git a/src/multimeter.c b/src/multimeter.c index 11ca42c1..e09d9f98 100644 --- a/src/multimeter.c +++ b/src/multimeter.c @@ -218,8 +218,9 @@ static void multimeter_submit (double value) vl.time = time (NULL); strcpy (vl.host, hostname_g); strcpy (vl.plugin, "multimeter"); + strcpy (vl.type, "multimeter"); - plugin_dispatch_values ("multimeter", &vl); + plugin_dispatch_values (&vl); } static int multimeter_read (void) diff --git a/src/mysql.c b/src/mysql.c index d4728531..444acaa2 100644 --- a/src/mysql.c +++ b/src/mysql.c @@ -128,9 +128,10 @@ static void counter_submit (const char *type, const char *type_instance, vl.time = time (NULL); strcpy (vl.host, hostname_g); strcpy (vl.plugin, "mysql"); - strncpy (vl.type_instance, type_instance, sizeof (vl.type_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 counter_submit */ static void qcache_submit (counter_t hits, counter_t inserts, @@ -151,8 +152,9 @@ static void qcache_submit (counter_t hits, counter_t inserts, vl.time = time (NULL); strcpy (vl.host, hostname_g); strcpy (vl.plugin, "mysql"); + strcpy (vl.type, "mysql_qcache"); - plugin_dispatch_values ("mysql_qcache", &vl); + plugin_dispatch_values (&vl); } /* void qcache_submit */ static void threads_submit (gauge_t running, gauge_t connected, gauge_t cached, @@ -171,8 +173,9 @@ static void threads_submit (gauge_t running, gauge_t connected, gauge_t cached, vl.time = time (NULL); strcpy (vl.host, hostname_g); strcpy (vl.plugin, "mysql"); + strcpy (vl.type, "mysql_threads"); - plugin_dispatch_values ("mysql_threads", &vl); + plugin_dispatch_values (&vl); } /* void threads_submit */ static void traffic_submit (counter_t rx, counter_t tx) @@ -188,8 +191,9 @@ static void traffic_submit (counter_t rx, counter_t tx) vl.time = time (NULL); strcpy (vl.host, hostname_g); strcpy (vl.plugin, "mysql"); + strcpy (vl.type, "mysql_octets"); - plugin_dispatch_values ("mysql_octets", &vl); + plugin_dispatch_values (&vl); } /* void traffic_submit */ static int mysql_read (void) diff --git a/src/netlink.c b/src/netlink.c index 22afdc77..f597b01d 100644 --- a/src/netlink.c +++ b/src/netlink.c @@ -173,12 +173,13 @@ static void submit_one (const char *dev, const char *type, vl.time = time (NULL); strcpy (vl.host, hostname_g); strcpy (vl.plugin, "netlink"); - strncpy (vl.plugin_instance, dev, sizeof (vl.plugin_instance)); + sstrncpy (vl.plugin_instance, dev, sizeof (vl.plugin_instance)); + sstrncpy (vl.type, type, sizeof (vl.type)); if (type_instance != NULL) - strncpy (vl.type_instance, type_instance, sizeof (vl.type_instance)); + sstrncpy (vl.type_instance, type_instance, sizeof (vl.type_instance)); - plugin_dispatch_values (type, &vl); + plugin_dispatch_values (&vl); } /* void submit_one */ static void submit_two (const char *dev, const char *type, @@ -196,12 +197,13 @@ static void submit_two (const char *dev, const char *type, vl.time = time (NULL); strcpy (vl.host, hostname_g); strcpy (vl.plugin, "netlink"); - strncpy (vl.plugin_instance, dev, sizeof (vl.plugin_instance)); + sstrncpy (vl.plugin_instance, dev, sizeof (vl.plugin_instance)); + sstrncpy (vl.type, type, sizeof (vl.type)); if (type_instance != NULL) - strncpy (vl.type_instance, type_instance, sizeof (vl.type_instance)); + sstrncpy (vl.type_instance, type_instance, sizeof (vl.type_instance)); - plugin_dispatch_values (type, &vl); + plugin_dispatch_values (&vl); } /* void submit_two */ static int link_filter (const struct sockaddr_nl *sa, @@ -395,11 +397,10 @@ static int qos_filter (const struct sockaddr_nl *sa, if (strcmp (tc_type, "filter") == 0) numberic_id = msg->tcm_parent; - snprintf (tc_inst, sizeof (tc_inst), "%s-%x:%x", + ssnprintf (tc_inst, sizeof (tc_inst), "%s-%x:%x", (const char *) RTA_DATA (attrs[TCA_KIND]), numberic_id >> 16, numberic_id & 0x0000FFFF); - tc_inst[sizeof (tc_inst) - 1] = '\0'; } DEBUG ("netlink plugin: qos_filter: got %s for %s (%i).", @@ -421,9 +422,8 @@ static int qos_filter (const struct sockaddr_nl *sa, struct gnet_stats_basic bs; char type_instance[DATA_MAX_NAME_LEN]; - snprintf (type_instance, sizeof (type_instance), "%s-%s", + ssnprintf (type_instance, sizeof (type_instance), "%s-%s", tc_type, tc_inst); - type_instance[sizeof (type_instance) - 1] = '\0'; memset (&bs, '\0', sizeof (bs)); memcpy (&bs, RTA_DATA (attrs_stats[TCA_STATS_BASIC]), @@ -443,9 +443,8 @@ static int qos_filter (const struct sockaddr_nl *sa, struct tc_stats ts; char type_instance[DATA_MAX_NAME_LEN]; - snprintf (type_instance, sizeof (type_instance), "%s-%s", + ssnprintf (type_instance, sizeof (type_instance), "%s-%s", tc_type, tc_inst); - type_instance[sizeof (type_instance) - 1] = '\0'; memset(&ts, '\0', sizeof (ts)); memcpy(&ts, RTA_DATA (attrs[TCA_STATS]), diff --git a/src/network.c b/src/network.c index e1503642..4e1504f5 100644 --- a/src/network.c +++ b/src/network.c @@ -246,7 +246,7 @@ static int cache_flush (void) return (0); } /* int cache_flush */ -static int cache_check (const char *type, const value_list_t *vl) +static int cache_check (const value_list_t *vl) { char key[1024]; time_t *value = NULL; @@ -256,7 +256,7 @@ static int cache_check (const char *type, const value_list_t *vl) return (-1); if (format_name (key, sizeof (key), vl->host, vl->plugin, - vl->plugin_instance, type, vl->type_instance)) + vl->plugin_instance, vl->type, vl->type_instance)) return (-1); pthread_mutex_lock (&cache_lock); @@ -678,14 +678,12 @@ static int parse_packet (void *buffer, int buffer_len) int status; value_list_t vl = VALUE_LIST_INIT; - char type[DATA_MAX_NAME_LEN]; notification_t n; DEBUG ("network plugin: parse_packet: buffer = %p; buffer_len = %i;", buffer, buffer_len); memset (&vl, '\0', sizeof (vl)); - memset (&type, '\0', sizeof (type)); memset (&n, '\0', sizeof (n)); status = 0; @@ -722,10 +720,10 @@ static int parse_packet (void *buffer, int buffer_len) if ((vl.time > 0) && (strlen (vl.host) > 0) && (strlen (vl.plugin) > 0) - && (strlen (type) > 0) - && (cache_check (type, &vl) == 0)) + && (strlen (vl.type) > 0) + && (cache_check (&vl) == 0)) { - plugin_dispatch_values (type, &vl); + plugin_dispatch_values (&vl); } else { @@ -782,9 +780,9 @@ static int parse_packet (void *buffer, int buffer_len) else if (pkg_type == TYPE_TYPE) { status = parse_part_string (&buffer, &buffer_len, - type, sizeof (type)); + vl.type, sizeof (vl.type)); if (status == 0) - sstrncpy (n.type, type, sizeof (n.type)); + sstrncpy (n.type, vl.type, sizeof (n.type)); } else if (pkg_type == TYPE_TYPE_INSTANCE) { @@ -1441,12 +1439,12 @@ static int add_to_buffer (char *buffer, int buffer_size, strcpy (vl_def->plugin_instance, vl->plugin_instance); } - if (strcmp (type_def, ds->type) != 0) + if (strcmp (type_def, vl->type) != 0) { if (write_part_string (&buffer, &buffer_size, TYPE_TYPE, - ds->type, strlen (ds->type)) != 0) + vl->type, strlen (vl->type)) != 0) return (-1); - strcpy (type_def, ds->type); + strcpy (type_def, vl->type); } if (strcmp (vl_def->type_instance, vl->type_instance) != 0) @@ -1483,7 +1481,7 @@ static int network_write (const data_set_t *ds, const value_list_t *vl) /* If the value is already in the cache, we have received it via the * network. We write it again if forwarding is activated. It's then in * the cache and should we receive it again we will ignore it. */ - status = cache_check (ds->type, vl); + status = cache_check (vl); if ((network_config_forward == 0) && (status != 0)) return (0); diff --git a/src/nfs.c b/src/nfs.c index 77c7f48f..34f01f43 100644 --- a/src/nfs.c +++ b/src/nfs.c @@ -190,18 +190,19 @@ static void nfs_procedures_submit (const char *plugin_instance, vl.time = time (NULL); strcpy (vl.host, hostname_g); strcpy (vl.plugin, "nfs"); - strncpy (vl.plugin_instance, plugin_instance, + sstrncpy (vl.plugin_instance, plugin_instance, sizeof (vl.plugin_instance)); + strcpy (vl.type, "nfs_procedure"); for (i = 0; i < len; i++) { values[0].counter = val[i]; - strncpy (vl.type_instance, names[i], + sstrncpy (vl.type_instance, names[i], sizeof (vl.type_instance)); DEBUG ("%s-%s/nfs_procedure-%s = %llu", vl.plugin, vl.plugin_instance, vl.type_instance, val[i]); - plugin_dispatch_values ("nfs_procedure", &vl); + plugin_dispatch_values (&vl); } } /* void nfs_procedures_submit */ @@ -240,9 +241,8 @@ static void nfs_read_stats_file (FILE *fh, char *inst) continue; } - snprintf (plugin_instance, sizeof (plugin_instance), + ssnprintf (plugin_instance, sizeof (plugin_instance), "v2%s", inst); - plugin_instance[DATA_MAX_NAME_LEN - 1] = '\0'; values = (unsigned long long *) malloc (nfs2_procedures_names_num * sizeof (unsigned long long)); if (values == NULL) @@ -277,9 +277,8 @@ static void nfs_read_stats_file (FILE *fh, char *inst) continue; } - snprintf (plugin_instance, sizeof (plugin_instance), + ssnprintf (plugin_instance, sizeof (plugin_instance), "v3%s", inst); - plugin_instance[DATA_MAX_NAME_LEN - 1] = '\0'; values = (unsigned long long *) malloc (nfs3_procedures_names_num * sizeof (unsigned long long)); if (values == NULL) diff --git a/src/nginx.c b/src/nginx.c index 3b107fb7..4de59f37 100644 --- a/src/nginx.c +++ b/src/nginx.c @@ -122,7 +122,8 @@ static int init (void) if (user != NULL) { - if (snprintf (credentials, 1024, "%s:%s", user, pass == NULL ? "" : pass) >= 1024) + if (ssnprintf (credentials, sizeof (credentials), + "%s:%s", user, pass == NULL ? "" : pass) >= sizeof (credentials)) { ERROR ("nginx plugin: Credentials would have been truncated."); return (-1); @@ -180,14 +181,12 @@ static void submit (char *type, char *inst, long long value) strcpy (vl.host, hostname_g); strcpy (vl.plugin, "nginx"); strcpy (vl.plugin_instance, ""); + sstrncpy (vl.type, type, sizeof (vl.type)); if (inst != NULL) - { - strncpy (vl.type_instance, inst, sizeof (vl.type_instance)); - vl.type_instance[sizeof (vl.type_instance) - 1] = '\0'; - } + sstrncpy (vl.type_instance, inst, sizeof (vl.type_instance)); - plugin_dispatch_values (type, &vl); + plugin_dispatch_values (&vl); } /* void submit */ static int nginx_read (void) diff --git a/src/ntpd.c b/src/ntpd.c index 90fdfd7c..600c0a34 100644 --- a/src/ntpd.c +++ b/src/ntpd.c @@ -269,11 +269,10 @@ static int ntpd_config (const char *key, const char *value) { 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) { @@ -305,9 +304,10 @@ static void ntpd_submit (char *type, char *type_inst, double value) strcpy (vl.host, hostname_g); strcpy (vl.plugin, "ntpd"); strcpy (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 @@ 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 @@ -883,7 +883,7 @@ static int ntpd_read (void) 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 --git a/src/nut.c b/src/nut.c index f7f026a6..75504d40 100644 --- a/src/nut.c +++ b/src/nut.c @@ -124,20 +124,17 @@ static void nut_submit (nut_ups_t *ups, const char *type, vl.values = values; vl.values_len = STATIC_ARRAY_SIZE (values); vl.time = time (NULL); - strncpy (vl.host, + sstrncpy (vl.host, (strcasecmp (ups->hostname, "localhost") == 0) ? hostname_g : ups->hostname, sizeof (vl.host)); strcpy (vl.plugin, "nut"); - strncpy (vl.plugin_instance, ups->upsname, sizeof (vl.plugin_instance)); - strncpy (vl.type_instance, type_instance, sizeof (vl.type_instance)); + sstrncpy (vl.plugin_instance, ups->upsname, sizeof (vl.plugin_instance)); + sstrncpy (vl.type, type, sizeof (vl.type)); + sstrncpy (vl.type_instance, type_instance, sizeof (vl.type_instance)); - vl.host[sizeof (vl.host) - 1] = '\0'; - vl.plugin_instance[sizeof (vl.plugin_instance) - 1] = '\0'; - vl.type_instance[sizeof (vl.type_instance) - 1] = '\0'; - - plugin_dispatch_values (type, &vl); + plugin_dispatch_values (&vl); } /* void nut_submit */ static int nut_read_one (nut_ups_t *ups) diff --git a/src/perl.c b/src/perl.c index bd6345ba..66cac7ef 100644 --- a/src/perl.c +++ b/src/perl.c @@ -210,8 +210,7 @@ static int hv2data_source (pTHX_ HV *hash, data_source_t *ds) 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."); @@ -373,6 +372,10 @@ static int value_list2hv (pTHX_ value_list_t *vl, data_set_t *ds, HV *hash) 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)) @@ -424,12 +427,11 @@ static int notification2hv (pTHX_ notification_t *n, HV *hash) 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 */ @@ -475,8 +477,7 @@ static int pplugin_register_data_set (pTHX_ char *name, AV *dataset) 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; @@ -511,7 +512,7 @@ static int pplugin_unregister_data_set (char *name) * 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; @@ -520,8 +521,15 @@ static int pplugin_dispatch_values (pTHX_ char *name, HV *values) 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)))))) { @@ -538,7 +546,8 @@ static int pplugin_dispatch_values (pTHX_ char *name, HV *values) 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) { @@ -555,29 +564,24 @@ static int pplugin_dispatch_values (pTHX_ char *name, HV *values) } 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 { strcpy (list.host, hostname_g); } - 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; @@ -620,31 +624,25 @@ static int pplugin_dispatch_notification (pTHX_ HV *notif) 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 *) */ @@ -693,6 +691,7 @@ static int pplugin_call_all (pTHX_ int type, ...) * time => $time, * host => $hostname, * plugin => $plugin, + * type => $type, * plugin_instance => $instance, * type_instance => $type_instance * }; @@ -868,33 +867,43 @@ static XS (Collectd_plugin_unregister_ds) */ 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; @@ -1352,8 +1361,7 @@ static int g_pv_get (pTHX_ SV *var, MAGIC *mg) 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 *) */ @@ -1546,8 +1554,7 @@ static int perl_config_basename (pTHX_ oconfig_item_t *ci) 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 --git a/src/ping.c b/src/ping.c index 2f7c064d..20388c37 100644 --- a/src/ping.c +++ b/src/ping.c @@ -189,9 +189,10 @@ static void ping_submit (char *host, double latency) strcpy (vl.host, hostname_g); strcpy (vl.plugin, "ping"); strcpy (vl.plugin_instance, ""); - strncpy (vl.type_instance, host, sizeof (vl.type_instance)); + strcpy (vl.type, "ping"); + sstrncpy (vl.type_instance, host, sizeof (vl.type_instance)); - plugin_dispatch_values ("ping", &vl); + plugin_dispatch_values (&vl); } static int ping_read (void) diff --git a/src/plugin.c b/src/plugin.c index 1aad97c1..dfab52c3 100644 --- a/src/plugin.c +++ b/src/plugin.c @@ -328,7 +328,8 @@ int plugin_load (const char *type) /* `cpu' should not match `cpufreq'. To solve this we add `.so' to the * type when matching the filename */ - if (snprintf (typename, BUFSIZE, "%s.so", type) >= BUFSIZE) + if (ssnprintf (typename, sizeof (typename), + "%s.so", type) >= sizeof (typename)) { WARNING ("snprintf: truncated: `%s.so'", type); return (-1); @@ -348,7 +349,8 @@ int plugin_load (const char *type) if (strncasecmp (de->d_name, typename, typename_len)) continue; - if (snprintf (filename, BUFSIZE, "%s/%s", dir, de->d_name) >= BUFSIZE) + if (ssnprintf (filename, sizeof (filename), + "%s/%s", dir, de->d_name) >= sizeof (filename)) { WARNING ("snprintf: truncated: `%s/%s'", dir, de->d_name); continue; @@ -717,12 +719,17 @@ void plugin_shutdown_all (void) } } /* void plugin_shutdown_all */ -int plugin_dispatch_values (const char *name, value_list_t *vl) +int plugin_dispatch_values (value_list_t *vl) { int (*callback) (const data_set_t *, const value_list_t *); data_set_t *ds; llentry_t *le; + if ((vl == NULL) || (*vl->type == '\0')) { + ERROR ("plugin_dispatch_values: Invalid value list."); + return (-1); + } + if (list_write == NULL) { ERROR ("plugin_dispatch_values: No write callback has been " @@ -739,9 +746,9 @@ int plugin_dispatch_values (const char *name, value_list_t *vl) return (-1); } - if (c_avl_get (data_sets, name, (void *) &ds) != 0) + if (c_avl_get (data_sets, vl->type, (void *) &ds) != 0) { - INFO ("plugin_dispatch_values: Dataset not found: %s", name); + INFO ("plugin_dispatch_values: Dataset not found: %s", vl->type); return (-1); } @@ -752,7 +759,15 @@ int plugin_dispatch_values (const char *name, value_list_t *vl) (unsigned int) vl->time, vl->interval, vl->host, vl->plugin, vl->plugin_instance, - ds->type, vl->type_instance); + vl->type, vl->type_instance); + +#if COLLECT_DEBUG + assert (0 == strcmp (ds->type, vl->type)); +#else + if (0 != strcmp (ds->type, vl->type)) + WARNING ("plugin_dispatch_values: (ds->type = %s) != (vl->type = %s)", + ds->type, vl->type); +#endif #if COLLECT_DEBUG assert (ds->ds_num == vl->values_len); @@ -770,6 +785,7 @@ int plugin_dispatch_values (const char *name, value_list_t *vl) escape_slashes (vl->host, sizeof (vl->host)); escape_slashes (vl->plugin, sizeof (vl->plugin)); escape_slashes (vl->plugin_instance, sizeof (vl->plugin_instance)); + escape_slashes (vl->type, sizeof (vl->type)); escape_slashes (vl->type_instance, sizeof (vl->type_instance)); /* Update the value cache */ diff --git a/src/plugin.h b/src/plugin.h index 7b59930d..488e041e 100644 --- a/src/plugin.h +++ b/src/plugin.h @@ -74,12 +74,13 @@ struct value_list_s char host[DATA_MAX_NAME_LEN]; char plugin[DATA_MAX_NAME_LEN]; char plugin_instance[DATA_MAX_NAME_LEN]; + char type[DATA_MAX_NAME_LEN]; char type_instance[DATA_MAX_NAME_LEN]; }; typedef struct value_list_s value_list_t; -#define VALUE_LIST_INIT { NULL, 0, 0, interval_g, "localhost", "", "", "" } -#define VALUE_LIST_STATIC { NULL, 0, 0, 0, "localhost", "", "", "" } +#define VALUE_LIST_INIT { NULL, 0, 0, interval_g, "localhost", "", "", "", "" } +#define VALUE_LIST_STATIC { NULL, 0, 0, 0, "localhost", "", "", "", "" } struct data_source_s { @@ -204,11 +205,10 @@ int plugin_unregister_notification (const char *name); * write-functions. * * ARGUMENTS - * `name' Name/type of the data-set that describe the values in `vl'. * `vl' Value list of the values that have been read by a `read' * function. */ -int plugin_dispatch_values (const char *name, value_list_t *vl); +int plugin_dispatch_values (value_list_t *vl); int plugin_dispatch_notification (const notification_t *notif); diff --git a/src/powerdns.c b/src/powerdns.c index 9caa7708..6a28856f 100644 --- a/src/powerdns.c +++ b/src/powerdns.c @@ -264,11 +264,12 @@ static void submit (const char *plugin_instance, /* {{{ */ vl.time = time (NULL); sstrncpy (vl.host, hostname_g, sizeof (vl.host)); sstrncpy (vl.plugin, "powerdns", sizeof (vl.plugin)); + sstrncpy (vl.type, type, sizeof (vl.type)); if (type_instance != NULL) sstrncpy (vl.type_instance, type_instance, sizeof (vl.type_instance)); sstrncpy (vl.plugin_instance, plugin_instance, sizeof (vl.plugin_instance)); - plugin_dispatch_values (type, &vl); + plugin_dispatch_values (&vl); } /* }}} static void submit */ static int powerdns_get_data_dgram (list_item_t *item, /* {{{ */ @@ -293,10 +294,9 @@ static int powerdns_get_data_dgram (list_item_t *item, /* {{{ */ memset (&sa_unix, 0, sizeof (sa_unix)); sa_unix.sun_family = AF_UNIX; - strncpy (sa_unix.sun_path, + sstrncpy (sa_unix.sun_path, (local_sockpath != NULL) ? local_sockpath : PDNS_LOCAL_SOCKPATH, sizeof (sa_unix.sun_path)); - sa_unix.sun_path[sizeof (sa_unix.sun_path) - 1] = 0; status = unlink (sa_unix.sun_path); if ((status != 0) && (errno != ENOENT)) @@ -663,7 +663,8 @@ static int powerdns_config_add_server (oconfig_item_t *ci) /* {{{ */ } item->sockaddr.sun_family = AF_UNIX; - sstrncpy (item->sockaddr.sun_path, socket_temp, UNIX_PATH_MAX); + sstrncpy (item->sockaddr.sun_path, socket_temp, + sizeof (item->sockaddr.sun_path)); e = llentry_create (item->instance, item); if (e == NULL) diff --git a/src/processes.c b/src/processes.c index 22d369df..8275022f 100644 --- a/src/processes.c +++ b/src/processes.c @@ -158,7 +158,7 @@ static void ps_list_register (const char *name) if ((new = (procstat_t *) malloc (sizeof (procstat_t))) == NULL) return; memset (new, 0, sizeof (procstat_t)); - strncpy (new->name, name, PROCSTAT_NAME_LEN); + sstrncpy (new->name, name, sizeof (new->name)); for (ptr = list_head_g; ptr != NULL; ptr = ptr->next) { @@ -412,9 +412,10 @@ static void ps_submit_state (const char *state, double value) strcpy (vl.host, hostname_g); strcpy (vl.plugin, "processes"); strcpy (vl.plugin_instance, ""); - strncpy (vl.type_instance, state, sizeof (vl.type_instance)); + strcpy (vl.type, "ps_state"); + sstrncpy (vl.type_instance, state, sizeof (vl.type_instance)); - plugin_dispatch_values ("ps_state", &vl); + plugin_dispatch_values (&vl); } static void ps_submit_proc_list (procstat_t *ps) @@ -427,26 +428,30 @@ static void ps_submit_proc_list (procstat_t *ps) vl.time = time (NULL); strcpy (vl.host, hostname_g); strcpy (vl.plugin, "processes"); - strncpy (vl.plugin_instance, ps->name, sizeof (vl.plugin_instance)); + sstrncpy (vl.plugin_instance, ps->name, sizeof (vl.plugin_instance)); + strcpy (vl.type, "ps_rss"); vl.values[0].gauge = ps->vmem_rss; vl.values_len = 1; - plugin_dispatch_values ("ps_rss", &vl); + plugin_dispatch_values (&vl); + strcpy (vl.type, "ps_cputime"); vl.values[0].counter = ps->cpu_user_counter; vl.values[1].counter = ps->cpu_system_counter; vl.values_len = 2; - plugin_dispatch_values ("ps_cputime", &vl); + plugin_dispatch_values (&vl); + strcpy (vl.type, "ps_count"); vl.values[0].gauge = ps->num_proc; vl.values[1].gauge = ps->num_lwp; vl.values_len = 2; - plugin_dispatch_values ("ps_count", &vl); + plugin_dispatch_values (&vl); + strcpy (vl.type, "ps_pagefaults"); vl.values[0].counter = ps->vmem_minflt_counter; vl.values[1].counter = ps->vmem_majflt_counter; vl.values_len = 2; - plugin_dispatch_values ("ps_pagefaults", &vl); + plugin_dispatch_values (&vl); DEBUG ("name = %s; num_proc = %lu; num_lwp = %lu; vmem_rss = %lu; " "vmem_minflt_counter = %lu; vmem_majflt_counter = %lu; " @@ -467,8 +472,7 @@ static int *ps_read_tasks (int pid) DIR *dh; struct dirent *ent; - snprintf (dirname, 64, "/proc/%i/task", pid); - dirname[63] = '\0'; + ssnprintf (dirname, sizeof (dirname), "/proc/%i/task", pid); if ((dh = opendir (dirname)) == NULL) { @@ -540,8 +544,7 @@ int ps_read_process (int pid, procstat_t *ps, char *state) memset (ps, 0, sizeof (procstat_t)); - snprintf (filename, 64, "/proc/%i/stat", pid); - filename[63] = '\0'; + ssnprintf (filename, sizeof (filename), "/proc/%i/stat", pid); if ((fh = fopen (filename, "r")) == NULL) return (-1); diff --git a/src/rrdtool.c b/src/rrdtool.c index 93c9d7a8..29e8a7d3 100644 --- a/src/rrdtool.c +++ b/src/rrdtool.c @@ -211,7 +211,7 @@ static int rra_get (char ***ret, const value_list_t *vl) if (rra_num >= rra_max) break; - if (snprintf (buffer, sizeof (buffer), "RRA:%s:%3.1f:%u:%u", + if (ssnprintf (buffer, sizeof (buffer), "RRA:%s:%3.1f:%u:%u", rra_types[j], xff, cdp_len, cdp_num) >= sizeof (buffer)) { @@ -284,26 +284,16 @@ static int ds_get (char ***ret, const data_set_t *ds, const value_list_t *vl) } if (isnan (d->min)) - { strcpy (min, "U"); - } else - { - snprintf (min, sizeof (min), "%lf", d->min); - min[sizeof (min) - 1] = '\0'; - } + ssnprintf (min, sizeof (min), "%lf", d->min); if (isnan (d->max)) - { strcpy (max, "U"); - } else - { - snprintf (max, sizeof (max), "%lf", d->max); - max[sizeof (max) - 1] = '\0'; - } + ssnprintf (max, sizeof (max), "%lf", d->max); - status = snprintf (buffer, sizeof (buffer), + status = ssnprintf (buffer, sizeof (buffer), "DS:%s:%s:%i:%s:%s", d->name, type, (heartbeat > 0) ? heartbeat : (2 * vl->interval), @@ -395,10 +385,8 @@ static int srrd_create (char *filename, unsigned long pdp_step, time_t last_up, if (last_up == 0) last_up = time (NULL) - 10; - snprintf (pdp_step_str, sizeof (pdp_step_str), "%lu", pdp_step); - pdp_step_str[sizeof (pdp_step_str) - 1] = '\0'; - snprintf (last_up_str, sizeof (last_up_str), "%u", (unsigned int) last_up); - last_up_str[sizeof (last_up_str) - 1] = '\0'; + ssnprintf (pdp_step_str, sizeof (pdp_step_str), "%lu", pdp_step); + ssnprintf (last_up_str, sizeof (last_up_str), "%u", (unsigned int) last_up); new_argv[0] = "create"; new_argv[1] = filename; @@ -531,7 +519,7 @@ static int value_list_to_string (char *buffer, int buffer_len, memset (buffer, '\0', buffer_len); - status = snprintf (buffer, buffer_len, "%u", (unsigned int) vl->time); + status = ssnprintf (buffer, buffer_len, "%u", (unsigned int) vl->time); if ((status < 1) || (status >= buffer_len)) return (-1); offset = status; @@ -543,10 +531,10 @@ static int value_list_to_string (char *buffer, int buffer_len, return (-1); if (ds->ds[i].type == DS_TYPE_COUNTER) - status = snprintf (buffer + offset, buffer_len - offset, + status = ssnprintf (buffer + offset, buffer_len - offset, ":%llu", vl->values[i].counter); else - status = snprintf (buffer + offset, buffer_len - offset, + status = ssnprintf (buffer + offset, buffer_len - offset, ":%lf", vl->values[i].gauge); if ((status < 1) || (status >= (buffer_len - offset))) @@ -566,35 +554,35 @@ static int value_list_to_filename (char *buffer, int buffer_len, if (datadir != NULL) { - status = snprintf (buffer + offset, buffer_len - offset, + status = ssnprintf (buffer + offset, buffer_len - offset, "%s/", datadir); if ((status < 1) || (status >= buffer_len - offset)) return (-1); offset += status; } - status = snprintf (buffer + offset, buffer_len - offset, + status = ssnprintf (buffer + offset, buffer_len - offset, "%s/", vl->host); if ((status < 1) || (status >= buffer_len - offset)) return (-1); offset += status; if (strlen (vl->plugin_instance) > 0) - status = snprintf (buffer + offset, buffer_len - offset, + status = ssnprintf (buffer + offset, buffer_len - offset, "%s-%s/", vl->plugin, vl->plugin_instance); else - status = snprintf (buffer + offset, buffer_len - offset, + status = ssnprintf (buffer + offset, buffer_len - offset, "%s/", vl->plugin); if ((status < 1) || (status >= buffer_len - offset)) return (-1); offset += status; if (strlen (vl->type_instance) > 0) - status = snprintf (buffer + offset, buffer_len - offset, - "%s-%s.rrd", ds->type, vl->type_instance); + status = ssnprintf (buffer + offset, buffer_len - offset, + "%s-%s.rrd", vl->type, vl->type_instance); else - status = snprintf (buffer + offset, buffer_len - offset, - "%s.rrd", ds->type); + status = ssnprintf (buffer + offset, buffer_len - offset, + "%s.rrd", vl->type); if ((status < 1) || (status >= buffer_len - offset)) return (-1); offset += status; @@ -913,6 +901,11 @@ static int rrd_write (const data_set_t *ds, const value_list_t *vl) char values[512]; int status; + if (0 != strcmp (ds->type, vl->type)) { + ERROR ("rrdtool plugin: DS type does not match value list type"); + return -1; + } + if (value_list_to_filename (filename, sizeof (filename), ds, vl) != 0) return (-1); diff --git a/src/sensors.c b/src/sensors.c index 0968e311..5ed82a8c 100644 --- a/src/sensors.c +++ b/src/sensors.c @@ -182,7 +182,7 @@ static int sensors_snprintf_chip_name (char *buf, size_t buf_size, if (chip->bus == SENSORS_CHIP_NAME_BUS_ISA) { - status = snprintf (buf, buf_size, + status = ssnprintf (buf, buf_size, "%s-isa-%04x", chip->prefix, chip->addr); @@ -480,11 +480,10 @@ static void sensors_submit (const char *plugin_instance, value_t values[1]; value_list_t vl = VALUE_LIST_INIT; - status = snprintf (match_key, sizeof (match_key), "%s/%s-%s", + status = ssnprintf (match_key, sizeof (match_key), "%s/%s-%s", plugin_instance, type, type_instance); if (status < 1) return; - match_key[sizeof (match_key) - 1] = '\0'; if (sensor_list != NULL) { @@ -499,17 +498,14 @@ static void sensors_submit (const char *plugin_instance, vl.values_len = 1; vl.time = time (NULL); - strncpy (vl.host, hostname_g, sizeof (vl.host)); - vl.host[sizeof (vl.host) - 1] = '\0'; - strncpy (vl.plugin, "sensors", sizeof (vl.plugin)); - vl.plugin[sizeof (vl.plugin) - 1] = '\0'; - strncpy (vl.plugin_instance, plugin_instance, + sstrncpy (vl.host, hostname_g, sizeof (vl.host)); + sstrncpy (vl.plugin, "sensors", sizeof (vl.plugin)); + sstrncpy (vl.plugin_instance, plugin_instance, sizeof (vl.plugin_instance)); - vl.plugin_instance[sizeof (vl.plugin_instance) - 1] = '\0'; - strncpy (vl.type_instance, type_instance, sizeof (vl.type_instance)); - vl.type_instance[sizeof (vl.type_instance) - 1] = '\0'; + 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 sensors_submit */ static int sensors_read (void) @@ -536,11 +532,9 @@ static int sensors_read (void) sizeof (plugin_instance), fl->chip); if (status < 0) continue; - plugin_instance[sizeof (plugin_instance) - 1] = '\0'; - strncpy (type_instance, fl->data->name, + sstrncpy (type_instance, fl->data->name, sizeof (type_instance)); - type_instance[sizeof (type_instance) - 1] = '\0'; sensors_submit (plugin_instance, sensor_type_name_map[fl->type], @@ -567,11 +561,9 @@ static int sensors_read (void) sizeof (plugin_instance), fl->chip); if (status < 0) continue; - plugin_instance[sizeof (plugin_instance) - 1] = '\0'; - strncpy (type_instance, fl->feature->name, + sstrncpy (type_instance, fl->feature->name, sizeof (type_instance)); - type_instance[sizeof (type_instance) - 1] = '\0'; if (fl->feature->type == SENSORS_FEATURE_IN) type = "voltage"; diff --git a/src/serial.c b/src/serial.c index 9cfe1dd4..1c5d5a55 100644 --- a/src/serial.c +++ b/src/serial.c @@ -43,10 +43,11 @@ static void serial_submit (const char *type_instance, vl.time = time (NULL); strcpy (vl.host, hostname_g); strcpy (vl.plugin, "serial"); - strncpy (vl.type_instance, type_instance, + strcpy (vl.type, "serial_octets"); + sstrncpy (vl.type_instance, type_instance, sizeof (vl.type_instance)); - plugin_dispatch_values ("serial_octets", &vl); + plugin_dispatch_values (&vl); } static int serial_read (void) diff --git a/src/snmp.c b/src/snmp.c index 4311ff16..6f11af04 100644 --- a/src/snmp.c +++ b/src/snmp.c @@ -198,7 +198,8 @@ static int csnmp_config_add_data_instance (data_definition_t *dd, oconfig_item_t 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); @@ -833,11 +834,10 @@ static int csnmp_instance_list_add (csnmp_list_instances_t **head, 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++) { @@ -851,10 +851,9 @@ static int csnmp_instance_list_add (csnmp_list_instances_t **head, 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 */ @@ -907,8 +906,7 @@ static int csnmp_dispatch_table (host_definition_t *host, data_definition_t *dat 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)); strcpy (vl.plugin, "snmp"); vl.interval = host->interval; @@ -972,30 +970,28 @@ static int csnmp_dispatch_table (host_definition_t *host, data_definition_t *dat || (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) */ @@ -1299,11 +1295,10 @@ static int csnmp_read_value (host_definition_t *host, data_definition_t *data) 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)); strcpy (vl.plugin, "snmp"); - 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; @@ -1361,8 +1356,8 @@ static int csnmp_read_value (host_definition_t *host, data_definition_t *data) 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); diff --git a/src/swap.c b/src/swap.c index e91ebefd..4f0a0ba9 100644 --- a/src/swap.c +++ b/src/swap.c @@ -126,9 +126,10 @@ static void swap_submit (const char *type_instance, double value) vl.time = time (NULL); strcpy (vl.host, hostname_g); strcpy (vl.plugin, "swap"); - strncpy (vl.type_instance, type_instance, sizeof (vl.type_instance)); + strcpy (vl.type, "swap"); + sstrncpy (vl.type_instance, type_instance, sizeof (vl.type_instance)); - plugin_dispatch_values ("swap", &vl); + plugin_dispatch_values (&vl); } /* void swap_submit */ static int swap_read (void) diff --git a/src/tape.c b/src/tape.c index 465688ed..67750efc 100644 --- a/src/tape.c +++ b/src/tape.c @@ -71,10 +71,11 @@ static void tape_submit (const char *plugin_instance, vl.time = time (NULL); strcpy (vl.host, hostname_g); strcpy (vl.plugin, "tape"); - strncpy (vl.plugin_instance, plugin_instance, + sstrncpy (vl.plugin_instance, plugin_instance, sizeof (vl.plugin_instance)); + sstrncpy (vl.type, type, sizeof (vl.type)); - plugin_dispatch_values (type, &vl); + plugin_dispatch_values (&vl); } /* void tape_submit */ static int tape_read (void) diff --git a/src/tcpconns.c b/src/tcpconns.c index fdf7ec1b..4f46e78a 100644 --- a/src/tcpconns.c +++ b/src/tcpconns.c @@ -137,39 +137,36 @@ static void conn_submit_port_entry (port_entry_t *pe) vl.time = time (NULL); strcpy (vl.host, hostname_g); strcpy (vl.plugin, "tcpconns"); + strcpy (vl.type, "tcp_connections"); if (((port_collect_listening != 0) && (pe->flags & PORT_IS_LISTENING)) || (pe->flags & PORT_COLLECT_LOCAL)) { - snprintf (vl.plugin_instance, sizeof (vl.plugin_instance), + ssnprintf (vl.plugin_instance, sizeof (vl.plugin_instance), "%hu-local", pe->port); - vl.plugin_instance[sizeof (vl.plugin_instance) - 1] = '\0'; for (i = 1; i <= TCP_STATE_MAX; i++) { vl.values[0].gauge = pe->count_local[i]; - strncpy (vl.type_instance, tcp_state[i], sizeof (vl.type_instance)); - vl.type_instance[sizeof (vl.type_instance) - 1] = '\0'; + sstrncpy (vl.type_instance, tcp_state[i], sizeof (vl.type_instance)); - plugin_dispatch_values ("tcp_connections", &vl); + plugin_dispatch_values (&vl); } } if (pe->flags & PORT_COLLECT_REMOTE) { - snprintf (vl.plugin_instance, sizeof (vl.plugin_instance), + ssnprintf (vl.plugin_instance, sizeof (vl.plugin_instance), "%hu-remote", pe->port); - vl.plugin_instance[sizeof (vl.plugin_instance) - 1] = '\0'; for (i = 1; i <= TCP_STATE_MAX; i++) { vl.values[0].gauge = pe->count_remote[i]; - strncpy (vl.type_instance, tcp_state[i], sizeof (vl.type_instance)); - vl.type_instance[sizeof (vl.type_instance) - 1] = '\0'; + sstrncpy (vl.type_instance, tcp_state[i], sizeof (vl.type_instance)); - plugin_dispatch_values ("tcp_connections", &vl); + plugin_dispatch_values (&vl); } } } /* void conn_submit */ diff --git a/src/teamspeak2.c b/src/teamspeak2.c index b7992d80..a945bbcd 100644 --- a/src/teamspeak2.c +++ b/src/teamspeak2.c @@ -136,12 +136,14 @@ static void tss2_submit_gauge (const char *plugin_instance, if (plugin_instance != NULL) sstrncpy (vl.plugin_instance, plugin_instance, sizeof (vl.plugin_instance)); - + + sstrncpy (vl.type, type, sizeof (vl.type)); + if (type_instance != NULL) sstrncpy (vl.type_instance, type_instance, sizeof (vl.type_instance)); - plugin_dispatch_values (type, &vl); + plugin_dispatch_values (&vl); } /* void tss2_submit_gauge */ static void tss2_submit_io (const char *plugin_instance, const char *type, @@ -165,8 +167,10 @@ static void tss2_submit_io (const char *plugin_instance, const char *type, if (plugin_instance != NULL) sstrncpy (vl.plugin_instance, plugin_instance, sizeof (vl.plugin_instance)); - - plugin_dispatch_values (type, &vl); + + sstrncpy (vl.type, type, sizeof (vl.type)); + + plugin_dispatch_values (&vl); } /* void tss2_submit_gauge */ static void tss2_close_socket (void) @@ -372,8 +376,7 @@ static int tss2_select_vserver (FILE *read_fh, FILE *write_fh, vserver_list_t *v int status; /* Send request */ - snprintf (command, sizeof (command), "sel %i\r\n", vserver->port); - command[sizeof (command) - 1] = 0; + ssnprintf (command, sizeof (command), "sel %i\r\n", vserver->port); status = tss2_send_request (write_fh, command); if (status != 0) @@ -527,9 +530,8 @@ static int tss2_read_vserver (vserver_list_t *vserver) else { /* Request server information */ - snprintf (plugin_instance, sizeof (plugin_instance), "vserver%i", + ssnprintf (plugin_instance, sizeof (plugin_instance), "vserver%i", vserver->port); - plugin_instance[sizeof (plugin_instance) - 1] = 0; /* Select the server */ status = tss2_select_vserver (read_fh, write_fh, vserver); diff --git a/src/types.db b/src/types.db index 97c170b7..8350fb47 100644 --- a/src/types.db +++ b/src/types.db @@ -4,7 +4,7 @@ apache_requests count:COUNTER:0:134217728 apache_scoreboard count:GAUGE:0:65535 bitrate value:GAUGE:0:4294967295 cache_result value:COUNTER:0:4294967295 -cache_size value:GAUGE:0:4294967295 +cache_size value:GAUGE:0:4294967295 charge value:GAUGE:0:U connections value:COUNTER:0:U counter value:COUNTER:U:U diff --git a/src/types_list.c b/src/types_list.c index 3be792d5..a9af9e6d 100644 --- a/src/types_list.c +++ b/src/types_list.c @@ -62,8 +62,7 @@ static int parse_ds (data_source_t *dsrc, char *buf, size_t buf_len) return (-1); } - strncpy (dsrc->name, fields[0], sizeof (dsrc->name)); - dsrc->name[sizeof (dsrc->name) - 1] = '\0'; + sstrncpy (dsrc->name, fields[0], sizeof (dsrc->name)); if (strcasecmp (fields[1], "GAUGE") == 0) dsrc->type = DS_TYPE_GAUGE; @@ -105,8 +104,7 @@ static void parse_line (char *buf) memset (ds, '\0', sizeof (data_set_t)); - strncpy (ds->type, fields[0], sizeof (ds->type)); - ds->type[sizeof (ds->type) - 1] = '\0'; + sstrncpy (ds->type, fields[0], sizeof (ds->type)); ds->ds_num = fields_num - 1; ds->ds = (data_source_t *) calloc (ds->ds_num, sizeof (data_source_t)); diff --git a/src/unixsock.c b/src/unixsock.c index 025c91d5..07598020 100644 --- a/src/unixsock.c +++ b/src/unixsock.c @@ -86,8 +86,8 @@ static int us_open_socket (void) memset (&sa, '\0', sizeof (sa)); sa.sun_family = AF_UNIX; - strncpy (sa.sun_path, (sock_file != NULL) ? sock_file : US_DEFAULT_PATH, - sizeof (sa.sun_path) - 1); + sstrncpy (sa.sun_path, (sock_file != NULL) ? sock_file : US_DEFAULT_PATH, + sizeof (sa.sun_path)); /* unlink (sa.sun_path); */ DEBUG ("unixsock plugin: socket path = %s", sa.sun_path); diff --git a/src/users.c b/src/users.c index afe26e1e..bec908ca 100644 --- a/src/users.c +++ b/src/users.c @@ -47,8 +47,9 @@ static void users_submit (gauge_t value) vl.time = time (NULL); strcpy (vl.host, hostname_g); strcpy (vl.plugin, "users"); + strcpy (vl.type, "users"); - plugin_dispatch_values ("users", &vl); + plugin_dispatch_values (&vl); } /* void users_submit */ static int users_read (void) diff --git a/src/utils_cache.c b/src/utils_cache.c index 9f7e3b68..d7d31c53 100644 --- a/src/utils_cache.c +++ b/src/utils_cache.c @@ -156,13 +156,12 @@ static int uc_send_notification (const char *name) return (-1); } - snprintf (n.message, sizeof (n.message), + ssnprintf (n.message, sizeof (n.message), "%s has not been updated for %i seconds.", name, (int) (n.time - ce->last_update)); pthread_mutex_unlock (&cache_lock); - n.message[sizeof (n.message) - 1] = '\0'; plugin_dispatch_notification (&n); return (0); @@ -450,10 +449,9 @@ int uc_update (const data_set_t *ds, const value_list_t *vl) n.severity = NOTIF_OKAY; n.time = vl->time; - snprintf (n.message, sizeof (n.message), + ssnprintf (n.message, sizeof (n.message), "Received a value for %s. It was missing for %u seconds.", name, (unsigned int) update_delay); - n.message[sizeof (n.message) - 1] = '\0'; plugin_dispatch_notification (&n); diff --git a/src/utils_cmd_putval.c b/src/utils_cmd_putval.c index 98b5043f..023e4a71 100644 --- a/src/utils_cmd_putval.c +++ b/src/utils_cmd_putval.c @@ -24,7 +24,6 @@ #include "plugin.h" static int parse_value (const data_set_t *ds, value_list_t *vl, - const char *type, FILE *fh, char *buffer) { char *dummy; @@ -82,7 +81,7 @@ static int parse_value (const data_set_t *ds, value_list_t *vl, return (-1); } - plugin_dispatch_values (type, vl); + plugin_dispatch_values (vl); return (0); } /* int parse_value */ @@ -170,6 +169,7 @@ int handle_putval (FILE *fh, char **fields, int fields_num) strcpy (vl.plugin, plugin); if (plugin_instance != NULL) strcpy (vl.plugin_instance, plugin_instance); + strcpy (vl.type, type); if (type_instance != NULL) strcpy (vl.type_instance, type_instance); @@ -197,7 +197,7 @@ int handle_putval (FILE *fh, char **fields, int fields_num) /* It's parse_value's job to write an error to `fh'. * This is not the case with `parse_option below. * Neither will write an success message. */ - if (parse_value (ds, &vl, type, fh, fields[i]) != 0) + if (parse_value (ds, &vl, fh, fields[i]) != 0) break; } else if (strchr (fields[i], '=') != NULL) diff --git a/src/utils_dns.c b/src/utils_dns.c index 25ef1899..b72cd5ca 100644 --- a/src/utils_dns.c +++ b/src/utils_dns.c @@ -34,6 +34,7 @@ */ #include "collectd.h" +#include "common.h" #if HAVE_NETINET_IN_SYSTM_H # include @@ -813,8 +814,7 @@ const char *qtype_str(int t) case T_ANY: return ("ANY"); /* ... 255 */ #endif /* __BIND >= 19950621 */ default: - snprintf (buf, 32, "#%i", t); - buf[31] = '\0'; + ssnprintf (buf, sizeof (buf), "#%i", t); return (buf); }; /* switch (t) */ /* NOTREACHED */ @@ -841,7 +841,7 @@ const char *opcode_str (int o) return "Update"; break; default: - snprintf(buf, 30, "Opcode%d", o); + ssnprintf(buf, sizeof (buf), "Opcode%d", o); return buf; } /* NOTREACHED */ @@ -885,8 +885,7 @@ const char *rcode_str (int rcode) #endif /* RFC2136 rcodes */ #endif /* __BIND >= 19950621 */ default: - snprintf (buf, 32, "RCode%i", rcode); - buf[31] = '\0'; + ssnprintf (buf, sizeof (buf), "RCode%i", rcode); return (buf); } /* Never reached */ diff --git a/src/utils_ignorelist.c b/src/utils_ignorelist.c index 1d9467fe..518715b1 100644 --- a/src/utils_ignorelist.c +++ b/src/utils_ignorelist.c @@ -310,7 +310,7 @@ int ignorelist_add (ignorelist_t *il, const char *entry) /* We need to copy `entry' since it's const */ entry_copy = smalloc (entry_len); memset (entry_copy, '\0', entry_len); - strncpy (entry_copy, entry + 1, entry_len - 2); + sstrncpy (entry_copy, entry + 1, entry_len - 2); DEBUG("I'm about to add regex entry: %s", entry_copy); ret = ignorelist_append_regex(il, entry_copy); diff --git a/src/utils_mount.c b/src/utils_mount.c index 44ad7ea8..c53431f1 100644 --- a/src/utils_mount.c +++ b/src/utils_mount.c @@ -260,7 +260,7 @@ uuidcache_init(void) * (This is useful, if the cdrom on /dev/hdc must not * be accessed.) */ - snprintf(device, sizeof(device), "%s/%s", + ssnprintf(device, sizeof(device), "%s/%s", DEVLABELDIR, ptname); if(!get_label_uuid(device, &label, uuid)) { uuidcache_addentry(sstrdup(device), @@ -769,8 +769,6 @@ cu_mount_getoptionvalue(char *line, char *keyword) return r; } /* char *cu_mount_getoptionvalue(char *line, char *keyword) */ - - int cu_mount_type(const char *type) { @@ -782,5 +780,3 @@ cu_mount_type(const char *type) return CUMT_UNKNOWN; } /* int cu_mount_type(const char *type) */ - - diff --git a/src/utils_tail_match.c b/src/utils_tail_match.c index 34fe2dce..f518b1cd 100644 --- a/src/utils_tail_match.c +++ b/src/utils_tail_match.c @@ -85,10 +85,11 @@ static int simple_submit_match (cu_match_t *match, void *user_data) sstrncpy (vl.plugin, data->plugin, sizeof (vl.plugin)); sstrncpy (vl.plugin_instance, data->plugin_instance, sizeof (vl.plugin_instance)); + sstrncpy (vl.type, data->type, sizeof (vl.type)); sstrncpy (vl.type_instance, data->type_instance, sizeof (vl.type_instance)); - plugin_dispatch_values (data->type, &vl); + plugin_dispatch_values (&vl); if (match_value->ds_type & UTILS_MATCH_DS_TYPE_GAUGE) { diff --git a/src/utils_threshold.c b/src/utils_threshold.c index 6c131ba6..91959b9d 100644 --- a/src/utils_threshold.c +++ b/src/utils_threshold.c @@ -184,9 +184,8 @@ static int ut_config_type_instance (threshold_t *th, oconfig_item_t *ci) return (-1); } - strncpy (th->type_instance, ci->values[0].value.string, + sstrncpy (th->type_instance, ci->values[0].value.string, sizeof (th->type_instance)); - th->type_instance[sizeof (th->type_instance) - 1] = '\0'; return (0); } /* int ut_config_type_instance */ @@ -284,8 +283,7 @@ static int ut_config_type (const threshold_t *th_orig, oconfig_item_t *ci) } memcpy (&th, th_orig, sizeof (th)); - strncpy (th.type, ci->values[0].value.string, sizeof (th.type)); - th.type[sizeof (th.type) - 1] = '\0'; + sstrncpy (th.type, ci->values[0].value.string, sizeof (th.type)); th.warning_min = NAN; th.warning_max = NAN; @@ -340,9 +338,8 @@ static int ut_config_plugin_instance (threshold_t *th, oconfig_item_t *ci) return (-1); } - strncpy (th->plugin_instance, ci->values[0].value.string, + sstrncpy (th->plugin_instance, ci->values[0].value.string, sizeof (th->plugin_instance)); - th->plugin_instance[sizeof (th->plugin_instance) - 1] = '\0'; return (0); } /* int ut_config_plugin_instance */ @@ -369,8 +366,7 @@ static int ut_config_plugin (const threshold_t *th_orig, oconfig_item_t *ci) } memcpy (&th, th_orig, sizeof (th)); - strncpy (th.plugin, ci->values[0].value.string, sizeof (th.plugin)); - th.plugin[sizeof (th.plugin) - 1] = '\0'; + sstrncpy (th.plugin, ci->values[0].value.string, sizeof (th.plugin)); for (i = 0; i < ci->children_num; i++) { @@ -417,8 +413,7 @@ static int ut_config_host (const threshold_t *th_orig, oconfig_item_t *ci) } memcpy (&th, th_orig, sizeof (th)); - strncpy (th.host, ci->values[0].value.string, sizeof (th.host)); - th.host[sizeof (th.host) - 1] = '\0'; + sstrncpy (th.host, ci->values[0].value.string, sizeof (th.host)); for (i = 0; i < ci->children_num; i++) { @@ -501,46 +496,45 @@ int ut_config (const oconfig_item_t *ci) */ /* }}} */ -static threshold_t *threshold_search (const data_set_t *ds, - const value_list_t *vl) +static threshold_t *threshold_search (const value_list_t *vl) { threshold_t *th; if ((th = threshold_get (vl->host, vl->plugin, vl->plugin_instance, - ds->type, vl->type_instance)) != NULL) + vl->type, vl->type_instance)) != NULL) return (th); else if ((th = threshold_get (vl->host, vl->plugin, vl->plugin_instance, - ds->type, NULL)) != NULL) + vl->type, NULL)) != NULL) return (th); else if ((th = threshold_get (vl->host, vl->plugin, NULL, - ds->type, vl->type_instance)) != NULL) + vl->type, vl->type_instance)) != NULL) return (th); else if ((th = threshold_get (vl->host, vl->plugin, NULL, - ds->type, NULL)) != NULL) + vl->type, NULL)) != NULL) return (th); else if ((th = threshold_get (vl->host, "", NULL, - ds->type, vl->type_instance)) != NULL) + vl->type, vl->type_instance)) != NULL) return (th); else if ((th = threshold_get (vl->host, "", NULL, - ds->type, NULL)) != NULL) + vl->type, NULL)) != NULL) return (th); else if ((th = threshold_get ("", vl->plugin, vl->plugin_instance, - ds->type, vl->type_instance)) != NULL) + vl->type, vl->type_instance)) != NULL) return (th); else if ((th = threshold_get ("", vl->plugin, vl->plugin_instance, - ds->type, NULL)) != NULL) + vl->type, NULL)) != NULL) return (th); else if ((th = threshold_get ("", vl->plugin, NULL, - ds->type, vl->type_instance)) != NULL) + vl->type, vl->type_instance)) != NULL) return (th); else if ((th = threshold_get ("", vl->plugin, NULL, - ds->type, NULL)) != NULL) + vl->type, NULL)) != NULL) return (th); else if ((th = threshold_get ("", "", NULL, - ds->type, vl->type_instance)) != NULL) + vl->type, vl->type_instance)) != NULL) return (th); else if ((th = threshold_get ("", "", NULL, - ds->type, NULL)) != NULL) + vl->type, NULL)) != NULL) return (th); return (NULL); @@ -597,26 +591,26 @@ static int ut_report_state (const data_set_t *ds, n.time = vl->time; - status = snprintf (buf, bufsize, "Host %s, plugin %s", + status = ssnprintf (buf, bufsize, "Host %s, plugin %s", vl->host, vl->plugin); buf += status; bufsize -= status; if (vl->plugin_instance[0] != '\0') { - status = snprintf (buf, bufsize, " (instance %s)", + status = ssnprintf (buf, bufsize, " (instance %s)", vl->plugin_instance); buf += status; bufsize -= status; } - status = snprintf (buf, bufsize, " type %s", ds->type); + status = ssnprintf (buf, bufsize, " type %s", vl->type); buf += status; bufsize -= status; if (vl->type_instance[0] != '\0') { - status = snprintf (buf, bufsize, " (instance %s)", + status = ssnprintf (buf, bufsize, " (instance %s)", vl->type_instance); buf += status; bufsize -= status; @@ -625,7 +619,7 @@ static int ut_report_state (const data_set_t *ds, /* Send an okay notification */ if (state == STATE_OKAY) { - status = snprintf (buf, bufsize, ": All data sources are within range again."); + status = ssnprintf (buf, bufsize, ": All data sources are within range again."); buf += status; bufsize -= status; } @@ -641,7 +635,7 @@ static int ut_report_state (const data_set_t *ds, { if (!isnan (min) && !isnan (max)) { - status = snprintf (buf, bufsize, ": Data source \"%s\" is currently " + status = ssnprintf (buf, bufsize, ": Data source \"%s\" is currently " "%f. That is within the %s region of %f and %f.", ds->ds[ds_index].name, values[ds_index], (state == STATE_ERROR) ? "failure" : "warning", @@ -649,7 +643,7 @@ static int ut_report_state (const data_set_t *ds, } else { - status = snprintf (buf, bufsize, ": Data source \"%s\" is currently " + status = ssnprintf (buf, bufsize, ": Data source \"%s\" is currently " "%f. That is %s the %s threshold of %f.", ds->ds[ds_index].name, values[ds_index], isnan (min) ? "below" : "above", @@ -659,7 +653,7 @@ static int ut_report_state (const data_set_t *ds, } else /* is not inverted */ { - status = snprintf (buf, bufsize, ": Data source \"%s\" is currently " + status = ssnprintf (buf, bufsize, ": Data source \"%s\" is currently " "%f. That is %s the %s threshold of %f.", ds->ds[ds_index].name, values[ds_index], (values[ds_index] < min) ? "below" : "above", @@ -783,7 +777,7 @@ int ut_check_threshold (const data_set_t *ds, const value_list_t *vl) /* Is this lock really necessary? So far, thresholds are only inserted at * startup. -octo */ pthread_mutex_lock (&threshold_lock); - th = threshold_search (ds, vl); + th = threshold_search (vl); pthread_mutex_unlock (&threshold_lock); if (th == NULL) return (0); @@ -865,27 +859,19 @@ int ut_check_interesting (const char *name) memset (&ds, '\0', sizeof (ds)); memset (&vl, '\0', sizeof (vl)); - strncpy (vl.host, host, sizeof (vl.host)); - vl.host[sizeof (vl.host) - 1] = '\0'; - strncpy (vl.plugin, plugin, sizeof (vl.plugin)); - vl.plugin[sizeof (vl.plugin) - 1] = '\0'; + sstrncpy (vl.host, host, sizeof (vl.host)); + sstrncpy (vl.plugin, plugin, sizeof (vl.plugin)); if (plugin_instance != NULL) - { - strncpy (vl.plugin_instance, plugin_instance, sizeof (vl.plugin_instance)); - vl.plugin_instance[sizeof (vl.plugin_instance) - 1] = '\0'; - } - strncpy (ds.type, type, sizeof (ds.type)); - ds.type[sizeof (ds.type) - 1] = '\0'; + sstrncpy (vl.plugin_instance, plugin_instance, sizeof (vl.plugin_instance)); + sstrncpy (ds.type, type, sizeof (ds.type)); + sstrncpy (vl.type, type, sizeof (vl.type)); if (type_instance != NULL) - { - strncpy (vl.type_instance, type_instance, sizeof (vl.type_instance)); - vl.type_instance[sizeof (vl.type_instance) - 1] = '\0'; - } + sstrncpy (vl.type_instance, type_instance, sizeof (vl.type_instance)); sfree (name_copy); host = plugin = plugin_instance = type = type_instance = NULL; - th = threshold_search (&ds, &vl); + th = threshold_search (&vl); if (th == NULL) return (0); if ((th->flags & UT_FLAG_PERSIST) == 0) diff --git a/src/uuid.c b/src/uuid.c index d54301a2..e0de0d9b 100644 --- a/src/uuid.c +++ b/src/uuid.c @@ -257,8 +257,7 @@ uuid_init (void) char *uuid = uuid_get_local (); if (uuid) { - strncpy (hostname_g, uuid, DATA_MAX_NAME_LEN); - hostname_g[DATA_MAX_NAME_LEN-1] = '\0'; + sstrncpy (hostname_g, uuid, DATA_MAX_NAME_LEN); sfree (uuid); return 0; } diff --git a/src/vmem.c b/src/vmem.c index e0f76e76..1e826a16 100644 --- a/src/vmem.c +++ b/src/vmem.c @@ -50,10 +50,11 @@ static void submit (const char *plugin_instance, const char *type, strcpy (vl.plugin, "vmem"); if (plugin_instance != NULL) sstrncpy (vl.plugin_instance, plugin_instance, sizeof (vl.plugin_instance)); + sstrncpy (vl.type, type, sizeof (vl.type)); if (type_instance != NULL) sstrncpy (vl.type_instance, type_instance, sizeof (vl.type_instance)); - plugin_dispatch_values (type, &vl); + plugin_dispatch_values (&vl); } /* void vmem_submit */ static void submit_two (const char *plugin_instance, const char *type, diff --git a/src/vserver.c b/src/vserver.c index 7b83c617..4cc82516 100644 --- a/src/vserver.c +++ b/src/vserver.c @@ -59,10 +59,11 @@ static void traffic_submit (const char *plugin_instance, vl.time = time (NULL); strcpy (vl.host, hostname_g); strcpy (vl.plugin, "vserver"); - 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)); + strcpy (vl.type, "if_octets"); + 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, @@ -80,9 +81,10 @@ static void load_submit (const char *plugin_instance, vl.time = time (NULL); strcpy (vl.host, hostname_g); strcpy (vl.plugin, "vserver"); - strncpy (vl.plugin_instance, plugin_instance, sizeof (vl.plugin_instance)); + sstrncpy (vl.plugin_instance, plugin_instance, sizeof (vl.plugin_instance)); + strcpy (vl.type, "load"); - plugin_dispatch_values ("load", &vl); + plugin_dispatch_values (&vl); } static void submit_gauge (const char *plugin_instance, const char *type, @@ -99,10 +101,11 @@ static void submit_gauge (const char *plugin_instance, const char *type, vl.time = time (NULL); strcpy (vl.host, hostname_g); strcpy (vl.plugin, "vserver"); - 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) @@ -147,8 +150,9 @@ static int vserver_read (void) 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"))) @@ -194,8 +198,9 @@ static int vserver_read (void) } /* 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"))) @@ -246,8 +251,9 @@ static int vserver_read (void) } /* 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"))) diff --git a/src/wireless.c b/src/wireless.c index 285fb744..1282b48c 100644 --- a/src/wireless.c +++ b/src/wireless.c @@ -58,10 +58,11 @@ static void wireless_submit (const char *plugin_instance, const char *type, vl.time = time (NULL); strcpy (vl.host, hostname_g); strcpy (vl.plugin, "wireless"); - strncpy (vl.plugin_instance, plugin_instance, + sstrncpy (vl.plugin_instance, plugin_instance, sizeof (vl.plugin_instance)); + sstrncpy (vl.type, type, sizeof (vl.type)); - plugin_dispatch_values (type, &vl); + plugin_dispatch_values (&vl); } /* void wireless_submit */ #define POWER_MIN -90.0 diff --git a/src/xmms.c b/src/xmms.c index 1e646d21..01c7e0cf 100644 --- a/src/xmms.c +++ b/src/xmms.c @@ -39,8 +39,9 @@ static void cxmms_submit (const char *type, gauge_t value) vl.time = time (NULL); strcpy (vl.host, hostname_g); strcpy (vl.plugin, "xmms"); + sstrncpy (vl.type, type, sizeof (vl.type)); - plugin_dispatch_values (type, &vl); + plugin_dispatch_values (&vl); } /* void cxmms_submit */ int cxmms_read (void)