From 3f5c71ae57470595dfa18f0de54dd1e0022cf653 Mon Sep 17 00:00:00 2001 From: robert Date: Mon, 13 Dec 2010 10:40:52 +0000 Subject: [PATCH] Update tthis patch from the zabbix repo with a fixed socket leak --- net/zabbix/Makefile | 4 +- .../patch-src_libs_zbxsysinfo_openbsd_net_c | 466 ++++++++++++++++-- 2 files changed, 418 insertions(+), 52 deletions(-) diff --git a/net/zabbix/Makefile b/net/zabbix/Makefile index 0a60f4f115d..3d6d04ccafd 100644 --- a/net/zabbix/Makefile +++ b/net/zabbix/Makefile @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile,v 1.41 2010/12/11 12:57:37 ajacoutot Exp $ +# $OpenBSD: Makefile,v 1.42 2010/12/13 10:40:52 robert Exp $ COMMENT-main = network and application monitoring - agent COMMENT-server = network and application monitoring - server @@ -13,7 +13,7 @@ FULLPKGNAME-web = zabbix-web-${VERSION} FULLPKGPATH-web = net/zabbix,-web CATEGORIES = net -REVISION-main = 7 +REVISION-main = 8 REVISION-server = 7 REVISION-web = 2 diff --git a/net/zabbix/patches/patch-src_libs_zbxsysinfo_openbsd_net_c b/net/zabbix/patches/patch-src_libs_zbxsysinfo_openbsd_net_c index 0a791cf76dc..a70abbecbb0 100644 --- a/net/zabbix/patches/patch-src_libs_zbxsysinfo_openbsd_net_c +++ b/net/zabbix/patches/patch-src_libs_zbxsysinfo_openbsd_net_c @@ -1,36 +1,45 @@ -$OpenBSD: patch-src_libs_zbxsysinfo_openbsd_net_c,v 1.3 2010/09/27 08:10:32 robert Exp $ +$OpenBSD: patch-src_libs_zbxsysinfo_openbsd_net_c,v 1.4 2010/12/13 10:40:52 robert Exp $ --- src/libs/zbxsysinfo/openbsd/net.c.orig Mon Aug 16 10:19:32 2010 -+++ src/libs/zbxsysinfo/openbsd/net.c Sun Sep 26 16:28:44 2010 -@@ -21,6 +21,10 @@ ++++ src/libs/zbxsysinfo/openbsd/net.c Mon Dec 13 11:36:59 2010 +@@ -21,6 +21,8 @@ #include "sysinfo.h" +#include -+ -+#define N_UNDF 0x00 /* undefined */ + static struct nlist kernel_symbols[] = { {"_ifnet", N_UNDF, 0, 0, 0}, -@@ -37,15 +41,50 @@ static int get_ifdata(const char *if_name, zbx_uint64_ +@@ -32,69 +34,71 @@ static struct nlist kernel_symbols[] = + + static int get_ifdata(const char *if_name, zbx_uint64_t *ibytes, zbx_uint64_t *ipackets, zbx_uint64_t *ierrors, zbx_uint64_t *idropped, + zbx_uint64_t *obytes, zbx_uint64_t *opackets, zbx_uint64_t *oerrors, +- zbx_uint64_t *tbytes, zbx_uint64_t *tpackets, zbx_uint64_t *terrors, zbx_uint64_t *tdropped, ++ zbx_uint64_t *tbytes, zbx_uint64_t *tpackets, zbx_uint64_t *terrors, + zbx_uint64_t *icollisions) { struct ifnet_head head; - struct ifnet *ifp; +- struct ifnet *ifp; - struct ifnet v; ++ struct ifnet *ifp; - kvm_t *kp; +- kvm_t *kp; ++ kvm_t *kp; int len = 0; - int ret = SYSINFO_RET_FAIL; +- int ret = SYSINFO_RET_FAIL; ++ int ret = SYSINFO_RET_FAIL; -+ /* if_ibytes; total number of octets received */ -+ /* if_ipackets; packets received on interface */ -+ /* if_ierrors; input errors on interface */ -+ /* if_iqdrops; dropped on input, this interface */ -+ /* if_obytes; total number of octets sent */ -+ /* if_opackets; packets sent on interface */ -+ /* if_oerrors; output errors on interface */ -+ /* if_collisions; collisions on csma interfaces */ -+ +- kp = kvm_open(NULL, NULL, NULL, O_RDONLY, NULL); ++ /* if(i)_ibytes; total number of octets received */ ++ /* if(i)_ipackets; packets received on interface */ ++ /* if(i)_ierrors; input errors on interface */ ++ /* if(i)_iqdrops; dropped on input, this interface */ ++ /* if(i)_obytes; total number of octets sent */ ++ /* if(i)_opackets; packets sent on interface */ ++ /* if(i)_oerrors; output errors on interface */ ++ /* if(i)_collisions; collisions on csma interfaces */ + +- if (kp) { + if (ibytes) + *ibytes = 0; + if (ipackets) @@ -51,21 +60,25 @@ $OpenBSD: patch-src_libs_zbxsysinfo_openbsd_net_c,v 1.3 2010/09/27 08:10:32 robe + *tpackets = 0; + if (terrors) + *terrors = 0; -+ if (tdropped) -+ *tdropped = 0; + if (icollisions) + *icollisions = 0; + - kp = kvm_open(NULL, NULL, NULL, O_RDONLY, NULL); - - if (kp) { -+ struct ifnet v; ++ if (NULL != (kp = kvm_open(NULL, NULL, NULL, O_RDONLY, NULL))) /* requires root privileges */ ++ { ++ struct ifnet v; + if (N_UNDF == kernel_symbols[IFNET_ID].n_type) if (0 != kvm_nlist(kp, &kernel_symbols[0])) kernel_symbols[IFNET_ID].n_type = N_UNDF; -@@ -56,40 +95,6 @@ static int get_ifdata(const char *if_name, zbx_uint64_ - if (kvm_read(kp, kernel_symbols[IFNET_ID].n_value, &head, len) >= len) { + +- if (N_UNDF != kernel_symbols[IFNET_ID].n_type) { ++ if (N_UNDF != kernel_symbols[IFNET_ID].n_type) ++ { + len = sizeof(struct ifnet_head); + +- if (kvm_read(kp, kernel_symbols[IFNET_ID].n_value, &head, len) >= len) { ++ if (kvm_read(kp, kernel_symbols[IFNET_ID].n_value, &head, len) >= len) ++ { len = sizeof(struct ifnet); - /* if_ibytes; total number of octets received */ @@ -102,28 +115,60 @@ $OpenBSD: patch-src_libs_zbxsysinfo_openbsd_net_c,v 1.3 2010/09/27 08:10:32 robe - if (icollisions) - *icollisions = 0; - - for(ifp = head.tqh_first; ifp; ifp = v.if_list.tqe_next) { +- for(ifp = head.tqh_first; ifp; ifp = v.if_list.tqe_next) { ++ for (ifp = head.tqh_first; ifp; ifp = v.if_list.tqe_next) ++ { if (kvm_read(kp, (u_long)ifp, &v, len) < len) break; -@@ -125,8 +130,53 @@ static int get_ifdata(const char *if_name, zbx_uint64_ - } + +- if (*if_name == '\0' || 0 == strcmp(if_name, v.if_xname)) { ++ if ('\0' == *if_name || 0 == strcmp(if_name, v.if_xname)) ++ { + if (ibytes) + *ibytes += v.if_ibytes; + if (ipackets) +@@ -115,8 +119,6 @@ static int get_ifdata(const char *if_name, zbx_uint64_ + *tpackets += v.if_ipackets + v.if_opackets; + if (terrors) + *terrors += v.if_ierrors + v.if_oerrors; +- if (tdropped) +- *tdropped += v.if_iqdrops; + if (icollisions) + *icollisions += v.if_collisions; + ret = SYSINFO_RET_OK; +@@ -126,80 +128,63 @@ static int get_ifdata(const char *if_name, zbx_uint64_ } kvm_close(kp); -+ } else { /* Fallback to using SIOCGIFDATA */ -+ int if_s = -1; -+ struct ifreq ifr; -+ struct if_data v; -+ + } ++ else ++ { ++ /* Fallback to using SIOCGIFDATA */ + +- return ret; +-} ++ int if_s; ++ struct ifreq ifr; ++ struct if_data v; + +-static int NET_IF_IN_BYTES(const char *if_name, AGENT_RESULT *result) +-{ +- zbx_uint64_t value; + if ((if_s = socket(AF_INET, SOCK_DGRAM, 0)) < 0) -+ goto out; -+ ++ goto clean; + +- if (SYSINFO_RET_OK != get_ifdata(if_name, &value, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL)) +- return SYSINFO_RET_FAIL; + zbx_strlcpy(ifr.ifr_name, if_name, IFNAMSIZ - 1); + ifr.ifr_data = (caddr_t)&v; -+ -+ if (ioctl(if_s, SIOCGIFDATA, &ifr)) -+ goto out; -+ -+ if (*if_name == '\0' || 0 == strcmp(if_name, ifr.ifr_name)) { + +- SET_UI64_RESULT(result, value); ++ if (ioctl(if_s, SIOCGIFDATA, &ifr) < 0) ++ goto clean; + +- return SYSINFO_RET_OK; +-} ++ if ('\0' == *if_name || 0 == strcmp(if_name, ifr.ifr_name)) ++ { + if (ibytes) + *ibytes += v.ifi_ibytes; + if (ipackets) @@ -144,18 +189,339 @@ $OpenBSD: patch-src_libs_zbxsysinfo_openbsd_net_c,v 1.3 2010/09/27 08:10:32 robe + *tpackets += v.ifi_ipackets + v.ifi_opackets; + if (terrors) + *terrors += v.ifi_ierrors + v.ifi_oerrors; -+ if (tdropped) -+ *tdropped += v.ifi_iqdrops; + if (icollisions) + *icollisions += v.ifi_collisions; + } -+ -+ close(if_s); -+ -+ ret = SYSINFO_RET_OK; - } -+out: - return ret; +-static int NET_IF_IN_PACKETS(const char *if_name, AGENT_RESULT *result) +-{ +- zbx_uint64_t value; ++ ret = SYSINFO_RET_OK; ++clean: ++ if (if_s >= 0) ++ close(if_s); ++ } + +- if (SYSINFO_RET_OK != get_ifdata(if_name, NULL, &value, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL)) +- return SYSINFO_RET_FAIL; +- +- SET_UI64_RESULT(result, value); +- +- return SYSINFO_RET_OK; ++ return ret; } +-static int NET_IF_IN_ERRORS(const char *if_name, AGENT_RESULT *result) +-{ +- zbx_uint64_t value; +- +- if (SYSINFO_RET_OK != get_ifdata(if_name, NULL, NULL, &value, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL)) +- return SYSINFO_RET_FAIL; +- +- SET_UI64_RESULT(result, value); +- +- return SYSINFO_RET_OK; +-} +- +-static int NET_IF_IN_DROPPED(const char *if_name, AGENT_RESULT *result) +-{ +- zbx_uint64_t value; +- +- if (SYSINFO_RET_OK != get_ifdata(if_name, NULL, NULL, NULL, &value, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL)) +- return SYSINFO_RET_FAIL; +- +- SET_UI64_RESULT(result, value); +- +- return SYSINFO_RET_OK; +-} +- + int NET_IF_IN(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result) + { +-#define NET_FNCLIST struct net_fnclist_s +-NET_FNCLIST +-{ +- char *mode; +- int (*function)(); +-}; ++ char if_name[MAX_STRING_LEN], mode[16]; ++ zbx_uint64_t ibytes, ipackets, ierrors, idropped; + +- NET_FNCLIST fl[] = +- { +- {"bytes", NET_IF_IN_BYTES}, +- {"packets", NET_IF_IN_PACKETS}, +- {"errors", NET_IF_IN_ERRORS}, +- {"dropped", NET_IF_IN_DROPPED}, +- {0, 0} +- }; +- +- char if_name[MAX_STRING_LEN]; +- char mode[MAX_STRING_LEN]; +- int i; +- + assert(result); + + init_result(result); +@@ -213,75 +198,36 @@ NET_FNCLIST + if (0 != get_param(param, 2, mode, sizeof(mode))) + *mode = '\0'; + +- /* default parameter */ +- if (*mode == '\0') +- zbx_snprintf(mode, sizeof(mode), "bytes"); +- +- for (i = 0; fl[i].mode != 0; i++) +- if (0 == strncmp(mode, fl[i].mode, MAX_STRING_LEN)) +- return (fl[i].function)(if_name, result); +- +- return SYSINFO_RET_FAIL; +-} +- +-static int NET_IF_OUT_BYTES(const char *if_name, AGENT_RESULT *result) +-{ +- zbx_uint64_t value; +- +- if (SYSINFO_RET_OK != get_ifdata(if_name, NULL, NULL, NULL, NULL, &value, NULL, NULL, NULL, NULL, NULL, NULL, NULL)) ++ if (SYSINFO_RET_OK != get_ifdata(if_name, &ibytes, &ipackets, &ierrors, &idropped, NULL, NULL, NULL, NULL, NULL, NULL, NULL)) + return SYSINFO_RET_FAIL; + +- SET_UI64_RESULT(result, value); +- +- return SYSINFO_RET_OK; +-} +- +-static int NET_IF_OUT_PACKETS(const char *if_name, AGENT_RESULT *result) +-{ +- zbx_uint64_t value; +- +- if (SYSINFO_RET_OK != get_ifdata(if_name, NULL, NULL, NULL, NULL, NULL, &value, NULL, NULL, NULL, NULL, NULL, NULL)) ++ if ('\0' == *mode || 0 == strcmp(mode, "bytes")) /* default parameter */ ++ { ++ SET_UI64_RESULT(result, ibytes); ++ } ++ else if (0 == strcmp(mode, "packets")) ++ { ++ SET_UI64_RESULT(result, ipackets); ++ } ++ else if (0 == strcmp(mode, "errors")) ++ { ++ SET_UI64_RESULT(result, ierrors); ++ } ++ else if (0 == strcmp(mode, "dropped")) ++ { ++ SET_UI64_RESULT(result, idropped); ++ } ++ else + return SYSINFO_RET_FAIL; + +- SET_UI64_RESULT(result, value); +- + return SYSINFO_RET_OK; + } + +-static int NET_IF_OUT_ERRORS(const char *if_name, AGENT_RESULT *result) +-{ +- zbx_uint64_t value; +- +- if (SYSINFO_RET_OK != get_ifdata(if_name, NULL, NULL, NULL, NULL, NULL, NULL, &value, NULL, NULL, NULL, NULL, NULL)) +- return SYSINFO_RET_FAIL; +- +- SET_UI64_RESULT(result, value); +- +- return SYSINFO_RET_OK; +-} +- + int NET_IF_OUT(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result) + { +-#define NET_FNCLIST struct net_fnclist_s +-NET_FNCLIST +-{ +- char *mode; +- int (*function)(); +-}; ++ char if_name[MAX_STRING_LEN], mode[16]; ++ zbx_uint64_t obytes, opackets, oerrors; + +- NET_FNCLIST fl[] = +- { +- {"bytes", NET_IF_OUT_BYTES}, +- {"packets", NET_IF_OUT_PACKETS}, +- {"errors", NET_IF_OUT_ERRORS}, +-/* {"dropped", NET_IF_OUT_DROPPED},*/ +- {0, 0} +- }; +- +- char if_name[MAX_STRING_LEN]; +- char mode[MAX_STRING_LEN]; +- int i; +- + assert(result); + + init_result(result); +@@ -295,87 +241,32 @@ NET_FNCLIST + if (0 != get_param(param, 2, mode, sizeof(mode))) + *mode = '\0'; + +- /* default parameter */ +- if (*mode == '\0') +- zbx_snprintf(mode, sizeof(mode), "bytes"); +- +- for (i = 0; fl[i].mode != 0; i++) +- if (0 == strncmp(mode, fl[i].mode, MAX_STRING_LEN)) +- return (fl[i].function)(if_name, result); +- +- return SYSINFO_RET_FAIL; +-} +- +-static int NET_IF_TOTAL_BYTES(const char *if_name, AGENT_RESULT *result) +-{ +- zbx_uint64_t value; +- +- if (SYSINFO_RET_OK != get_ifdata(if_name, NULL, NULL, NULL, NULL, NULL, NULL, NULL, &value, NULL, NULL, NULL, NULL)) ++ if (SYSINFO_RET_OK != get_ifdata(if_name, NULL, NULL, NULL, NULL, &obytes, &opackets, &oerrors, NULL, NULL, NULL, NULL)) + return SYSINFO_RET_FAIL; + +- SET_UI64_RESULT(result, value); +- +- return SYSINFO_RET_OK; +-} +- +-static int NET_IF_TOTAL_PACKETS(const char *if_name, AGENT_RESULT *result) +-{ +- zbx_uint64_t value; +- +- if (SYSINFO_RET_OK != get_ifdata(if_name, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, &value, NULL, NULL, NULL)) ++ if ('\0' == *mode || 0 == strcmp(mode, "bytes")) /* default parameter */ ++ { ++ SET_UI64_RESULT(result, obytes); ++ } ++ else if (0 == strcmp(mode, "packets")) ++ { ++ SET_UI64_RESULT(result, opackets); ++ } ++ else if (0 == strcmp(mode, "errors")) ++ { ++ SET_UI64_RESULT(result, oerrors); ++ } ++ else + return SYSINFO_RET_FAIL; + +- SET_UI64_RESULT(result, value); +- + return SYSINFO_RET_OK; + } + +-static int NET_IF_TOTAL_ERRORS(const char *if_name, AGENT_RESULT *result) +-{ +- zbx_uint64_t value; +- +- if (SYSINFO_RET_OK != get_ifdata(if_name, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, &value, NULL, NULL)) +- return SYSINFO_RET_FAIL; +- +- SET_UI64_RESULT(result, value); +- +- return SYSINFO_RET_OK; +-} +- +-static int NET_IF_TOTAL_DROPPED(const char *if_name, AGENT_RESULT *result) +-{ +- zbx_uint64_t value; +- +- if (SYSINFO_RET_OK != get_ifdata(if_name, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, &value, NULL)) +- return SYSINFO_RET_FAIL; +- +- SET_UI64_RESULT(result, value); +- +- return SYSINFO_RET_OK; +-} +- + int NET_IF_TOTAL(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result) + { +-#define NET_FNCLIST struct net_fnclist_s +-NET_FNCLIST +-{ +- char *mode; +- int (*function)(); +-}; ++ char if_name[MAX_STRING_LEN], mode[16]; ++ zbx_uint64_t tbytes, tpackets, terrors; + +- NET_FNCLIST fl[] = +- { +- {"bytes", NET_IF_TOTAL_BYTES}, +- {"packets", NET_IF_TOTAL_PACKETS}, +- {"errors", NET_IF_TOTAL_ERRORS}, +-/* {"dropped", NET_IF_TOTAL_DROPPED},*/ /* disabled because net.if.out does not support dropped packets */ +- {0, 0} +- }; +- +- char if_name[MAX_STRING_LEN]; +- char mode[MAX_STRING_LEN]; +- int i; +- + assert(result); + + init_result(result); +@@ -389,18 +280,28 @@ NET_FNCLIST + if (0 != get_param(param, 2, mode, sizeof(mode))) + *mode = '\0'; + +- /* default parameter */ +- if (*mode == '\0') +- zbx_snprintf(mode, sizeof(mode), "bytes"); ++ if (SYSINFO_RET_OK != get_ifdata(if_name, NULL, NULL, NULL, NULL, NULL, NULL, NULL, &tbytes, &tpackets, &terrors, NULL)) ++ return SYSINFO_RET_FAIL; + +- for (i = 0; fl[i].mode != 0; i++) +- if (0 == strncmp(mode, fl[i].mode, MAX_STRING_LEN)) +- return (fl[i].function)(if_name, result); ++ if ('\0' == *mode || 0 == strcmp(mode, "bytes")) /* default parameter */ ++ { ++ SET_UI64_RESULT(result, tbytes); ++ } ++ else if (0 == strcmp(mode, "packets")) ++ { ++ SET_UI64_RESULT(result, tpackets); ++ } ++ else if (0 == strcmp(mode, "errors")) ++ { ++ SET_UI64_RESULT(result, terrors); ++ } ++ else ++ return SYSINFO_RET_FAIL; + +- return SYSINFO_RET_FAIL; ++ return SYSINFO_RET_OK; + } + +-int NET_TCP_LISTEN(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result) ++int NET_TCP_LISTEN(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result) + { + assert(result); + +@@ -409,10 +310,10 @@ int NET_TCP_LISTEN(const char *cmd, const char *pa + return SYSINFO_RET_FAIL; + } + +-int NET_IF_COLLISIONS(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result) ++int NET_IF_COLLISIONS(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result) + { +- zbx_uint64_t value; + char if_name[MAX_STRING_LEN]; ++ zbx_uint64_t icollisions; + + assert(result); + +@@ -424,10 +325,10 @@ int NET_IF_COLLISIONS(const char *cmd, const char + if (0 != get_param(param, 1, if_name, sizeof(if_name))) + *if_name = '\0'; + +- if (SYSINFO_RET_OK != get_ifdata(if_name, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, &value)) ++ if (SYSINFO_RET_OK != get_ifdata(if_name, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, &icollisions)) + return SYSINFO_RET_FAIL; + +- SET_UI64_RESULT(result, value); ++ SET_UI64_RESULT(result, icollisions); + + return SYSINFO_RET_OK; + }