X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fopenvpn.c;h=8bbb82b20ddb28afac7f432f9f13bdd1642325c9;hb=13c83b972a8ade7dff6f8f2d00832d446ef6f502;hp=0fd940584e1dac434bcf6ca4ea3db4d05b18a995;hpb=5c78be034ebf8edbf2ae98e9163a38b2d61fbb68;p=collectd.git diff --git a/src/openvpn.c b/src/openvpn.c index 0fd94058..8bbb82b2 100644 --- a/src/openvpn.c +++ b/src/openvpn.c @@ -26,6 +26,7 @@ **/ #include "collectd.h" + #include "common.h" #include "plugin.h" @@ -95,7 +96,8 @@ static int openvpn_strsplit (char *string, char **fields, size_t size) } /* int openvpn_strsplit */ /* dispatches number of users */ -static void numusers_submit (char *pinst, char *tinst, gauge_t value) +static void numusers_submit (const char *pinst, const char *tinst, + gauge_t value) { value_t values[1]; value_list_t vl = VALUE_LIST_INIT; @@ -115,8 +117,10 @@ static void numusers_submit (char *pinst, char *tinst, gauge_t value) plugin_dispatch_values (&vl); } /* void numusers_submit */ -/* dispatches stats about traffic (TCP or UDP) generated by the tunnel per single endpoint */ -static void iostats_submit (char *pinst, char *tinst, derive_t rx, derive_t tx) +/* dispatches stats about traffic (TCP or UDP) generated by the tunnel + * per single endpoint */ +static void iostats_submit (const char *pinst, const char *tinst, + derive_t rx, derive_t tx) { value_t values[2]; value_list_t vl = VALUE_LIST_INIT; @@ -145,7 +149,7 @@ static void iostats_submit (char *pinst, char *tinst, derive_t rx, derive_t tx) } /* void traffic_submit */ /* dispatches stats about data compression shown when in single mode */ -static void compression_submit (char *pinst, char *tinst, +static void compression_submit (const char *pinst, const char *tinst, derive_t uncompressed, derive_t compressed) { value_t values[2]; @@ -168,7 +172,7 @@ static void compression_submit (char *pinst, char *tinst, plugin_dispatch_values (&vl); } /* void compression_submit */ -static int single_read (char *name, FILE *fh) +static int single_read (const char *name, FILE *fh) { char buffer[1024]; char *fields[4]; @@ -189,8 +193,6 @@ static int single_read (char *name, FILE *fh) post_compress = 0; pre_decompress = 0; post_decompress = 0; - overhead_rx = 0; - overhead_tx = 0; while (fgets (buffer, sizeof (buffer), fh) != NULL) { @@ -263,7 +265,7 @@ static int single_read (char *name, FILE *fh) } /* int single_read */ /* for reading status version 1 */ -static int multi1_read (char *name, FILE *fh) +static int multi1_read (const char *name, FILE *fh) { char buffer[1024]; char *fields[10]; @@ -326,7 +328,7 @@ static int multi1_read (char *name, FILE *fh) } /* int multi1_read */ /* for reading status version 2 */ -static int multi2_read (char *name, FILE *fh) +static int multi2_read (const char *name, FILE *fh) { char buffer[1024]; char *fields[10]; @@ -388,7 +390,7 @@ static int multi2_read (char *name, FILE *fh) } /* int multi2_read */ /* for reading status version 3 */ -static int multi3_read (char *name, FILE *fh) +static int multi3_read (const char *name, FILE *fh) { char buffer[1024]; char *fields[15]; @@ -453,7 +455,7 @@ static int multi3_read (char *name, FILE *fh) } /* int multi3_read */ /* for reading status version 4 */ -static int multi4_read (char *name, FILE *fh) +static int multi4_read (const char *name, FILE *fh) { char buffer[1024]; char *fields[11]; @@ -520,13 +522,15 @@ static int multi4_read (char *name, FILE *fh) static int openvpn_read (void) { FILE *fh; - int i, vpn_read, read; + int i, read; - vpn_read = read = 0; + read = 0; /* call the right read function for every status entry in the list */ for (i = 0; i < vpn_num; i++) { + int vpn_read = 0; + fh = fopen (vpn_list[i]->file, "r"); if (fh == NULL) { @@ -696,22 +700,32 @@ static int openvpn_config (const char *key, const char *value) } /* create a new vpn element since file, version and name are ok */ - temp = (vpn_status_t *) malloc (sizeof (vpn_status_t)); + temp = malloc (sizeof (*temp)); + if (temp == NULL) + { + char errbuf[1024]; + ERROR ("openvpn plugin: malloc failed: %s", + sstrerror (errno, errbuf, sizeof (errbuf))); + sfree (status_file); + return (1); + } temp->file = status_file; temp->version = status_version; temp->name = status_name; - vpn_list = (vpn_status_t **) realloc (vpn_list, (vpn_num + 1) * sizeof (vpn_status_t *)); - if (vpn_list == NULL) + vpn_status_t **tmp_list = realloc (vpn_list, (vpn_num + 1) * sizeof (*vpn_list)); + if (tmp_list == NULL) { char errbuf[1024]; - ERROR ("openvpn plugin: malloc failed: %s", + ERROR ("openvpn plugin: realloc failed: %s", sstrerror (errno, errbuf, sizeof (errbuf))); + sfree (vpn_list); sfree (temp->file); sfree (temp); return (1); } + vpn_list = tmp_list; vpn_list[vpn_num] = temp; vpn_num++;