Hi,

plan9/plan9port is broken after network stack changes in net/if_var.h
here is a diff that convert plan9port to use getifaddrs(3) instead of kvm(3) in 
p9p auxstats.

builds and runs fine(auxstats is incrementing and seems ok), but I would 
appreciate other eyes(review),

// gsoares
Index: Makefile
===================================================================
RCS file: /cvs/ports/plan9/plan9port/Makefile,v
retrieving revision 1.10
diff -u -p -u -p -r1.10 Makefile
--- Makefile    4 Dec 2015 04:26:33 -0000       1.10
+++ Makefile    7 Dec 2015 21:36:31 -0000
@@ -6,7 +6,7 @@ BROKEN-powerpc =        threading issues
 COMMENT =              Plan 9 from user space
 
 DISTNAME =             plan9port-20151111
-REVISION =             0
+REVISION =             1
 
 GH_ACCOUNT =           9fans
 GH_PROJECT =           plan9port
Index: patches/patch-src_cmd_auxstats_OpenBSD_c
===================================================================
RCS file: patches/patch-src_cmd_auxstats_OpenBSD_c
diff -N patches/patch-src_cmd_auxstats_OpenBSD_c
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ patches/patch-src_cmd_auxstats_OpenBSD_c    7 Dec 2015 21:36:31 -0000
@@ -0,0 +1,157 @@
+$OpenBSD$
+
+replace kvm(3) with getifaddrs(3)
+
+--- src/cmd/auxstats/OpenBSD.c.orig    Wed Nov 11 12:09:34 2015
++++ src/cmd/auxstats/OpenBSD.c Mon Dec  7 02:20:58 2015
+@@ -1,14 +1,12 @@
+ #include <u.h>
+-#include <kvm.h>
+-#include <nlist.h>
+ #include <sys/types.h>
+ #include <sys/param.h>
+ #include <sys/sched.h>
+ #include <sys/socket.h>
++#include <ifaddrs.h>
+ #include <sys/sysctl.h>
+ #include <sys/time.h>
+ #include <net/if.h>
+-#include <net/if_var.h>
+ #include <machine/apmvar.h>
+ #include <sys/ioctl.h>
+ #include <uvm/uvm_param.h>
+@@ -24,11 +22,9 @@ void xcpu(int);
+ void xswap(int);
+ void xsysctl(int);
+ void xnet(int);
+-void xkvm(int);
+ 
+ void (*statfn[])(int) =
+ {
+-      xkvm,
+       xapm,
+       xloadavg,
+       xcpu,
+@@ -37,14 +33,6 @@ void (*statfn[])(int) =
+       0
+ };
+ 
+-static kvm_t *kvm;
+-
+-static struct nlist nl[] = {
+-      { "_ifnet" },
+-      { "_cp_time" },
+-      { "" }
+-};
+-
+ void
+ xloadavg(int first)
+ {
+@@ -76,78 +64,37 @@ xapm(int first)
+               Bprint(&bout, "battery =%d 100\n", ai.battery_life);
+ }
+ 
+-
+ void
+-kvminit(void)
+-{
+-      char buf[_POSIX2_LINE_MAX];
+-
+-      if(kvm)
+-              return;
+-      kvm = kvm_openfiles(nil, nil, nil, O_RDONLY, buf);
+-      if(kvm == nil) {
+-              fprint(2, "kvm open error\n%s", buf);
+-              return;
+-      }
+-      if(kvm_nlist(kvm, nl) < 0 || nl[0].n_type == 0){
+-              kvm = nil;
+-              return;
+-      }
+-}
+-
+-void
+-xkvm(int first)
+-{
+-      if(first)
+-              kvminit();
+-}
+-
+-int
+-kread(ulong addr, char *buf, int size)
+-{
+-      if(kvm_read(kvm, addr, buf, size) != size){
+-              memset(buf, 0, size);
+-              return -1;
+-      }
+-      return size;
+-}
+-
+-void
+ xnet(int first)
+ {
+       ulong out, in, outb, inb, err;
+-      static ulong ifnetaddr;
+-      ulong addr;
+-      struct ifnet ifnet;
+-      struct ifnet_head ifnethead;
+-      char name[16];
++      struct ifaddrs *ifa, *ifap;
++      struct if_data *ifd = NULL;
+ 
+-      if(first)
++      if (first)
+               return;
+ 
+-      if(ifnetaddr == 0){
+-              ifnetaddr = nl[0].n_value;
+-              if(ifnetaddr == 0)
+-                      return;
+-      }
++      out = in = outb = inb = err = 0;
+ 
+-      if(kread(ifnetaddr, (char*)&ifnethead, sizeof ifnethead) < 0)
++      if (getifaddrs(&ifap) == -1)
+               return;
+ 
+-      out = in = outb = inb = err = 0;
+-      addr = (ulong)TAILQ_FIRST(&ifnethead);
+-      while(addr){
+-              if(kread(addr, (char*)&ifnet, sizeof ifnet) < 0
+-              || kread((ulong)ifnet.if_xname, name, 16) < 0)
+-                      return;
+-              name[15] = 0;
+-              addr = (ulong)TAILQ_NEXT(&ifnet, if_list);
+-              out += ifnet.if_opackets;
+-              in += ifnet.if_ipackets;
+-              outb += ifnet.if_obytes;
+-              inb += ifnet.if_ibytes;
+-              err += ifnet.if_oerrors+ifnet.if_ierrors;
++      for (ifa = ifap; ifa != NULL; ifa = ifa->ifa_next) {
++              if (ifa->ifa_addr == NULL ||
++                  ifa->ifa_addr->sa_family != AF_LINK)
++                      continue;
++
++              ifd = ifa->ifa_data;
++
++              if (ifd != NULL) {
++                      out += ifd->ifi_opackets;
++                      in += ifd->ifi_ipackets;
++                      outb += ifd->ifi_obytes;
++                      inb += ifd->ifi_ibytes;
++                      err += ifd->ifi_ierrors;
++              }
+       }
++
+       Bprint(&bout, "etherin %lud 1000\n", in);
+       Bprint(&bout, "etherout %lud 1000\n", out);
+       Bprint(&bout, "etherinb %lud 1000000\n", inb);
+@@ -155,6 +102,8 @@ xnet(int first)
+       Bprint(&bout, "ethererr %lud 1000\n", err);
+       Bprint(&bout, "ether %lud 1000\n", in+out);
+       Bprint(&bout, "etherb %lud 1000000\n", inb+outb);
++
++      freeifaddrs(ifap);
+ }
+ 
+ void

Reply via email to