#define log_err(...) ERROR ("ipvs: " __VA_ARGS__)
#define log_info(...) INFO ("ipvs: " __VA_ARGS__)
-
/*
* private variables
*/
-
-static int sockfd = -1;
-
+static int sockfd = -1;
/*
* libipvs API
*/
-
static struct ip_vs_get_services *ipvs_get_services (void)
{
struct ip_vs_getinfo ipvs_info;
return ret;
} /* ip_vs_get_dests */
-
/*
* collectd plugin API and helper functions
*/
-
static int cipvs_init (void)
{
struct ip_vs_getinfo ipvs_info;
log_err ("cipvs_init: getsockopt() failed: %s",
sstrerror (errno, errbuf, sizeof (errbuf)));
close (sockfd);
+ sockfd = -1;
return -1;
}
log_err ("cipvs_init: IPVS version too old (%d.%d.%d < %d.%d.%d)",
NVERSION (ipvs_info.version), 1, 1, 4);
close (sockfd);
+ sockfd = -1;
return -1;
}
else {
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_instance, (NULL != ti) ? ti : "total", sizeof (vl.type_instance));
plugin_dispatch_values ("connections", &vl);
return;
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_instance, (NULL != ti) ? ti : "total", sizeof (vl.type_instance));
plugin_dispatch_values (t, &vl);
return;
static int cipvs_read (void)
{
struct ip_vs_get_services *services = NULL;
-
int i = 0;
+ if (sockfd < 0)
+ return (-1);
+
if (NULL == (services = ipvs_get_services ()))
return -1;
static int cipvs_shutdown (void)
{
- close (sockfd);
+ if (sockfd >= 0)
+ close (sockfd);
+ sockfd = -1;
+
return 0;
} /* cipvs_shutdown */
} /* module_register */
/* vim: set sw=4 ts=4 tw=78 noexpandtab : */
-