pkgsrc-Changes-HG archive

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

[pkgsrc/trunk]: pkgsrc/sysutils/libgtop Fix libgtop for NetBSD by adapting Fr...



details:   https://anonhg.NetBSD.org/pkgsrc/rev/8fdc15e5dfee
branches:  trunk
changeset: 308650:8fdc15e5dfee
user:      youri <youri%pkgsrc.org@localhost>
date:      Mon May 28 15:16:39 2018 +0000

description:
Fix libgtop for NetBSD by adapting FreeBSD's netload backend.

diffstat:

 sysutils/libgtop/distinfo                            |    4 +-
 sysutils/libgtop/patches/patch-ca                    |   26 -
 sysutils/libgtop/patches/patch-sysdeps_bsd_netload.c |  381 +++++++++++++++++++
 3 files changed, 383 insertions(+), 28 deletions(-)

diffs (truncated from 440 to 300 lines):

diff -r 386cbcd3b4aa -r 8fdc15e5dfee sysutils/libgtop/distinfo
--- a/sysutils/libgtop/distinfo Mon May 28 14:16:15 2018 +0000
+++ b/sysutils/libgtop/distinfo Mon May 28 15:16:39 2018 +0000
@@ -1,4 +1,4 @@
-$NetBSD: distinfo,v 1.33 2017/06/23 16:42:05 kamil Exp $
+$NetBSD: distinfo,v 1.34 2018/05/28 15:16:39 youri Exp $
 
 SHA1 (libgtop-2.28.4.tar.bz2) = b6f002cc80a61dc0908dd96e0b543113a46bc4b7
 RMD160 (libgtop-2.28.4.tar.bz2) = 96ac76aa409bbd202bedacd94df14cd549e10d6b
@@ -19,7 +19,6 @@
 SHA1 (patch-aq) = 1d6f04fa2674f66a5702847c03f4740074b5dd24
 SHA1 (patch-bc) = 3638dfee30a4f10bc9662c23063df3f6a8cdc914
 SHA1 (patch-bd) = 7825fd4d2e6c06510fa3d76b4efa4d2ffab2a7d8
-SHA1 (patch-ca) = 06bc86bce721155315a1905b750f795629460ff7
 SHA1 (patch-cb) = cabc971530d8113694ff6d04108490749d40bcec
 SHA1 (patch-cc) = 2cb1d2da57a8622c93ed255a416ed9c811e775a2
 SHA1 (patch-cd) = cf96896ddde9c830c1e808d8bf37b9fdb611ed24
@@ -38,6 +37,7 @@
 SHA1 (patch-dm) = ef08973aecacb1fb69f258632dd36edfdafd8c50
 SHA1 (patch-dn) = 66f66731a3abd1290f67d62f9ef654f68756bccb
 SHA1 (patch-sysdeps_bsd_glibtop__machine.h) = 1682156e3cb21d335499e38b6b91b8c315f1b962
+SHA1 (patch-sysdeps_bsd_netload.c) = d143e392982afdd095fd052f857bfca2319ac7e7
 SHA1 (patch-sysdeps_bsd_procmap.c) = 8b65993423099040f20256ea8b3f797ecbca21b0
 SHA1 (patch-sysdeps_bsd_sem_limits.c) = 0cdc5e85a4d8d1297f2f658c1f345bf54abfb02c
 SHA1 (patch-sysdeps_bsd_shm_limits.c) = 2750d6b5c440f6071111c62ef1069d07867edcf2
diff -r 386cbcd3b4aa -r 8fdc15e5dfee sysutils/libgtop/patches/patch-ca
--- a/sysutils/libgtop/patches/patch-ca Mon May 28 14:16:15 2018 +0000
+++ /dev/null   Thu Jan 01 00:00:00 1970 +0000
@@ -1,26 +0,0 @@
-$NetBSD: patch-ca,v 1.2 2009/04/07 11:26:48 drochner Exp $
-
---- sysdeps/bsd/netload.c.orig 2008-05-24 00:13:21.000000000 +0200
-+++ sysdeps/bsd/netload.c
-@@ -220,8 +220,12 @@ glibtop_get_netload_p (glibtop *server, 
-               sin = (struct sockaddr_in *)sa;
- #if !defined(__bsdi__)
-               /* Commenting out to "fix" #13345. */
-+#ifdef __NetBSD__
-+              buf->subnet = ifaddr.in.ia_subnet;
-+#else
-               buf->subnet = htonl (ifaddr.in.ia_subnet);
- #endif
-+#endif
-               buf->address = sin->sin_addr.s_addr;
-               buf->mtu = ifnet.if_mtu;
- 
-@@ -233,7 +237,7 @@ glibtop_get_netload_p (glibtop *server, 
-               buf->flags |= GLIBTOP_NETLOAD_ADDRESS6;
-           }
-           /* FIXME prefix6, scope6 */
--#if defined (__OpenBSD__)
-+#if defined (__OpenBSD__) || defined(__NetBSD__)
-           ifaddraddr = (u_long) ifaddr.ifa.ifa_list.tqe_next;
- #else
-           ifaddraddr = (u_long) ifaddr.ifa.ifa_link.tqe_next;
diff -r 386cbcd3b4aa -r 8fdc15e5dfee sysutils/libgtop/patches/patch-sysdeps_bsd_netload.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sysutils/libgtop/patches/patch-sysdeps_bsd_netload.c      Mon May 28 15:16:39 2018 +0000
@@ -0,0 +1,381 @@
+$NetBSD: patch-sysdeps_bsd_netload.c,v 1.1 2018/05/28 15:16:39 youri Exp $
+
+Adapt backend from FreeBSD for NetBSD.
+
+--- sysdeps/bsd/netload.c.orig 2018-05-28 15:09:43.000000000 +0000
++++ sysdeps/bsd/netload.c
+@@ -1,7 +1,9 @@
+ /* Copyright (C) 1998-99 Martin Baulig
++   Copyright (C) 2014 Gleb Smirnoff
+    This file is part of LibGTop 1.0.
+ 
+    Contributed by Martin Baulig <martin%home-of-linux.org@localhost>, October 1998.
++   Contributed by Gleb Smirnoff <glebius%FreeBSD.org@localhost>, September 2014
+ 
+    LibGTop is free software; you can redistribute it and/or modify it
+    under the terms of the GNU General Public License as published by
+@@ -15,8 +17,8 @@
+ 
+    You should have received a copy of the GNU General Public License
+    along with LibGTop; see the file COPYING. If not, write to the
+-   Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+-   Boston, MA 02111-1307, USA.
++   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
++   Boston, MA 02110-1301, USA.
+ */
+ 
+ #include <config.h>
+@@ -26,21 +28,16 @@
+ 
+ #include <glibtop_suid.h>
+ 
+-#include <string.h>
+-
++#include <sys/ioctl.h>
++#include <sys/sockio.h>
++#include <netinet/in.h>
+ #include <net/if.h>
+ #include <net/if_dl.h>
+-#include <net/if_types.h>
+-
+-#ifdef HAVE_NET_IF_VAR_H
+-#include <net/if_var.h>
+-#endif
+-
+-#include <netinet/in.h>
+-#include <netinet/in_var.h>
++#include <ifaddrs.h>
+ 
+ static const unsigned long _glibtop_sysdeps_netload =
+ (1L << GLIBTOP_NETLOAD_IF_FLAGS) +
++(1L << GLIBTOP_NETLOAD_MTU) +
+ (1L << GLIBTOP_NETLOAD_PACKETS_IN) +
+ (1L << GLIBTOP_NETLOAD_PACKETS_OUT) +
+ (1L << GLIBTOP_NETLOAD_PACKETS_TOTAL) +
+@@ -50,195 +47,151 @@ static const unsigned long _glibtop_sysd
+ (1L << GLIBTOP_NETLOAD_ERRORS_IN) +
+ (1L << GLIBTOP_NETLOAD_ERRORS_OUT) +
+ (1L << GLIBTOP_NETLOAD_ERRORS_TOTAL) +
+-(1L << GLIBTOP_NETLOAD_COLLISIONS);
++(1L << GLIBTOP_NETLOAD_COLLISIONS) +
++(1L << GLIBTOP_NETLOAD_HWADDRESS);
+ 
+-static const unsigned _glibtop_sysdeps_netload_data =
+-(1L << GLIBTOP_NETLOAD_ADDRESS) +
+-#if !defined(__bsdi__)
++static const unsigned long _glibtop_sysdeps_netload_data =
+ (1L << GLIBTOP_NETLOAD_SUBNET) +
+-#endif
+-(1L << GLIBTOP_NETLOAD_MTU);
++(1L << GLIBTOP_NETLOAD_ADDRESS);
+ 
+-/* nlist structure for kernel access */
+-static struct nlist nlst [] = {
+-    { "_ifnet" },
+-    { 0 }
+-};
++static const unsigned long _glibtop_sysdeps_netload6 =
++(1L << GLIBTOP_NETLOAD_ADDRESS6) +
++(1L << GLIBTOP_NETLOAD_PREFIX6) +
++(1L << GLIBTOP_NETLOAD_SCOPE6);
+ 
+ /* Init function. */
+ 
+ void
+ _glibtop_init_netload_p (glibtop *server)
+ {
+-    server->sysdeps.netload = _glibtop_sysdeps_netload;
+-
+-    if (kvm_nlist (server->machine.kd, nlst) < 0)
+-      glibtop_error_io_r (server, "kvm_nlist");
++        server->sysdeps.netload = _glibtop_sysdeps_netload;
+ }
+ 
+ /* Provides Network statistics. */
+ 
+ void
+ glibtop_get_netload_p (glibtop *server, glibtop_netload *buf,
+-                     const char *interface)
++                       const char *interface)
+ {
+-    struct ifnet ifnet;
+-    u_long ifnetaddr, ifnetfound;
+-    struct sockaddr *sa = NULL;
+-#if (defined(__FreeBSD__) && (__FreeBSD_version < 501113)) || defined(__bsdi__)
+-    char tname [16];
+-#endif
+-    char name [32];
+-
+-    union {
+-      struct ifaddr ifa;
+-      struct in_ifaddr in;
+-    } ifaddr;
+-
+-    glibtop_init_p (server, (1L << GLIBTOP_SYSDEPS_NETLOAD), 0);
+-
+-    memset (buf, 0, sizeof (glibtop_netload));
+-
+-    if (kvm_read (server->machine.kd, nlst [0].n_value,
+-                &ifnetaddr, sizeof (ifnetaddr)) != sizeof (ifnetaddr))
+-      glibtop_error_io_r (server, "kvm_read (ifnet)");
+-
+-    while (ifnetaddr) {
+-      struct sockaddr_in *sin;
+-      register char *cp;
+-      u_long ifaddraddr;
+-
+-      {
+-          ifnetfound = ifnetaddr;
+-
+-          if (kvm_read (server->machine.kd, ifnetaddr, &ifnet,
+-                        sizeof (ifnet)) != sizeof (ifnet))
+-                  glibtop_error_io_r (server, "kvm_read (ifnetaddr)");
+-
+-#if (defined(__FreeBSD__) && (__FreeBSD_version < 501113)) || defined(__bsdi__)
+-          if (kvm_read (server->machine.kd, (u_long) ifnet.if_name,
+-                        tname, 16) != 16)
+-                  glibtop_error_io_r (server, "kvm_read (if_name)");
+-          tname[15] = '\0';
+-          snprintf (name, 32, "%s%d", tname, ifnet.if_unit);
+-#else
+-          g_strlcpy (name, ifnet.if_xname, sizeof(name));
+-#endif
+-#if defined(__FreeBSD__) && (__FreeBSD_version >= 300000)
+-          ifnetaddr = (u_long) ifnet.if_link.tqe_next;
+-#elif defined(__FreeBSD__) || defined(__bsdi__)
+-          ifnetaddr = (u_long) ifnet.if_next;
+-#else
+-          ifnetaddr = (u_long) ifnet.if_list.tqe_next;
+-#endif
+-
+-          if (strcmp (name, interface) != 0)
+-                  continue;
+-
+-#if defined(__FreeBSD__) && (__FreeBSD_version >= 300000)
+-          ifaddraddr = (u_long) ifnet.if_addrhead.tqh_first;
+-#elif defined(__FreeBSD__) || defined(__bsdi__)
+-          ifaddraddr = (u_long) ifnet.if_addrlist;
+-#else
+-          ifaddraddr = (u_long) ifnet.if_addrlist.tqh_first;
+-#endif
+-      }
+-      if (ifnet.if_flags & IFF_UP)
+-              buf->if_flags |= (1L << GLIBTOP_IF_FLAGS_UP);
+-      if (ifnet.if_flags & IFF_BROADCAST)
+-              buf->if_flags |= (1L << GLIBTOP_IF_FLAGS_BROADCAST);
+-      if (ifnet.if_flags & IFF_DEBUG)
+-              buf->if_flags |= (1L << GLIBTOP_IF_FLAGS_DEBUG);
+-      if (ifnet.if_flags & IFF_LOOPBACK)
+-              buf->if_flags |= (1L << GLIBTOP_IF_FLAGS_LOOPBACK);
+-      if (ifnet.if_flags & IFF_POINTOPOINT)
+-              buf->if_flags |= (1L << GLIBTOP_IF_FLAGS_POINTOPOINT);
+-#ifdef IFF_DRV_RUNNING
+-      if (ifnet.if_drv_flags & IFF_DRV_RUNNING)
+-#else
+-      if (ifnet.if_flags & IFF_RUNNING)
+-#endif
+-              buf->if_flags |= (1L << GLIBTOP_IF_FLAGS_RUNNING);
+-      if (ifnet.if_flags & IFF_NOARP)
+-              buf->if_flags |= (1L << GLIBTOP_IF_FLAGS_NOARP);
+-      if (ifnet.if_flags & IFF_PROMISC)
+-              buf->if_flags |= (1L << GLIBTOP_IF_FLAGS_PROMISC);
+-      if (ifnet.if_flags & IFF_ALLMULTI)
+-              buf->if_flags |= (1L << GLIBTOP_IF_FLAGS_ALLMULTI);
+-#ifdef IFF_DRV_OACTIVE
+-      if (ifnet.if_drv_flags & IFF_DRV_OACTIVE)
+-#else
+-      if (ifnet.if_flags & IFF_OACTIVE)
+-#endif
+-              buf->if_flags |= (1L << GLIBTOP_IF_FLAGS_OACTIVE);
+-      if (ifnet.if_flags & IFF_SIMPLEX)
+-              buf->if_flags |= (1L << GLIBTOP_IF_FLAGS_SIMPLEX);
+-      if (ifnet.if_flags & IFF_LINK0)
+-              buf->if_flags |= (1L << GLIBTOP_IF_FLAGS_LINK0);
+-      if (ifnet.if_flags & IFF_LINK1)
+-              buf->if_flags |= (1L << GLIBTOP_IF_FLAGS_LINK1);
+-      if (ifnet.if_flags & IFF_LINK2)
+-              buf->if_flags |= (1L << GLIBTOP_IF_FLAGS_LINK2);
+-#ifdef __FreeBSD__
+-      if (ifnet.if_flags & IFF_ALTPHYS)
+-              buf->if_flags |= (1L << GLIBTOP_IF_FLAGS_ALTPHYS);
+-#endif
+-      if (ifnet.if_flags & IFF_MULTICAST)
+-              buf->if_flags |= (1L << GLIBTOP_IF_FLAGS_MULTICAST);
+-
+-      buf->packets_in = ifnet.if_ipackets;
+-      buf->packets_out = ifnet.if_opackets;
+-      buf->packets_total = buf->packets_in + buf->packets_out;
+-
+-      buf->bytes_in = ifnet.if_ibytes;
+-      buf->bytes_out = ifnet.if_obytes;
+-      buf->bytes_total = buf->bytes_in + buf->bytes_out;
+-
+-      buf->errors_in = ifnet.if_ierrors;
+-      buf->errors_out = ifnet.if_oerrors;
+-      buf->errors_total = buf->errors_in + buf->errors_out;
+-
+-      buf->collisions = ifnet.if_collisions;
+-      buf->flags = _glibtop_sysdeps_netload;
+-
+-      while (ifaddraddr) {
+-          if ((kvm_read (server->machine.kd, ifaddraddr, &ifaddr,
+-                         sizeof (ifaddr)) != sizeof (ifaddr)))
+-              glibtop_error_io_r (server, "kvm_read (ifaddraddr)");
+-
+-#define CP(x) ((char *)(x))
+-          cp = (CP(ifaddr.ifa.ifa_addr) - CP(ifaddraddr)) +
+-              CP(&ifaddr);
+-          sa = (struct sockaddr *)cp;
+-
+-          if (sa->sa_family == AF_LINK) {
+-              struct sockaddr_dl *dl = (struct sockaddr_dl *) sa;
+-
+-              memcpy (buf->hwaddress, LLADDR (dl), sizeof (buf->hwaddress));
+-              buf->flags |= GLIBTOP_NETLOAD_HWADDRESS;
+-          } else if (sa->sa_family == AF_INET) {
+-              sin = (struct sockaddr_in *)sa;
+-#if !defined(__bsdi__)
+-              /* Commenting out to "fix" #13345. */
+-              buf->subnet = htonl (ifaddr.in.ia_subnet);
+-#endif
+-              buf->address = sin->sin_addr.s_addr;



Home | Main Index | Thread Index | Old Index