[collectd] [PATCH] ipvs plugin: Get IP_VS_SO_GET_INFO in ip_vs_get_services().
Sebastian Harl
sh at tokkee.org
Fri Oct 12 14:31:29 CEST 2007
IP_VS_SO_GET_INFO also provides the number of services which might change after
initializing the plugin. Also, the globale variable ipvs_info could be removed
as ip_vs_get_services() is the only function using these information.
Signed-off-by: Sebastian Harl <sh at tokkee.org>
---
This is a replacement for "ipvs plugin: Get IP_VS_SO_GET_INFO in cipvs_read()
instead of cipvs_init()".
---
src/ipvs.c | 23 +++++++++++------------
1 files changed, 11 insertions(+), 12 deletions(-)
diff --git a/src/ipvs.c b/src/ipvs.c
index c670b09..f9acab5 100644
--- a/src/ipvs.c
+++ b/src/ipvs.c
@@ -61,8 +61,6 @@
static int sockfd = -1;
static void *ipvs_func = NULL;
-static struct ip_vs_getinfo ipvs_info;
-
/*
* libipvs API
@@ -99,9 +97,20 @@ static const char *ipvs_strerror (int err)
static struct ip_vs_get_services *ipvs_get_services (void)
{
+ struct ip_vs_getinfo ipvs_info;
struct ip_vs_get_services *ret;
+
socklen_t len;
+ len = sizeof (ipvs_info);
+
+ if (0 != getsockopt (sockfd, IPPROTO_IP, IP_VS_SO_GET_INFO,
+ (void *)&ipvs_info, &len)) {
+ log_err ("ip_vs_get_services: getsockopt() failed: %s",
+ ipvs_strerror (errno));
+ return NULL;
+ }
+
len = sizeof (*ret) +
sizeof (struct ip_vs_service_entry) * ipvs_info.num_services;
@@ -162,20 +171,10 @@ static struct ip_vs_get_dests *ipvs_get_dests (struct ip_vs_service_entry *se)
static int cipvs_init (void)
{
- socklen_t len;
-
- len = sizeof (ipvs_info);
-
if (-1 == (sockfd = socket (AF_INET, SOCK_RAW, IPPROTO_RAW))) {
log_err ("cipvs_init: socket() failed: %s", ipvs_strerror (errno));
return -1;
}
-
- if (0 != getsockopt (sockfd, IPPROTO_IP, IP_VS_SO_GET_INFO,
- (void *)&ipvs_info, &len)) {
- log_err ("cipvs_init: getsockopt() failed: %s", ipvs_strerror (errno));
- return -1;
- }
return 0;
} /* cipvs_init */
--
1.5.3.4.206.g58ba4
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : http://mailman.verplant.org/pipermail/collectd/attachments/20071012/f7ea0dd2/attachment.pgp
More information about the collectd
mailing list