pkgsrc-WIP-changes archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

zabbix62-agent: make this build, and convert to sysctl() in net.c.



Module Name:	pkgsrc-wip
Committed By:	Havard Eidnes <he%NetBSD.org@localhost>
Pushed By:	he
Date:		Sun Mar 26 21:18:59 2023 +0200
Changeset:	c5fa5642c839a0bd4300f24cefc0d833f13158a2

Modified Files:
	zabbix62-agent/distinfo
	zabbix62-agent/patches/patch-configure
	zabbix62-agent/patches/patch-src_libs_zbxsysinfo_netbsd_net.c
Added Files:
	zabbix62-agent/patches/patch-src_libs_zbxsysinfo_simple_simple.c

Log Message:
zabbix62-agent: make this build, and convert to sysctl() in net.c.

src/libs/zbxsysinfo/simple/simple.c: with newer curl,
curl_easy_setopt() can be a macro, so ensure to enclose "complex"
arguments containing assignments in ().  Now builds OK with
curl 7.87.0.

Rework network interface statistics code for NetBSD from doing
kvm groveling to use the more modern sysctl() interface.
Partly adapted from sysutils/zabbix patch and sysutils/zabbix50-agent
patch, but with "static" added to a couple of local variables to avoid
repeated malloc()/free() for each call, and also avoid trying to
free() a NULL pointer.

To see a diff of this commit:
https://wip.pkgsrc.org/cgi-bin/gitweb.cgi?p=pkgsrc-wip.git;a=commitdiff;h=c5fa5642c839a0bd4300f24cefc0d833f13158a2

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

diffstat:
 zabbix62-agent/distinfo                            |   5 +-
 zabbix62-agent/patches/patch-configure             |  47 +++++-
 .../patches/patch-src_libs_zbxsysinfo_netbsd_net.c | 170 +++++++++++----------
 .../patch-src_libs_zbxsysinfo_simple_simple.c      |  38 +++++
 4 files changed, 179 insertions(+), 81 deletions(-)

diffs:
diff --git a/zabbix62-agent/distinfo b/zabbix62-agent/distinfo
index 76656dc1fb..ac959d7ab6 100644
--- a/zabbix62-agent/distinfo
+++ b/zabbix62-agent/distinfo
@@ -3,6 +3,7 @@ $NetBSD$
 BLAKE2s (zabbix-6.2.7.tar.gz) = d362ccc4195ce29476e498ac2a76ab4aca46dfe8618a798a5ede51a21b1e9c86
 SHA512 (zabbix-6.2.7.tar.gz) = 5cafae600d7a83729ac2d28c1cace2a6fb0ac1bdca06ac89e7fd272f1227d2d19e3aa3ccfaefb00229a61f55c608c4d97a5595724c600d8a46950a92c6e20fd0
 Size (zabbix-6.2.7.tar.gz) = 41462274 bytes
-SHA1 (patch-configure) = 661087a4a5342bbce494b5eac45c294f3412318e
-SHA1 (patch-src_libs_zbxsysinfo_netbsd_net.c) = 0371a5cafe00d01f293a847105f7c501f443616c
+SHA1 (patch-configure) = 269a0db811c184e687456db66aea6b34acecf441
+SHA1 (patch-src_libs_zbxsysinfo_netbsd_net.c) = 16409e7afbaf1b16af344ba2e2a47931ca50b471
+SHA1 (patch-src_libs_zbxsysinfo_simple_simple.c) = a9f20a4886612cba0bed125527c9ef6c56707cd0
 SHA1 (patch-src_zabbix__agent_Makefile.in) = efbd804ecee4b99db36db5f4fd61583b2ef96a86
diff --git a/zabbix62-agent/patches/patch-configure b/zabbix62-agent/patches/patch-configure
index 6cd67a7bef..f990b760b1 100644
--- a/zabbix62-agent/patches/patch-configure
+++ b/zabbix62-agent/patches/patch-configure
@@ -4,7 +4,7 @@ Fix bash-ism.
 
 --- configure.orig	2022-03-02 19:06:50.761881804 +0900
 +++ configure	2022-03-02 19:06:46.903210187 +0900
-@@ -8649,7 +8649,7 @@
+@@ -8802,7 +8802,7 @@ fi
  rm -f core conftest.err conftest.$ac_objext \
      conftest$ac_exeext conftest.$ac_ext
  
@@ -13,3 +13,48 @@ Fix bash-ism.
  
  	{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for TLS ciphersuites in MySQL library" >&5
  $as_echo_n "checking for TLS ciphersuites in MySQL library... " >&6; }
+@@ -15087,7 +15087,7 @@ $as_echo "$as_me: WARNING: proceeding wi
+ 		if test "x$enable_static" = "xyes"; then
+ 			LIBPCRE_LIBS=" $LIBPCRE_LIBS -lpthread"
+ 		elif test "x$enable_static_libs" = "xyes"; then
+-			if test "x$static_linking_support" == "xno"; then
++			if test "x$static_linking_support" = "xno"; then
+ 				{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: compiler has no direct suppor for static linkage" >&5
+ $as_echo "$as_me: WARNING: compiler has no direct suppor for static linkage" >&2;}
+ 
+@@ -15496,7 +15496,7 @@ $as_echo "$as_me: WARNING: proceeding wi
+ 		if test "x$enable_static" = "xyes"; then
+ 			LIBPCRE2_LIBS=" $LIBPCRE2_LIBS -lpthread"
+ 		elif test "x$enable_static_libs" = "xyes"; then
+-			if test "x$static_linking_support" == "xno"; then
++			if test "x$static_linking_support" = "xno"; then
+ 				{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: compiler has no direct suppor for static linkage" >&5
+ $as_echo "$as_me: WARNING: compiler has no direct suppor for static linkage" >&2;}
+ 
+@@ -15913,7 +15913,7 @@ $as_echo "$as_me: WARNING: proceeding wi
+ 		if test "x$enable_static" = "xyes"; then
+ 			LIBPCRE_LIBS=" $LIBPCRE_LIBS -lpthread"
+ 		elif test "x$enable_static_libs" = "xyes"; then
+-			if test "x$static_linking_support" == "xno"; then
++			if test "x$static_linking_support" = "xno"; then
+ 				{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: compiler has no direct suppor for static linkage" >&5
+ $as_echo "$as_me: WARNING: compiler has no direct suppor for static linkage" >&2;}
+ 
+@@ -16327,7 +16327,7 @@ $as_echo "$as_me: WARNING: proceeding wi
+ 		if test "x$enable_static" = "xyes"; then
+ 			LIBPCRE_LIBS=" $LIBPCRE_LIBS -lpthread"
+ 		elif test "x$enable_static_libs" = "xyes"; then
+-			if test "x$static_linking_support" == "xno"; then
++			if test "x$static_linking_support" = "xno"; then
+ 				{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: compiler has no direct suppor for static linkage" >&5
+ $as_echo "$as_me: WARNING: compiler has no direct suppor for static linkage" >&2;}
+ 
+@@ -16754,7 +16754,7 @@ $as_echo "$as_me: WARNING: proceeding wi
+ 		if test "x$enable_static" = "xyes"; then
+ 			LIBPCRE2_LIBS=" $LIBPCRE2_LIBS -lpthread"
+ 		elif test "x$enable_static_libs" = "xyes"; then
+-			if test "x$static_linking_support" == "xno"; then
++			if test "x$static_linking_support" = "xno"; then
+ 				{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: compiler has no direct suppor for static linkage" >&5
+ $as_echo "$as_me: WARNING: compiler has no direct suppor for static linkage" >&2;}
+ 
diff --git a/zabbix62-agent/patches/patch-src_libs_zbxsysinfo_netbsd_net.c b/zabbix62-agent/patches/patch-src_libs_zbxsysinfo_netbsd_net.c
index 3ac229d762..8326520cf5 100644
--- a/zabbix62-agent/patches/patch-src_libs_zbxsysinfo_netbsd_net.c
+++ b/zabbix62-agent/patches/patch-src_libs_zbxsysinfo_netbsd_net.c
@@ -4,25 +4,26 @@ Rework interface statistics code from using kvm to using sysctl interface.
 
 --- src/libs/zbxsysinfo/netbsd/net.c.orig	2021-10-25 09:49:27.000000000 +0000
 +++ src/libs/zbxsysinfo/netbsd/net.c
-@@ -22,6 +22,9 @@
+@@ -22,14 +22,25 @@
  #include "zbxjson.h"
  #include "log.h"
  
+-static struct nlist kernel_symbols[] =
 +#include <net/route.h>
 +#include <net/if_dl.h>
 +
- static struct nlist kernel_symbols[] =
- {
- 	{"_ifnet", N_UNDF, 0, 0, 0},
-@@ -31,42 +34,91 @@ static struct nlist kernel_symbols[] =
- 
- #define IFNET_ID 0
- 
++static void get_rtaddrs(int, struct sockaddr *, struct sockaddr **);
++
 +static void
 +get_rtaddrs(int addrs, struct sockaddr *sa, struct sockaddr **rti_info)
-+{
+ {
+-	{"_ifnet", N_UNDF, 0, 0, 0},
+-	{"_tcbtable", N_UNDF, 0, 0, 0},
+-	{NULL, 0, 0, 0, 0}
+-};
 +	int i;
-+
+ 
+-#define IFNET_ID 0
 +	for (i = 0; i < RTAX_MAX; i++) {
 +		if (addrs & (1 << i)) {
 +			rti_info[i] = sa;
@@ -32,46 +33,44 @@ Rework interface statistics code from using kvm to using sysctl interface.
 +			rti_info[i] = NULL;
 +	}
 +}
-+
+ 
  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,
+@@ -37,12 +48,19 @@ static int	get_ifdata(const char *if_nam
  		zbx_uint64_t *tbytes, zbx_uint64_t *tpackets, zbx_uint64_t *terrors,
  		zbx_uint64_t *icollisions, char **error)
  {
 -	struct ifnet_head	head;
 -	struct ifnet		*ifp;
 -	struct ifnet		v;
-+	struct	if_msghdr *ifm;
-+	int	mib[6] = { CTL_NET, AF_ROUTE, 0, 0, NET_RT_IFLIST, 0 };
-+	char	*buf = NULL;
-+	char	*lim, *next;
-+	struct	rt_msghdr *rtm;
-+	struct	if_data *ifd = NULL;
-+	struct	sockaddr *sa, *rti_info[RTAX_MAX];
-+	struct	sockaddr_dl *sdl;
-+
-+	size_t	len = 0;
-+	size_t	olen = 0;
-+	int		ret = SYSINFO_RET_FAIL;
++	struct  if_msghdr *ifm;
++	int     mib[6] = { CTL_NET, AF_ROUTE, 0, 0, NET_RT_IFLIST, 0 };
++	static char *buf;
++	char    *lim, *next;
++	struct  rt_msghdr *rtm;
++	struct  if_data *ifd = NULL;
++	struct  sockaddr *sa, *rti_info[RTAX_MAX];
++	struct  sockaddr_dl *sdl;
  
 -	kvm_t	*kp;
--	int	ret = SYSINFO_RET_FAIL;
++	size_t  len = 0;
++	static size_t olen;
+ 	int	ret = SYSINFO_RET_FAIL;
 +	static char name[IFNAMSIZ];
  
  	if (NULL == if_name || '\0' == *if_name)
  	{
- 		*error = zbx_strdup(NULL, "Network interface name cannot be empty.");
--		return FAIL;
-+		ret = FAIL;
-+		goto out;
+@@ -50,32 +68,60 @@ static int	get_ifdata(const char *if_nam
+ 		return FAIL;
  	}
  
 -	if (NULL == (kp = kvm_open(NULL, NULL, NULL, O_RDONLY, NULL))) /* requires root privileges */
 -	{
 -		*error = zbx_strdup(NULL, "Cannot obtain a descriptor to access kernel virtual memory.");
--		return FAIL;
--	}
++	if (sysctl(mib, 6, NULL, &len, NULL, 0) == -1) {
++		*error = zbx_strdup(NULL, "Failed to read network interfaces data");
+ 		return FAIL;
+ 	}
  
 -	if (N_UNDF == kernel_symbols[IFNET_ID].n_type)
 -		if (0 != kvm_nlist(kp, &kernel_symbols[0]))
@@ -80,41 +79,42 @@ Rework interface statistics code from using kvm to using sysctl interface.
 -	if (N_UNDF != kernel_symbols[IFNET_ID].n_type)
 -	{
 -		int	len = sizeof(struct ifnet_head);
-+	if (sysctl(mib, 6, NULL, &len, NULL, 0) == -1) {
-+		*error = zbx_strdup(NULL, "Failed to read network interfaces data");
-+		ret = FAIL;
-+		goto out;
-+	}
- 
--		if (kvm_read(kp, kernel_symbols[IFNET_ID].n_value, &head, len) >= len)
--		{
--			len = sizeof(struct ifnet);
 +	if (len > olen) {
-+		free(buf);
++		if (buf)
++			free(buf);
 +		if ((buf = zbx_malloc(NULL, len)) == NULL) {
 +			*error = zbx_strdup(NULL, "Failed to allocate buffer for network interfaces data");
-+			ret = FAIL;
-+			goto out;
++			return FAIL;
 +		}
 +		olen = len;
 +	}
 +	if (sysctl(mib, 6, buf, &len, NULL, 0) == -1) {
 +		*error = zbx_strdup(NULL, "Failed to allocate buffer for network interfaces data");
-+		ret = FAIL;
-+		goto out;
++		return FAIL;
 +	}
-+
+ 
+-		if (kvm_read(kp, kernel_symbols[IFNET_ID].n_value, &head, len) >= len)
 +	lim = buf + len;
 +	for (next = buf; next < lim; next += rtm->rtm_msglen) {
 +		rtm = (struct rt_msghdr *)next;
 +		if ((rtm->rtm_version == RTM_VERSION) &&
-+				(rtm->rtm_type == RTM_IFINFO)) {
++			(rtm->rtm_type == RTM_IFINFO))
+ 		{
+-			len = sizeof(struct ifnet);
 +			ifm = (struct if_msghdr *)next;
 +			ifd = &ifm->ifm_data;
 +
 +			sa = (struct sockaddr *)(ifm + 1);
 +			get_rtaddrs(ifm->ifm_addrs, sa, rti_info);
-+
+ 
+-			/* 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 */
 +			sdl = (struct sockaddr_dl *)rti_info[RTAX_IFP];
 +			if (sdl == NULL || sdl->sdl_family != AF_LINK) {
 +				continue;
@@ -124,10 +124,24 @@ Rework interface statistics code from using kvm to using sysctl interface.
 +				memcpy(name, sdl->sdl_data, IFNAMSIZ - 1);
 +			else if (sdl->sdl_nlen > 0)
 +				memcpy(name, sdl->sdl_data, sdl->sdl_nlen);
++			else
++				continue;
++
++			/* ibytes;		total number of octets received */
++			/* ipackets;		packets received on interface */
++			/* ierrors;		input errors on interface */
++			/* iqdrops;		dropped on input, this interface */
++			/* obytes;		total number of octets sent */
++			/* opackets;		packets sent on interface */
++			/* oerrors;		output errors on interface */
++			/* icollisions;		collisions on csma interfaces */
++			/* tbytes;              total (in+out) bytes */
++			/* tpackets;            total (in+out) packets */
++			/* terrors;             total (in+out) errors */
  
- 			/* if_ibytes;		total number of octets received */
- 			/* if_ipackets;		packets received on interface */
-@@ -100,42 +152,38 @@ static int	get_ifdata(const char *if_nam
+ 			if (ibytes)
+ 				*ibytes = 0;
+@@ -100,42 +146,39 @@ static int	get_ifdata(const char *if_nam
  			if (icollisions)
  				*icollisions = 0;
  
@@ -136,7 +150,32 @@ Rework interface statistics code from using kvm to using sysctl interface.
  			{
 -				if (kvm_read(kp, (u_long)ifp, &v, len) < len)
 -					break;
--
++				if (ibytes)
++					*ibytes += ifd->ifi_ibytes;
++				if (ipackets)
++					*ipackets += ifd->ifi_ipackets;
++				if (ierrors)
++					*ierrors += ifd->ifi_ierrors;
++				if (idropped)
++					*idropped += ifd->ifi_iqdrops;
++				if (obytes)
++					*obytes += ifd->ifi_obytes;
++				if (opackets)
++					*opackets += ifd->ifi_opackets;
++				if (oerrors)
++					*oerrors += ifd->ifi_oerrors;
++				if (tbytes)
++					*tbytes += ifd->ifi_ibytes +
++						ifd->ifi_obytes;
++				if (tpackets)
++					*tpackets += ifd->ifi_ipackets +
++						ifd->ifi_opackets;
++				if (terrors)
++					*terrors += ifd->ifi_ierrors +
++						ifd->ifi_oerrors;
++				if (icollisions)
++					*icollisions += ifd->ifi_collisions;
+ 
 -				if (0 == strcmp(if_name, v.if_xname))
 -				{
 -					if (ibytes)
@@ -163,37 +202,12 @@ Rework interface statistics code from using kvm to using sysctl interface.
 -						*icollisions += v.if_collisions;
 -					ret = SYSINFO_RET_OK;
 -				}
-+				if (ibytes)
-+					*ibytes += ifd->ifi_ibytes;
-+				if (ipackets)
-+					*ipackets += ifd->ifi_ipackets;
-+				if (ierrors)
-+					*ierrors += ifd->ifi_ierrors;
-+				if (idropped)
-+					*idropped += ifd->ifi_iqdrops;
-+				if (obytes)
-+					*obytes += ifd->ifi_obytes;
-+				if (opackets)
-+					*opackets += ifd->ifi_opackets;
-+				if (oerrors)
-+					*oerrors += ifd->ifi_oerrors;
-+				if (tbytes)
-+					*tbytes += ifd->ifi_ibytes + ifd->ifi_obytes;
-+				if (tpackets)
-+					*tpackets += ifd->ifi_ipackets + ifd->ifi_opackets;
-+				if (terrors)
-+					*terrors += ifd->ifi_ierrors + ifd->ifi_oerrors;
-+				if (icollisions)
-+					*icollisions += ifd->ifi_collisions;
-+				ret = SYSINFO_RET_OK;
-+				goto out;
++				return SYSINFO_RET_OK;
  			}
  		}
  	}
  
 -	kvm_close(kp);
-+out:
-+	free(buf);
  
  	if (SYSINFO_RET_FAIL == ret)
  	{
diff --git a/zabbix62-agent/patches/patch-src_libs_zbxsysinfo_simple_simple.c b/zabbix62-agent/patches/patch-src_libs_zbxsysinfo_simple_simple.c
new file mode 100644
index 0000000000..da57f12f73
--- /dev/null
+++ b/zabbix62-agent/patches/patch-src_libs_zbxsysinfo_simple_simple.c
@@ -0,0 +1,38 @@
+$NetBSD$
+
+Enclose macro argument in () to ensure proper handling.
+
+--- src/libs/zbxsysinfo/simple/simple.c.orig	2023-02-01 07:20:47.633230938 +0000
++++ src/libs/zbxsysinfo/simple/simple.c
+@@ -176,14 +176,14 @@ static int	check_https(const char *host,
+ 	else
+ 		zbx_snprintf(https_host, sizeof(https_host), "%s%s", (0 == strncmp(host, "https://";, 8) ? "" : "https://";), host);
+ 
+-	if (CURLE_OK != (err = curl_easy_setopt(easyhandle, opt = CURLOPT_USERAGENT, "Zabbix " ZABBIX_VERSION)) ||
+-		CURLE_OK != (err = curl_easy_setopt(easyhandle, opt = CURLOPT_URL, https_host)) ||
+-		CURLE_OK != (err = curl_easy_setopt(easyhandle, opt = CURLOPT_PORT, (long)port)) ||
+-		CURLE_OK != (err = curl_easy_setopt(easyhandle, opt = CURLOPT_NOBODY, 1L)) ||
+-		CURLE_OK != (err = curl_easy_setopt(easyhandle, opt = CURLOPT_SSL_VERIFYPEER, 0L)) ||
+-		CURLE_OK != (err = curl_easy_setopt(easyhandle, opt = CURLOPT_SSL_VERIFYHOST, 0L)) ||
+-		CURLE_OK != (err = curl_easy_setopt(easyhandle, opt = CURLOPT_TIMEOUT, (long)timeout)) ||
+-		CURLE_OK != (err = curl_easy_setopt(easyhandle, opt = ZBX_CURLOPT_ACCEPT_ENCODING, "")))
++	if (CURLE_OK != (err = curl_easy_setopt(easyhandle, (opt = CURLOPT_USERAGENT), "Zabbix " ZABBIX_VERSION)) ||
++		CURLE_OK != (err = curl_easy_setopt(easyhandle, (opt = CURLOPT_URL), https_host)) ||
++		CURLE_OK != (err = curl_easy_setopt(easyhandle, (opt = CURLOPT_PORT), (long)port)) ||
++		CURLE_OK != (err = curl_easy_setopt(easyhandle, (opt = CURLOPT_NOBODY), 1L)) ||
++		CURLE_OK != (err = curl_easy_setopt(easyhandle, (opt = CURLOPT_SSL_VERIFYPEER), 0L)) ||
++		CURLE_OK != (err = curl_easy_setopt(easyhandle, (opt = CURLOPT_SSL_VERIFYHOST), 0L)) ||
++		CURLE_OK != (err = curl_easy_setopt(easyhandle, (opt = CURLOPT_TIMEOUT), (long)timeout)) ||
++		CURLE_OK != (err = curl_easy_setopt(easyhandle, (opt = ZBX_CURLOPT_ACCEPT_ENCODING), "")))
+ 	{
+ 		zabbix_log(LOG_LEVEL_DEBUG, "%s: could not set cURL option [%d]: %s",
+ 				__func__, (int)opt, curl_easy_strerror(err));
+@@ -192,7 +192,7 @@ static int	check_https(const char *host,
+ 
+ 	if (NULL != CONFIG_SOURCE_IP)
+ 	{
+-		if (CURLE_OK != (err = curl_easy_setopt(easyhandle, opt = CURLOPT_INTERFACE, CONFIG_SOURCE_IP)))
++		if (CURLE_OK != (err = curl_easy_setopt(easyhandle, (opt = CURLOPT_INTERFACE), CONFIG_SOURCE_IP)))
+ 		{
+ 			zabbix_log(LOG_LEVEL_DEBUG, "%s: could not set source interface option [%d]: %s",
+ 					__func__, (int)opt, curl_easy_strerror(err));


Home | Main Index | Thread Index | Old Index