X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fipvs.c;h=fa894897bae658b532e9af4f692d3bd802e6f4b6;hb=4ecefb9fb8183eadee48538553615c0425e51f69;hp=cec309274d03b0ef291123add1036daa41a96c07;hpb=83149d73b8a3bd4889517a2e4d0adca0a52e7a06;p=collectd.git diff --git a/src/ipvs.c b/src/ipvs.c index cec30927..fa894897 100644 --- a/src/ipvs.c +++ b/src/ipvs.c @@ -45,7 +45,9 @@ #endif /* HAVE_NETINET_IN_H */ /* this can probably only be found in the kernel sources */ -#if HAVE_NET_IP_VS_H +#if HAVE_LINUX_IP_VS_H +# include +#elif HAVE_NET_IP_VS_H # include #elif HAVE_IP_VS_H # include @@ -191,7 +193,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 +217,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)) { @@ -225,49 +227,47 @@ static int get_ti (struct ip_vs_dest_entry *de, char *ti, size_t size) return 0; } /* get_ti */ -static void cipvs_submit_connections (char *pi, char *ti, counter_t value) +static void cipvs_submit_connections (char *pi, char *ti, derive_t value) { value_t values[1]; value_list_t vl = VALUE_LIST_INIT; - values[0].counter = value; + values[0].derive = value; vl.values = values; vl.values_len = 1; - vl.time = time (NULL); - vl.interval = interval_g; + sstrncpy (vl.host, hostname_g, sizeof (vl.host)); + sstrncpy (vl.plugin, "ipvs", sizeof (vl.plugin)); + sstrncpy (vl.plugin_instance, pi, sizeof (vl.plugin_instance)); + sstrncpy (vl.type, "connections", sizeof (vl.type)); + sstrncpy (vl.type_instance, (NULL != ti) ? ti : "total", + sizeof (vl.type_instance)); - strcpy (vl.host, hostname_g); - strcpy (vl.plugin, "ipvs"); - strcpy (vl.plugin_instance, pi); - strcpy (vl.type_instance, (NULL != ti) ? ti : "total"); - - plugin_dispatch_values ("connections", &vl); + plugin_dispatch_values (&vl); return; } /* cipvs_submit_connections */ static void cipvs_submit_if (char *pi, char *t, char *ti, - counter_t rx, counter_t tx) + derive_t rx, derive_t tx) { value_t values[2]; value_list_t vl = VALUE_LIST_INIT; - values[0].counter = rx; - values[1].counter = tx; + values[0].derive = rx; + values[1].derive = tx; vl.values = values; vl.values_len = 2; - vl.time = time (NULL); - vl.interval = interval_g; - - strcpy (vl.host, hostname_g); - strcpy (vl.plugin, "ipvs"); - strcpy (vl.plugin_instance, pi); - strcpy (vl.type_instance, (NULL != ti) ? ti : "total"); + sstrncpy (vl.host, hostname_g, sizeof (vl.host)); + sstrncpy (vl.plugin, "ipvs", sizeof (vl.plugin)); + 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 */ @@ -276,7 +276,7 @@ static void cipvs_submit_dest (char *pi, struct ip_vs_dest_entry *de) { char ti[DATA_MAX_NAME_LEN]; - if (0 != get_ti (de, ti, DATA_MAX_NAME_LEN)) + if (0 != get_ti (de, ti, sizeof (ti))) return; cipvs_submit_connections (pi, ti, stats.conns); @@ -294,7 +294,7 @@ static void cipvs_submit_service (struct ip_vs_service_entry *se) int i = 0; - if (0 != get_pi (se, pi, DATA_MAX_NAME_LEN)) + if (0 != get_pi (se, pi, sizeof (pi))) return; cipvs_submit_connections (pi, NULL, stats.conns); @@ -330,7 +330,7 @@ static int cipvs_shutdown (void) { if (sockfd >= 0) close (sockfd); - sockfs = -1; + sockfd = -1; return 0; } /* cipvs_shutdown */