Re: libgtop2: Use getifaddrs(3) instead of KVM
On Sat, Dec 05, 2015 at 05:05:07PM +0100, Martin Pieuchot wrote: > Here's a rewrite of glibtop_get_netload_p(). I tested it with custom > code because I could not trigger this code path with our ports. > > This unbreaks devel/libgtop2 after the recent commit. > > I believe this should go upstream, how should I submit this? I can merge it directly upstream (with proper git authorship set). Note that our libgtop could use an update but as of yet I didn't get around to fixing the build breakage yet. When that's been done I'll merge your patch upstream, alright? > ok? OK with me. > Index: Makefile > === > RCS file: /cvs/ports/devel/libgtop2/Makefile,v > retrieving revision 1.130 > diff -u -p -r1.130 Makefile > --- Makefile 22 May 2015 11:31:13 - 1.130 > +++ Makefile 5 Dec 2015 15:58:01 - > @@ -6,7 +6,7 @@ GNOME_VERSION=2.30.0 > GNOME_PROJECT= libgtop > PKGNAME= libgtop2-${VERSION} > > -REVISION=3 > +REVISION=4 > > SHARED_LIBS= gtop-2.09.0 # .10.0 > > Index: patches/patch-sysdeps_openbsd_netload_c > === > RCS file: patches/patch-sysdeps_openbsd_netload_c > diff -N patches/patch-sysdeps_openbsd_netload_c > --- /dev/null 1 Jan 1970 00:00:00 - > +++ patches/patch-sysdeps_openbsd_netload_c 5 Dec 2015 15:59:31 - > @@ -0,0 +1,345 @@ > +$OpenBSD$ > + > +Rewrite of glibtop_get_netload_p() to use getifaddrs(3) instead of KVM. > + > +--- sysdeps/openbsd/netload.c.orig Mon Apr 28 23:09:24 2014 > sysdeps/openbsd/netload.cSat Dec 5 16:27:56 2015 > +@@ -1,48 +1,39 @@ > +-/* Copyright (C) 1998-99 Martin Baulig > +- This file is part of LibGTop 1.0. > ++/* > ++ * Copyright (c) 2015 Martin Pieuchot > ++ * > ++ * Permission to use, copy, modify, and distribute this software for any > ++ * purpose with or without fee is hereby granted, provided that the above > ++ * copyright notice and this permission notice appear in all copies. > ++ * > ++ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES > ++ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF > ++ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR > ++ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES > ++ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN > ++ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF > ++ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. > ++ */ > + > +- Contributed by Martin Baulig , October 1998. > ++#include "config.h" > + > +- LibGTop is free software; you can redistribute it and/or modify it > +- under the terms of the GNU General Public License as published by > +- the Free Software Foundation; either version 2 of the License, > +- or (at your option) any later version. > ++#include > ++#include > ++#include > + > +- LibGTop is distributed in the hope that it will be useful, but WITHOUT > +- ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or > +- FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License > +- for more details. > +- > +- 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. > +-*/ > +- > +-#include > +-#include > +-#include > +-#include > +- > +-#include > +- > +-#include > +- > + #include > + #include > +-#include > + > +-#include > +- > +-#include > +- > + #include > +-#define _KERNEL > + #include > +-#undef _KERNEL > + #include > + > ++#include > ++ > ++#include "glibtop.h" > ++#include "glibtop/netload.h" > ++ > + static const unsigned long _glibtop_sysdeps_netload = > ++(1L << GLIBTOP_NETLOAD_MTU) + > + (1L << GLIBTOP_NETLOAD_IF_FLAGS) + > + (1L << GLIBTOP_NETLOAD_PACKETS_IN) + > + (1L << GLIBTOP_NETLOAD_PACKETS_OUT) + > +@@ -55,183 +46,115 @@ static const unsigned long _glibtop_sysdeps_netload = > + (1L << GLIBTOP_NETLOAD_ERRORS_TOTAL) + > + (1L << GLIBTOP_NETLOAD_COLLISIONS); > + > +-static const unsigned _glibtop_sysdeps_netload_data = > +-(1L << GLIBTOP_NETLOAD_ADDRESS) + > +-(1L << GLIBTOP_NETLOAD_SUBNET) + > +-(1L << GLIBTOP_NETLOAD_MTU); > +- > +-/* nlist structure for kernel access */ > +-static struct nlist nlst [] = { > +-{ "_ifnet" }, > +-{ 0 } > +-}; > +- > +-/* 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"); > + } > + > +-/* Provides Network statistics. */ > +- > + void > + glibtop_get_netload_p (glibtop *server, glibtop_netload *buf
Re: libgtop2: Use getifaddrs(3) instead of KVM
On Sat, Dec 05, 2015 at 05:05:07PM +0100, Martin Pieuchot wrote: > Here's a rewrite of glibtop_get_netload_p(). I tested it with custom > code because I could not trigger this code path with our ports. > > This unbreaks devel/libgtop2 after the recent commit. > > I believe this should go upstream, how should I submit this? You can open a bug report here: https://bugzilla.gnome.org/ Jasper and I have commit access to gnome and since it's OpenBSD-only code, it can be pushed pretty fast. > ok? > > Index: Makefile > === > RCS file: /cvs/ports/devel/libgtop2/Makefile,v > retrieving revision 1.130 > diff -u -p -r1.130 Makefile > --- Makefile 22 May 2015 11:31:13 - 1.130 > +++ Makefile 5 Dec 2015 15:58:01 - > @@ -6,7 +6,7 @@ GNOME_VERSION=2.30.0 > GNOME_PROJECT= libgtop > PKGNAME= libgtop2-${VERSION} > > -REVISION=3 > +REVISION=4 > > SHARED_LIBS= gtop-2.09.0 # .10.0 > > Index: patches/patch-sysdeps_openbsd_netload_c > === > RCS file: patches/patch-sysdeps_openbsd_netload_c > diff -N patches/patch-sysdeps_openbsd_netload_c > --- /dev/null 1 Jan 1970 00:00:00 - > +++ patches/patch-sysdeps_openbsd_netload_c 5 Dec 2015 15:59:31 - > @@ -0,0 +1,345 @@ > +$OpenBSD$ > + > +Rewrite of glibtop_get_netload_p() to use getifaddrs(3) instead of KVM. > + > +--- sysdeps/openbsd/netload.c.orig Mon Apr 28 23:09:24 2014 > sysdeps/openbsd/netload.cSat Dec 5 16:27:56 2015 > +@@ -1,48 +1,39 @@ > +-/* Copyright (C) 1998-99 Martin Baulig > +- This file is part of LibGTop 1.0. > ++/* > ++ * Copyright (c) 2015 Martin Pieuchot > ++ * > ++ * Permission to use, copy, modify, and distribute this software for any > ++ * purpose with or without fee is hereby granted, provided that the above > ++ * copyright notice and this permission notice appear in all copies. > ++ * > ++ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES > ++ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF > ++ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR > ++ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES > ++ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN > ++ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF > ++ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. > ++ */ > + > +- Contributed by Martin Baulig , October 1998. > ++#include "config.h" > + > +- LibGTop is free software; you can redistribute it and/or modify it > +- under the terms of the GNU General Public License as published by > +- the Free Software Foundation; either version 2 of the License, > +- or (at your option) any later version. > ++#include > ++#include > ++#include > + > +- LibGTop is distributed in the hope that it will be useful, but WITHOUT > +- ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or > +- FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License > +- for more details. > +- > +- 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. > +-*/ > +- > +-#include > +-#include > +-#include > +-#include > +- > +-#include > +- > +-#include > +- > + #include > + #include > +-#include > + > +-#include > +- > +-#include > +- > + #include > +-#define _KERNEL > + #include > +-#undef _KERNEL > + #include > + > ++#include > ++ > ++#include "glibtop.h" > ++#include "glibtop/netload.h" > ++ > + static const unsigned long _glibtop_sysdeps_netload = > ++(1L << GLIBTOP_NETLOAD_MTU) + > + (1L << GLIBTOP_NETLOAD_IF_FLAGS) + > + (1L << GLIBTOP_NETLOAD_PACKETS_IN) + > + (1L << GLIBTOP_NETLOAD_PACKETS_OUT) + > +@@ -55,183 +46,115 @@ static const unsigned long _glibtop_sysdeps_netload = > + (1L << GLIBTOP_NETLOAD_ERRORS_TOTAL) + > + (1L << GLIBTOP_NETLOAD_COLLISIONS); > + > +-static const unsigned _glibtop_sysdeps_netload_data = > +-(1L << GLIBTOP_NETLOAD_ADDRESS) + > +-(1L << GLIBTOP_NETLOAD_SUBNET) + > +-(1L << GLIBTOP_NETLOAD_MTU); > +- > +-/* nlist structure for kernel access */ > +-static struct nlist nlst [] = { > +-{ "_ifnet" }, > +-{ 0 } > +-}; > +- > +-/* 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"); > + } > + > +-/* Provides Network statistics. */ > +- > + void > + glibtop_get_netload_p (glibtop *server, glibtop_netload *buf, > +const char *interface) > + { > +-struct ifnet ifnet;
libgtop2: Use getifaddrs(3) instead of KVM
Here's a rewrite of glibtop_get_netload_p(). I tested it with custom code because I could not trigger this code path with our ports. This unbreaks devel/libgtop2 after the recent commit. I believe this should go upstream, how should I submit this? ok? Index: Makefile === RCS file: /cvs/ports/devel/libgtop2/Makefile,v retrieving revision 1.130 diff -u -p -r1.130 Makefile --- Makefile22 May 2015 11:31:13 - 1.130 +++ Makefile5 Dec 2015 15:58:01 - @@ -6,7 +6,7 @@ GNOME_VERSION= 2.30.0 GNOME_PROJECT= libgtop PKGNAME= libgtop2-${VERSION} -REVISION= 3 +REVISION= 4 SHARED_LIBS= gtop-2.09.0 # .10.0 Index: patches/patch-sysdeps_openbsd_netload_c === RCS file: patches/patch-sysdeps_openbsd_netload_c diff -N patches/patch-sysdeps_openbsd_netload_c --- /dev/null 1 Jan 1970 00:00:00 - +++ patches/patch-sysdeps_openbsd_netload_c 5 Dec 2015 15:59:31 - @@ -0,0 +1,345 @@ +$OpenBSD$ + +Rewrite of glibtop_get_netload_p() to use getifaddrs(3) instead of KVM. + +--- sysdeps/openbsd/netload.c.orig Mon Apr 28 23:09:24 2014 sysdeps/openbsd/netload.c Sat Dec 5 16:27:56 2015 +@@ -1,48 +1,39 @@ +-/* Copyright (C) 1998-99 Martin Baulig +- This file is part of LibGTop 1.0. ++/* ++ * Copyright (c) 2015 Martin Pieuchot ++ * ++ * Permission to use, copy, modify, and distribute this software for any ++ * purpose with or without fee is hereby granted, provided that the above ++ * copyright notice and this permission notice appear in all copies. ++ * ++ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES ++ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF ++ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ++ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES ++ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ++ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF ++ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ++ */ + +- Contributed by Martin Baulig , October 1998. ++#include "config.h" + +- LibGTop is free software; you can redistribute it and/or modify it +- under the terms of the GNU General Public License as published by +- the Free Software Foundation; either version 2 of the License, +- or (at your option) any later version. ++#include ++#include ++#include + +- LibGTop is distributed in the hope that it will be useful, but WITHOUT +- ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +- FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +- for more details. +- +- 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. +-*/ +- +-#include +-#include +-#include +-#include +- +-#include +- +-#include +- + #include + #include +-#include + +-#include +- +-#include +- + #include +-#define _KERNEL + #include +-#undef _KERNEL + #include + ++#include ++ ++#include "glibtop.h" ++#include "glibtop/netload.h" ++ + static const unsigned long _glibtop_sysdeps_netload = ++(1L << GLIBTOP_NETLOAD_MTU) + + (1L << GLIBTOP_NETLOAD_IF_FLAGS) + + (1L << GLIBTOP_NETLOAD_PACKETS_IN) + + (1L << GLIBTOP_NETLOAD_PACKETS_OUT) + +@@ -55,183 +46,115 @@ static const unsigned long _glibtop_sysdeps_netload = + (1L << GLIBTOP_NETLOAD_ERRORS_TOTAL) + + (1L << GLIBTOP_NETLOAD_COLLISIONS); + +-static const unsigned _glibtop_sysdeps_netload_data = +-(1L << GLIBTOP_NETLOAD_ADDRESS) + +-(1L << GLIBTOP_NETLOAD_SUBNET) + +-(1L << GLIBTOP_NETLOAD_MTU); +- +-/* nlist structure for kernel access */ +-static struct nlist nlst [] = { +-{ "_ifnet" }, +-{ 0 } +-}; +- +-/* 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"); + } + +-/* Provides Network statistics. */ +- + void + glibtop_get_netload_p (glibtop *server, glibtop_netload *buf, + const char *interface) + { +-struct ifnet ifnet; +-u_long ifnetaddr, ifnetfound; +-struct sockaddr *sa = NULL; +-char name [32]; ++struct ifaddrs *ifap, *ifa; ++struct if_data *ifd = NULL; + +-union { +- struct ifaddr ifa; +- struct in_ifaddr in; +-} ifaddr; ++buf->flags = 0; + +-glibtop_init_p (server, (1L << GLIBTOP_SYSDEPS_NETLOAD), 0); ++if (getifaddrs(&ifap) != 0) ++return; + +-memset (buf, 0, sizeof (glibtop_netload)); ++for (ifa = ifap; ifa != NULL; ifa = ifa->ifa_next) { ++if (