summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: da3b65f)
raw | patch | inline | side by side (parent: da3b65f)
author | Florian Forster <octo@collectd.org> | |
Sun, 11 Mar 2012 14:53:39 +0000 (15:53 +0100) | ||
committer | Florian Forster <octo@collectd.org> | |
Sun, 11 Mar 2012 14:53:39 +0000 (15:53 +0100) |
And remove uses of strcpy(3).
src/ethstat.c | patch | blob | history | |
src/ethstat.h | patch | blob | history |
diff --git a/src/ethstat.c b/src/ethstat.c
index d3343746a13f0aaefded13c801e55af1636e894c..8bc47ad4a071d3cfafa7eba77014352d7fa71807 100644 (file)
--- a/src/ethstat.c
+++ b/src/ethstat.c
static int ethstat_config (const char *key, const char *value)
{
- if (strcasecmp (key, "Iface") == 0) {
- ifacelist[ifacenumber] = malloc(strlen(value) + 1);
- strcpy(ifacelist[ifacenumber++], value);
- INFO("ethstat: Registred iface %s", value);
+ if (strcasecmp ("Iface", key) == 0)
+ {
+ char **tmp;
+
+ tmp = realloc (ifacelist,
+ sizeof (*ifacelist) * (ifacenumber + 1));
+ if (tmp == NULL)
+ return (-1);
+ ifacelist = tmp;
+
+ ifacelist[ifacenumber] = strdup (value);
+ if (ifacelist[ifacenumber] == NULL)
+ {
+ ERROR ("ethstat plugin: strdup() failed.");
+ return (-1);
+ }
+
+ ifacenumber++;
+ INFO("ethstat plugin: Registred interface %s", value);
}
return (0);
}
-
static void ethstat_submit_value (char *devname, char *counter, unsigned long long value)
{
value_t values[1];
free(strings);
free(stats);
-
return 0;
}
-
static int ethstat_read(void)
{
struct ifreq ifr;
for (i = 0 ; i < ifacenumber ; i++) {
DEBUG("ethstat - Processing : %s\n", ifacelist[i]);
memset(&ifr, 0, sizeof(ifr));
- strcpy(ifr.ifr_name, ifacelist[i]);
+ sstrncpy(ifr.ifr_name, ifacelist[i], sizeof (ifr.ifr_name));
getstats(ifacelist[i], &ifr);
}
return 0;
void module_register (void)
{
- ifacelist = malloc(sizeof(char*));
plugin_register_config ("ethstat", ethstat_config,
config_keys, config_keys_num);
plugin_register_read ("ethstat", ethstat_read);
diff --git a/src/ethstat.h b/src/ethstat.h
index d544db51182fbde08b1278e8ac6f47c4ecbcee63..531e2be0e2aa84c0484f71e1a5adcf30c971a5cb 100644 (file)
--- a/src/ethstat.h
+++ b/src/ethstat.h
};
static int config_keys_num = STATIC_ARRAY_SIZE (config_keys);
-static char **ifacelist;
+static char **ifacelist = NULL;
static int ifacenumber = 0;
struct ethtool_drvinfo {
__u32 cmd;